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

Add optimization trial code

This commit is contained in:
Takashi Kokubun 2015-11-03 22:10:46 +09:00
parent 4ce32bedd5
commit 7ab540e2ab
2 changed files with 25 additions and 4 deletions

View file

@ -1,7 +1,5 @@
require 'hamlit/attribute_builder'
require 'hamlit/engine'
require 'hamlit/error'
require 'hamlit/hash_parser'
require 'hamlit/version'
begin

View file

@ -1,4 +1,6 @@
require 'haml/util'
require 'hamlit/attribute_builder'
require 'hamlit/hash_parser'
module Hamlit
class Compiler
@ -22,7 +24,8 @@ module Hamlit
[:html, :attrs].tap do |temple|
case
when !node.value[:attributes_hashes].empty?
compile_dynamic_attributes!(temple, node)
# compile_dynamic_attributes!(temple, node)
compile_on_runtime!(temple, node)
when !node.value[:attributes].empty?
compile_static_attributes!(temple, node)
end
@ -30,10 +33,30 @@ module Hamlit
end
def compile_dynamic_attributes!(temple, node)
attrs = [node.value[:attributes].inspect, *node.value[:attributes_hashes]]
hashes = []
node.value[:attributes_hashes].each do |hash_str|
hash = HashParser.parse(hash_str)
return compile_on_runtime!(temple, node) unless hash
hashes << hash
end
hashes.unshift(node.value[:attributes]) if node.value[:attributes] != {}
compile_statically!(temple, hashes)
end
def compile_on_runtime!(temple, node)
attrs = node.value[:attributes_hashes]
attrs.unshift(node.value[:attributes].inspect) if node.value[:attributes] != {}
temple << [:dynamic, "::Hamlit::AttributeBuilder.build(#{@quote}, #{@format.inspect}, #{attrs.join(', ')})"]
end
def compile_statically!(temple, hashes)
hashes.each do |hash|
hash.each do |key, value|
temple << [:html, :attr, key, [:escape, @escape_attrs, [:dynamic, value]]]
end
end
end
def compile_static_attributes!(temple, node)
node.value[:attributes].sort_by(&:first).each do |name, value|
case