Class: Faml::AttributeCompiler

Inherits:
Object
  • Object
show all
Defined in:
lib/faml/attribute_compiler.rb

Instance Method Summary collapse

Instance Method Details

#compile(ast) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/faml/attribute_compiler.rb', line 7

def compile(ast)
  if !ast.object_ref && !ast.old_attributes && !ast.new_attributes
    return compile_static_id_and_class(ast.static_id, ast.static_class)
  end

  unless ast.object_ref
    attrs = try_optimize_attributes(ast.old_attributes, ast.new_attributes, ast.static_id, ast.static_class)
    if attrs
      line_count = 0
      if ast.old_attributes
        line_count += ast.old_attributes.count("\n")
      end
      if ast.new_attributes
        line_count += ast.new_attributes.count("\n")
      end
      return [:multi, [:html, :attrs, *attrs]].concat([[:newline]] * line_count)
    end
  end

  compile_slow_attributes(ast.old_attributes, ast.new_attributes, ast.static_id, ast.static_class, ast.object_ref)
end