Class: Brock::FieldTemplate

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field) ⇒ FieldTemplate

Returns a new instance of FieldTemplate.



14
15
16
# File 'lib/brock/field_template.rb', line 14

def initialize(field)
  @field = field
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



12
13
14
# File 'lib/brock/field_template.rb', line 12

def field
  @field
end

Class Method Details

.share_pathObject



7
8
9
10
# File 'lib/brock/field_template.rb', line 7

def self.share_path
  # __FILE__ is a special variable that is inlined at compile time so its value is this path to this file, not a subclasses'.
  File.expand_path('../../../share', __FILE__)
end

Instance Method Details

#pathObject



29
30
31
# File 'lib/brock/field_template.rb', line 29

def path
  File.join(self.class.share_path, "#{field.class.type}_field.erb")
end

#rawObject

private



25
26
27
# File 'lib/brock/field_template.rb', line 25

def raw
  File.read(path)
end

#render(value = nil) ⇒ Object



18
19
20
21
# File 'lib/brock/field_template.rb', line 18

def render(value = nil)
  ctx = FieldTemplateContext.new(@field, value)
  ERB.new(raw).result(ctx.binding)
end