Class: DapperDan::HTML

Inherits:
Object
  • Object
show all
Defined in:
lib/dapper-dan/tag.rb,
lib/dapper-dan/html.rb,
lib/dapper-dan/tags/html.rb

Direct Known Subclasses

HTML4, HTML4Strict, HTML4Transitional, HTML5

Defined Under Namespace

Classes: A, Abbr, Address, Area, B, Base, Blockquote, Body, Br, Button, Caption, Cite, Code, Colgroup, DD, Del, Dfn, Div, Dl, Dt, Edit, Em, Embedded, Fieldset, Form, Forms, Grouping, H1, H2, H3, H4, H5, H6, Head, Hr, I, Iframe, Img, Input, Ins, Interactive, Kbd, Label, Legend, Li, Link, Map, Menu, Meta, Metadata, Noscript, Object, Ol, Optgroup, Option, P, Param, Pre, Q, Root, S, Samp, Script, Scripting, Sections, Select, Small, Span, Strong, Style, Sub, Sup, Table, Tabular, Tag, Tbody, Td, Text, Textarea, Tfoot, Th, Thead, Title, Tr, U, Ul, Var

Constant Summary

DEFAULTS =
{
  :to_html => true,
  :validate => true,
  :root => false
}

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (HTML) initialize

A new instance of HTML



11
12
13
14
# File 'lib/dapper-dan/html.rb', line 11

def initialize
  @content ||= []
  @parent  ||= self
end

Instance Attribute Details

- (Object) content

Returns the value of attribute content



3
4
5
# File 'lib/dapper-dan/html.rb', line 3

def content
  @content
end

- (Object) document

Returns the value of attribute document



3
4
5
# File 'lib/dapper-dan/html.rb', line 3

def document
  @document
end

- (Object) options

Returns the value of attribute options



3
4
5
# File 'lib/dapper-dan/html.rb', line 3

def options
  @options
end

- (Object) parent

Returns the value of attribute parent



3
4
5
# File 'lib/dapper-dan/html.rb', line 3

def parent
  @parent
end

Class Method Details

+ (Object) generate(*args, &block)



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/dapper-dan/html.rb', line 16

def self.generate(*args, &block)
  unless args.first.nil?
    options = DEFAULTS.merge(args.first)
  else
    options = DEFAULTS
  end
  @document ||= self.new
  @document.instance_exec &block
  @document.validate if @options[:validate]
  @document.to_html(options[:root]) if options[:to_html]
end

Instance Method Details

- (Object) abbreviation(*args, &block)



229
230
231
# File 'lib/dapper-dan/tags/html.rb', line 229

def abbreviation(*args, &block)
  tag :Abbr, *args, &block
end

- (Object) address(*args, &block)



99
100
101
# File 'lib/dapper-dan/tags/html.rb', line 99

def address(*args, &block)
  tag :Address, *args, &block
end

- (Object) area(*args, &block)



328
329
330
# File 'lib/dapper-dan/tags/html.rb', line 328

def area(*args, &block)
  tag :Area, *args, &block
end

- (Object) base(*args, &block)



24
25
26
# File 'lib/dapper-dan/tags/html.rb', line 24

def base(*args, &block)
  tag :Base, *args, &block
end

- (Object) blockquote(*args, &block)



131
132
133
# File 'lib/dapper-dan/tags/html.rb', line 131

def blockquote(*args, &block)
  tag :Blockquote, *args, &block
end

- (Object) body(*args, &block)



71
72
73
# File 'lib/dapper-dan/tags/html.rb', line 71

def body(*args, &block)
  tag :Body, *args, &block
end

- (Object) bold(*args, &block)



261
262
263
# File 'lib/dapper-dan/tags/html.rb', line 261

def bold(*args, &block)
  tag :B, *args, &block
end

- (Object) break(*args, &block)



273
274
275
# File 'lib/dapper-dan/tags/html.rb', line 273

def break(*args, &block)
  tag :Br, *args, &block
end

- (Object) button(*args, &block)



420
421
422
# File 'lib/dapper-dan/tags/html.rb', line 420

def button(*args, &block)
  tag :Button, *args, &block
end

- (Object) caption(*args, &block)



349
350
351
# File 'lib/dapper-dan/tags/html.rb', line 349

