Class: Plate::View

Inherits:
Object
  • Object
show all
Includes:
BloggingHelper, MetaHelper, PartialsHelper, URLHelper
Defined in:
lib/plate/view.rb

Overview

Views are utility classes that are only called within a page or layout file to be able to access site or page specific variables.

All default helpers as well as any custom helpers are automatically included into each view and are accessible within your pages.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from URLHelper

#absolutize_paths, #sanitize_slug

Methods included from PartialsHelper

#render

Methods included from MetaHelper

#description?, #keywords, #keywords?, #meta_description_tag, #meta_keywords_tag, #meta_tags, #title?

Methods included from BloggingHelper

#category_archives, #html_escape, #month_name, #next_post, #post_count, #post_index, #posts_for_category, #posts_for_month, #posts_for_year, #previous_post, #years_for_category

Constructor Details

#initialize(site, page) ⇒ View

Create a new view by passing in the current site and page instance.



21
22
23
24
# File 'lib/plate/view.rb', line 21

def initialize(site, page)
  @site = site
  @page = page
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

Allow this class to pass through to access attributes on the page



62
63
64
65
66
# File 'lib/plate/view.rb', line 62

def method_missing(method, *args, &block)
  self.page.send(method, *args, &block)
rescue NoMethodError
  super
end

Instance Attribute Details

#pagePage (readonly)

Returns The current page (or post) being rendered.

Returns:

  • (Page)

    The current page (or post) being rendered.



14
15
16
# File 'lib/plate/view.rb', line 14

def page
  @page
end

#siteSite (readonly)

Returns The current site build.

Returns:

  • (Site)

    The current site build.



17
18
19
# File 'lib/plate/view.rb', line 17

def site
  @site
end

Instance Method Details

#assetsArray

The full list of assets for this site.

Returns:

  • (Array)


29
30
31
# File 'lib/plate/view.rb', line 29

def assets
  self.site.assets
end

#inspectString

Dump out information about this view.

Returns:

  • (String)


36
37
38
# File 'lib/plate/view.rb', line 36

def inspect
  "#<#{self.class}:0x#{object_id.to_s(16)} site=#{site ? site.source : nil} page=#{page ? page.file : nil}>"
end

#pagesArray

Reference to all pages and static files in this site.

Returns:

  • (Array)


43
44
45
# File 'lib/plate/view.rb', line 43

def pages
  self.site.pages
end

#postPost, Page

Reference to the current post, if this view is rendered with a blog post.

Returns:



50
51
52
# File 'lib/plate/view.rb', line 50

def post
  self.page
end

#postsPostCollection

Reference to all posts in this site.

Returns:



57
58
59
# File 'lib/plate/view.rb', line 57

def posts
  self.site.posts
end