Sha256: b7d2ee6142c834dbd131fc382b72fbf05314f13bd9385c8e2b4e0beb92985210

Contents?: true

Size: 1.14 KB

Versions: 4

Compression:

Stored size: 1.14 KB

Contents

require 'sass-css-importer'
module Sass::Script::Functions
  def asset(url)
    assert_type url, :String
    Sass::Script::Value::String.new("url(\"#{Maglove::Engine.config.asset_uri}/#{url.value}\")")
  end

  def asset_data(url)
    assert_type url, :String
    theme = options[:locals][:theme]
    asset_path = "dist/themes/#{theme}/#{url.value}"
    asset_contents = File.open(asset_path).read
    base64_string = Base64.strict_encode64(asset_contents)
    mime_type = Workspace.file(asset_path).mimetype
    data_uri = "data:#{mime_type};base64,#{base64_string}"
    Sass::Script::Value::String.new("url(#{data_uri})")
  end
  declare(:asset_data, [:url])
end

module MagLove
  module Tilt
    class ScssTemplate < ::Tilt::SassTemplate
      self.default_mime_type = 'text/css'

      def prepare; end

      def evaluate(scope, locals, &block)
        engine = Sass::Engine.new(data, sass_options.merge({ locals: locals }))
        @output ||= engine.render
      end

      private

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

Tilt.mappings["scss"] = [MagLove::Tilt::ScssTemplate]

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
maglove-2.0.11 lib/maglove/tilt/scss_template.rb
maglove-2.0.10 lib/maglove/tilt/scss_template.rb
maglove-2.0.9 lib/maglove/tilt/scss_template.rb
maglove-2.0.8 lib/maglove/tilt/scss_template.rb