Class: JekyllPagesApi::Page
- Inherits:
-
Object
- Object
- JekyllPagesApi::Page
- Defined in:
- lib/jekyll_pages_api/page.rb
Overview
wrapper for a Jekyll::Page
Constant Summary collapse
- HTML_EXTS =
%w(.html .md .markdown .textile).to_set
Instance Attribute Summary collapse
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#site ⇒ Object
readonly
Returns the value of attribute site.
Instance Method Summary collapse
- #base_url ⇒ Object
- #body_text ⇒ Object
- #filterer ⇒ Object
- #html? ⇒ Boolean
-
#initialize(page, site) ⇒ Page
constructor
Jekyll::StaticFile doesn't expose a
siteaccessor, so we require an explicitsiteargument here. - #rel_path ⇒ Object
- #skip_index? ⇒ Boolean
- #tags ⇒ Object
- #title ⇒ Object
- #to_json ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(page, site) ⇒ Page
Jekyll::StaticFile doesn't expose a site accessor, so we require an
explicit site argument here.
11 12 13 14 |
# File 'lib/jekyll_pages_api/page.rb', line 11 def initialize(page, site) @page = page @site = site end |
Instance Attribute Details
#page ⇒ Object (readonly)
Returns the value of attribute page.
7 8 9 |
# File 'lib/jekyll_pages_api/page.rb', line 7 def page @page end |
#site ⇒ Object (readonly)
Returns the value of attribute site.
7 8 9 |
# File 'lib/jekyll_pages_api/page.rb', line 7 def site @site end |
Instance Method Details
#base_url ⇒ Object
31 32 33 |
# File 'lib/jekyll_pages_api/page.rb', line 31 def base_url self.site.baseurl end |
#body_text ⇒ Object
45 46 47 48 49 |
# File 'lib/jekyll_pages_api/page.rb', line 45 def body_text output = self.page.content if self.page.respond_to?(:content) output ||= File.read(self.page.path) self.filterer.text_only(output) end |
#filterer ⇒ Object
21 22 23 |
# File 'lib/jekyll_pages_api/page.rb', line 21 def filterer @filterer ||= Filters.new end |
#html? ⇒ Boolean
16 17 18 19 |
# File 'lib/jekyll_pages_api/page.rb', line 16 def html? path = self.page.path path.end_with?('/') || HTML_EXTS.include?(File.extname(path)) end |
#rel_path ⇒ Object
35 36 37 38 39 |
# File 'lib/jekyll_pages_api/page.rb', line 35 def rel_path path = self.page.url if self.page.respond_to?(:url) path ||= self.page.relative_path if self.page.respond_to?(:relative_path) path end |
#skip_index? ⇒ Boolean
55 56 57 |
# File 'lib/jekyll_pages_api/page.rb', line 55 def skip_index? (self.page.data['skip_index'] if self.page.respond_to?(:data)) || false end |
#tags ⇒ Object
51 52 53 |
# File 'lib/jekyll_pages_api/page.rb', line 51 def (self.page.data['tags'] if self.page.respond_to?(:data)) || [] end |
#title ⇒ Object
25 26 27 28 29 |
# File 'lib/jekyll_pages_api/page.rb', line 25 def title title = self.page.data['title'] if self.page.respond_to?(:data) title ||= self.page.title if self.page.respond_to?(:title) self.filterer.decode_html(title || '') end |
#to_json ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/jekyll_pages_api/page.rb', line 59 def to_json optional = {} optional['skip_index'] = true if self.skip_index? optional.merge({ title: self.title, url: self.url, tags: self., body: self.body_text }) end |
#url ⇒ Object
41 42 43 |
# File 'lib/jekyll_pages_api/page.rb', line 41 def url [self.base_url, rel_path].join end |