def caption(*args, &block)
  tag :Caption, *args, &block
end

- (Object) cite(*args, &block)



217
218
219
# File 'lib/dapper-dan/tags/html.rb', line 217

def cite(*args, &block)
  tag :Cite, *args, &block
end

- (Object) code(*args, &block)



233
234
235
# File 'lib/dapper-dan/tags/html.rb', line 233

def code(*args, &block)
  tag :Code, *args, &block
end

- (Object) column_group(*args, &block)



353
354
355
# File 'lib/dapper-dan/tags/html.rb', line 353

def column_group(*args, &block)
  tag :Colgroup, *args, &block
end

- (Object) definition(*args, &block)



155
156
157
# File 'lib/dapper-dan/tags/html.rb', line 155

def definition(*args, &block)
  tag :DD, *args, &block
end

- (Object) definition_group(*args, &block)



225
226
227
# File 'lib/dapper-dan/tags/html.rb', line 225

def definition_group(*args, &block)
  tag :Dfn, *args, &block
end

- (Object) definition_list(*args, &block)



147
148
149
# File 'lib/dapper-dan/tags/html.rb', line 147

def definition_list(*args, &block)
  tag :Dl, *args, &block
end

- (Object) delete(*args, &block)



286
287
288
# File 'lib/dapper-dan/tags/html.rb', line 286

def delete(*args, &block)
  tag :Del, *args, &block
end

- (Object) div(*args, &block)



159
160
161
# File 'lib/dapper-dan/tags/html.rb', line 159

def div(*args, &block)
  tag :Div, *args, &block
end

- (Object) emphasis(*args, &block)



201
202
203
# File 'lib/dapper-dan/tags/html.rb', line 201

def emphasis(*args, &block)
  tag :Em, *args, &block
end

- (Object) fieldset(*args, &block)



404
405
406
# File 'lib/dapper-dan/tags/html.rb', line 404

def fieldset(*args, &block)
  tag :Fieldset, *args, &block
end

- (Object) form(*args, &block)



400
401
402
# File 'lib/dapper-dan/tags/html.rb', line 400

def form(*args, &block)
  tag :Form, *args, &block
end

- (Object) h1(*args, &block)



75
76
77
# File 'lib/dapper-dan/tags/html.rb', line 75

def h1(*args, &block)
  tag :H1, *args, &block
end

- (Object) h2(*args, &block)



79
80
81
# File 'lib/dapper-dan/tags/html.rb', line 79

def h2(*args, &block)
  tag :H2, *args, &block
end

- (Object) h3(*args, &block)



83
84
85
# File 'lib/dapper-dan/tags/html.rb', line 83

def h3(*args, &block)
  tag :H3, *args, &block
end

- (Object) h4(*args, &block)



87
88
89
# File 'lib/dapper-dan/tags/html.rb', line 87

def h4(*args, &block)
  tag :H4, *args, &block
end

- (Object) h5(*args, &block)



91
92
93
# File 'lib/dapper-dan/tags/html.rb', line 91

def h5(*args, &block)
  tag :H5, *args, &block
end

- (Object) h6(*args, &block)



95
96
97
# File 'lib/dapper-dan/tags/html.rb', line 95

def h6(*args, &block)
  tag :H6, *args, &block
end

- (Object) head(*args, &block)



16
17
18
# File 'lib/dapper-dan/tags/html.rb', line 16

def head(*args, &block)
  tag :Head, *args, &block
end

- (Object) iframe(*args, &block)



312
313
314
# File 'lib/dapper-dan/tags/html.rb', line 312

def iframe(*args, &block)
  tag :Iframe, *args, &block
end

- (Object) image(*args, &block)



308
309
310
# File 'lib/dapper-dan/tags/html.rb', line 308

def image(*args, &block)
  tag :Img, *args, &block
end

- (Object) inline_style(*args, &block)



36
37
38
# File 'lib/dapper-dan/tags/html.rb', line 36

def inline_style(*args, &block)
  tag :Style, *args, &block
end

- (Object) input(*args, &block)



416
417
418
# File 'lib/dapper-dan/tags/html.rb', line 416

def input(*args, &block)
  tag :Input, *args, &block
end

- (Object) insert(*args, &block)



282
283
284
# File 'lib/dapper-dan/tags/html.rb', line 282

