Sha256: 554762b801e49266edfa3e7779f8ad1e5941234dc3a78f01b819509501ee1eed

Contents?: true

Size: 1.76 KB

Versions: 17

Compression:

Stored size: 1.76 KB

Contents

require 'tilt/template'

module Tilt
  # Sass template implementation. See:
  # http://haml.hamptoncatlin.com/
  #
  # Sass templates do not support object scopes, locals, or yield.
  class SassTemplate < Template
    self.default_mime_type = 'text/css'

    begin
      require 'sass-embedded'
      require 'uri'
      Engine = nil
    rescue LoadError => err
      begin
        require 'sassc'
        Engine = ::SassC::Engine
      rescue LoadError
        begin
          require 'sass'
          Engine = ::Sass::Engine
        rescue LoadError
          raise err
        end
      end
    end

    def prepare
      @engine = unless Engine.nil?
                  Engine.new(data, sass_options)
                end
    end

    def evaluate(scope, locals, &block)
      @output ||= if @engine.nil?
                    ::Sass.compile_string(data, **sass_embedded_options).css
                  else
                    @engine.render
                  end
    end

    def allows_script?
      false
    end

  private
    def eval_file_url
      path = File.absolute_path(eval_file)
      path = '/' + path unless path.start_with?('/')
      ::URI::File.build([nil, ::URI::DEFAULT_PARSER.escape(path)]).to_s
    end

    def sass_embedded_options
      options.merge(:url => eval_file_url, :syntax => :indented)
    end

    def sass_options
      options.merge(:filename => eval_file, :line => line, :syntax => :sass)
    end
  end

  # Sass's new .scss type template implementation.
  class ScssTemplate < SassTemplate
    self.default_mime_type = 'text/css'

  private
    def sass_embedded_options
      options.merge(:url => eval_file_url, :syntax => :scss)
    end

    def sass_options
      options.merge(:filename => eval_file, :line => line, :syntax => :scss)
    end
  end

end

Version data entries

17 entries across 17 versions & 4 rubygems

Version Path
brakeman-6.1.2 bundle/ruby/3.3.0/gems/tilt-2.0.11/lib/tilt/sass.rb
brakeman-6.1.1 bundle/ruby/3.0.0/gems/tilt-2.0.11/lib/tilt/sass.rb
brakeman-6.1.0 bundle/ruby/3.1.0/gems/tilt-2.0.11/lib/tilt/sass.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/tilt-2.0.11/lib/tilt/sass.rb
brakeman-6.0.1 bundle/ruby/3.1.0/gems/tilt-2.0.11/lib/tilt/sass.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/tilt-2.0.11/lib/tilt/sass.rb
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tilt-2.0.11/lib/tilt/sass.rb
brakeman-6.0.0 bundle/ruby/3.0.0/gems/tilt-2.0.11/lib/tilt/sass.rb
brakeman-5.4.1 bundle/ruby/3.1.0/gems/tilt-2.0.11/lib/tilt/sass.rb
tilt-2.1.0 lib/tilt/sass.rb
rubypitaya-3.12.4 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tilt-2.0.11/lib/tilt/sass.rb
rubypitaya-3.12.3 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tilt-2.0.11/lib/tilt/sass.rb
rubypitaya-3.12.2 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tilt-2.0.11/lib/tilt/sass.rb
brakeman-5.4.0 bundle/ruby/2.7.0/gems/tilt-2.0.11/lib/tilt/sass.rb
brakeman-5.3.1 bundle/ruby/2.7.0/gems/tilt-2.0.11/lib/tilt/sass.rb
brakeman-5.3.0 bundle/ruby/2.7.0/gems/tilt-2.0.11/lib/tilt/sass.rb
tilt-2.0.11 lib/tilt/sass.rb