Class: Parade::Section

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_classesArray<String>

Returns an array of css classes names

Returns:

  • (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

#descriptionString

Returns the description of the section.

Returns:

  • (String)

    the description of the section



37
38
39
# File 'lib/parade/section.rb', line 37

def description
  @description
end


159
160
161
162
# File 'lib/parade/section.rb', line 159

def footer
  footer_erb = ERB.new File.read(@footer || default_footer)
  footer_erb.result(binding)
end

#pause_messageString

Returns the pause message for the section, if none has been specified the default pause message is returned.

Returns:

  • (String)

    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
  @pause_message || default_pause_message
end

#post_renderersArray<#render> (readonly)

Returns a list of Renderers that will perform their renderering on the slides after the slides have all habe been rendered.

Returns:

  • (Array<#render>)

    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

#sectionSection

Returns the parent section of this section. nil if this is a root section.

Returns:

  • (Section)

    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

#sectionsArray<#slides> (readonly)

Returns an array of a Section objects or array of Slide objects.

Returns:

  • (Array<#slides>)

    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

#themeObject

Note:

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

#titleString

Returns the title of the section.

Returns:

  • (String)

    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

Parameters:

  • renderer (#render)

    add a renderer, any object responding to #render, that will process the slides HTML content.



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.

Parameters:

  • content (Section, Array<Section>)

    this any section that you want to add 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.

Parameters:

  • content (Slide, Array<Slide>)

    this any section that you want to add to this section.



77
78
79
80
81
82
83
84
85
# File 'lib/parade/section.rb', line 77

def add_slides(slides)
  sub_slides = Array(slides).compact.flatten.map do |slide|
    slide.section = self
    slide
  end

  @sections = @sections + sub_slides
  sub_slides
end

#add_template(template_name, template_filepath) ⇒ Object

Examples:

'opening' would be the template name and 'custom_template.erb'

would be the template filename.

  section "Introduction" do
    template "opening", "custom_template.erb"
  end

Parameters:

  • template_name (String)

    the name of the template which it is referred to by the slides.

  • template_filepath (Types)

    the filepath to the template to be loaded



100
101
102
# File 'lib/parade/section.rb', line 100

def add_template(template_name,template_filepath)
  @templates[template_name] = template_filepath
end


164
165
166
# File 'lib/parade/section.rb', line 164

def default_footer
  File.join(File.dirname(__FILE__), "..", "views", "footer.erb")
end

#default_pause_messageObject



153
154
155
# File 'lib/parade/section.rb', line 153

def default_pause_message
  ""
end

#default_templateString

Returns the filepath of the default slide template.

Returns:

  • (String)

    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

#hierarchyArray<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.

Returns:

  • (Array<String>)

    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.

Parameters:

  • template_name (String)

    the name of the template

  • use_default_when_nil (Boolean) (defaults to: true)

    if while searching for the template it should use the parent section's default template. This usually wants to be false when looking for a specific template.

Returns:

  • (String)

    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

#resourcesObject



168
169
170
# File 'lib/parade/section.rb', line 168

def resources
  @resources || []
end

#slidesArray<Slide>

Returns the slides contained within this section and any sub-section.

Returns:

  • (Array<Slide>)

    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 slides
  sections_slides = sections.map do |section_or_slide|
    section_or_slide.slides
  end.flatten

  # Update the sequence on all the slides for the entire section.
  sections_slides.each_with_index {|slide,count| slide.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.

Parameters:

  • template_name (String)

    the name of the template to retrieve.

Returns:

  • (String)

    the filepath to the template, given the template name.



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.

Returns:

  • (String)

    HTML representation of the section



206
207
208
209
210
211
212
# File 'lib/parade/section.rb', line 206

def to_html(options = {})
  slides.map do |section_or_slide|
    post_renderers.inject(section_or_slide.to_html) do |content,renderer|
      renderer.render(content,options)
    end
  end.join("\n")
end