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

TMP_BINARY_ITEMS_DIR

Class Attribute Summary (collapse)

Attributes inherited from Nanoc3::Filter

assigns

Instance Method Summary (collapse)

Methods inherited from Nanoc3::Filter

#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

+ (Object) current

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

- (Object) depend_on(items)

TODO:

Remove me in nanoc 3.2.x



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/nanoc3/filters/sass.rb', line 66

def depend_on(items)
  # Notify
  items.each do |item|
    Nanoc3::NotificationCenter.post(:visit_started, item)
    Nanoc3::NotificationCenter.post(:visit_ended,   item)
  end

  # Raise unmet dependency error if necessary
  items.each do |item|
    rep = item.reps.find { |r| !r.compiled? }
    raise Nanoc3::Errors::UnmetDependency.new(rep) if rep
  end
end

- (Object) imported_filename_to_item(filename)



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

- (String) run(content, params = {})

Runs the content through Sass. 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