Sha256: 68eea7c78c0645e97232b8c9732f7b90292385988f3373f1d72db5650ca7c306

Contents?: true

Size: 1.89 KB

Versions: 3

Compression:

Stored size: 1.89 KB

Contents

# frozen_string_literal: true

module Bridgetown
  module Site::Renderable
    # Render the site to the destination.
    # @return [void]
    def render
      payload = site_payload

      Bridgetown::Hooks.trigger :site, :pre_render, self, payload

      execute_inline_ruby_for_layouts!

      render_docs(payload)
      render_pages(payload)

      Bridgetown::Hooks.trigger :site, :post_render, self, payload
    end

    # Executes inline Ruby frontmatter if
    # +ENV+["BRIDGETOWN_RUBY_IN_FRONTMATTER"] equals "true"
    #
    # @example
    #   calculation: !ruby/string:Rb |
    #     [2 * 4, 5 + 2].min
    # @return [void]
    # @see https://www.bridgetownrb.com/docs/front-matter#ruby-front-matter
    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

    # Renders all documents
    # @param payload [Hash] A hash of site data.
    # @return [void]
    # @see Bridgetown::Site::Content#site_payload
    def render_docs(payload)
      collections.each_value do |collection|
        collection.docs.each do |document|
          render_regenerated(document, payload)
        end
      end
    end

    # Renders all pages
    # @param payload [Hash] A hash of site data.
    # @return [void]
    # @see Bridgetown::Site::Content#site_payload
    def render_pages(payload)
      pages.each do |page|
        render_regenerated(page, payload)
      end
    end

    # Regenerates a site using {Bridgetown::Renderer}
    # @param document [Post] The document to regenerate.
    # @param payload [Hash] A hash of site data.
    # @return [void]
    # @see Bridgetown::Renderer
    def render_regenerated(document, payload)
      return unless regenerator.regenerate?(document)

      Bridgetown::Renderer.new(self, document, payload).run
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bridgetown-core-0.16.0 lib/bridgetown-core/concerns/site/renderable.rb
bridgetown-core-0.16.0.beta2 lib/bridgetown-core/concerns/site/renderable.rb
bridgetown-core-0.16.0.beta1 lib/bridgetown-core/concerns/site/renderable.rb