def insert(*args, &block)
  tag :Ins, *args, &block
end

- (Object) italics(*args, &block)



257
258
259
# File 'lib/dapper-dan/tags/html.rb', line 257

def italics(*args, &block)
  tag :I, *args, &block
end

- (Object) item(*args, &block)



143
144
145
# File 'lib/dapper-dan/tags/html.rb', line 143

def item(*args, &block)
  tag :Li, *args, &block
end

- (Object) keyboard(*args, &block)



245
246
247
# File 'lib/dapper-dan/tags/html.rb', line 245

def keyboard(*args, &block)
  tag :Kbd, *args, &block
end

- (Object) label(*args, &block)



412
413
414
# File 'lib/dapper-dan/tags/html.rb', line 412

def label(*args, &block)
  tag :Label, *args, &block
end

- (Object) legend(*args, &block)



408
409
410
# File 'lib/dapper-dan/tags/html.rb', line 408

def legend(*args, &block)
  tag :Legend, *args, &block
end

- (Object) line(*args, &block)



123
124
125
# File 'lib/dapper-dan/tags/html.rb', line 123

def line(*args, &block)
  tag :Hr, *args, &block
end


28
29
30
# File 'lib/dapper-dan/tags/html.rb', line 28

def link(*args, &block)
  tag :A, *args, &block
end

- (Object) map(*args, &block)



324
325
326
# File 'lib/dapper-dan/tags/html.rb', line 324

def map(*args, &block)
  tag :Map, *args, &block
end


448
449
450
# File 'lib/dapper-dan/tags/html.rb', line 448

def menu(*args, &block)
  tag :Menu, *args, &block
end

- (Object) meta(*args, &block)



32
33
34
# File 'lib/dapper-dan/tags/html.rb', line 32

def meta(*args, &block)
  tag :Meta, *args, &block
end

- (Object) noscript(*args, &block)



49
50
51
# File 'lib/dapper-dan/tags/html.rb', line 49

def noscript(*args, &block)
  tag :Noscript, *args, &block
end

- (Object) object(*args, &block)



316
317
318
# File 'lib/dapper-dan/tags/html.rb', line 316

def object(*args, &block)
  tag :Object, *args, &block
end

- (Object) option(*args, &block)



432
433
434
# File 'lib/dapper-dan/tags/html.rb', line 432

def option(*args, &block)
  tag :Option, *args, &block
end

- (Object) option_group(*args, &block)



428
429
430
# File 'lib/dapper-dan/tags/html.rb', line 428

def option_group(*args, &block)
  tag :Optgroup, *args, &block
end

- (Object) ordered_list(*args, &block)



135
136
137
# File 'lib/dapper-dan/tags/html.rb', line 135

def ordered_list(*args, &block)
  tag :Ol, *args, &block
end

- (Object) para(*args, &block)



119
120
121
# File 'lib/dapper-dan/tags/html.rb', line 119

def para(*args, &block)
  tag :P, *args, &block
end

- (Object) param(*args, &block)



320
321
322
# File 'lib/dapper-dan/tags/html.rb', line 320

def param(*args, &block)
  tag :Param, *args, &block
end

- (Object) preformatted(*args, &block)



127
128
129
# File 'lib/dapper-dan/tags/html.rb', line 127

def preformatted(*args, &block)
  tag :Pre, *args, &block
end

- (Object) quote(*args, &block)



221
222
223
# File 'lib/dapper-dan/tags/html.rb', line 221

def quote(*args, &block)
  tag :Q, *args, &block
end

- (Object) sample(*args, &block)



241
242
243
# File 'lib/dapper-dan/tags/html.rb', line 241

def sample(*args, &block)
  tag :Samp, *args, &block
end

- (Object) script(*args, &block)



45
46
47
# File 'lib/dapper-dan/tags/html.rb', line 45

def script(*args, &block)
  tag :Script, *args, &block
end

- (Object) select(*args, &block)



424
425
426
# File 'lib/dapper-dan/tags/html.rb', line 424

def select(*args, &block)
  tag :Select, *args, &block
end

- (Object) small(*args, &block)



209
210
211
# File 'lib/dapper-dan/tags/html.rb', line 209

def small(*args, &block)
  tag :Small, *args, &block
end

- (Object) span(*args, &block)



