Class: Hermeneutics::Html::Generator
- Inherits:
-
Object
- Object
- Hermeneutics::Html::Generator
- Defined in:
- lib/hermeneutics/html.rb
Instance Attribute Summary collapse
-
#assign_attributes ⇒ Object
Returns the value of attribute assign_attributes.
-
#cdata_block ⇒ Object
Returns the value of attribute cdata_block.
-
#close_standalone ⇒ Object
Returns the value of attribute close_standalone.
Instance Method Summary collapse
- #comment(str) ⇒ Object
- #doctype(*args) ⇒ Object
- #encoding ⇒ Object
- #file_path ⇒ Object
-
#initialize(out) ⇒ Generator
constructor
A new instance of Generator.
- #merge(str) ⇒ Object
-
#pi_tag(tag, attrs = nil) ⇒ Object
Processing Instruction.
- #plain(str) ⇒ Object
-
#tag(tag, type, attrs = nil) ⇒ Object
nls 0 = no newline 1 = newline after 2 = newline after both 3 = and advance indent 4 = Block without any indent.
- #verbose_block(str) ⇒ Object
Constructor Details
Instance Attribute Details
#assign_attributes ⇒ Object
Returns the value of attribute assign_attributes.
108 109 110 |
# File 'lib/hermeneutics/html.rb', line 108 def assign_attributes @assign_attributes end |
#cdata_block ⇒ Object
Returns the value of attribute cdata_block.
108 109 110 |
# File 'lib/hermeneutics/html.rb', line 108 def cdata_block @cdata_block end |
#close_standalone ⇒ Object
Returns the value of attribute close_standalone.
108 109 110 |
# File 'lib/hermeneutics/html.rb', line 108 def close_standalone @close_standalone end |
Instance Method Details
#comment(str) ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/hermeneutics/html.rb', line 198 def comment str if str =~ /\A.*\z/ then brace_comment do @out << " " << str << " " end else brace_comment do brk out_brk str do_ind end end end |
#doctype(*args) ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/hermeneutics/html.rb', line 185 def doctype *args brace true do @out << "!DOCTYPE" args.each { |x| @out << " " if x =~ /\W/ then @out << '"' << (@ent.encode x) << '"' else @out << x end } end end |
#encoding ⇒ Object
114 115 116 117 118 119 |
# File 'lib/hermeneutics/html.rb', line 114 def encoding case @out when IO then @out.external_encoding||Encoding.default_external else @out.encoding end end |
#file_path ⇒ Object
120 121 122 123 |
# File 'lib/hermeneutics/html.rb', line 120 def file_path @out.path rescue NoMethodError end |
#merge(str) ⇒ Object
124 125 126 127 |
# File 'lib/hermeneutics/html.rb', line 124 def merge str do_ind @out << str end |
#pi_tag(tag, attrs = nil) ⇒ Object
Processing Instruction
174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/hermeneutics/html.rb', line 174 def pi_tag tag, attrs = nil tag = tag.to_s brace true do begin @out << "?" << tag mkattrs attrs ensure @out << " ?" end end end |
#plain(str) ⇒ Object
128 129 130 131 |
# File 'lib/hermeneutics/html.rb', line 128 def plain str do_ind @out << (@ent.encode str) end |
#tag(tag, type, attrs = nil) ⇒ Object
nls 0 = no newline 1 = newline after 2 = newline after both 3 = and advance indent 4 = Block without any indent
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/hermeneutics/html.rb', line 138 def tag tag, type, attrs = nil tag = tag.to_s nls = type & 0xf if (type & 0x10).nonzero? then brace nls>0 do @out << tag mkattrs attrs @out << " /" if @close_standalone end else begin brk if nls>1 brace nls>1 do @out << tag mkattrs attrs end if nls>3 then verbose_block yield else indent_if nls>2 do if block_given? then r = yield plain r if String === r end end end ensure brk if nls>1 brace nls>0 do @out << "/" << tag end end end nil end |
#verbose_block(str) ⇒ Object
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/hermeneutics/html.rb', line 211 def verbose_block str if @cdata_block then @out << "/* " brace false do @out << "![CDATA[" @out << " */\n" @out << str @out << "\n/* " @out << "]]" end @out << " */" else out_brk str end end |