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



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

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

rubocop:todo Metrics



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/bridgetown-core/concerns/site/renderable.rb', line 30

def matched_converters_for_convertible(convertible) # rubocop:todo Metrics
  @layout_converters ||= {}

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

  if convertible.is_a?(Bridgetown::GeneratedPage) && convertible.original_resource
    convertible = convertible.original_resource
  end

  directly_matched_template_engine = nil
  matches = converters.map do |converter|
    result = [
      converter,
      converter.matches(convertible.extname, convertible),
      converter.determine_template_engine(convertible),
    ]

    directly_matched_template_engine = converter if result[1] && converter.class.template_engine

    result
  end

  matches = matches.filter_map do |result|
    converter, ext_matched, engine_matched = result
    next nil if !ext_matched && !engine_matched

    next nil if !ext_matched &&
      engine_matched && directly_matched_template_engine &&
      converter != directly_matched_template_engine

    if !convertible.data["template_engine"] && engine_matched
      convertible.data["template_engine"] = converter.class.template_engine
    end

    converter
  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


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

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



103
104
105
106
107
108
109
110
111
# File 'lib/bridgetown-core/concerns/site/renderable.rb', line 103

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



118
119
120
121
122
123
124
125
126
127
# File 'lib/bridgetown-core/concerns/site/renderable.rb', line 118

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:



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

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



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

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