Skip to content

Commit d91c6ee

Browse files
committed
refactor: put rake task arg handling into methods
1 parent 781d840 commit d91c6ee

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

lib/tailwindcss/commands.rb

+8
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ def watch_command(poll: false, **kwargs)
7272
command << "-p" if poll
7373
end
7474
end
75+
76+
def debug_option(rake_task_args_extras)
77+
rake_task_args_extras.include?("debug")
78+
end
79+
80+
def poll_option(rake_task_args_extras)
81+
rake_task_args_extras.include?("poll")
82+
end
7583
end
7684
end
7785
end

lib/tasks/build.rake

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
namespace :tailwindcss do
22
desc "Build your Tailwind CSS"
33
task :build do |_, args|
4-
debug = args.extras.include?("debug")
4+
debug = Tailwindcss::Commands.debug_option(args.extras)
55
command = Tailwindcss::Commands.compile_command(debug: debug)
66
puts command.inspect if args.extras.include?("verbose")
77
system(*command, exception: true)
88
end
99

1010
desc "Watch and build your Tailwind CSS on file changes"
1111
task :watch do |_, args|
12-
debug = args.extras.include?("debug")
13-
poll = args.extras.include?("poll")
12+
debug = Tailwindcss::Commands.debug_option(args.extras)
13+
poll = Tailwindcss::Commands.poll_option(args.extras)
1414
command = Tailwindcss::Commands.watch_command(debug: debug, poll: poll)
1515
puts command.inspect if args.extras.include?("verbose")
1616
system(*command)

test/lib/tailwindcss/commands_test.rb

+12
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,16 @@ def mock_exe_directory(platform)
8484
end
8585
end
8686
end
87+
88+
test ".debug_option" do
89+
refute(Tailwindcss::Commands.debug_option([]))
90+
assert(Tailwindcss::Commands.debug_option(["debug"]))
91+
refute(Tailwindcss::Commands.debug_option(["poll"]))
92+
end
93+
94+
test ".poll_option" do
95+
refute(Tailwindcss::Commands.poll_option([]))
96+
refute(Tailwindcss::Commands.poll_option(["debug"]))
97+
assert(Tailwindcss::Commands.poll_option(["poll"]))
98+
end
8799
end

0 commit comments

Comments
 (0)