Module: Middleman::Blog::Helpers
- Defined in:
- lib/middleman-blog/extension_3_0.rb
Overview
Helpers for use within templates and layouts.
Instance Method Summary collapse
-
#blog(options = nil) ⇒ BlogData
Get the BlogData for this site.
-
#blog_day_path(year, month, day) ⇒ String
Get a path to the given day-based calendar page, based on the :day_link setting.
-
#blog_month_path(year, month) ⇒ String
Get a path to the given month-based calendar page, based on the :month_link setting.
-
#blog_year_path(year) ⇒ String
Get a path to the given year-based calendar page, based on the :year_link setting.
-
#current_article ⇒ Middleman::Sitemap::Resource
Get a Resource with mixed in BlogArticle methods representing the current article.
-
#is_blog_article? ⇒ Boolean
Determine whether the currently rendering template is a blog article.
-
#page_articles ⇒ Array<Middleman::Sitemap::Resource>
Returns the list of articles to display on this page.
-
#paginate ⇒ Boolean
Returns true if pagination is turned on for this template; false otherwise.
-
#tag_path(tag) ⇒ String
Get a path to the given tag, based on the :taglink setting.
Instance Method Details
#blog(options = nil) ⇒ BlogData
Get the BlogData for this site.
153 154 155 |
# File 'lib/middleman-blog/extension_3_0.rb', line 153 def blog(=nil) @_blog ||= BlogData.new(self, ) end |
#blog_day_path(year, month, day) ⇒ String
Get a path to the given day-based calendar page, based on the :day_link setting.
197 198 199 |
# File 'lib/middleman-blog/extension_3_0.rb', line 197 def blog_day_path(year, month, day) sitemap.find_resource_by_path(CalendarPages.link(self.blog., year, month, day)).try(:url) end |
#blog_month_path(year, month) ⇒ String
Get a path to the given month-based calendar page, based on the :month_link setting.
188 189 190 |
# File 'lib/middleman-blog/extension_3_0.rb', line 188 def blog_month_path(year, month) sitemap.find_resource_by_path(CalendarPages.link(self.blog., year, month)).try(:url) end |
#blog_year_path(year) ⇒ String
Get a path to the given year-based calendar page, based on the :year_link setting.
180 181 182 |
# File 'lib/middleman-blog/extension_3_0.rb', line 180 def blog_year_path(year) sitemap.find_resource_by_path(CalendarPages.link(self.blog., year)).try(:url) end |
#current_article ⇒ Middleman::Sitemap::Resource
Get a Resource with mixed in BlogArticle methods representing the current article.
166 167 168 |
# File 'lib/middleman-blog/extension_3_0.rb', line 166 def current_article blog.article(current_resource.path) end |
#is_blog_article? ⇒ Boolean
Determine whether the currently rendering template is a blog article. This can be useful in layouts.
160 161 162 |
# File 'lib/middleman-blog/extension_3_0.rb', line 160 def is_blog_article? !current_article.nil? end |
#page_articles ⇒ Array<Middleman::Sitemap::Resource>
Returns the list of articles to display on this page.
212 213 214 215 216 217 218 |
# File 'lib/middleman-blog/extension_3_0.rb', line 212 def page_articles limit = (current_resource.[:page]["per_page"] || 0) - 1 # "articles" local variable is populated by Calendar and Tag page generators # If it's not set then use the complete list of articles (current_resource.[:locals]["articles"] || blog.articles)[0..limit] end |
#paginate ⇒ Boolean
Returns true if pagination is turned on for this template; false otherwise.
208 |
# File 'lib/middleman-blog/extension_3_0.rb', line 208 def paginate; false; end |
#tag_path(tag) ⇒ String
Get a path to the given tag, based on the :taglink setting.
173 174 175 |
# File 'lib/middleman-blog/extension_3_0.rb', line 173 def tag_path(tag) sitemap.find_resource_by_path(TagPages.link(self.blog., tag)).try(:url) end |