From c27dbe1460732f0be3026ec98cf75539dd010ff7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=AA=E3=81=A4=E3=81=8D?= Date: Sun, 10 Sep 2023 15:56:15 -0700 Subject: [PATCH] Use array args instead of string args for system command --- README.md | 13 +++++++++++-- dartsass-rails.gemspec | 2 +- lib/dartsass/engine.rb | 2 +- lib/tasks/build.rake | 14 +++++++------- lib/tasks/install.rake | 2 +- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 570c7ad..0ac9db9 100644 --- a/README.md +++ b/README.md @@ -35,13 +35,22 @@ Rails.application.config.dartsass.builds = { The hash key is the relative path to a Sass file in `app/assets/stylesheets/` and the hash value will be the name of the file output to `app/assets/builds/`. +If both the hash key and the hash value are directories instead of files, it configures a directory to directory compliation, which compiles all public Sass files whose filenames do not start with underscore (`_`). + +```ruby +# config/initializers/dartsass.rb +Rails.application.config.dartsass.builds = { + "." => "." +} +``` + ## Configuring build options -By default, sass is invoked with `--style=compressed --no-source-map`. You can adjust these options by overwriting `Rails.application.config.dartsass.build_options`. +By default, sass is invoked with `["--style=compressed", "--no-source-map"]`. You can adjust these options by overwriting `Rails.application.config.dartsass.build_options`. ```ruby # config/initializers/dartsass.rb -Rails.application.config.dartsass.build_options << " --quiet-deps" +Rails.application.config.dartsass.build_options << "--no-charset" << "--quiet-deps" ``` ## Importing assets from gems diff --git a/dartsass-rails.gemspec b/dartsass-rails.gemspec index a4ecd4c..5cd405b 100644 --- a/dartsass-rails.gemspec +++ b/dartsass-rails.gemspec @@ -14,7 +14,7 @@ Gem::Specification.new do |spec| "rubygems_mfa_required" => "true" } - spec.files = Dir["{lib,exe}/**/*", "MIT-LICENSE", "LICENSE-DEPENDENCIES", "Rakefile", "README.md"] + spec.files = Dir["{lib,exe}/**/*", "MIT-LICENSE", "Rakefile", "README.md"] spec.bindir = "exe" spec.executables << "dartsass" diff --git a/lib/dartsass/engine.rb b/lib/dartsass/engine.rb index 4104253..d10248d 100644 --- a/lib/dartsass/engine.rb +++ b/lib/dartsass/engine.rb @@ -4,6 +4,6 @@ module Dartsass class Engine < ::Rails::Engine config.dartsass = ActiveSupport::OrderedOptions.new config.dartsass.builds = { "application.scss" => "application.css" } - config.dartsass.build_options = "--style=compressed --no-source-map" + config.dartsass.build_options = ["--style=compressed", "--no-source-map"] end end diff --git a/lib/tasks/build.rake b/lib/tasks/build.rake index 89b65d4..c5de8bc 100644 --- a/lib/tasks/build.rake +++ b/lib/tasks/build.rake @@ -4,31 +4,31 @@ CSS_BUILD_PATH = Rails.root.join("app/assets/builds") def dartsass_build_mapping Rails.application.config.dartsass.builds.map { |input, output| - "#{Shellwords.escape(CSS_LOAD_PATH.join(input))}:#{Shellwords.escape(CSS_BUILD_PATH.join(output))}" - }.join(" ") + "#{CSS_LOAD_PATH.join(input)}:#{CSS_BUILD_PATH.join(output)}" + } end def dartsass_build_options - Rails.application.config.dartsass.build_options + Rails.application.config.dartsass.build_options.map(&:strip) end def dartsass_load_paths - [ CSS_LOAD_PATH ].concat(Rails.application.config.assets.paths).map { |path| "--load-path #{Shellwords.escape(path)}" }.join(" ") + [ CSS_LOAD_PATH ].concat(Rails.application.config.assets.paths).flat_map { |path| ["--load-path", path.to_s] } end def dartsass_compile_command - "#{EXEC_PATH} #{dartsass_build_options} #{dartsass_load_paths} #{dartsass_build_mapping}" + [ RbConfig.ruby, EXEC_PATH ].concat(dartsass_build_options).concat(dartsass_load_paths).concat(dartsass_build_mapping) end namespace :dartsass do desc "Build your Dart Sass CSS" task build: :environment do - system dartsass_compile_command, exception: true + system(*dartsass_compile_command, exception: true) end desc "Watch and build your Dart Sass CSS on file changes" task watch: :environment do - system "#{dartsass_compile_command} -w", exception: true + system(*dartsass_compile_command, "--watch", exception: true) end end diff --git a/lib/tasks/install.rake b/lib/tasks/install.rake index 8d6c8a0..c86f865 100644 --- a/lib/tasks/install.rake +++ b/lib/tasks/install.rake @@ -1,6 +1,6 @@ namespace :dartsass do desc "Install Dart Sass into the app" task :install do - system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../install/dartsass.rb", __dir__)}", exception: true + system RbConfig.ruby, "./bin/rails", "app:template", "LOCATION=#{File.expand_path("../install/dartsass.rb", __dir__)}", exception: true end end