Class: Msgtrail::PartialRenderer

Inherits:
Object
  • Object
show all
Includes:
RenderHelper
Defined in:
lib/msgtrail/renderers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RenderHelper

#as_rfc3339, #now_as_rfc3339, #titlecase, #xml_safe

Constructor Details

#initialize(partial_filepath, variables, config) ⇒ PartialRenderer

Returns a new instance of PartialRenderer.



95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/msgtrail/renderers.rb', line 95

def initialize(partial_filepath, variables, config)
  begin
    self.partial = File.read(partial_filepath)
  rescue
    puts("Can't find '#{partial_filepath}' (#{$!})")
    exit(2)
  end
  self.config = config
  self.markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, fenced_code_blocks: true, strikethrough: true)
  self.plaintext = Redcarpet::Markdown.new(Redcarpet::Render::StripDown)
  self.variables = variables
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(missing_method_name, *args, &block) ⇒ Object



108
109
110
111
112
113
114
# File 'lib/msgtrail/renderers.rb', line 108

def method_missing(missing_method_name, *args, &block)
  if 'cfg' == missing_method_name.to_s
    self.config.settings
  else
    super
  end
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



93
94
95
# File 'lib/msgtrail/renderers.rb', line 93

def config
  @config
end

#markdownObject

Returns the value of attribute markdown.



93
94
95
# File 'lib/msgtrail/renderers.rb', line 93

def markdown
  @markdown
end

#partialObject

Returns the value of attribute partial.



93
94
95
# File 'lib/msgtrail/renderers.rb', line 93

def partial
  @partial
end

#plaintextObject

Returns the value of attribute plaintext.



93
94
95
# File 'lib/msgtrail/renderers.rb', line 93

def plaintext
  @plaintext
end

#variablesObject

Returns the value of attribute variables.



93
94
95
# File 'lib/msgtrail/renderers.rb', line 93

def variables
  @variables
end

Instance Method Details

#renderObject



116
117
118
# File 'lib/msgtrail/renderers.rb', line 116

def render
  ERB.new(self.partial).result(binding)
end