mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Create coffee script filter
This commit is contained in:
parent
f1b5a34994
commit
8f1220c23b
5 changed files with 40 additions and 9 deletions
|
@ -21,8 +21,10 @@ Gem::Specification.new do |spec|
|
|||
|
||||
spec.add_dependency 'haml', '~> 4.0'
|
||||
spec.add_dependency 'temple', '~> 0.7.6'
|
||||
spec.add_dependency 'tilt', '~> 2.0'
|
||||
|
||||
spec.add_development_dependency 'bundler', '~> 1.10'
|
||||
spec.add_development_dependency 'coffee-script'
|
||||
spec.add_development_dependency 'faml', '>= 0.3.3'
|
||||
spec.add_development_dependency 'minitest-reporters', '~> 1.1'
|
||||
spec.add_development_dependency 'rails', '>= 4.0.0'
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
require 'hamlit/filters/base'
|
||||
require 'hamlit/filters/tilt_base'
|
||||
require 'hamlit/filters/coffee'
|
||||
require 'hamlit/filters/css'
|
||||
require 'hamlit/filters/escaped'
|
||||
require 'hamlit/filters/javascript'
|
||||
|
@ -20,12 +22,14 @@ module Hamlit
|
|||
end
|
||||
end
|
||||
|
||||
register :css, Css
|
||||
register :escaped, Escaped
|
||||
register :javascript, Javascript
|
||||
register :plain, Plain
|
||||
register :preserve, Preserve
|
||||
register :ruby, Ruby
|
||||
register :coffee, Coffee
|
||||
register :coffeescript, Coffee
|
||||
register :css, Css
|
||||
register :escaped, Escaped
|
||||
register :javascript, Javascript
|
||||
register :plain, Plain
|
||||
register :preserve, Preserve
|
||||
register :ruby, Ruby
|
||||
|
||||
def initialize(options = {})
|
||||
@options = options
|
||||
|
|
15
lib/hamlit/filters/coffee.rb
Normal file
15
lib/hamlit/filters/coffee.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
require 'tilt'
|
||||
|
||||
module Hamlit
|
||||
class Filters
|
||||
class Coffee < TiltBase
|
||||
def compile(node)
|
||||
temple = [:multi]
|
||||
temple << [:static, "<script>\n".freeze]
|
||||
temple << [:static, TiltBase.render('coffee', node.value[:text])]
|
||||
temple << [:static, "</script>".freeze]
|
||||
temple
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
12
lib/hamlit/filters/tilt_base.rb
Normal file
12
lib/hamlit/filters/tilt_base.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
module Hamlit
|
||||
class Filters
|
||||
class TiltBase < Base
|
||||
class << self
|
||||
def render(name, source)
|
||||
text = ::Tilt["t.#{name}"].new { source }.render
|
||||
text.gsub!(/^/, ' '.freeze)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -3,7 +3,6 @@ describe Hamlit::Filters do
|
|||
|
||||
describe '#compile' do
|
||||
it 'renders coffee filter' do
|
||||
skip
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
:coffee
|
||||
foo = ->
|
||||
|
@ -23,9 +22,8 @@ describe Hamlit::Filters do
|
|||
end
|
||||
|
||||
it 'renders coffeescript filter' do
|
||||
skip
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
:coffee
|
||||
:coffeescript
|
||||
foo = ->
|
||||
alert('hello')
|
||||
HAML
|
||||
|
|
Loading…
Reference in a new issue