Module: SelfRenderer
- Defined in:
- lib/self_renderer.rb,
lib/self_renderer/version.rb
Constant Summary collapse
- VERSION =
"0.1.1"
Instance Method Summary collapse
-
#render_to_hash(template: nil, partial: nil, assigns: {}, locals: {}) ⇒ Object
Returns a Hash representation of this object as rendered by #render_to_json.
-
#render_to_html(template: nil, partial: nil, assigns: {}, locals: {}) ⇒ Object
Renders an HTML string reprsenting this object.
-
#render_to_json(template: nil, partial: nil, assigns: {}, locals: {}) ⇒ Object
Renders a JSON string reprsenting this object.
Instance Method Details
#render_to_hash(template: nil, partial: nil, assigns: {}, locals: {}) ⇒ Object
Returns a Hash representation of this object as rendered by #render_to_json
19 20 21 |
# File 'lib/self_renderer.rb', line 19 def render_to_hash(template: nil, partial: nil, assigns: {}, locals: {}) JSON.load render_to_json(template: template, partial: partial, assigns: assigns, locals: locals) end |
#render_to_html(template: nil, partial: nil, assigns: {}, locals: {}) ⇒ Object
Renders an HTML string reprsenting this object
7 8 9 10 |
# File 'lib/self_renderer.rb', line 7 def render_to_html(template: nil, partial: nil, assigns: {}, locals: {}) return render_self template: "#{template}.html", assigns: assigns, locals: locals if template.present? render_self partial: "#{partial}.html", assigns: assigns, locals: locals end |
#render_to_json(template: nil, partial: nil, assigns: {}, locals: {}) ⇒ Object
Renders a JSON string reprsenting this object
13 14 15 16 |
# File 'lib/self_renderer.rb', line 13 def render_to_json(template: nil, partial: nil, assigns: {}, locals: {}) return render_self template: "#{template}.json", assigns: assigns, locals: locals if template.present? render_self partial: "#{partial}.json", assigns: assigns, locals: locals end |