Skip to content

Commit

Permalink
Cleanup generated code to reuse erb runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Feb 7, 2014
1 parent 5e6453c commit 0bdd3eb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,8 @@

* Implicitly require `opal-haml` when any haml template is required

* Cleanup generated code to be use Opal ERB runtime directly

## 0.2.0 2013-12-17

* Remove opal-sprockets dependency
Expand Down
8 changes: 7 additions & 1 deletion lib/opal/haml.rb
Expand Up @@ -6,11 +6,17 @@ module Opal
module Haml
def self.compile(source, file = '(haml)')
haml = ::Haml::Engine.new(source, :ugly => true).precompiled
haml = haml.gsub('_hamlout.buffer', '_hamlout')
Opal.compile(wrap(haml, file))
end

def self.wrap(haml, file)
"Template.new('#{file}') do |_hamlout|\n#{haml}\n_hamlout.join\nend\n"
<<-EOS
Template.new('#{file}') do |_hamlout|
#{haml}
_hamlout.join
end
EOS
end
end
end
Expand Down
4 changes: 0 additions & 4 deletions opal/opal-haml.rb
Expand Up @@ -2,10 +2,6 @@

class Template
class OutputBuffer
def buffer
self
end

alias << append

# allow tags in haml to have dynamic attributes
Expand Down

0 comments on commit 0bdd3eb

Please sign in to comment.