Module: Bridgetown::Site::Renderable
- Included in:
- Bridgetown::Site
- Defined in:
- lib/bridgetown-core/concerns/site/renderable.rb
Instance Method Summary collapse
-
#execute_inline_ruby_for_layouts! ⇒ void
Executes procs in Ruby frontmatter.
- #matched_converters_for_convertible(convertible) ⇒ Object
-
#render ⇒ void
Render all pages & documents so they're ready to be written out to disk.
-
#render_resources ⇒ void
Renders all resources.
-
#render_with_locale(item) { ... } ⇒ void
Renders a content item while ensuring site locale is set if the data is available.
- #validated_layouts_for(convertible, layout_name) ⇒ Array<Bridgetown::Layout>
- #warn_on_missing_layout(convertible, layout, layout_name) ⇒ Object
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 |
#render ⇒ void
This method returns an undefined value.
Render all pages & documents so they're ready to be written out to disk.
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_resources ⇒ void
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.
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>
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 |