Skip to content

allow users to always generate unminified CSS #248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ If you want unminified assets, you can pass a `debug` argument to the rake task,
Note that you can combine task options, e.g. `rails tailwindcss:watch[debug,poll]`.


### Never minify assets

If you _always_ want unminified assets, you can set the environment variable `TAILWINDCSS_RAILS_NO_MINIFY` to something that [looks truthy](https://api.rubyonrails.org/classes/ActiveModel/Type/Boolean.html) (hint: "t" or "1" will work).


### Custom inputs or outputs

If you need to use a custom input or output file, you can run `bundle exec tailwindcss` to access the platform-specific executable, and give it your own build options.
Expand Down
17 changes: 17 additions & 0 deletions lib/tailwindcss/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,23 @@ def watch_command(poll: false, **kwargs)
command << "-p" if poll
end
end

def debug_option(rake_task_args_extras)
rake_task_args_extras.include?("debug") || truthy_string_value(ENV['TAILWINDCSS_RAILS_NO_MINIFY'])
end

def poll_option(rake_task_args_extras)
rake_task_args_extras.include?("poll")
end

def truthy_string_value(value)
if !value.present? ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have present? available? The core_ext is not being required in this gem. I think it only works in tests because the app is configured to require all core_ext.

["f", "F", "false", "FALSE", "off", "OFF", "0"].include?(value)
false
else
true
end
end
end
end
end
6 changes: 3 additions & 3 deletions lib/tasks/build.rake
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
namespace :tailwindcss do
desc "Build your Tailwind CSS"
task :build do |_, args|
debug = args.extras.include?("debug")
debug = Tailwindcss::Commands.debug_option(args.extras)
command = Tailwindcss::Commands.compile_command(debug: debug)
puts command.inspect if args.extras.include?("verbose")
system(*command, exception: true)
end

desc "Watch and build your Tailwind CSS on file changes"
task :watch do |_, args|
debug = args.extras.include?("debug")
poll = args.extras.include?("poll")
debug = Tailwindcss::Commands.debug_option(args.extras)
poll = Tailwindcss::Commands.poll_option(args.extras)
command = Tailwindcss::Commands.watch_command(debug: debug, poll: poll)
puts command.inspect if args.extras.include?("verbose")
system(*command)
Expand Down
57 changes: 57 additions & 0 deletions test/lib/tailwindcss/commands_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ def mock_exe_directory(platform)
end
end

def with_env(env)
before = ENV.to_h.dup
env.each { |k, v| ENV[k] = v }
yield
ensure
ENV.replace(before)
end

test ".executable returns the absolute path to the binary" do
mock_exe_directory("sparc-solaris2.8") do |dir, executable|
expected = File.expand_path(File.join(dir, "sparc-solaris2.8", "tailwindcss"))
Expand Down Expand Up @@ -84,4 +92,53 @@ def mock_exe_directory(platform)
end
end
end

test ".debug_option" do
refute(Tailwindcss::Commands.debug_option([]))
assert(Tailwindcss::Commands.debug_option(["debug"]))
refute(Tailwindcss::Commands.debug_option(["poll"]))

with_env({"TAILWINDCSS_RAILS_NO_MINIFY" => "f"}) do
refute(Tailwindcss::Commands.debug_option([]))
end

with_env({"TAILWINDCSS_RAILS_NO_MINIFY" => "t"}) do
assert(Tailwindcss::Commands.debug_option([]))
end
end

test ".poll_option" do
refute(Tailwindcss::Commands.poll_option([]))
refute(Tailwindcss::Commands.poll_option(["debug"]))
assert(Tailwindcss::Commands.poll_option(["poll"]))
end

test ".truthy_string_value" do
[
nil,
"",
"F", "FALSE",
"f", "false",
"off", "OFF",
"0",
].each do |value|
refute(
Tailwindcss::Commands.truthy_string_value(value),
"#{value.inspect} should be falsey",
)
end

[
"T", "TRUE",
"t", "true",
"on", "ON",
"1",
"anything not falsey really",
].each do |value|
assert(
Tailwindcss::Commands.truthy_string_value(value),
"#{value.inspect} should be truthy",
)
end
end
end