1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00
haml--haml/lib/hamlit/engine.rb

43 lines
860 B
Ruby
Raw Normal View History

2015-03-10 00:37:41 +09:00
require 'temple'
2015-03-28 17:37:06 +09:00
require 'hamlit/compiler'
2015-03-27 15:49:18 +09:00
require 'hamlit/html/pretty'
2015-03-27 21:12:09 +09:00
require 'hamlit/html/ugly'
require 'hamlit/parser'
2015-03-10 00:37:41 +09:00
module Hamlit
2015-03-10 00:37:41 +09:00
class Engine < Temple::Engine
2015-03-25 01:51:40 +09:00
define_options(
generator: Temple::Generators::ArrayBuffer,
format: :html,
attr_quote: "'",
2015-03-27 14:53:54 +09:00
ugly: false,
2015-03-25 01:51:40 +09:00
)
2015-03-12 22:56:34 +09:00
2015-03-10 00:37:41 +09:00
use Parser
2015-03-28 19:21:52 +09:00
use Compiler
2015-03-27 14:53:54 +09:00
use :Html, -> { create(html_compiler) }
2015-03-15 19:27:53 +09:00
filter :Escapable
2015-03-16 01:07:54 +09:00
filter :ControlFlow
filter :MultiFlattener
filter :StaticMerger
2015-03-27 14:53:54 +09:00
use :Generator, -> { create(options[:generator]) }
2015-03-27 14:53:54 +09:00
private
def create(klass)
2015-03-16 12:53:53 +09:00
valid_options = options.to_hash.select do |key, value|
2015-03-27 14:53:54 +09:00
klass.options.valid_key?(key)
end
klass.new(valid_options)
end
def html_compiler
if options[:ugly]
2015-03-27 21:12:09 +09:00
HTML::Ugly
2015-03-27 14:53:54 +09:00
else
2015-03-27 21:12:09 +09:00
HTML::Pretty
2015-03-16 12:53:53 +09:00
end
2015-03-12 22:56:34 +09:00
end
2015-03-10 00:37:41 +09:00
end
end