Module: Sablon::Content

Included in:
HTML, String, WordML
Defined in:
lib/sablon/content.rb

Defined Under Namespace

Classes: HTML, Image, String, WordML

Class Method Summary collapse

Class Method Details

.make(type_id, *args) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/sablon/content.rb', line 19

def make(type_id, *args)
  if types.key?(type_id)
    types[type_id].new(*args)
  else
    raise ArgumentError, "Could not find Sablon content type with id '#{type_id}'"
  end
end

.register(content_type) ⇒ Object



27
28
29
# File 'lib/sablon/content.rb', line 27

def register(content_type)
  types[content_type.id] = content_type
end

.remove(content_type_or_id) ⇒ Object



31
32
33
# File 'lib/sablon/content.rb', line 31

def remove(content_type_or_id)
  types.delete_if {|k,v| k == content_type_or_id || v == content_type_or_id }
end

.wrap(value) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/sablon/content.rb', line 6

def wrap(value)
  case value
  when Sablon::Content
    value
  else
    if type = type_wrapping(value)
      type.new(value)
    else
      raise ArgumentError, "Could not find Sablon content type to wrap #{value.inspect}"
    end
  end
end