Module: Sass::Script::Functions

Defined in:
lib/maglove/tilt/scss_template.rb

Instance Method Summary collapse

Instance Method Details

#asset(url) ⇒ Object



3
4
5
6
# File 'lib/maglove/tilt/scss_template.rb', line 3

def asset(url)
  assert_type url, :String
  Sass::Script::Value::String.new("url(\"#{Maglove::Engine.config.asset_uri}/#{url.value}\")")
end

#asset_data(url) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/maglove/tilt/scss_template.rb', line 8

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