From 9e3574bd9ea23867f3b2c7a9231d492a7dc674c1 Mon Sep 17 00:00:00 2001 From: Matt Wildig Date: Mon, 23 Jan 2012 03:26:49 +0000 Subject: [PATCH] Add SCSS filter. Add filter to generate CSS from Sass using SCSS syntax. Addresses issue #474. Signed-off-by: Norman Clarke --- CHANGELOG.md | 5 ++++- REFERENCE.md | 5 +++++ lib/haml/filters.rb | 11 +++++++++++ test/results/filters.xhtml | 7 +++++++ test/templates/filters.haml | 14 ++++++++++++++ 5 files changed, 41 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca23c8e7..09def345 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,8 +13,11 @@ * Generate object references based on `#to_key` if it exists in preference to `#id`. +* Add SCSS filter. + (thanks to [Matt Wildig](https://github.com/mattwildig)) + * Helper `list_of` takes an extra argument that is rendered into list item attributes - (thanks [Iain Barnett](http://iainbarnett.me.uk/)) + (thanks [Iain Barnett](http://iainbarnett.me.uk/)) * Fix parser to allow lines ending with `some_method?` to be a Ruby multinline (thanks to [Brad Ediger](https://github.com/bradediger)) diff --git a/REFERENCE.md b/REFERENCE.md index 9d1d1671..b04e484c 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -1259,6 +1259,11 @@ Embedded Ruby code is evaluated in the same context as the Haml template. ### `:sass` Parses the filtered text with Sass to produce CSS output. +{#scss-filter} +### `:scss` +Parses the filtered text with Sass like the `:sass` filter, but uses the newer SCSS +syntax to produce CSS output. + {#textile-filter} ### `:textile` Parses the filtered text with [Textile](http://www.textism.com/tools/textile). diff --git a/lib/haml/filters.rb b/lib/haml/filters.rb index bb9f4d1a..32f3401c 100644 --- a/lib/haml/filters.rb +++ b/lib/haml/filters.rb @@ -313,6 +313,17 @@ END end end + # Parses the filtered text with {Sass} to produce CSS output using SCSS syntax. + module Scss + include Base + lazy_require 'sass/plugin' + + # @see Base#render + def render(text) + ::Sass::Engine.new(text, ::Sass::Plugin.engine_options.merge(:syntax => :scss)).render + end + end + # Parses the filtered text with ERB. # Not available if the {file:HAML_REFERENCE.md#suppress_eval-option `:suppress_eval`} option is set to true. # Embedded Ruby code is evaluated in the same context as the Haml template. diff --git a/test/results/filters.xhtml b/test/results/filters.xhtml index 32af24d3..89fec76e 100644 --- a/test/results/filters.xhtml +++ b/test/results/filters.xhtml @@ -5,6 +5,13 @@ /* line 6 */ h1 { font-weight: normal; } + TESTING HAHAHAHA!