Module: Middleman::BlogPage::BlogPageArticle
- Defined in:
- lib/middleman-blog_page/blog_page_article.rb
Overview
A module that adds blog_page-article methods to Resources.
Class Method Summary collapse
Instance Method Summary collapse
- #blog_options ⇒ Object
- #blog_page_data ⇒ Object
-
#body ⇒ String
The body of this article, in HTML.
- #inspect ⇒ Object
-
#path_part(part) ⇒ String
Retrieve a section of the source path.
-
#priority ⇒ Integer
The “priority” of the article make how order articles.
-
#published? ⇒ Boolean
Whether or not this article has been published.
-
#render(opts = {}, locs = {}, &block) ⇒ String
Render this resource.
-
#slug ⇒ String
The “slug” of the article that shows up in its URL.
-
#title ⇒ String
The title of the article, set from frontmatter.
Class Method Details
.extended(base) ⇒ Object
8 9 10 |
# File 'lib/middleman-blog_page/blog_page_article.rb', line 8 def self.extended(base) base.class.send(:attr_accessor, :blog_page_controller) end |
Instance Method Details
#blog_options ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/middleman-blog_page/blog_page_article.rb', line 20 def if self.blog_page_controller self.blog_page_controller. else app.blog_page. end end |
#blog_page_data ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/middleman-blog_page/blog_page_article.rb', line 12 def blog_page_data if self.blog_page_controller self.blog_page_controller.data else app.blog_page end end |
#body ⇒ String
The body of this article, in HTML. This is for things like RSS feeds or lists of articles - individual articles will automatically be rendered from their template.
65 66 67 |
# File 'lib/middleman-blog_page/blog_page_article.rb', line 65 def body render(:layout => false) end |
#inspect ⇒ Object
97 98 99 |
# File 'lib/middleman-blog_page/blog_page_article.rb', line 97 def inspect "#<Middleman::BlogPage::BlogPageArticle: #{data.inspect}>" end |
#path_part(part) ⇒ String
Retrieve a section of the source path
72 73 74 75 |
# File 'lib/middleman-blog_page/blog_page_article.rb', line 72 def path_part(part) @_path_parts ||= blog_page_data.path_matcher.match(path).captures @_path_parts[blog_page_data.matcher_indexes[part]] end |
#priority ⇒ Integer
The “priority” of the article make how order articles
93 94 95 |
# File 'lib/middleman-blog_page/blog_page_article.rb', line 93 def priority @_priority ||= data["priority"].to_i end |
#published? ⇒ Boolean
Whether or not this article has been published
An article is considered published in the following scenarios:
-
frontmatter does not set published to false and either
-
published_future_dated is true or
-
article date is after the current time
56 57 58 |
# File 'lib/middleman-blog_page/blog_page_article.rb', line 56 def published? data["published"] != false end |
#render(opts = {}, locs = {}, &block) ⇒ String
Render this resource
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/middleman-blog_page/blog_page_article.rb', line 30 def render(opts={}, locs={}, &block) if opts[:layout].nil? if [:options] && ![:options][:layout].nil? opts[:layout] = [:options][:layout] end opts[:layout] = .layout if opts[:layout].nil? opts[:layout] = opts[:layout].to_s if opts[:layout].is_a? Symbol end super(opts, locs, &block) end |
#slug ⇒ String
The “slug” of the article that shows up in its URL.
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/middleman-blog_page/blog_page_article.rb', line 79 def slug @_slug ||= data["slug"] @_slug ||= if .sources.include?(":title") path_part("title") elsif title title.parameterize else raise "Can't generate a slug for #{path} because it has no :title in its path pattern or title/slug in its frontmatter." end end |
#title ⇒ String
The title of the article, set from frontmatter
44 45 46 |
# File 'lib/middleman-blog_page/blog_page_article.rb', line 44 def title data["title"] end |