class Webgen::ContentProcessor::Sass::NodeTreeImporter
Custom importer for Sass
to load files by resolving them in the node tree.
Public Class Methods
new(context)
click to toggle source
Creates a new importer that imports files from the node tree relative to the given node alcn.
# File lib/webgen/content_processor/sass.rb 32 def initialize(context) 33 @context = context 34 end
Public Instance Methods
find(name, options)
click to toggle source
@see Base#find
# File lib/webgen/content_processor/sass.rb 48 def find(name, options) 49 _find(@context.ref_node.alcn, name, options) 50 end
find_relative(name, base, options)
click to toggle source
@see Base#find_relative
# File lib/webgen/content_processor/sass.rb 43 def find_relative(name, base, options) 44 _find(base, name, options) 45 end
Private Instance Methods
_find(base, name, options)
click to toggle source
Find the @import-ed name under the given base filename.
Returns a Sass::Engine object if found or nil
otherwise.
# File lib/webgen/content_processor/sass.rb 72 def _find(base, name, options) 73 node, syntax = resolve_node(base, name) 74 return unless node 75 76 @context.website.ext.item_tracker.add(@context.dest_node, :node_content, node) 77 options[:syntax] = syntax 78 options[:filename] = node.alcn 79 options[:importer] = self 80 ::Sass::Engine.new(node.node_info[:path].data, options) 81 end
possible_filenames(path)
click to toggle source
Return an array of all possible (filename, syntax) pairs for the given path.
# File lib/webgen/content_processor/sass.rb 95 def possible_filenames(path) 96 dirname, basename = File.split(path) 97 basename, ext = basename.scan(/^(.*?)(?:\.(sass|scss))?$/).first 98 (ext.nil? ? %w{sass scss} : [ext]).map do |iext| 99 [["#{dirname}/_#{basename}.#{iext}", iext.to_sym], ["#{dirname}/#{basename}.#{iext}", iext.to_sym]] 100 end.flatten(1) 101 end
resolve_node(base, path)
click to toggle source
Resolve the path using the given base filename.
Returns [node, syntax] if a node was found or nil otherwise
# File lib/webgen/content_processor/sass.rb 86 def resolve_node(base, path) 87 possible_filenames(path).each do |filename, syntax| 88 node = @context.website.tree.resolve_node(Webgen::Path.append(base, filename), nil) 89 return [node, syntax] if node 90 end 91 nil 92 end