mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Add CLI option to show compiled code for rails
This commit is contained in:
parent
918573ab60
commit
a33a8ff5c3
1 changed files with 18 additions and 1 deletions
|
@ -10,6 +10,7 @@ module Hamlit
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'compile HAML', 'Show compile result'
|
desc 'compile HAML', 'Show compile result'
|
||||||
|
option :actionview, type: :boolean, default: false, aliases: %w[-a]
|
||||||
def compile(file)
|
def compile(file)
|
||||||
print_code generate_code(file)
|
print_code generate_code(file)
|
||||||
end
|
end
|
||||||
|
@ -23,7 +24,23 @@ module Hamlit
|
||||||
|
|
||||||
def generate_code(file)
|
def generate_code(file)
|
||||||
template = File.read(file)
|
template = File.read(file)
|
||||||
Hamlit::Engine.new.call(template)
|
if options[:actionview]
|
||||||
|
require 'action_view'
|
||||||
|
require 'action_view/base'
|
||||||
|
require 'hamlit/rails_template'
|
||||||
|
handler = Hamlit::RailsTemplate.new
|
||||||
|
template = ActionView::Template.new(template, 'inline template', handler, { locals: [] })
|
||||||
|
code = handler.call(template)
|
||||||
|
source = <<-end_src
|
||||||
|
def _inline_template___2144273726781623612_70327218547300(local_assigns, output_buffer)
|
||||||
|
_old_virtual_path, @virtual_path = @virtual_path, nil;_old_output_buffer = @output_buffer;;#{code}
|
||||||
|
ensure
|
||||||
|
@virtual_path, @output_buffer = _old_virtual_path, _old_output_buffer
|
||||||
|
end
|
||||||
|
end_src
|
||||||
|
else
|
||||||
|
Hamlit::Engine.new.call(template)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_ast(file)
|
def generate_ast(file)
|
||||||
|
|
Loading…
Add table
Reference in a new issue