Module: ExpressTemplates::Components::Capabilities::Parenting::InstanceMethods

Defined in:
lib/express_templates/components/capabilities/parenting.rb

Instance Method Summary collapse

Instance Method Details

#childrenObject



38
39
40
# File 'lib/express_templates/components/capabilities/parenting.rb', line 38

def children
  @children ||= []
end

#children=(children) ⇒ Object



42
43
44
# File 'lib/express_templates/components/capabilities/parenting.rb', line 42

def children=(children)
  @children =children
end

#compileObject



46
47
48
49
50
# File 'lib/express_templates/components/capabilities/parenting.rb', line 46

def compile
  null_wrapped_children = "null_wrap { #{compile_children} }"
  wrap_children_src = self.class[:markup].source.gsub(/\W_yield\W/, null_wrapped_children)
  _compile_fragment(Proc.from_source(wrap_children_src))
end

#compile_childrenObject



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/express_templates/components/capabilities/parenting.rb', line 52

def compile_children
  compiled_children = nil
  Indenter.for(:compile) do |indent, indent_with_newline|
    compiled_children = children.map do |child|
      indent_with_newline +
      (child.respond_to?(:compile) ? child.compile : child.inspect) # Bare strings may be children
    end.join("+\n")
    compiled_children.gsub!('"+"', '') # avoid unnecessary string concatenation
  end
  return compiled_children
end