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

Instance Method Details

#blog(options = nil) ⇒ BlogData

Get the BlogData for this site.

Returns:



180
181
182
# File 'lib/middleman-blog/extension_3_0.rb', line 180

def blog(options=nil)
  @_blog ||= BlogData.new(self, options)
end

#blog_day_path(year, month, day) ⇒ String

Get a path to the given day-based calendar page, based on the :day_link setting.

Parameters:

  • year (Number)
  • month (Number)
  • day (Number)

Returns:

  • (String)


224
225
226
# File 'lib/middleman-blog/extension_3_0.rb', line 224

def blog_day_path(year, month, day)
  sitemap.find_resource_by_path(CalendarPages.link(self.blog.options, 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.

Parameters:

  • year (Number)
  • month (Number)

Returns:

  • (String)


215
216
217
# File 'lib/middleman-blog/extension_3_0.rb', line 215

def blog_month_path(year, month)
  sitemap.find_resource_by_path(CalendarPages.link(self.blog.options, 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.

Parameters:

  • year (Number)

Returns:

  • (String)


207
208
209
# File 'lib/middleman-blog/extension_3_0.rb', line 207

def blog_year_path(year)
  sitemap.find_resource_by_path(CalendarPages.link(self.blog.options, year)).try(:url)
end

#current_articleMiddleman::Sitemap::Resource

Get a Resource with mixed in BlogArticle methods representing the current article.

Returns:

  • (Middleman::Sitemap::Resource)


193
194
195
# File 'lib/middleman-blog/extension_3_0.rb', line 193

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.

Returns:

  • (Boolean)


187
188
189
# File 'lib/middleman-blog/extension_3_0.rb', line 187

def is_blog_article?
  !current_article.nil?
end

#page_articlesArray<Middleman::Sitemap::Resource>

Returns the list of articles to display on this page.

Returns:

  • (Array<Middleman::Sitemap::Resource>)


239
240
241
242
243
244
245
# File 'lib/middleman-blog/extension_3_0.rb', line 239

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

#paginateBoolean

Returns true if pagination is turned on for this template; false otherwise.

Returns:

  • (Boolean)


235
# File 'lib/middleman-blog/extension_3_0.rb', line 235

def paginate; false; end

#tag_path(tag) ⇒ String

Get a path to the given tag, based on the :taglink setting.

Parameters:

  • tag (String)

Returns:

  • (String)


200
201
202
# File 'lib/middleman-blog/extension_3_0.rb', line 200

def tag_path(tag)
  sitemap.find_resource_by_path(TagPages.link(self.blog.options, tag)).try(:url)
end