diff --git a/hamlit.gemspec b/hamlit.gemspec index 493663c3..6c4be1cf 100644 --- a/hamlit.gemspec +++ b/hamlit.gemspec @@ -20,6 +20,7 @@ Gem::Specification.new do |spec| spec.require_paths = ['lib'] spec.add_dependency 'haml', '~> 4.0' + spec.add_dependency 'temple', '~> 0.7.6' spec.add_development_dependency 'bundler', '~> 1.10' spec.add_development_dependency 'rake', '~> 10.0' diff --git a/lib/hamlit.rb b/lib/hamlit.rb index a0686e2c..29f6f0a4 100644 --- a/lib/hamlit.rb +++ b/lib/hamlit.rb @@ -1,5 +1,2 @@ +require 'hamlit/engine' require 'hamlit/version' - -module Hamlit - # Your code goes here... -end diff --git a/lib/hamlit/compiler.rb b/lib/hamlit/compiler.rb new file mode 100644 index 00000000..2eb605ce --- /dev/null +++ b/lib/hamlit/compiler.rb @@ -0,0 +1,11 @@ +module Hamlit + class Compiler + def initialize(options = {}) + @options = options + end + + def call(template) + [:multi, [:static, 'Hamlit']] + end + end +end diff --git a/lib/hamlit/engine.rb b/lib/hamlit/engine.rb new file mode 100644 index 00000000..4f769229 --- /dev/null +++ b/lib/hamlit/engine.rb @@ -0,0 +1,24 @@ +require 'temple' +require 'hamlit/compiler' +require 'hamlit/parser' + +module Hamlit + class Engine < Temple::Engine + define_options( + generator: Temple::Generators::ArrayBuffer, + format: :html, + attr_quote: "'", + escape_html: true, + pretty: false, + ) + + use Parser + use Compiler + html :Pretty + filter :Escapable + filter :ControlFlow + filter :MultiFlattener + filter :StaticMerger + use :Generator, -> { options[:generator] } + end +end diff --git a/lib/hamlit/parser.rb b/lib/hamlit/parser.rb new file mode 100644 index 00000000..3b6d98fc --- /dev/null +++ b/lib/hamlit/parser.rb @@ -0,0 +1,13 @@ +require 'haml' + +module Hamlit + class Parser + def initialize(options = {}) + @options = options + end + + def call(template) + Haml::Parser.new(template, {}).parse + end + end +end