Module: Halogen::Embeds::InstanceMethods

Defined in:
lib/halogen/embeds.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#child_embed_opts(key) ⇒ Hash


60
61
62
63
64
65
66
67
# File 'lib/halogen/embeds.rb', line 60

def child_embed_opts(key)
  opts = embed_options.fetch(key, {})

  # Turn { :report => 1 } into { :report => {} } for child
  opts = {} unless opts.is_a?(Hash)

  opts
end

#embed_optionsHash


87
88
89
90
91
# File 'lib/halogen/embeds.rb', line 87

def embed_options
  @_embed_options ||= options.fetch(:embed, {}).tap do |result|
    Halogen::HashUtil.stringify_keys!(result)
  end
end

#embeddedHash


31
32
33
34
35
36
37
38
39
# File 'lib/halogen/embeds.rb', line 31

def embedded
  render_definitions(Definition.name) do |definition, result|
    value = instance_eval(&definition.procedure)

    child = embedded_child(definition.name.to_s, value)

    result[definition.name] = child if child
  end
end

#embedded_child(key, value) ⇒ nil, ...


44
45
46
47
48
49
50
51
52
53
54
# File 'lib/halogen/embeds.rb', line 44

def embedded_child(key, value)
  return unless value

  opts = child_embed_opts(key)

  if value.is_a?(Array)
    value.map { |item| render_child(item, opts) }.compact
  else
    render_child(value, opts)
  end
end

#renderHash


25
26
27
# File 'lib/halogen/embeds.rb', line 25

def render
  decorate_render :embedded, super
end

#render_child(repr, opts) ⇒ nil, Hash


74
75
76
77
78
79
80
81
82
83
# File 'lib/halogen/embeds.rb', line 74

def render_child(repr, opts)
  return unless repr.class.included_modules.include?(Halogen)

  repr.options[:embed] ||= {}
  repr.options[:embed].merge!(opts)

  repr.options[:parent] = self

  repr.render
end