Module: Sprockets::SassProcessor::Functions

Defined in:
lib/sprockets/sass_processor.rb

Overview

Public: Functions injected into Sass context during Sprockets evaluation.

This module may be extended to add global functionality to all Sprockets Sass environments. Though, scoping your functions to just your environment is preferred.

module Sprockets::SassProcessor::Functions

def asset_path(path, options = {})
end

end

Instance Method Summary collapse

Instance Method Details

#asset_data_url(path) ⇒ Object

Public: Generate a data URI for asset path.

path - Sass::Script::String logical asset path

Returns a Sass::Script::String.



246
247
248
249
# File 'lib/sprockets/sass_processor.rb', line 246

def asset_data_url(path)
  url = sprockets_context.asset_data_uri(path.value)
  Autoload::Sass::Script::String.new("url(" + url + ")")
end

#asset_path(path, options = {}) ⇒ Object

Public: Generate a url for asset path.

Default implementation is deprecated. Currently defaults to Context#asset_path.

Will raise NotImplementedError in the future. Users should provide their own base implementation.

Returns a Sass::Script::String.



113
114
115
116
117
118
119
120
121
122
# File 'lib/sprockets/sass_processor.rb', line 113

def asset_path(path, options = {})
  path = path.value

  path, _, query, fragment = URI.split(path)[5..8]
  path     = sprockets_context.asset_path(path, options)
  query    = "?#{query}" if query
  fragment = "##{fragment}" if fragment

  Autoload::Sass::Script::String.new("#{path}#{query}#{fragment}", :string)
end

#asset_url(path, options = {}) ⇒ Object

Public: Generate a asset url() link.

path - Sass::Script::String URL path

Returns a Sass::Script::String.



129
130
131
# File 'lib/sprockets/sass_processor.rb', line 129

def asset_url(path, options = {})
  Autoload::Sass::Script::String.new("url(#{asset_path(path, options).value})")
end

#audio_path(path) ⇒ Object

Public: Generate url for audio path.

path - Sass::Script::String URL path

Returns a Sass::Script::String.



174
175
176
# File 'lib/sprockets/sass_processor.rb', line 174

def audio_path(path)
  asset_path(path, type: :audio)
end

#audio_url(path) ⇒ Object

Public: Generate a audio url() link.

path - Sass::Script::String URL path

Returns a Sass::Script::String.



183
184
185
# File 'lib/sprockets/sass_processor.rb', line 183

def audio_url(path)
  asset_url(path, type: :audio)
end

#font_path(path) ⇒ Object

Public: Generate url for font path.

path - Sass::Script::String URL path

Returns a Sass::Script::String.



192
193
194
# File 'lib/sprockets/sass_processor.rb', line 192

def font_path(path)
  asset_path(path, type: :font)
end

#font_url(path) ⇒ Object

Public: Generate a font url() link.

path - Sass::Script::String URL path

Returns a Sass::Script::String.



201
202
203
# File 'lib/sprockets/sass_processor.rb', line 201

def font_url(path)
  asset_url(path, type: :font)
end

#image_path(path) ⇒ Object

Public: Generate url for image path.

path - Sass::Script::String URL path

Returns a Sass::Script::String.



138
139
140
# File 'lib/sprockets/sass_processor.rb', line 138

def image_path(path)
  asset_path(path, type: :image)
end

#image_url(path) ⇒ Object

Public: Generate a image url() link.

path - Sass::Script::String URL path

Returns a Sass::Script::String.



147
148
149
# File 'lib/sprockets/sass_processor.rb', line 147

def image_url(path)
  asset_url(path, type: :image)
end

#javascript_path(path) ⇒ Object

Public: Generate url for javascript path.

path - Sass::Script::String URL path

Returns a Sass::Script::String.



210
211
212
# File 'lib/sprockets/sass_processor.rb', line 210

def javascript_path(path)
  asset_path(path, type: :javascript)
end

#javascript_url(path) ⇒ Object

Public: Generate a javascript url() link.

path - Sass::Script::String URL path

Returns a Sass::Script::String.



219
220
221
# File 'lib/sprockets/sass_processor.rb', line 219

def javascript_url(path)
  asset_url(path, type: :javascript)
end

#stylesheet_path(path) ⇒ Object

Public: Generate url for stylesheet path.

path - Sass::Script::String URL path

Returns a Sass::Script::String.



228
229
230
# File 'lib/sprockets/sass_processor.rb', line 228

def stylesheet_path(path)
  asset_path(path, type: :stylesheet)
end

#stylesheet_url(path) ⇒ Object

Public: Generate a stylesheet url() link.

path - Sass::Script::String URL path

Returns a Sass::Script::String.



237
238
239
# File 'lib/sprockets/sass_processor.rb', line 237

def stylesheet_url(path)
  asset_url(path, type: :stylesheet)
end

#video_path(path) ⇒ Object

Public: Generate url for video path.

path - Sass::Script::String URL path

Returns a Sass::Script::String.



156
157
158
# File 'lib/sprockets/sass_processor.rb', line 156

def video_path(path)
  asset_path(path, type: :video)
end

#video_url(path) ⇒ Object

Public: Generate a video url() link.

path - Sass::Script::String URL path

Returns a Sass::Script::String.



165
166
167
# File 'lib/sprockets/sass_processor.rb', line 165

def video_url(path)
  asset_url(path, type: :video)
end