class Flatrack::Sass::SassTemplate

Attributes

sass_functions_initialized[RW]
sass_functions_initialized?[RW]
context[R]

A reference to the current Sprockets context

Public Class Methods

engine_initialized?() click to toggle source

Templates are initialized once the functions are added.

Calls superclass method
# File lib/flatrack/sass/sass_template.rb, line 19
def engine_initialized?
  super && sass_functions_initialized?
end

Public Instance Methods

evaluate(context, locals, &block) click to toggle source

See ‘Tilt::Template#evaluate`.

# File lib/flatrack/sass/sass_template.rb, line 42
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_engine() click to toggle source

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

Calls superclass method
# File lib/flatrack/sass/sass_template.rb, line 25
def initialize_engine
  super unless self.class.superclass.engine_initialized?
  require 'flatrack/sass/functions'
end
prepare() click to toggle source

See ‘Tilt::Template#prepare`.

# File lib/flatrack/sass/sass_template.rb, line 36
def prepare
  @context = nil
  @output  = nil
end
syntax() click to toggle source

Define the expected syntax for the template

# File lib/flatrack/sass/sass_template.rb, line 31
def syntax
  :sass
end

Protected Instance Methods

cache_store() click to toggle source

Returns a Sprockets-aware cache store for Sass::Engine.

# File lib/flatrack/sass/sass_template.rb, line 56
def cache_store
  return nil if context.environment.cache.nil?

  if defined?(Sprockets::SassCacheStore)
    Sprockets::SassCacheStore.new context.environment
  else
    CacheStore.new context.environment
  end
end
default_sass_options() click to toggle source

Get the default, global Sass options. Start with Compass’s options, if it’s available.

# File lib/flatrack/sass/sass_template.rb, line 80
def default_sass_options
  if defined?(Compass)
    merge_sass_options Compass.sass_engine_options.dup, Flatrack.sass_options
  else
    Flatrack.sass_options.dup
  end
end
merge_sass_options(options, other_options) click to toggle source

Merges two sets of ‘Sass::Engine` options, prepending the `:load_paths` instead of clobbering them.

# File lib/flatrack/sass/sass_template.rb, line 90
def merge_sass_options(options, other_options)
  if (load_paths = options[:load_paths]) && (other_paths = other_options[:load_paths])
    other_options[:load_paths] = other_paths + load_paths
  end
  options.merge other_options
end
sass_options() click to toggle source

Assemble the options for the ‘Sass::Engine`

# File lib/flatrack/sass/sass_template.rb, line 67
def sass_options
  merge_sass_options(default_sass_options, options).merge(
    filename: eval_file,
    line: line,
    syntax: syntax,
    cache_store: cache_store,
    importer: Importer.new,
    custom: { sprockets_context: context }
  )
end