Class: Bop::BlockType

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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, options = {})
  options = options.symbolize_keys
  @name = name
  @@types.push self
  @@type_lookup[@name] = self
end

Instance Attribute Details

#nameObject (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