Skip to content

Commit

Permalink
Use Thor's apply instead of a prerequisite task (#150)
Browse files Browse the repository at this point in the history
The `css:install:shared` task serves only as a prerequisite for the
other installer tasks; it should not be run on its own (nor listed with
`rake --tasks`).  By replacing this task with corresponding calls to
Thor's `apply` method, we avoid the overhead of running
`bin/rails app:template` (and `bundle install`) multiple times.
  • Loading branch information
jonathanhefner authored Jan 21, 2024
1 parent 02caad4 commit 7638f92
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
2 changes: 2 additions & 0 deletions lib/install/bootstrap/install.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require_relative "../helpers"
self.extend Helpers

apply "#{__dir__}/../install.rb"

say "Install Bootstrap with Bootstrap Icons, Popperjs/core and Autoprefixer"
copy_file "#{__dir__}/application.bootstrap.scss",
"app/assets/stylesheets/application.bootstrap.scss"
Expand Down
2 changes: 2 additions & 0 deletions lib/install/bulma/install.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require_relative "../helpers"
self.extend Helpers

apply "#{__dir__}/../install.rb"

say "Install Bulma"
copy_file "#{__dir__}/application.bulma.scss",
"app/assets/stylesheets/application.bulma.scss"
Expand Down
2 changes: 2 additions & 0 deletions lib/install/postcss/install.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require_relative "../helpers"
self.extend Helpers

apply "#{__dir__}/../install.rb"

say "Install PostCSS w/ nesting and autoprefixer"
copy_file "#{__dir__}/postcss.config.js", "postcss.config.js"
copy_file "#{__dir__}/application.postcss.css", "app/assets/stylesheets/application.postcss.css"
Expand Down
2 changes: 2 additions & 0 deletions lib/install/sass/install.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require_relative "../helpers"
self.extend Helpers

apply "#{__dir__}/../install.rb"

say "Install Sass"
copy_file "#{__dir__}/application.sass.scss", "app/assets/stylesheets/application.sass.scss"
run "#{bundler_cmd} add sass"
Expand Down
2 changes: 2 additions & 0 deletions lib/install/tailwind/install.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require_relative "../helpers"
self.extend Helpers

apply "#{__dir__}/../install.rb"

say "Install Tailwind (+PostCSS w/ autoprefixer)"
copy_file "#{__dir__}/tailwind.config.js", "tailwind.config.js"
copy_file "#{__dir__}/application.tailwind.css", "app/assets/stylesheets/application.tailwind.css"
Expand Down
15 changes: 5 additions & 10 deletions lib/tasks/cssbundling/install.rake
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
namespace :css do
namespace :install do
desc "Install shared elements for all bundlers"
task :shared do
system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/install.rb", __dir__)}"
end

desc "Install Tailwind"
task tailwind: "css:install:shared" do
task :tailwind do
system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/tailwind/install.rb", __dir__)}"
end

desc "Install PostCSS"
task postcss: "css:install:shared" do
task :postcss do
system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/postcss/install.rb", __dir__)}"
end

desc "Install Sass"
task sass: "css:install:shared" do
task :sass do
system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/sass/install.rb", __dir__)}"
end

desc "Install Bootstrap"
task bootstrap: "css:install:shared" do
task :bootstrap do
system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/bootstrap/install.rb", __dir__)}"
end

desc "Install Bulma"
task bulma: "css:install:shared" do
task :bulma do
system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/bulma/install.rb", __dir__)}"
end
end
Expand Down

0 comments on commit 7638f92

Please sign in to comment.