Class: Nanoc3::Filters::Sass

Inherits:
Nanoc3::Filter show all
Defined in:
lib/nanoc3/filters/sass.rb

Defined Under Namespace

Classes: SassFilesystemImporter

Constant Summary

Constants inherited from Nanoc3::Filter

Nanoc3::Filter::TMP_BINARY_ITEMS_DIR

Class Attribute Summary collapse

Attributes inherited from Nanoc3::Filter

#assigns

Instance Method Summary collapse

Methods inherited from Nanoc3::Filter

#depend_on, #filename, from_binary?, #initialize, #output_filename, to_binary?, type

Methods included from PluginRegistry::PluginMethods

#identifier, #identifiers, #named, #register

Methods inherited from Context

#get_binding, #initialize

Constructor Details

This class inherits a constructor from Nanoc3::Filter

Class Attribute Details

.currentObject

The current filter. This is definitely going to bite me if I ever get to multithreading nanoc.



12
13
14
# File 'lib/nanoc3/filters/sass.rb', line 12

def current
  @current
end

Instance Method Details

#imported_filename_to_item(filename) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/nanoc3/filters/sass.rb', line 57

def imported_filename_to_item(filename)
  path = Pathname.new(filename).realpath
  @items.find do |i|
    next if i[:content_filename].nil?
    Pathname.new(i[:content_filename]).realpath == path
  end
end

#run(content, params = {}) ⇒ String

Runs the content through [Sass](sass-lang.com/). Parameters passed to this filter will be passed on to Sass.

Parameters:

  • content (String)

    The content to filter

Returns:

  • (String)

    The filtered content



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/nanoc3/filters/sass.rb', line 42

def run(content, params={})
  # Build options
  options = params.dup
  sass_filename = options[:filename] ||
    (@item && @item[:content_filename])
  options[:filename] ||= sass_filename
  options[:filesystem_importer] ||=
    Nanoc3::Filters::Sass::SassFilesystemImporter

  # Render
  engine = ::Sass::Engine.new(content, options)
  self.class.current = self
  engine.render
end