Sha256: acb84f0a08ca984f69cfb0acab8042a8aa3fb61016dde8c3e4b4850f533b4f79

Contents?: true

Size: 1.49 KB

Versions: 48

Compression:

Stored size: 1.49 KB

Contents

# frozen_string_literal: true

module Haml
  module Filters
    # This is an extension of Sass::Rails's SassTemplate class that allows
    # Rails's asset helpers to be used inside Haml Sass filter.
    class SassRailsTemplate < ::Sass::Rails::SassTemplate
      if Gem::Version.new(Sprockets::VERSION) >= Gem::Version.new('3.0.0')
        def render(scope=Object.new, locals={}, &block)
          environment = ::Sprockets::Railtie.build_environment(::Rails.application)
          scope = environment.context_class.new(
            environment: environment,
            filename: "/",
            metadata: {}
          )
          super
        end
      else
        def render(scope=Object.new, locals={}, &block)
          scope = ::Rails.application.assets.context_class.new(::Rails.application.assets, "/", "/")
          super
        end
      end

      def sass_options(scope)
        options = super
        options[:custom][:resolver] = ::ActionView::Base.new
        options
      end
    end

    # This is an extension of Sass::Rails's SassTemplate class that allows
    # Rails's asset helpers to be used inside a Haml SCSS filter.
    class ScssRailsTemplate < SassRailsTemplate
      self.default_mime_type = 'text/css'

      def syntax
        :scss
      end
    end

    remove_filter :Sass
    remove_filter :Scss
    register_tilt_filter "Sass", :extend => "Css", :template_class => SassRailsTemplate
    register_tilt_filter "Scss", :extend => "Css", :template_class => ScssRailsTemplate
  end
end

Version data entries

48 entries across 45 versions & 3 rubygems

Version Path
brakeman-7.0.0 bundle/ruby/3.1.0/gems/haml-5.2.2/lib/haml/sass_rails_filter.rb
brakeman-6.2.2 bundle/ruby/3.1.0/gems/haml-5.2.2/lib/haml/sass_rails_filter.rb
brakeman-6.2.2.rc1 bundle/ruby/3.3.0/gems/haml-5.2.2/lib/haml/sass_rails_filter.rb
brakeman-6.2.1 bundle/ruby/3.1.0/gems/haml-5.2.2/lib/haml/sass_rails_filter.rb
brakeman-6.2.0 bundle/ruby/3.1.0/gems/haml-5.2.2/lib/haml/sass_rails_filter.rb
brakeman-6.1.2 bundle/ruby/3.3.0/gems/haml-5.2.2/lib/haml/sass_rails_filter.rb
brakeman-6.1.1 bundle/ruby/3.0.0/gems/haml-5.2.2/lib/haml/sass_rails_filter.rb
brakeman-6.1.0 bundle/ruby/3.1.0/gems/haml-5.2.2/lib/haml/sass_rails_filter.rb
brakeman-6.0.1 bundle/ruby/3.1.0/gems/haml-5.2.2/lib/haml/sass_rails_filter.rb
brakeman-6.0.0 bundle/ruby/3.0.0/gems/haml-5.2.2/lib/haml/sass_rails_filter.rb
brakeman-5.4.1 bundle/ruby/3.1.0/gems/haml-5.2.2/lib/haml/sass_rails_filter.rb
brakeman-5.4.0 bundle/ruby/2.7.0/gems/haml-5.2.2/lib/haml/sass_rails_filter.rb
brakeman-5.3.1 bundle/ruby/2.7.0/gems/haml-5.2.2/lib/haml/sass_rails_filter.rb
brakeman-5.3.0 bundle/ruby/2.7.0/gems/haml-5.2.2/lib/haml/sass_rails_filter.rb
brakeman-5.2.3 bundle/ruby/2.7.0/gems/haml-5.2.2/lib/haml/sass_rails_filter.rb
brakeman-5.2.2 bundle/ruby/2.7.0/gems/haml-5.2.2/lib/haml/sass_rails_filter.rb
brakeman-5.2.1 bundle/ruby/2.7.0/gems/haml-5.2.2/lib/haml/sass_rails_filter.rb
brakeman-5.2.0 bundle/ruby/2.7.0/gems/haml-5.2.2/lib/haml/sass_rails_filter.rb
brakeman-5.1.2 bundle/ruby/2.7.0/gems/haml-5.2.2/lib/haml/sass_rails_filter.rb
haml-5.2.2 lib/haml/sass_rails_filter.rb