Module: Sprockets::SasscProcessor::Functions

Defined in:
lib/sprockets/sassc_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::SasscProcessor::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 - SassC::Script::Value::String logical asset path

Returns a SassC::Script::Value::String.



243
244
245
246
# File 'lib/sprockets/sassc_processor.rb', line 243

def asset_data_url(path)
  url = sprockets_context.asset_data_uri(path.value)
  Autoload::SassC::Script::Value::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 SassC::Script::Value::String.



110
111
112
113
114
115
116
117
118
119
# File 'lib/sprockets/sassc_processor.rb', line 110

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::SassC::Script::Value::String.new("#{path}#{query}#{fragment}", :string)
end

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

Public: Generate a asset url() link.

path - SassC::Script::Value::String URL path

Returns a SassC::Script::Value::String.



126
127
128
# File 'lib/sprockets/sassc_processor.rb', line 126

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

#audio_path(path) ⇒ Object

Public: Generate url for audio path.

path - SassC::Script::Value::String URL path

Returns a SassC::Script::Value::String.



171
172
173
# File 'lib/sprockets/sassc_processor.rb', line 171

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

#audio_url(path) ⇒ Object

Public: Generate a audio url() link.

path - SassC::Script::Value::String URL path

Returns a SassC::Script::Value::String.



180
181
182
# File 'lib/sprockets/sassc_processor.rb', line 180

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

#font_path(path) ⇒ Object

Public: Generate url for font path.

path - SassC::Script::Value::String URL path

Returns a SassC::Script::Value::String.



189
190
191
# File 'lib/sprockets/sassc_processor.rb', line 189

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

#font_url(path) ⇒ Object

Public: Generate a font url() link.

path - SassC::Script::Value::String URL path

Returns a SassC::Script::Value::String.



198
199
200
# File 'lib/sprockets/sassc_processor.rb', line 198

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

#image_path(path) ⇒ Object

Public: Generate url for image path.

path - SassC::Script::Value::String URL path

Returns a SassC::Script::Value::String.



135
136
137
# File 'lib/sprockets/sassc_processor.rb', line 135

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

#image_url(path) ⇒ Object

Public: Generate a image url() link.

path - SassC::Script::Value::String URL path

Returns a SassC::Script::Value::String.



144
145
146
# File 'lib/sprockets/sassc_processor.rb', line 144

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

#javascript_path(path) ⇒ Object

Public: Generate url for javascript path.

path - SassC::Script::Value::String URL path

Returns a SassC::Script::Value::String.



207
208
209
# File 'lib/sprockets/sassc_processor.rb', line 207

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

#javascript_url(path) ⇒ Object

Public: Generate a javascript url() link.

path - SassC::Script::Value::String URL path

Returns a SassC::Script::Value::String.



216
217
218
# File 'lib/sprockets/sassc_processor.rb', line 216

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

#stylesheet_path(path) ⇒ Object

Public: Generate url for stylesheet path.

path - SassC::Script::Value::String URL path

Returns a SassC::Script::Value::String.



225
226
227
# File 'lib/sprockets/sassc_processor.rb', line 225

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

#stylesheet_url(path) ⇒ Object

Public: Generate a stylesheet url() link.

path - SassC::Script::Value::String URL path

Returns a SassC::Script::Value::String.



234
235
236
# File 'lib/sprockets/sassc_processor.rb', line 234

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

#video_path(path) ⇒ Object

Public: Generate url for video path.

path - SassC::Script::Value::String URL path

Returns a SassC::Script::Value::String.



153
154
155
# File 'lib/sprockets/sassc_processor.rb', line 153

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

#video_url(path) ⇒ Object

Public: Generate a video url() link.

path - SassC::Script::Value::String URL path

Returns a SassC::Script::Value::String.



162
163
164
# File 'lib/sprockets/sassc_processor.rb', line 162

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