Class: Parade::Section
- Inherits:
-
Object
- Object
- Parade::Section
- Defined in:
- lib/parade/section.rb
Overview
A Parade presentation is composed of a Section that may also be composed of many slides and sub-sections (child sections) of slides.
Instance Attribute Summary collapse
-
#css_classes ⇒ Array<String>
Returns an array of css classes names.
-
#description ⇒ String
The description of the section.
- #footer ⇒ Object
-
#pause_message ⇒ String
The pause message for the section, if none has been specified the default pause message is returned.
-
#post_renderers ⇒ Array<#render>
readonly
Returns a list of Renderers that will perform their renderering on the slides after the slides have all habe been rendered.
-
#section ⇒ Section
The parent section of this section.
-
#sections ⇒ Array<#slides>
readonly
Returns an array of a Section objects or array of Slide objects.
-
#theme ⇒ Object
Allows for the scene to have a theme defined for it.
-
#title ⇒ String
The title of the section.
Instance Method Summary collapse
- #add_post_renderer(renderer) ⇒ Object
- #add_resource(resource_filepath) ⇒ Object
-
#add_section(sub_sections) ⇒ Object
Append sections to this section.
-
#add_slides(slides) ⇒ Object
Append slides to this setion.
- #add_template(template_name, template_filepath) ⇒ Object
- #default_footer ⇒ Object
- #default_pause_message ⇒ Object
-
#default_template ⇒ String
The filepath of the default slide template.
-
#hierarchy ⇒ Array<String>
The name of all the parent sections.
-
#initialize(params = {}) ⇒ Section
constructor
A new instance of Section.
-
#parent_section_template(template_name, use_default_when_nil = true) ⇒ String
The filepath of the parent section template.
- #resources ⇒ Object
-
#slides ⇒ Array<Slide>
The slides contained within this section and any sub-section.
-
#template(template_name, use_default_when_nil = true) ⇒ String
Given the template name return the template file name associated with it.
-
#to_html(options = {}) ⇒ String
HTML representation of the section.
Constructor Details
#initialize(params = {}) ⇒ Section
Returns a new instance of Section.
11 12 13 14 15 16 17 18 |
# File 'lib/parade/section.rb', line 11 def initialize(params = {}) @description = "" @post_renderers = [] @sections = [] @templates = {} params.each {|k,v| send("#{k}=",v) if respond_to? "#{k}=" } end |
Instance Attribute Details
#css_classes ⇒ Array<String>
Returns an array of css classes names
52 53 54 |
# File 'lib/parade/section.rb', line 52 def css_classes @css_classes || [] end |
#description ⇒ String
Returns the description of the section.
37 38 39 |
# File 'lib/parade/section.rb', line 37 def description @description end |
#footer ⇒ Object
159 160 161 162 |
# File 'lib/parade/section.rb', line 159 def = ERB.new File.read(@footer || ) .result(binding) end |
#pause_message ⇒ String
Returns the pause message for the section, if none has been specified the default pause message is returned.
149 150 151 |
# File 'lib/parade/section.rb', line 149 def @pause_message || end |
#post_renderers ⇒ Array<#render> (readonly)
Returns a list of Renderers that will perform their renderering on the slides after the slides have all habe been rendered.
195 196 197 |
# File 'lib/parade/section.rb', line 195 def post_renderers @post_renderers end |
#section ⇒ Section
Returns the parent section of this section. nil if this is a root section.
45 46 47 |
# File 'lib/parade/section.rb', line 45 def section @section end |
#sections ⇒ Array<#slides> (readonly)
Returns an array of a Section objects or array of Slide objects.
41 42 43 |
# File 'lib/parade/section.rb', line 41 def sections @sections end |
#theme ⇒ Object
this is only respected by the top-level scene in the presentation
Allows for the scene to have a theme defined for it.
179 180 181 |
# File 'lib/parade/section.rb', line 179 def theme @theme end |
#title ⇒ String
Returns the title of the section.
24 25 26 |
# File 'lib/parade/section.rb', line 24 def title @title ? @title : (section ? section.title : "Section") end |
Instance Method Details
#add_post_renderer(renderer) ⇒ Object
201 202 203 |
# File 'lib/parade/section.rb', line 201 def add_post_renderer(renderer) @post_renderers << renderer end |
#add_resource(resource_filepath) ⇒ Object
172 173 174 175 |
# File 'lib/parade/section.rb', line 172 def add_resource(resource_filepath) @resources ||= [] @resources << resource_filepath end |
#add_section(sub_sections) ⇒ Object
Append sections to this section.
62 63 64 65 66 67 68 69 |
# File 'lib/parade/section.rb', line 62 def add_section(sub_sections) sub_sections = Array(sub_sections).compact.flatten.map do |sub_section| sub_section.section = self sub_section end @sections = @sections + sub_sections sub_sections end |
#add_slides(slides) ⇒ Object
Append slides to this setion.
77 78 79 80 81 82 83 84 85 |
# File 'lib/parade/section.rb', line 77 def () = Array().compact.flatten.map do || .section = self end @sections = @sections + end |
#add_template(template_name, template_filepath) ⇒ Object
100 101 102 |
# File 'lib/parade/section.rb', line 100 def add_template(template_name,template_filepath) @templates[template_name] = template_filepath end |
#default_footer ⇒ Object
164 165 166 |
# File 'lib/parade/section.rb', line 164 def File.join(File.dirname(__FILE__), "..", "views", "footer.erb") end |
#default_pause_message ⇒ Object
153 154 155 |
# File 'lib/parade/section.rb', line 153 def "" end |
#default_template ⇒ String
Returns the filepath of the default slide template.
117 118 119 |
# File 'lib/parade/section.rb', line 117 def default_template File.join(File.dirname(__FILE__), "..", "views", "slide.erb") end |
#hierarchy ⇒ Array<String>
Returns the name of all the parent sections. In this instance we are not interested in sections without names. These are the lowest level sections and are usually within a parent section that they are acurrately named.
32 33 34 |
# File 'lib/parade/section.rb', line 32 def hierarchy Array(@title) + (section ? section.hierarchy : []) end |
#parent_section_template(template_name, use_default_when_nil = true) ⇒ String
Returns the filepath of the parent section template.
111 112 113 |
# File 'lib/parade/section.rb', line 111 def parent_section_template(template_name,use_default_when_nil=true) section.template(template_name,use_default_when_nil) if section end |
#resources ⇒ Object
168 169 170 |
# File 'lib/parade/section.rb', line 168 def resources @resources || [] end |
#slides ⇒ Array<Slide>
Returns the slides contained within this section and any sub-section.
183 184 185 186 187 188 189 190 |
# File 'lib/parade/section.rb', line 183 def = sections.map do || . end.flatten # Update the sequence on all the slides for the entire section. .each_with_index {|,count| .sequence = (count + 1) } end |
#template(template_name, use_default_when_nil = true) ⇒ String
Given the template name return the template file name associated with it. When a template is not found with the name within the section, the section traverses parent sections until it is found.
A default template can be defined for a section which it will default to when no template name has been specified or the template name could not be found. Again the parent sections will be traversed if they have a default template.
When there is no template specified or found within then it will default to the original slide template.
138 139 140 141 142 |
# File 'lib/parade/section.rb', line 138 def template(template_name,use_default_when_nil = true) template_for_name = @templates[template_name] || parent_section_template(template_name,false) template_for_name = (@templates['default'] || parent_section_template('default')) unless template_for_name and use_default_when_nil template_for_name || default_template end |
#to_html(options = {}) ⇒ String
Returns HTML representation of the section.
206 207 208 209 210 211 212 |
# File 'lib/parade/section.rb', line 206 def to_html( = {}) .map do || post_renderers.inject(.to_html) do |content,renderer| renderer.render(content,) end end.join("\n") end |