class Parade::TemplateGenerator

TemplateGenator uses ERB to generate a template and uses itself as the reference as the binding. This template generator is being used primarily as a way to generate static versions of the content in HTML.

When created an :erb_template_file needs to be specified in the Hash, all other fields are dependent on what is contained within the template itself

Public Instance Methods

css(*filepaths) click to toggle source

Return stylesheet to be inlined in a template

@param [String] filepath the filepath to the stylesheet file @return [String] HTML content that is inlined stylesheet data

# File lib/parade/helpers/template_generator.rb, line 41
def css(*filepaths)
  filepaths.map {|filepath| css_template(filepath).render }.join("\n")
end
css_template(filepath) click to toggle source

@param [String] filepath the filepath to load

# File lib/parade/helpers/template_generator.rb, line 18
def css_template(filepath)
  CSSTemplateGenerator.new :filepath => filepath
end
custom_css_files() click to toggle source
# File lib/parade/helpers/template_generator.rb, line 45
def custom_css_files
  if custom_asset_path
    Dir.glob("#{custom_asset_path}**/*.css").map do |path|
      css_template(path).render
    end.join("\n")
  end
end
erb(filepath) click to toggle source

To provide support of having references to other templates, this will handle erb method calls and in-line that template’s content

@param [Strign] filepath the filepath to another template @return [String] HTML content of the specfied template at the filepath

# File lib/parade/helpers/template_generator.rb, line 68
def erb(filepath)
  template_filepath = File.join File.dirname(erb_template_file), "#{filepath}.erb"
  template_file = ERB.new File.read(template_filepath)
  template_file.result(binding)
end
js(*filepaths) click to toggle source

Return javascript to be inlined in a template

@param [String] filepath the filepath to the javascript file @return [String] HTML content that is inlined javascript data

# File lib/parade/helpers/template_generator.rb, line 31
def js(*filepaths)
  filepaths.map {|filepath| js_template(filepath).render }.join("\n")
end
js_template(filepath) click to toggle source
# File lib/parade/helpers/template_generator.rb, line 22
def js_template(filepath)
  JSTemplateGenerator.new :filepath => filepath
end
render() click to toggle source

@return [Types] the HTML content of the template specified

# File lib/parade/helpers/template_generator.rb, line 77
def render
  template_file = ERB.new File.read(erb_template_file)
  template_file.result(binding)
end
theme_css() click to toggle source

This helper method is called within the header to return the theme specified by the preseation

# File lib/parade/helpers/template_generator.rb, line 57
def theme_css
  css("themes/#{presentation.theme}.css") if presentation.theme
end