Module: Skyline::Rendering::Helpers::RendererHelper

Defined in:
lib/skyline/rendering/helpers/renderer_helper.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

Deprecated.

Don’t use the name of the object anymore, use ‘renderer.object` instead.

Simple, quick ‘n dirty solution so you can use ’acticle_version’, ‘news_item’, .. in all your templates. So you don’t have to use @.… or pass the local to all partials.



141
142
143
144
# File 'lib/skyline/rendering/helpers/renderer_helper.rb', line 141

def method_missing(method, *params, &block)
  return @_local_object if @_local_object_name == method
  super
end

Instance Method Details

#assign(key, value = nil) { ... } ⇒ Object

Set global renderer assigns. These are accessible throughout all render/render_collection calls. They are especially usefull in scenarios where you want a sub-item render a piece of the page. You can assign it to ‘:content_for_sidebar` and in your page template you can read `assigns(:content_for_sidebar)` and place the content the content item rendered to the variable `:content_for_sidebar`

Parameters:

  • key (Symbol)

    The key to store or read

  • value (Object) (defaults to: nil)

    Anything you want to store, if empty and no block given this method just returns the stored value

Yields:

  • A block to capture, see also the ‘capture` documentation in Rails

Yield Returns:

  • (String)

    The result of doing a regular ‘capture`

Returns:

  • The value stored with the key.



18
19
20
21
22
23
24
25
# File 'lib/skyline/rendering/helpers/renderer_helper.rb', line 18

def assign(key, value = nil, &block)
  return @_template_assigns[key] if value.nil? && !block_given?
  if block_given?
    @_template_assigns[key] = capture(&block)
  else
    @_template_assigns[key] = value
  end
end

#cookiesObject

See Also:

  • ActionController::Cookies#cookies


80
81
82
# File 'lib/skyline/rendering/helpers/renderer_helper.rb', line 80

def cookies
  @_controller.cookies
end

#flashObject



91
92
93
# File 'lib/skyline/rendering/helpers/renderer_helper.rb', line 91

def flash
  @_controller.send(:flash)
end

#form_authenticity_tokenObject

See Also:

  • ActionController::RequestForgeryProtection#form_authenticity_token


133
134
135
# File 'lib/skyline/rendering/helpers/renderer_helper.rb', line 133

def form_authenticity_token
  @_controller.send(:form_authenticity_token)
end

#paramsObject

See Also:

  • ActionController::Request#params


75
76
77
# File 'lib/skyline/rendering/helpers/renderer_helper.rb', line 75

def params
  @_controller.params
end

#peek(n = 1, &block) ⇒ Object

See Also:



45
46
47
# File 'lib/skyline/rendering/helpers/renderer_helper.rb', line 45

def peek(n=1, &block)
  renderer.peek(n, &block)
end

#peek_until(&block) ⇒ Object

See Also:

  • Renderer#peek_until}


50
51
52
# File 'lib/skyline/rendering/helpers/renderer_helper.rb', line 50

def peek_until(&block)
  renderer.peek_until(&block)
end

#protect_against_forgery?Boolean

Returns:

  • (Boolean)

See Also:

  • ActionController::RequestForgeryProtection#protect_against_forgery?


123
124
125
# File 'lib/skyline/rendering/helpers/renderer_helper.rb', line 123

def protect_against_forgery?
  @_controller.send(:protect_against_forgery?)
end

#render_collection(objects, options = {}, &block) ⇒ Object



40
41
42
# File 'lib/skyline/rendering/helpers/renderer_helper.rb', line 40

def render_collection(objects, options = {},&block)
  renderer.render_collection(objects, options, &block)
end

#render_object(object, options = {}) ⇒ Object

See Also:



35
36
37
# File 'lib/skyline/rendering/helpers/renderer_helper.rb', line 35

def render_object(object, options = {})
  renderer.render(object, options)
end

#render_until(&block) ⇒ Object



55
56
57
# File 'lib/skyline/rendering/helpers/renderer_helper.rb', line 55

def render_until(&block)
  renderer.render_until(&block)
end

#rendererSkyline::Rendering::Renderer

Get’s the current Renderer instance that is rendering the template we’re in.

Returns:



30
31
32
# File 'lib/skyline/rendering/helpers/renderer_helper.rb', line 30

def renderer
  @_renderer
end

#requestObject

The request that’s currently being processed

Returns:

  • ActiveRecord::Request



87
88
89
# File 'lib/skyline/rendering/helpers/renderer_helper.rb', line 87

def request
  @_controller.request
end

#request_forgery_protection_tokenObject

See Also:

  • ActionController::RequestForgeryProtection#request_forgery_protection_token


128
129
130
# File 'lib/skyline/rendering/helpers/renderer_helper.rb', line 128

def request_forgery_protection_token
  @_controller.request_forgery_protection_token
end

#sessionObject

See Also:

  • ActionController::Request#session


70
71
72
# File 'lib/skyline/rendering/helpers/renderer_helper.rb', line 70

def session
  @_controller.session
end

#siteObject

The site that’s currently in scope for this template

Returns:

  • Skyline::Site



98
99
100
# File 'lib/skyline/rendering/helpers/renderer_helper.rb', line 98

def site
  @_site
end

#skip!(n = 1) ⇒ Object

See Also:



60
61
62
# File 'lib/skyline/rendering/helpers/renderer_helper.rb', line 60

def skip!(n=1)
  renderer.skip!(n)
end

#skip_until!(&block) ⇒ Object



65
66
67
# File 'lib/skyline/rendering/helpers/renderer_helper.rb', line 65

def skip_until!(&block)
  renderer.skip_until!(&block)
end

#url_for(options = {}) ⇒ Object

See Also:

  • ActionView::Helpers::UrlHelper#url_for


103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/skyline/rendering/helpers/renderer_helper.rb', line 103

def url_for(options = {})
  options ||= {}
  url = case options
  when String
    super
  when Hash
    options = { :only_path => options[:host].nil? }.update(options.symbolize_keys)
    escape  = options.key?(:escape) ? options.delete(:escape) : true
    @_controller.send(:url_for, options)
  when :back
    escape = false
    @_controller.request.env["HTTP_REFERER"] || 'javascript:history.back()'
  else
    super
  end

  escape ? escape_once(url) : url
end