Class: MovableErb::Erb

Inherits:
Object
  • Object
show all
Defined in:
lib/movable_erb.rb

Overview

Convenience class to setup and parse data with an ERB template.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dataObject

Returns the value of attribute data.



90
91
92
# File 'lib/movable_erb.rb', line 90

def data
  @data
end

#parsed_stringObject

Returns the value of attribute parsed_string.



90
91
92
# File 'lib/movable_erb.rb', line 90

def parsed_string
  @parsed_string
end

#templateObject

Returns the value of attribute template.



90
91
92
# File 'lib/movable_erb.rb', line 90

def template
  @template
end

Class Method Details

.setup {|erb| ... } ⇒ MovableErb::Erb

Creates a new instance and allow manipulation of it via block.

This can be used to initialize and parse quickly.

Examples:

Create a new instance, setup and build the template

@erb = MovableErb::Erb.setup do |erb|
  erb.data = {'hash' => 'of', 'meaningful' => 'values'}
  erb.template = "path/to/template.erb"
  erb.build!
end

Yields:

Returns:



106
107
108
109
110
# File 'lib/movable_erb.rb', line 106

def self.setup
  erb = self.new
  yield erb
  erb
end

Instance Method Details

#build!String

Using the specified template, this will parse the template

Returns:

  • (String)

    the parsed template



124
125
126
127
# File 'lib/movable_erb.rb', line 124

def build!
  erb = ERB.new(template, nil, '<>')
  @parsed_string = erb.result(binding) if erb
end