Module: Bridgetown::Site::Renderable

Included in:
Bridgetown::Site
Defined in:
lib/bridgetown-core/concerns/site/renderable.rb

Instance Method Summary collapse

Instance Method Details

#execute_inline_ruby_for_layouts!void

This method returns an undefined value.

Executes procs in Ruby frontmatter



21
22
23
24
25
26
27
# File 'lib/bridgetown-core/concerns/site/renderable.rb', line 21

def execute_inline_ruby_for_layouts!
  return unless config.should_execute_inline_ruby?

  layouts.each_value do |layout|
    Bridgetown::Utils::RubyExec.search_data_for_ruby_code(layout)
  end
end

#matched_converters_for_convertible(convertible) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/bridgetown-core/concerns/site/renderable.rb', line 29

def matched_converters_for_convertible(convertible)
  @layout_converters ||= {}

  if convertible.is_a?(Bridgetown::Layout) && @layout_converters[convertible]
    return @layout_converters[convertible]
  end

  matches = converters.select do |converter|
    if converter.method(:matches).arity == 1
      converter.matches(convertible.extname)
    else
      converter.matches(convertible.extname, convertible)
    end
  end

  @layout_converters[convertible] = matches if convertible.is_a?(Bridgetown::Layout)

  matches
end

#rendervoid

This method returns an undefined value.

Render all pages & documents so they're ready to be written out to disk.

See Also:

  • Page
  • Document


9
10
11
12
13
14
15
# File 'lib/bridgetown-core/concerns/site/renderable.rb', line 9

def render
  Bridgetown::Hooks.trigger :site, :pre_render, self
  execute_inline_ruby_for_layouts!
  render_resources
  generated_pages.each(&:transform!)
  Bridgetown::Hooks.trigger :site, :post_render, self
end

#render_resourcesvoid

This method returns an undefined value.

Renders all resources



77
78
79
80
81
82
83
84
85
# File 'lib/bridgetown-core/concerns/site/renderable.rb', line 77

def render_resources
  collections.each_value do |collection|
    collection.resources.each do |resource|
      render_with_locale(resource) do
        resource.transform!
      end
    end
  end
end

#render_with_locale(item) { ... } ⇒ void

This method returns an undefined value.

Renders a content item while ensuring site locale is set if the data is available.

Parameters:

Yields:

  • Runs the block in between locale setting and resetting



91
92
93
94
95
96
97
98
99
100
# File 'lib/bridgetown-core/concerns/site/renderable.rb', line 91

def render_with_locale(item)
  if item.data["locale"]
    previous_locale = locale
    self.locale = item.data["locale"]
    yield
    self.locale = previous_locale
  else
    yield
  end
end

#validated_layouts_for(convertible, layout_name) ⇒ Array<Bridgetown::Layout>

Returns:



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/bridgetown-core/concerns/site/renderable.rb', line 50

def validated_layouts_for(convertible, layout_name)
  layout = layouts[layout_name]
  warn_on_missing_layout convertible, layout, layout_name

  layout_list = Set.new([layout])
  while layout
    layout_name = layout.data.layout
    layout = layouts[layout_name]
    warn_on_missing_layout convertible, layout, layout_name

    layout_list << layout
  end

  layout_list.to_a.compact
end

#warn_on_missing_layout(convertible, layout, layout_name) ⇒ Object



66
67
68
69
70
71
72
73
# File 'lib/bridgetown-core/concerns/site/renderable.rb', line 66

def warn_on_missing_layout(convertible, layout, layout_name)
  return unless layout.nil? && layout_name

  Bridgetown.logger.warn(
    "Build Warning:",
    "Layout '#{layout_name}' requested via #{convertible.relative_path} does not exist."
  )
end