diff --git a/CHANGELOG.md b/CHANGELOG.md index 7acd1256..d74302a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ Master === +* Fix Sass/Scss filter in Slim templates * Added SMACSS template * Give file metadata (such as frontmatter) precedence over path meta. #552 * Add `sass_assets_paths` option for arbitrary sass partial locations. diff --git a/middleman-core/lib/middleman-core/application.rb b/middleman-core/lib/middleman-core/application.rb index 66539136..1beeafbd 100644 --- a/middleman-core/lib/middleman-core/application.rb +++ b/middleman-core/lib/middleman-core/application.rb @@ -223,7 +223,7 @@ module Middleman # messages, which can take a long time (minutes at full CPU) # if the object is huge or has cyclic references, like this. def to_s - "the Middleman application context" + "#" end # Expand a path to include the index file if it's a directory diff --git a/middleman-core/lib/middleman-core/renderers/sass.rb b/middleman-core/lib/middleman-core/renderers/sass.rb index e77546ad..c77ff611 100644 --- a/middleman-core/lib/middleman-core/renderers/sass.rb +++ b/middleman-core/lib/middleman-core/renderers/sass.rb @@ -39,6 +39,14 @@ module Middleman # A SassTemplate for Tilt which outputs debug messages class SassPlusCSSFilenameTemplate < ::Tilt::SassTemplate + def initialize(*args, &block) + super + + if @options.has_key?(:context) + @context = @options[:context] + end + end + # Define the expected syntax for the template # @return [Symbol] def syntax @@ -52,7 +60,7 @@ module Middleman # @param [Hash] locals # @return [String] def evaluate(context, locals, &block) - @context = context + @context ||= context @engine = ::Sass::Engine.new(data, sass_options) begin @@ -62,17 +70,20 @@ module Middleman end end - private # Change Sass path, for url functions, to the build folder if we're building # @return [Hash] def sass_options - location_of_sass_file = File.expand_path(@context.source, @context.root) - - parts = basename.split('.') - parts.pop - css_filename = File.join(location_of_sass_file, @context.css_dir, parts.join(".")) - - options.merge(:filename => eval_file, :line => line, :syntax => syntax, :css_filename => css_filename) + more_opts = { :filename => eval_file, :line => line, :syntax => syntax } + + if @context.is_a?(::Middleman::Application) && file + location_of_sass_file = File.expand_path(@context.source, @context.root) + + parts = basename.split('.') + parts.pop + more_opts[:css_filename] = File.join(location_of_sass_file, @context.css_dir, parts.join(".")) + end + + options.merge(more_opts) end end diff --git a/middleman-core/lib/middleman-core/renderers/slim.rb b/middleman-core/lib/middleman-core/renderers/slim.rb index 2887503c..caa23675 100644 --- a/middleman-core/lib/middleman-core/renderers/slim.rb +++ b/middleman-core/lib/middleman-core/renderers/slim.rb @@ -21,6 +21,14 @@ module Middleman :buffer => '@_out_buf', :generator => ::Temple::Generators::StringBuffer ) + + app.after_configuration do + sass_context_hack = { + :context => self + } + ::Slim::EmbeddedEngine.default_options[:sass] = sass_context_hack + ::Slim::EmbeddedEngine.default_options[:scss] = sass_context_hack + end end alias :included :registered diff --git a/middleman-more/features/slim.feature b/middleman-more/features/slim.feature index e2f203b2..acf8b82c 100644 --- a/middleman-more/features/slim.feature +++ b/middleman-more/features/slim.feature @@ -18,4 +18,52 @@ Feature: Support slim templating language """ And the Server is running at "empty_app" When I go to "/slim.html" - Then I should see "

Welcome to Slim

" \ No newline at end of file + Then I should see "

Welcome to Slim

" + + Scenario: Rendering Scss in a Slim filter + Given an empty app + And a file named "config.rb" with: + """ + """ + And a file named "source/scss.html.slim" with: + """ + doctype 5 + html lang='en' + head + meta charset="utf-8" + scss: + @import "compass"; + @include global-reset; + body + h1 Welcome to Slim + """ + And a file named "source/sass.html.slim" with: + """ + doctype 5 + html lang='en' + head + meta charset="utf-8" + sass: + @import "compass" + +global-reset + body + h1 Welcome to Slim + """ + And a file named "source/error.html.slim" with: + """ + doctype 5 + html lang='en' + head + meta charset="utf-8" + scss: + +global-reset + body + h1 Welcome to Slim + """ + And the Server is running at "empty_app" + When I go to "/scss.html" + Then I should see "html, body, div" + When I go to "/sass.html" + Then I should see "html, body, div" + When I go to "/error.html" + Then I should see "Syntax error" \ No newline at end of file diff --git a/middleman-more/lib/middleman-more/core_extensions/compass.rb b/middleman-more/lib/middleman-more/core_extensions/compass.rb index 2123d0cc..2f9f98dd 100644 --- a/middleman-more/lib/middleman-more/core_extensions/compass.rb +++ b/middleman-more/lib/middleman-more/core_extensions/compass.rb @@ -73,7 +73,6 @@ module Middleman # A Compass Sass template for Tilt, adding our options in class CompassSassTemplate < ::Middleman::Renderers::Sass::SassPlusCSSFilenameTemplate - private def sass_options super.merge(::Compass.configuration.to_sass_engine_options) end @@ -81,7 +80,6 @@ module Middleman # A Compass Scss template for Tilt, adding our options in class CompassScssTemplate < ::Middleman::Renderers::Sass::ScssPlusCSSFilenameTemplate - private def sass_options super.merge(::Compass.configuration.to_sass_engine_options) end