Class: Bop::BlockType
- Inherits:
-
Object
- Object
- Bop::BlockType
- Defined in:
- app/models/bop/block_type.rb
Overview
At the moment block types are just parameterised template-finders.
Constant Summary collapse
- @@types =
[]
- @@type_lookup =
{}
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name, options = {}) ⇒ BlockType
constructor
A new instance of BlockType.
- #template(name) ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ BlockType
Returns a new instance of BlockType.
10 11 12 13 14 15 |
# File 'app/models/bop/block_type.rb', line 10 def initialize(name, = {}) = .symbolize_keys @name = name @@types.push self @@type_lookup[@name] = self end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'app/models/bop/block_type.rb', line 8 def name @name end |
Instance Method Details
#template(name) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/models/bop/block_type.rb', line 17 def template(name) unless @templates[name] # Here we will need to support various file types and should probably just hook into ActionView. That's going to be fun. tpl = null [Bop::Engine.root, Rails.root].each do |root| if !tpl && File.exist(root + "app/views/bop/block_types/#{name}.liquid") tpl = File.read(root + "app/views/bop/block_types/#{name}.liquid") end end raise Bop::MissingTemplateError unless tpl @templates[name] = Liquid::Template.parse(tpl) end @templates[name] end |