Class: ReduxGen::Template

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(component, name) ⇒ Template

Returns a new instance of Template.



5
6
7
8
# File 'lib/redux_gen/template.rb', line 5

def initialize(component, name)
  @renderer = Template.renderer_for component
  @name = Validations.sanitize component, name
end

Instance Attribute Details

#nameObject

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



18
19
20
# File 'lib/redux_gen/template.rb', line 18

def self.path component
  "#{template_directory}/#{component}.js.erb"
end

.renderer_for(component) ⇒ Object



22
23
24
# File 'lib/redux_gen/template.rb', line 22

def self.renderer_for component
  ERB.new(open(Template.path(component)).read)
end

.template_directoryObject



14
15
16
# File 'lib/redux_gen/template.rb', line 14

def self.template_directory
  File.expand_path("../../../template", __FILE__)
end

Instance Method Details

#renderObject



10
11
12
# File 'lib/redux_gen/template.rb', line 10

def render
  @renderer.result(binding)
end