module Bridgetown::Site::Renderable

Public Instance Methods

execute_inline_ruby_for_layouts!() click to toggle source

Executes inline Ruby frontmatter

@example

calculation: !ruby/string:Rb |
  [2 * 4, 5 + 2].min

@return [void] @see www.bridgetownrb.com/docs/front-matter#ruby-front-matter

# File lib/bridgetown-core/concerns/site/renderable.rb, line 24
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, self)
  end
end
matched_converters_for_convertible(convertible) click to toggle source
# File lib/bridgetown-core/concerns/site/renderable.rb, line 32
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() click to toggle source

Render all pages & documents so they're ready to be written out to disk. @return [void] @see Page @see Document

# 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_docs
  render_pages
  Bridgetown::Hooks.trigger :site, :post_render, self
end
render_docs() click to toggle source

Renders all documents @return [void]

# File lib/bridgetown-core/concerns/site/renderable.rb, line 54
def render_docs
  collections.each_value do |collection|
    collection.docs.each do |document|
      render_with_locale(document) do
        render_regenerated document
      end
    end

    collection.resources.each do |resource|
      render_with_locale(resource) do
        resource.transform!
      end
    end
  end
end
render_pages() click to toggle source

Renders all pages @return [void]

# File lib/bridgetown-core/concerns/site/renderable.rb, line 72
def render_pages
  pages.each do |page|
    render_regenerated page
  end
end
render_regenerated(document) click to toggle source

Regenerates a site using {Renderer} @param document [Document] The document to regenerate. @return [void]

# File lib/bridgetown-core/concerns/site/renderable.rb, line 96
def render_regenerated(document)
  return unless regenerator.regenerate?(document)

  Bridgetown::Renderer.new(self, document).run
end
render_with_locale(document) { || ... } click to toggle source

Renders a document while ensuring site locale is set if the data is available. @param document [Document] The document to render @yield Runs the block in between locale setting and resetting @return [void]

# File lib/bridgetown-core/concerns/site/renderable.rb, line 82
def render_with_locale(document)
  if document.data["locale"]
    previous_locale = locale
    self.locale = document.data["locale"]
    yield
    self.locale = previous_locale
  else
    yield
  end
end