1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

Integrate with tilt and add sass filter

This commit is contained in:
Takashi Kokubun 2015-03-30 16:49:11 +09:00
parent 78ae610212
commit da2fc7c729
5 changed files with 46 additions and 1 deletions

1
.gitignore vendored
View file

@ -13,3 +13,4 @@
*.a
*.cache
mkmf.log
.sass-cache/

View file

@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
spec.add_dependency "temple"
spec.add_dependency "thor"
spec.add_dependency "tilt"
spec.add_development_dependency "benchmark-ips"
spec.add_development_dependency "bundler"
spec.add_development_dependency "erubis"
@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "pry"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec", ">= 3"
spec.add_development_dependency "sass"
spec.add_development_dependency "slim"
spec.add_development_dependency "tenjin"
spec.add_development_dependency "unindent"

View file

@ -6,6 +6,7 @@ require 'hamlit/filters/javascript'
require 'hamlit/filters/plain'
require 'hamlit/filters/preserve'
require 'hamlit/filters/ruby'
require 'hamlit/filters/sass'
module Hamlit
module Compilers
@ -23,6 +24,7 @@ module Hamlit
register :plain, Filters::Plain
register :preserve, Filters::Preserve
register :ruby, Filters::Ruby
register :sass, Filters::Sass
end
def on_haml_filter(name, lines)

View file

@ -0,0 +1,22 @@
require 'tilt'
require 'hamlit/filters/base'
module Hamlit
module Filters
class Sass < Base
def compile(lines)
result = compile_with_tilt(lines)
content = [:multi, [:static, "\n"], result]
[:html, :tag, 'style', [:html, :attrs], content]
end
private
def compile_with_tilt(lines)
source = lines.join("\n")
result = ::Tilt['t.sass'].new { source }.render
[:static, compile_lines(result.split("\n"), indent_width: 2)]
end
end
end
end

View file

@ -0,0 +1,19 @@
describe Hamlit::Filters::Sass do
describe '#compile' do
it 'renders sass filter' do
assert_render(<<-HAML, <<-HTML)
:sass
.users_controller
.show_action
margin: 10px
padding: 20px
HAML
<style>
.users_controller .show_action {
margin: 10px;
padding: 20px; }
</style>
HTML
end
end
end