Class: ReduxGen::Template
- Inherits:
-
Object
- Object
- ReduxGen::Template
- Defined in:
- lib/redux_gen/template.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(component, name) ⇒ Template
constructor
A new instance of Template.
- #render ⇒ Object
Constructor Details
#initialize(component, name) ⇒ Template
Returns a new instance of Template.
18 19 20 21 22 23 |
# File 'lib/redux_gen/template.rb', line 18 def initialize(component, name) Template.validate component raw_template = open(Template.path(component)).read @renderer = ERB.new(raw_template) @name = name end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/redux_gen/template.rb', line 3 def name @name end |
Class Method Details
.path(component) ⇒ Object
14 15 16 |
# File 'lib/redux_gen/template.rb', line 14 def self.path component "#{template_directory}/#{component}.js.erb" end |
.template_directory ⇒ Object
5 6 7 |
# File 'lib/redux_gen/template.rb', line 5 def self.template_directory File.("../../../template", __FILE__) end |
.validate(component) ⇒ Object
9 10 11 12 |
# File 'lib/redux_gen/template.rb', line 9 def self.validate component components = ["action", "component", "reducer", "middleware"] raise ArgumentError unless components.include? component end |
Instance Method Details
#render ⇒ Object
25 26 27 |
# File 'lib/redux_gen/template.rb', line 25 def render @renderer.result(binding) end |