Sha256: b95d58f72501abc3d45ab1714f55c9269b098daa73ddf695a29ac2c73b0ea992

Contents?: true

Size: 1.3 KB

Versions: 2

Compression:

Stored size: 1.3 KB

Contents

# @author Mike Bland (michael.bland@gsa.gov)

require_relative 'generated_page_parser'

module JekyllPagesApi
  # Used by GeneratedSite to mimic a Jekyll page object when processing an
  # already-generated site using the Generator.
  class GeneratedPage
    attr_reader :path, :relative_path, :data, :content

    # @param path [String] full path to the generated page's file
    # @param basedir see {GeneratedSite#initialize}
    # @param title_prefix see {GeneratedSite#initialize}
    # @param body_element_tag see {GeneratedSite#initialize}
    # @param content [String] HTML content of the generated page's file
    # @raises [RuntimError] if path does not begin with basedir
    def initialize(path, basedir, title_prefix, body_element_tag, content)
      unless path.start_with? basedir
        raise "#{path} does not start with #{basedir}"
      end

      @path = path
      basedir_len = basedir.size
      basedir_len -= File::SEPARATOR.size if basedir.end_with? File::SEPARATOR

      end_path = path.size
      index_suffix = File.join "", "index.html"
      end_path -= index_suffix.size if path.end_with? index_suffix
      @relative_path = (path[basedir_len..end_path] || "")
      @data, @content = GeneratedPageParser.parse_generated_page(
        content, title_prefix, body_element_tag)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jekyll_pages_api-0.1.6 lib/jekyll_pages_api/generated_page.rb
jekyll_pages_api-0.1.5 lib/jekyll_pages_api/generated_page.rb