Class: Trekky::SassSource

Inherits:
Source
  • Object
show all
Defined in:
lib/trekky/sass_source.rb

Constant Summary collapse

HTML_ESCAPE_ONCE_REGEXP =
/["><']|&(?!([a-zA-Z]+|(#\d+));)/
HTML_ESCAPE =
{
  '&' => '&amp;',
  '>' => '&gt;',
  '<' => '&lt;',
  '"' => '&quot;',
  "'" => '&#39;'
}

Instance Attribute Summary

Attributes inherited from Source

#context, #errors, #output, #path

Instance Method Summary collapse

Methods inherited from Source

#add_error, #clear_errors, #extension, #initialize, #input, #render_errors, #type, #valid?

Constructor Details

This class inherits a constructor from Trekky::Source

Instance Method Details

#optionsObject



28
29
30
# File 'lib/trekky/sass_source.rb', line 28

def options
  { :syntax => :sass }
end

#renderObject



15
16
17
18
19
20
21
# File 'lib/trekky/sass_source.rb', line 15

def render
  clear_errors
  Sass.load_paths << @context.source_dir
  @output = Sass::Engine.new(input, options).render
rescue Exception => error
  add_error error
end

#render_error(error) ⇒ Object



23
24
25
26
# File 'lib/trekky/sass_source.rb', line 23

def render_error(error)
  input = error.message.to_s.gsub(HTML_ESCAPE_ONCE_REGEXP, HTML_ESCAPE)
  sprintf('body::before{ content:"%s" }', input)
end