Class: Yuzu::Core::Layout
- Inherits:
-
HamlTemplate
- Object
- Template
- HamlTemplate
- Yuzu::Core::Layout
- Defined in:
- lib/yuzu/core/layout.rb
Overview
A Layout is a Template that lays out an entire page. It consists of a collection of partial templates, namely for the HTML <head>, but also for a page header, footer, and navigation menu. In the future, this will be generalized.
Class Method Summary collapse
-
.get_partials ⇒ Object
Calculates the Hash for self.partials.
-
.partial_filenames ⇒ Hash
A hash of partial name to filename.
-
.partials ⇒ Hash
A hash of partial name to the corresponding HamlTemplate object for that partial.
Instance Method Summary collapse
-
#layout_locals(website_file) ⇒ Hash
A Hash of all the local variables passed into the Haml engine when the layout is rendered.
-
#render(website_file) ⇒ String
Actually renders the layout for the given file.
Methods inherited from HamlTemplate
Methods inherited from Template
#contents, #exists?, #fallback_exists?, #fallback_path, #get_contents, #get_template_contents, #initialize, #path
Constructor Details
This class inherits a constructor from Yuzu::Core::Template
Class Method Details
.get_partials ⇒ Object
Calculates the Hash for self.partials.
30 31 32 33 34 35 36 37 |
# File 'lib/yuzu/core/layout.rb', line 30 def self.get_partials tr = {} partial_filenames.each do |filename| partial_name = filename[1...-5] tr[partial_name] = HamlTemplate.new(filename) end tr end |
.partial_filenames ⇒ Hash
A hash of partial name to filename.
16 17 18 19 20 |
# File 'lib/yuzu/core/layout.rb', line 16 def self.partial_filenames relative_paths = Dir[(@@template_dir + "*").to_s] files = relative_paths.collect {|p| File.basename(p)} files.select {|filename| filename[0].chr == "_"} end |
.partials ⇒ Hash
A hash of partial name to the corresponding HamlTemplate object for that partial.
25 26 27 |
# File 'lib/yuzu/core/layout.rb', line 25 def self.partials @@partials ||= get_partials end |
Instance Method Details
#layout_locals(website_file) ⇒ Hash
A Hash of all the local variables passed into the Haml engine when the layout is rendered.
43 44 45 |
# File 'lib/yuzu/core/layout.rb', line 43 def layout_locals(website_file) {:layout => PageLayout.new(website_file, Layout.partials)} end |
#render(website_file) ⇒ String
Actually renders the layout for the given file.
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/yuzu/core/layout.rb', line 51 def render(website_file) # Contains the standard local variables `post` and `config`. local_variables = locals(website_file) # Add `layout` to the mix. layout_local_variables = layout_locals(website_file) engine.render( Yuzu::Core::TemplateMethods.new(website_file.root), local_variables.merge(layout_local_variables) ) end |