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

61 lines
1.4 KiB
Ruby
Raw Normal View History

2015-03-10 00:37:41 +09:00
require 'temple'
require 'hamlit/attribute_compiler'
require 'hamlit/attribute_sorter'
2015-03-16 13:46:35 +09:00
require 'hamlit/dynamic_formatter'
2015-03-23 01:43:47 +09:00
require 'hamlit/doctype_compiler'
2015-03-16 18:18:44 +09:00
require 'hamlit/filter_compiler'
2015-03-16 19:28:08 +09:00
require 'hamlit/filter_formatter'
2015-03-27 15:49:18 +09:00
require 'hamlit/html/pretty'
2015-03-27 21:12:09 +09:00
require 'hamlit/html/ugly'
2015-03-16 08:11:07 +09:00
require 'hamlit/multiline_preprocessor'
require 'hamlit/new_attribute_compiler'
require 'hamlit/parser'
2015-03-16 08:11:07 +09:00
require 'hamlit/script_compiler'
2015-03-17 08:17:31 +09:00
require 'hamlit/text_compiler'
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-16 08:11:07 +09:00
use MultilinePreprocessor
2015-03-10 00:37:41 +09:00
use Parser
2015-03-23 01:43:47 +09:00
use DoctypeCompiler
use AttributeCompiler
use NewAttributeCompier
use AttributeSorter
2015-03-16 19:28:08 +09:00
use FilterFormatter
2015-03-16 18:18:44 +09:00
use FilterCompiler
use ScriptCompiler
2015-03-17 08:17:31 +09:00
use TextCompiler
2015-03-16 13:46:35 +09:00
use DynamicFormatter
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