Integrate with tilt and add sass filter
This commit is contained in:
parent
78ae610212
commit
da2fc7c729
|
@ -13,3 +13,4 @@
|
||||||
*.a
|
*.a
|
||||||
*.cache
|
*.cache
|
||||||
mkmf.log
|
mkmf.log
|
||||||
|
.sass-cache/
|
||||||
|
|
|
@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
||||||
|
|
||||||
spec.add_dependency "temple"
|
spec.add_dependency "temple"
|
||||||
spec.add_dependency "thor"
|
spec.add_dependency "thor"
|
||||||
|
spec.add_dependency "tilt"
|
||||||
spec.add_development_dependency "benchmark-ips"
|
spec.add_development_dependency "benchmark-ips"
|
||||||
spec.add_development_dependency "bundler"
|
spec.add_development_dependency "bundler"
|
||||||
spec.add_development_dependency "erubis"
|
spec.add_development_dependency "erubis"
|
||||||
|
@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
|
||||||
spec.add_development_dependency "pry"
|
spec.add_development_dependency "pry"
|
||||||
spec.add_development_dependency "rake"
|
spec.add_development_dependency "rake"
|
||||||
spec.add_development_dependency "rspec", ">= 3"
|
spec.add_development_dependency "rspec", ">= 3"
|
||||||
|
spec.add_development_dependency "sass"
|
||||||
spec.add_development_dependency "slim"
|
spec.add_development_dependency "slim"
|
||||||
spec.add_development_dependency "tenjin"
|
spec.add_development_dependency "tenjin"
|
||||||
spec.add_development_dependency "unindent"
|
spec.add_development_dependency "unindent"
|
||||||
|
|
|
@ -6,6 +6,7 @@ require 'hamlit/filters/javascript'
|
||||||
require 'hamlit/filters/plain'
|
require 'hamlit/filters/plain'
|
||||||
require 'hamlit/filters/preserve'
|
require 'hamlit/filters/preserve'
|
||||||
require 'hamlit/filters/ruby'
|
require 'hamlit/filters/ruby'
|
||||||
|
require 'hamlit/filters/sass'
|
||||||
|
|
||||||
module Hamlit
|
module Hamlit
|
||||||
module Compilers
|
module Compilers
|
||||||
|
@ -23,6 +24,7 @@ module Hamlit
|
||||||
register :plain, Filters::Plain
|
register :plain, Filters::Plain
|
||||||
register :preserve, Filters::Preserve
|
register :preserve, Filters::Preserve
|
||||||
register :ruby, Filters::Ruby
|
register :ruby, Filters::Ruby
|
||||||
|
register :sass, Filters::Sass
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_haml_filter(name, lines)
|
def on_haml_filter(name, lines)
|
||||||
|
|
|
@ -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
|
|
@ -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
|
Loading…
Reference in New Issue