Module: Padrino::Rendering::ClassMethods
- Defined in:
- lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/application/rendering.rb
Overview
Class methods responsible for rendering templates as part of a request.
Instance Method Summary collapse
-
#cache_template_file!(template_file, render_options) ⇒ Object
Caches the template file for the given rendering options.
-
#fetch_layout_path(given_layout = nil) ⇒ Object
Returns the cached layout path.
-
#fetch_template_file(render_options) ⇒ Object
Returns the cached template file to render for a given url, content_type and locale.
-
#layout(name = :layout) { ... } ⇒ Object
Use layout like rails does or if a block given then like sinatra.
Instance Method Details
#cache_template_file!(template_file, render_options) ⇒ Object
Caches the template file for the given rendering options
112 113 114 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/application/rendering.rb', line 112 def cache_template_file!(template_file, ) (@_cached_templates ||= {})[] = template_file || [] end |
#fetch_layout_path(given_layout = nil) ⇒ Object
Returns the cached layout path.
122 123 124 125 126 127 128 129 130 131 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/application/rendering.rb', line 122 def fetch_layout_path(given_layout=nil) layout_name = given_layout || @layout || :application @_cached_layout ||= {} cached_layout_path = @_cached_layout[layout_name] return cached_layout_path if cached_layout_path has_layout_at_root = Dir["#{views}/#{layout_name}.*"].any? layout_path = has_layout_at_root ? layout_name.to_sym : File.join('layouts', layout_name.to_s).to_sym @_cached_layout[layout_name] = layout_path unless reload_templates? layout_path end |
#fetch_template_file(render_options) ⇒ Object
Returns the cached template file to render for a given url, content_type and locale.
100 101 102 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/application/rendering.rb', line 100 def fetch_template_file() (@_cached_templates ||= {})[] end |
#layout(name = :layout) { ... } ⇒ Object
Use layout like rails does or if a block given then like sinatra. If used without a block, sets the current layout for the route.
By default, searches in your:
app
/views
/layouts
/application
.(haml
|erb
|xxx
) app
/views
/layout_name
.(haml
|erb
|xxx
)
If you define layout
:custom
then searches for your layouts in app
/views
/layouts
/custom
.(haml
|erb
|xxx
) app
/views
/custom
.(haml
|erb
|xxx
)
90 91 92 93 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/application/rendering.rb', line 90 def layout(name=:layout, &block) return super(name, &block) if block_given? @layout = name end |