Module: Jets::Controller::Rendering
- Includes:
- Redirection
- Included in:
- Base
- Defined in:
- lib/jets/controller/rendering/rack_renderer.rb,
lib/jets/controller/rendering.rb
Overview
Special renderer. All the other renderers lead here
Defined Under Namespace
Classes: RackRenderer
Instance Method Summary collapse
-
#actual_host ⇒ Object
Actual host can be headers when cloudfront is in front.
-
#add_stage_name(url) ⇒ Object
Add API Gateway Stage Name.
- #adjust_content_type!(options) ⇒ Object
- #default_layout ⇒ Object
- #ensure_render ⇒ Object
- #managed_options ⇒ Object
-
#normalize_options(options, rest) ⇒ Object
Can normalize the options when it is a String or a Symbol Also set defaults here like the layout.
-
#render(options = {}, rest = {}) ⇒ Object
Many different ways to render:.
- #url_for(url) ⇒ Object
Methods included from Redirection
#ensure_protocol, #redirect_back, #redirect_to
Instance Method Details
#actual_host ⇒ Object
Actual host can be headers when cloudfront is in front. Remember to set custom header “origin” header in cloudfront distribution. Can also override with Jets.config.app.domain. The actual_host value is used by redirect_to.
78 79 80 |
# File 'lib/jets/controller/rendering.rb', line 78 def actual_host Jets.config.app.domain || headers["origin"] || headers["host"] end |
#add_stage_name(url) ⇒ Object
Add API Gateway Stage Name
64 65 66 67 68 |
# File 'lib/jets/controller/rendering.rb', line 64 def add_stage_name(url) return url unless actual_host Jets::Controller::Stage.add(actual_host, url) end |
#adjust_content_type!(options) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/jets/controller/rendering.rb', line 35 def adjust_content_type!() if .key?(:json) [:content_type] = "application/json" elsif .key?(:xml) [:content_type] = "application/xml" end end |
#default_layout ⇒ Object
50 51 52 53 |
# File 'lib/jets/controller/rendering.rb', line 50 def default_layout application_layout_exist = !Dir.glob("#{Jets.root}/app/views/layouts/application*").empty? "application" if application_layout_exist end |
#ensure_render ⇒ Object
5 6 7 8 9 10 |
# File 'lib/jets/controller/rendering.rb', line 5 def ensure_render return @rendered_data if @rendered # defaults to rendering templates RackRenderer.new(self, ).render end |
#managed_options ⇒ Object
43 44 45 46 47 48 |
# File 'lib/jets/controller/rendering.rb', line 43 def layout = self.class.layout.nil? ? default_layout : self.class.layout = { layout: layout } [:headers] = response.headers unless response.headers.empty? end |
#normalize_options(options, rest) ⇒ Object
Can normalize the options when it is a String or a Symbol Also set defaults here like the layout. Ensure options is a Hash, not a String or Symbol.
58 59 60 61 |
# File 'lib/jets/controller/rendering.rb', line 58 def (, rest) template = .to_s rest.merge(template: template) end |
#render(options = {}, rest = {}) ⇒ Object
Many different ways to render:
render "articles/index", layout: "application"
render :new
render template: "articles/index", layout: "application"
render json: {my: "data"}
render text: "plain text"
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/jets/controller/rendering.rb', line 19 def render(={}, rest={}) raise "DoubleRenderError" if @rendered if .is_a?(Symbol) or .is_a?(String) = (, rest) end .reverse_merge!() adjust_content_type!() @rendered_data = RackRenderer.new(self, ).render @rendered = true @rendered_data end |
#url_for(url) ⇒ Object
70 71 72 |
# File 'lib/jets/controller/rendering.rb', line 70 def url_for(url) add_stage_name(url) end |