Sha256: 3939ab87eae74c7746c02469ffa1edf3fe211a2bac0f168d396aa3e34323b0ef

Contents?: true

Size: 1.41 KB

Versions: 1

Compression:

Stored size: 1.41 KB

Contents

# encoding: utf-8

module Nanoc::Filters
  class Sass < Nanoc::Filter

    requires 'sass', 'nanoc/filters/sass/sass_filesystem_importer'

    # Runs the content through [Sass](http://sass-lang.com/).
    # Parameters passed to this filter will be passed on to Sass.
    #
    # @param [String] content The content to filter
    #
    # @return [String] The filtered content
    def run(content, params={})
      # Build options
      options = params.dup
      sass_filename = options[:filename] ||
        (@item && @item[:content_filename])
      options[:filename] ||= sass_filename
      options[:filesystem_importer] ||=
        Nanoc::Filters::Sass::SassFilesystemImporter

      # Find items
      item_dirglob = Pathname.new(sass_filename).dirname.realpath.to_s + '**'
      clean_items = @items.reject { |i| i.raw_filename.nil? }
      @scoped_items, @rest_items = clean_items.partition do |i|
        i.raw_filename &&
          Pathname.new(i.raw_filename).realpath.fnmatch(item_dirglob)
      end
      
      # Render
      options[:nanoc_current_filter] = self
      engine = ::Sass::Engine.new(content, options)
      engine.render
    end

    def imported_filename_to_item(filename)
      filematch = lambda do |i|
        i.raw_filename &&
          Pathname.new(i.raw_filename).realpath == Pathname.new(filename).realpath
      end
      @scoped_items.find(&filematch) || @rest_items.find(&filematch)
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nanoc-3.6.6 lib/nanoc/filters/sass.rb