269
270
271
# File 'lib/dapper-dan/tags/html.rb', line 269

def span(*args, &block)
  tag :Span, *args, &block
end

- (Object) strike(*args, &block)



213
214
215
# File 'lib/dapper-dan/tags/html.rb', line 213

def strike(*args, &block)
  tag :S, *args, &block
end

- (Object) strong(*args, &block)



205
206
207
# File 'lib/dapper-dan/tags/html.rb', line 205

def strong(*args, &block)
  tag :Strong, *args, &block
end

- (Object) sub(*args, &block)



249
250
251
# File 'lib/dapper-dan/tags/html.rb', line 249

def sub(*args, &block)
  tag :Sub, *args, &block
end

- (Object) sup(*args, &block)



253
254
255
# File 'lib/dapper-dan/tags/html.rb', line 253

def sup(*args, &block)
  tag :Sup, *args, &block
end

- (Object) table(*args, &block)



345
346
347
# File 'lib/dapper-dan/tags/html.rb', line 345

def table(*args, &block)
  tag :Table, *args, &block
end

- (Object) table_body(*args, &block)



357
358
359
# File 'lib/dapper-dan/tags/html.rb', line 357

def table_body(*args, &block)
  tag :Tbody, *args, &block
end

- (Object) table_cell(*args, &block)



373
374
375
# File 'lib/dapper-dan/tags/html.rb', line 373

def table_cell(*args, &block)
  tag :Td, *args, &block
end

- (Object) table_cell_head(*args, &block)



377
378
379
# File 'lib/dapper-dan/tags/html.rb', line 377

def table_cell_head(*args, &block)
  tag :Th, *args, &block
end

- (Object) table_foot(*args, &block)



365
366
367
# File 'lib/dapper-dan/tags/html.rb', line 365

def table_foot(*args, &block)
  tag :Tfoot, *args, &block
end

- (Object) table_header(*args, &block)



361
362
363
# File 'lib/dapper-dan/tags/html.rb', line 361

def table_header(*args, &block)
  tag :Thead, *args, &block
end

- (Object) table_row(*args, &block)



369
370
371
# File 'lib/dapper-dan/tags/html.rb', line 369

def table_row(*args, &block)
  tag :Tr, *args, &block
end

- (Object) tag(tag, *args, &block)



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/dapper-dan/html.rb', line 28

def tag(tag, *args, &block)
  options = args.first

  last_parent = @parent
  node = self.class.const_get(tag).new(self)

  if block_given?
    node.attributes    = options     if options.is_a?(Hash)
    block_value        = instance_exec &block
  else
    node.attributes    = options     if options.is_a?(Hash)
    node.content      << options
  end

  node.content        << block_value if block_value.is_a?(String)
  last_parent.content << node

  @parent = last_parent
end

- (Object) term(*args, &block)



151
152
153
# File 'lib/dapper-dan/tags/html.rb', line 151

def term(*args, &block)
  tag :Dt, *args, &block
end

- (Object) textarea(*args, &block)



436
437
438
# File 'lib/dapper-dan/tags/html.rb', line 436

def textarea(*args, &block)
  tag :Textarea, *args, &block
end

- (Object) title(*args, &block)



20
21
22
# File 'lib/dapper-dan/tags/html.rb', line 20

def title(*args, &block)
  tag :Title, *args, &block
end

- (Object) to_html(has_root)



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/dapper-dan/html.rb', line 48

def to_html(has_root)
  value = @content.map do |node|
    node.is_a?(String) ? node : node.to_tag
  end

  if has_root
    self.class::DOCTYPE +
    "<html>#{value.join}</html>"
  else
    value.join
  end
end

- (Object) underline(*args, &block)



265
266
267
# File 'lib/dapper-dan/tags/html.rb', line 265

def underline(*args, &block)
  tag :U, *args, &block
end

- (Object) unordered_list(*args, &block)



139
140
141
# File 'lib/dapper-dan/tags/html.rb', line 139

def unordered_list(*args, &block)
  tag :Ul, *args, &block
end

- (Object) validate



61
62
63
# File 'lib/dapper-dan/html.rb', line 61

def validate

end

- (Object) variable(*args, &block)



237
238
239
# File 'lib/dapper-dan/tags/html.rb', line 237

def variable(*args, &block)
  tag :Var, *args, &block
end