Skip to content
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

Define constants in separate module #47

Merged
merged 1 commit into from
Jul 30, 2024
Merged
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
27 changes: 27 additions & 0 deletions lib/dartsass/runner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module Dartsass
module Runner
EXEC_PATH = "#{Pathname.new(__dir__).to_s}/../../exe/dartsass"
CSS_LOAD_PATH = Rails.root.join("app/assets/stylesheets")
CSS_BUILD_PATH = Rails.root.join("app/assets/builds")

module_function

def dartsass_build_mapping
Rails.application.config.dartsass.builds.map { |input, output|
"#{CSS_LOAD_PATH.join(input)}:#{CSS_BUILD_PATH.join(output)}"
}
end

def dartsass_build_options
Rails.application.config.dartsass.build_options.flat_map(&:split)
end

def dartsass_load_paths
[ CSS_LOAD_PATH ].concat(Rails.application.config.assets.paths).flat_map { |path| ["--load-path", path.to_s] }
end

def dartsass_compile_command
[ RbConfig.ruby, EXEC_PATH ].concat(dartsass_build_options).concat(dartsass_load_paths).concat(dartsass_build_mapping)
end
end
end
26 changes: 3 additions & 23 deletions lib/tasks/build.rake
Original file line number Diff line number Diff line change
@@ -1,34 +1,14 @@
EXEC_PATH = "#{Pathname.new(__dir__).to_s}/../../exe/dartsass"
CSS_LOAD_PATH = Rails.root.join("app/assets/stylesheets")
CSS_BUILD_PATH = Rails.root.join("app/assets/builds")

def dartsass_build_mapping
Rails.application.config.dartsass.builds.map { |input, output|
"#{CSS_LOAD_PATH.join(input)}:#{CSS_BUILD_PATH.join(output)}"
}
end

def dartsass_build_options
Rails.application.config.dartsass.build_options.flat_map(&:split)
end

def dartsass_load_paths
[ CSS_LOAD_PATH ].concat(Rails.application.config.assets.paths).flat_map { |path| ["--load-path", path.to_s] }
end

def dartsass_compile_command
[ RbConfig.ruby, EXEC_PATH ].concat(dartsass_build_options).concat(dartsass_load_paths).concat(dartsass_build_mapping)
end
require "dartsass/runner"

namespace :dartsass do
desc "Build your Dart Sass CSS"
task build: :environment do
system(*dartsass_compile_command, exception: true)
system(*Dartsass::Runner.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, "--watch", exception: true)
system(*Dartsass::Runner.dartsass_compile_command, "--watch", exception: true)
end
end

Expand Down