Skip to content

Commit

Permalink
Compatibility with dartsass-rails 0.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
sfnelson committed Aug 6, 2024
1 parent f980f34 commit 087a4f3
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
katalyst-koi (4.12.3)
katalyst-koi (4.12.4)
bcrypt
importmap-rails
katalyst-content
Expand Down
14 changes: 9 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ load "rails/tasks/statistics.rake"
RSpec::Core::RakeTask.new(spec: %w[app:spec:prepare])

# dartsass.rake override – compile gem resources instead of dummy app resources
def dartsass_build_mapping
<<-BUILDS.gsub(/\s+/, " ")
app/assets/stylesheets/koi/admin.scss:app/assets/builds/koi/admin.css
BUILDS
module Dartsass
module Runner
module_function

def dartsass_build_mapping
["app/assets/stylesheets/koi/admin.scss:app/assets/builds/koi/admin.css"]
end
end
end

# compile css before building
task build: "app:dartsass:build" # rubocop:disable Rake/Desc
Rake::Task["build"].enhance(["app:dartsass:build"])

require "rubocop/katalyst/rake_task"
RuboCop::Katalyst::RakeTask.new
Expand Down
2 changes: 1 addition & 1 deletion katalyst-koi.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
s.name = "katalyst-koi"
s.version = "4.12.3"
s.version = "4.12.4"
s.authors = ["Katalyst Interactive"]
s.email = ["[email protected]"]

Expand Down
8 changes: 8 additions & 0 deletions lib/koi/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ class Engine < ::Rails::Engine
Katalyst::Content.config.errors_component = "Koi::Content::Editor::ErrorsComponent"
end

# Koi (& katalyst gems) generate css assets in build that are useful for non-sass consumers, but we don't
# want them getting picked up preferentially by dartsass over their similarly named scss counterparts.
initializer "koi.dartsass" do |app|
app.config.after_initialize do
::Dartsass::Runner.include(Koi::Extensions::Dartsass) if defined?(::Dartsass::Runner)
end
end

initializer "koi.factories", after: "factory_bot.set_factory_paths" do
FactoryBot.definition_file_paths << root.join("spec/factories") if defined?(FactoryBot)
end
Expand Down
23 changes: 23 additions & 0 deletions lib/koi/extensions/dartsass.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

module Koi
module Extensions
module Dartsass
extend ActiveSupport::Concern

included do
module_function

# Removes gem `build` directories from dartsass load path. This ensures
# that css assets will not take precedence over scss assets of the same
# name.
def dartsass_load_paths
[::Dartsass::Runner::CSS_LOAD_PATH]
.concat(Rails.application.config.assets.paths)
.reject { |path| %r{app/assets/builds$}.match?(path.to_s) }
.flat_map { |path| ["--load-path", path.to_s] }
end
end
end
end
end

0 comments on commit 087a4f3

Please sign in to comment.