Class: Amber::Render::View

Inherits:
Object
  • Object
show all
Includes:
BlogHelper, HtmlHelper, LanguageHelper, NavigationHelper, HamlHelper
Defined in:
lib/amber/render/view.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BlogHelper

#recent_summaries

Methods included from LanguageHelper

#available_languages, #t, #translation_missing?

Methods included from HamlHelper

#content_tag, #haml

Methods included from NavigationHelper

#child_summaries, #current_page_path, #has_navigation?, #menu_item_title, #navigation_items, #render_page_summary, #top_navigation_items

Methods included from HtmlHelper

#amber_path, #html_head_base, #link, #link_to, #time_tag

Constructor Details

#initialize(page, site) ⇒ View

Returns a new instance of View.



29
30
31
32
33
34
35
36
# File 'lib/amber/render/view.rb', line 29

def initialize(page, site)
  @page = page
  @site = site
  @stack = []
  @locals = {}
  @this = StaticPage::PropertySet.new # TODO: come up with a better way to handle this.
                                      # @this is not actually used, it is just there so haml headers don't bomb out.
end

Instance Attribute Details

#localsObject (readonly)

Returns the value of attribute locals.



18
19
20
# File 'lib/amber/render/view.rb', line 18

def locals
  @locals
end

#pageObject (readonly)

Returns the value of attribute page.



19
20
21
# File 'lib/amber/render/view.rb', line 19

def page
  @page
end

#siteObject (readonly)

Returns the value of attribute site.



20
21
22
# File 'lib/amber/render/view.rb', line 20

def site
  @site
end

Instance Method Details

#render(options = {}, locals = {}, toc_only = false, &block) ⇒ Object

more or less the same as Rails render()

supported options:

:page      -- page path or page object to render
:file      -- generic file to render, disables layout or toc.
              type determined by suffix or :type
:partial   -- same as :file, but searches for files with leading _
:text      -- string to render
:type      -- the format of the input, required for :text


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/amber/render/view.rb', line 49

def render(options={}, locals={}, toc_only=false, &block)
  push_context @locals, @page
  if options.is_a?(Hash) && options[:locals].is_a?(Hash)
    locals   = options.delete(:locals)
  end
  @locals    = @locals.merge(locals)
  locale     = I18n.locale = @locals[:locale]
  options    = parse_render_options(locale, options)
  @page      = options[:page] if options[:page]
  render_toc = should_render_toc?(locale, options, @page)
  template   = pick_template(locale, options)
  return unless template
  if toc_only
    template.render(self, :mode => :toc, :href_base => options[:href_base])
  else
    layout = pick_layout(locale, options)
    if layout
      layout.render(self) do |layout_yield_argument|
        template.render(self, :mode => layout_yield_argument, :toc => render_toc)
      end
    else
      template.render(self, :mode => :content, :toc => render_toc)
    end
  end
rescue StandardError => exc
  if @site.continue_on_error
    report_error(exc, options)
  else
    raise exc
  end
ensure
  @locals, @page = pop_context
  I18n.locale = @locals[:locale]
end

#render_toc(options = {}, locals = {}) ⇒ Object



84
85
86
# File 'lib/amber/render/view.rb', line 84

def render_toc(options={}, locals={})
  render(options, locals, true)
end