Class: Brock::FieldTemplate
- Inherits:
-
Object
- Object
- Brock::FieldTemplate
- Defined in:
- lib/brock/field_template.rb
Instance Attribute Summary collapse
-
#field ⇒ Object
readonly
Returns the value of attribute field.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(field) ⇒ FieldTemplate
constructor
A new instance of FieldTemplate.
- #path ⇒ Object
-
#raw ⇒ Object
private.
- #render(value = nil) ⇒ Object
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
#field ⇒ Object (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_path ⇒ Object
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.('../../../share', __FILE__) end |
Instance Method Details
#path ⇒ Object
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 |
#raw ⇒ Object
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 |