lib/hamlit/attribute_compiler.rb in hamlit-2.7.5 vs lib/hamlit/attribute_compiler.rb in hamlit-2.8.0

- old
+ new

@@ -1,10 +1,9 @@ # frozen_string_literal: true require 'hamlit/attribute_builder' require 'hamlit/attribute_parser' require 'hamlit/ruby_expression' -require 'hamlit/static_analyzer' module Hamlit class AttributeCompiler def initialize(identity, options) @identity = identity @@ -28,11 +27,11 @@ def runtime_compile(node) attrs = node.value[:attributes_hashes] attrs.unshift(node.value[:attributes].inspect) if node.value[:attributes] != {} - args = [@escape_attrs, @quote, @format].map(&:inspect).push(node.value[:object_ref]) + attrs + args = [@escape_attrs.inspect, "#{@quote.inspect}.freeze", @format.inspect].push(node.value[:object_ref]) + attrs [:html, :attrs, [:dynamic, "::Hamlit::AttributeBuilder.build(#{args.join(', ')})"]] end def static_compile(static_hash, dynamic_hashes) temple = [:html, :attrs] @@ -57,41 +56,41 @@ temple end def compile_id!(temple, key, values) build_code = attribute_builder(:id, values) - if values.all? { |type, exp| type == :static || StaticAnalyzer.static?(exp) } + if values.all? { |type, exp| type == :static || Temple::StaticAnalyzer.static?(exp) } temple << [:html, :attr, key, [:static, eval(build_code).to_s]] else temple << [:html, :attr, key, [:dynamic, build_code]] end end def compile_class!(temple, key, values) build_code = attribute_builder(:class, values) - if values.all? { |type, exp| type == :static || StaticAnalyzer.static?(exp) } + if values.all? { |type, exp| type == :static || Temple::StaticAnalyzer.static?(exp) } temple << [:html, :attr, key, [:static, eval(build_code).to_s]] else temple << [:html, :attr, key, [:dynamic, build_code]] end end def compile_data!(temple, key, values) - args = [@escape_attrs.inspect, @quote.inspect, values.map { |v| literal_for(v) }] + args = [@escape_attrs.inspect, "#{@quote.inspect}.freeze", values.map { |v| literal_for(v) }] build_code = "::Hamlit::AttributeBuilder.build_data(#{args.join(', ')})" - if values.all? { |type, exp| type == :static || StaticAnalyzer.static?(exp) } + if values.all? { |type, exp| type == :static || Temple::StaticAnalyzer.static?(exp) } temple << [:static, eval(build_code).to_s] else temple << [:dynamic, build_code] end end def compile_boolean!(temple, key, values) exp = literal_for(values.last) - if StaticAnalyzer.static?(exp) + if Temple::StaticAnalyzer.static?(exp) value = eval(exp) case value when true then temple << [:html, :attr, key, @format == :xhtml ? [:static, key] : [:multi]] when false, nil else temple << [:html, :attr, key, [:fescape, @escape_attrs, [:static, value.to_s]]] @@ -116,9 +115,9 @@ "::Hamlit::AttributeBuilder.build_#{type}(#{args.join(', ')})" end def literal_for(value) type, exp = value - type == :static ? exp.inspect : exp + type == :static ? "#{exp.inspect}.freeze" : exp end end end