Method: Docgenerator::Element.create
- Defined in:
- lib/docgenerator/compatibility_v1.rb
.create(name, attr = {}, content = false, output = {}) ⇒ Object
Generic creation of a new class to define a new element.
-
name must be defined.
-
attr is a hash with all attributes.
For details see Element.add_attributes
-
content is a flag, which defines if the element contains “content”.
Valid values are:
- true: content available and necessary (e.g. <p>)
- :empty_ok: content available, but not necessary (e.g. <td> or iframe)
- false: no content, no endtag, but tag closed with / (example: <br />)
- nil: no content, no endtag, no closing (example: <br>)
-
output contains a hash with logic, how to handle the output.
-:htmltag Tag for html-output.
-:latex Template for LaTeX-output
-:html Template for HTML-output
This code is obsolete. Please use Element.create_convert_to_code to get a template to replace your Element#create.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/docgenerator/compatibility_v1.rb', line 104 def self.create( name, attr = {}, content = false, output = {} ) DOCGENERATOR_LOGGER.warn("Element.create called -> to be replaced") if DOCGENERATOR_LOGGER.warn? create_convert_to_code( [name].flatten, attr, content, output ) if DOCGENERATOR_LOGGER.warn? #First some checks if ! attr.kind_of?( Hash ) raise "Type error Element.create: Expected Hash, get #{attr.class}" end #Generic class creation elementclass = Class.new( Element ) #Add the id of the new class to central collection. Element.add( name, elementclass ) #Set a flag, if the class can contain 'content'. #-true: content available and necessary (e.g. <p>) #-:empty_ok: content available, but not necessary (e.g. <td>) #-false: no content, no endtag, but tag closed with / (example: <br />) #-nil: no content, no endtag, no closing (example: <br>) elementclass.class_eval( %Q| def content?() return #{content.inspect} end|) output.each{ |k,v| case k when :latex elementclass.add_output( :latex, v ) when :context elementclass.add_output( :context, v ) when :html elementclass.add_output( :html, v ) when :text elementclass.add_output( :text, v ) when :wiki elementclass.add_output( :wiki, v ) when :creole elementclass.add_output( :creole, v ) when :htmltag if v elementclass.class_eval( "def htmltag()\n'#{v}'\nend" ) else elementclass.class_eval( "def htmltag()\nnil\nend" ) end else puts "#{__FILE__}##{__LINE__}: Unknown format #{k} for #{name}" end } elementclass.add_attributes( attr ) #Return the class. return elementclass end |