mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Add ugly mode for cli
This commit is contained in:
parent
5ce029a61b
commit
e8269b6c66
1 changed files with 13 additions and 2 deletions
|
@ -6,18 +6,21 @@ module Hamlit
|
|||
IGNORED_COMPILERS = ['HTML'].freeze
|
||||
|
||||
desc 'render HAML', 'Render haml template'
|
||||
option :ugly, type: :boolean, aliases: ['-u']
|
||||
def render(file)
|
||||
code = generate_code(file)
|
||||
puts eval(code)
|
||||
end
|
||||
|
||||
desc 'compile HAML', 'Show generated rendering code'
|
||||
option :ugly, type: :boolean, aliases: ['-u']
|
||||
def compile(file)
|
||||
code = generate_code(file)
|
||||
puts code
|
||||
end
|
||||
|
||||
desc 'temple HAML', 'Show a compile result of hamlit AST'
|
||||
option :ugly, type: :boolean, aliases: ['-u']
|
||||
def temple(file)
|
||||
pp generate_temple_ast(file)
|
||||
end
|
||||
|
@ -38,7 +41,7 @@ module Hamlit
|
|||
|
||||
def generate_code(file)
|
||||
template = File.read(file)
|
||||
Hamlit::Engine.new.call(template)
|
||||
Hamlit::Engine.new(options).call(template)
|
||||
end
|
||||
|
||||
def generate_temple_ast(file)
|
||||
|
@ -49,7 +52,7 @@ module Hamlit
|
|||
|
||||
template = File.read(file)
|
||||
compilers.inject(template) do |exp, compiler|
|
||||
Module.const_get(compiler).new.call(exp)
|
||||
Module.const_get(compiler).new(options).call(exp)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -74,5 +77,13 @@ module Hamlit
|
|||
def ignored_compilers
|
||||
IGNORED_COMPILERS.map { |name| "Hamlit::#{name}" }
|
||||
end
|
||||
|
||||
def options
|
||||
symbolize_keys(super)
|
||||
end
|
||||
|
||||
def symbolize_keys(hash)
|
||||
{}.tap { |h| hash.each { |k, v| h[k.to_sym] = v } }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue