Sha256: 0229da3c483a0813fb609e8b3f7655b16ccf09e4a8547d595b712a2a24a00463

Contents?: true

Size: 1.96 KB

Versions: 7

Compression:

Stored size: 1.96 KB

Contents

# frozen_string_literal: true

module Bridgetown
  module Site::Processable
    # Public: Read, process, and write this Site to output.
    #
    # Returns nothing.
    def process
      reset
      read
      generate  # Extensible
      render    # Renderable
      cleanup   # Writable
      write     # Writable
      print_stats if config["profile"]
    end

    # rubocop:disable Metrics/AbcSize
    #
    # Reset Site details.
    #
    # Returns nothing
    def reset
      self.time = if config["time"]
                    Utils.parse_date(config["time"].to_s, "Invalid time in bridgetown.config.yml.")
                  else
                    Time.now
                  end
      self.layouts = ActiveSupport::HashWithIndifferentAccess.new
      self.pages = []
      self.static_files = []
      self.data = ActiveSupport::HashWithIndifferentAccess.new
      @post_attr_hash = {}
      @collections = nil
      @documents = nil
      @docs_to_write = nil
      @regenerator.clear_cache
      @liquid_renderer.reset
      frontmatter_defaults.reset

      raise ArgumentError, "limit_posts must be a non-negative number" if limit_posts.negative?

      Bridgetown::Cache.clear_if_config_changed config
      Bridgetown::Hooks.trigger :site, :after_reset, self
    end
    # rubocop:enable Metrics/AbcSize

    # Read Site data from disk and load it into internal data structures.
    #
    # Returns nothing.
    def read
      Bridgetown::Hooks.trigger :site, :pre_read, self
      reader.read
      limit_posts!
      Bridgetown::Hooks.trigger :site, :post_read, self
    end

    private

    # Limits the current posts; removes the posts which exceed the limit_posts
    #
    # Returns nothing
    def limit_posts!
      if limit_posts.positive?
        limit = posts.docs.length < limit_posts ? posts.docs.length : limit_posts
        posts.docs = posts.docs[-limit, limit]
      end
    end

    def print_stats
      Bridgetown.logger.info @liquid_renderer.stats_table
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
bridgetown-core-0.15.0 lib/bridgetown-core/concerns/site/processable.rb
bridgetown-core-0.15.0.beta4 lib/bridgetown-core/concerns/site/processable.rb
bridgetown-core-0.15.0.beta3 lib/bridgetown-core/concerns/site/processable.rb
bridgetown-core-0.15.0.beta2 lib/bridgetown-core/concerns/site/processable.rb
bridgetown-core-0.15.0.beta1 lib/bridgetown-core/concerns/site/processable.rb
bridgetown-core-0.14.1 lib/bridgetown-core/concerns/site/processable.rb
bridgetown-core-0.14.0 lib/bridgetown-core/concerns/site/processable.rb