Sha256: 5d31adbd3c4e7c44c028a6a1517f359c5e9b6ec997f6b6ab30b130b721e1c6ab

Contents?: true

Size: 1.6 KB

Versions: 2

Compression:

Stored size: 1.6 KB

Contents

require "sass"
require "sass/plugin"

module Middleman::Renderers::Sass
  class << self
    def registered(app)
      # Default sass options
      app.set :sass, {}
    end
    alias :included :registered
  end
  
  class SassPlusCSSFilenameTemplate < ::Tilt::SassTemplate
    def sass_options
      return super if basename.nil?

      location_of_sass_file = if Middleman::Server.build?
        File.join(Middleman::Server.root, Middleman::Server.build_dir)
      else
        Middleman::Server.views
      end

      parts = basename.split('.')
      parts.pop
      css_filename = File.join(location_of_sass_file, Middleman::Server.css_dir, parts.join("."))
      super.merge(Middleman::Server.settings.sass).merge(:css_filename => css_filename)
    end

    def evaluate(scope, locals, &block)
      begin
        super
      rescue Sass::SyntaxError => e
        Sass::SyntaxError.exception_to_css(e, :full_exception => true)
      end
    end
  end
  ::Tilt.register 'sass', SassPlusCSSFilenameTemplate
  ::Tilt.prefer(SassPlusCSSFilenameTemplate)

  class ScssPlusCSSFilenameTemplate < SassPlusCSSFilenameTemplate
    def sass_options
      super.merge(:syntax => :scss)
    end
  end
  ::Tilt.register 'scss', ScssPlusCSSFilenameTemplate
  ::Tilt.prefer(ScssPlusCSSFilenameTemplate)
end

# Use sass settings in Haml filters
# Other, tilt-based filters (like those used in Slim) will
# work automatically.
module Middleman::Renderers::Haml
  module Sass
    include ::Haml::Filters::Base

    def render(text)
      sass_options = Middleman::Server.settings.sass
      ::Sass::Engine.new(text, sass_options).render
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
middleman-2.0.0.rc3 lib/middleman/renderers/sass.rb
middleman-2.0.0.rc2 lib/middleman/renderers/sass.rb