Class: JekyllPagesApi::GeneratedSite

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll_pages_api/generated_site.rb

Overview

Used by the standalone executable to mimic a Jekyll::Site when processing an already-generated site using the Generator.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(baseurl, basedir, title_prefix, body_element_tag) ⇒ GeneratedSite

Returns a new instance of GeneratedSite.

Parameters:

  • baseurl (String)

    URL prefix of every page of the generated site

  • basedir (String)

    Path to the generated site’s root directory

  • title_prefix (String)

    Prefix to strip from page titles

  • body_element_tag (String)

    Tag (or tag prefix) identifying the main content element within the <body> element of each document. Can be a complete tag (ending in ‘>’), or the prefix of a longer tag. Used to strip boilerplate out of the content exported via the API.



22
23
24
25
26
27
28
# File 'lib/jekyll_pages_api/generated_site.rb', line 22

def initialize(baseurl, basedir, title_prefix, body_element_tag)
  @baseurl = baseurl
  @basedir = basedir
  @title_prefix = title_prefix
  @body_element_tag = body_element_tag
  @pages = []
end

Instance Attribute Details

#basedirObject (readonly)

See Also:



10
11
12
# File 'lib/jekyll_pages_api/generated_site.rb', line 10

def basedir
  @basedir
end

#baseurlObject (readonly)

See Also:



10
11
12
# File 'lib/jekyll_pages_api/generated_site.rb', line 10

def baseurl
  @baseurl
end

#body_element_tagObject (readonly)

See Also:



10
11
12
# File 'lib/jekyll_pages_api/generated_site.rb', line 10

def body_element_tag
  @body_element_tag
end

#pagesArray<>

Returns a dummy empty Array.

Returns:

  • (Array<>)

    a dummy empty Array



13
14
15
# File 'lib/jekyll_pages_api/generated_site.rb', line 13

def pages
  @pages
end

#title_prefixObject (readonly)

See Also:



10
11
12
# File 'lib/jekyll_pages_api/generated_site.rb', line 10

def title_prefix
  @title_prefix
end

Instance Method Details

#each_site_fileObject

Generator yielding each HTML page (as a JekyllPagesApi::GeneratedPage) that should be exported via the API.



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/jekyll_pages_api/generated_site.rb', line 32

def each_site_file
  Dir.glob(File.join(self.basedir, '**', '*')) do |f|
    next unless f.end_with? '.html'
    begin
      page = GeneratedPage.new(f, self.basedir, self.title_prefix,
        self.body_element_tag, File.read(f))
      yield page unless page.data['title'].nil?
    rescue
      $stderr.puts "Error while processing #{f}:"
      raise
    end
  end
end