Module: Fortitude::Widget::Doctypes::ClassMethods

Defined in:
lib/fortitude/widget/doctypes.rb

Instance Method Summary collapse

Instance Method Details

#doctype(new_doctype = nil) ⇒ Object

PUBLIC API


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fortitude/widget/doctypes.rb', line 23

def doctype(new_doctype = nil)
  if new_doctype
    new_doctype = case new_doctype
    when Fortitude::Doctypes::Base then new_doctype
    when Symbol then Fortitude::Doctypes.standard_doctype(new_doctype)
    else raise ArgumentError, "You must supply a Symbol or an instance of Fortitude::Doctypes::Base, not: #{new_doctype.inspect}"
    end

    current_doctype = doctype
    if current_doctype
      if new_doctype != current_doctype
        raise ArgumentError, "The doctype has already been set to #{current_doctype} on this widget class or a superclass. You can't set it to #{new_doctype}; if you want to use a different doctype, you will need to make a new subclass that has no doctype set yet."
      end
    end

    if new_doctype.close_void_tags_must_be != nil
      self.close_void_tags(new_doctype.close_void_tags_must_be)
    end

    @_fortitude_doctype = new_doctype
    tags_added!(new_doctype.tags.values)
  else
    return @_fortitude_doctype if @_fortitude_doctype
    return superclass.doctype if superclass.respond_to?(:doctype)
    nil
  end
end