module Sablon::Content
Public Class Methods
make(type_id, *args)
click to toggle source
# 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)
click to toggle source
# File lib/sablon/content.rb, line 27 def register(content_type) types[content_type.id] = content_type end
remove(content_type_or_id)
click to toggle source
# 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)
click to toggle source
# 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
Private Class Methods
type_wrapping(value)
click to toggle source
# File lib/sablon/content.rb, line 36 def type_wrapping(value) types.values.reverse.detect { |type| type.wraps?(value) } end
types()
click to toggle source
# File lib/sablon/content.rb, line 40 def types @types ||= {} end