Class: Templette::Page
- Inherits:
-
Object
- Object
- Templette::Page
- Includes:
- DataAccessors
- Defined in:
- lib/templette/page.rb
Overview
The Page is the core object of a Templette project. Pages won’t get generate unless there are available .yml files to build out the necessary info.
A general Page yaml structure example:
template_name: main
sections:
title: Page Title
nav:
active-class: foo
title: Foo!
The template_name
will be used to load a template.
Everything in sections
will be made available as methods in the template when it’s evaluated by ERB. Yaml hash items nested within others will be loaded into nested objects. To call the nav title, the template should call nav.title
.
Defined Under Namespace
Classes: Section
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Class Method Summary collapse
-
.find_all ⇒ Object
Grabs all of the yaml files found in /pages, and loads them as Page objects.
- .pages_dir ⇒ Object
- .pages_dir=(path) ⇒ Object
Instance Method Summary collapse
- #_binding ⇒ Object
- #generate(out_dir) ⇒ Object
-
#initialize(page_config) ⇒ Page
constructor
A new instance of Page.
-
#page ⇒ Object
A requriement of the Templette::DataAccessors interface.
Methods included from DataAccessors
#attributes, #generate_accessors, #image_tag, #include_helpers, #method_missing, #partial, #script_tag, #stylesheet_tag
Constructor Details
#initialize(page_config) ⇒ Page
Returns a new instance of Page.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/templette/page.rb', line 42 def initialize(page_config) raise PageError.new(self, "missing page #{page_config}") unless File.exists?(page_config) data = YAML::load_file(page_config) @name = page_config.dup @name.slice!(self.class.pages_dir + '/') @name.chomp!('.yml') raise PageError.new(self, "missing required section \"template_name\" for page config #{page_config}") unless data['template_name'] @template = Template.new(data['template_name']) raise PageError.new(self, "missing sections in yml for page config #{page_config}") unless data['sections'] generate_accessors(data['sections']) include_helpers(template.helpers) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Templette::DataAccessors
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
24 25 26 |
# File 'lib/templette/page.rb', line 24 def name @name end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
24 25 26 |
# File 'lib/templette/page.rb', line 24 def template @template end |
Class Method Details
.find_all ⇒ Object
Grabs all of the yaml files found in /pages, and loads them as Page objects.
37 38 39 |
# File 'lib/templette/page.rb', line 37 def find_all Dir["#{pages_dir}/**/*.yml"].map {|f| new f } end |
.pages_dir ⇒ Object
27 28 29 |
# File 'lib/templette/page.rb', line 27 def pages_dir @@pages_dir ||= 'pages' end |
.pages_dir=(path) ⇒ Object
31 32 33 |
# File 'lib/templette/page.rb', line 31 def pages_dir=(path) @@pages_dir = path end |
Instance Method Details
#_binding ⇒ Object
64 |
# File 'lib/templette/page.rb', line 64 def _binding; binding; end |
#generate(out_dir) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/templette/page.rb', line 57 def generate(out_dir) generate_subdirectory(out_dir) File.open(output_file_name(out_dir), 'w') do |f| f << @template.render(binding) end end |
#page ⇒ Object
A requriement of the Templette::DataAccessors interface. Returns self.
67 |
# File 'lib/templette/page.rb', line 67 def page; self end |