Class: Sprockets::Sass::SassTemplate

Inherits:
Tilt::SassTemplate
  • Object
show all
Defined in:
lib/sprockets/sass/sass_template.rb

Direct Known Subclasses

ScssTemplate

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.sass_functions_initializedObject Also known as: sass_functions_initialized?

Returns the value of attribute sass_functions_initialized.



15
16
17
# File 'lib/sprockets/sass/sass_template.rb', line 15

def sass_functions_initialized
  @sass_functions_initialized
end

Instance Attribute Details

#contextObject (readonly)

A reference to the current Sprockets context



9
10
11
# File 'lib/sprockets/sass/sass_template.rb', line 9

def context
  @context
end

Class Method Details

.engine_initialized?Boolean

Templates are initialized once the functions are added.

Returns:

  • (Boolean)


19
20
21
# File 'lib/sprockets/sass/sass_template.rb', line 19

def engine_initialized?
  super && sass_functions_initialized?
end

Instance Method Details

#evaluate(context, locals, &block) ⇒ Object

See ‘Tilt::Template#evaluate`.



50
51
52
53
54
55
56
57
58
59
# File 'lib/sprockets/sass/sass_template.rb', line 50

def evaluate(context, locals, &block)
  @output ||= begin
    @context = context
    ::Sass::Engine.new(data, sass_options).render
  rescue ::Sass::SyntaxError => e
    # Annotates exception message with parse line number
    context.__LINE__ = e.sass_backtrace.first[:line]
    raise e
  end
end

#initialize_engineObject

Add the Sass functions if they haven’t already been added.



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/sprockets/sass/sass_template.rb', line 25

def initialize_engine
  super unless self.class.superclass.engine_initialized?

  if Sass.add_sass_functions != false
    begin
      require 'sprockets/helpers'
      require 'sprockets/sass/functions'
    rescue LoadError; end
  end

  self.class.sass_functions_initialized = true
end

#prepareObject

See ‘Tilt::Template#prepare`.



44
45
46
47
# File 'lib/sprockets/sass/sass_template.rb', line 44

def prepare
  @context = nil
  @output  = nil
end

#syntaxObject

Define the expected syntax for the template



39
40
41
# File 'lib/sprockets/sass/sass_template.rb', line 39

def syntax
  :sass
end