hermeneutics 1.10 → 1.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -26,7 +26,7 @@ module Hermeneutics
26
26
  # a ":visited", ATTR_COL2, ATTR_DECON
27
27
  # a ":active", ATTR_COL1, ATTR_DECON
28
28
  # a ":focus", ATTR_COL1, ATTR_DECOU
29
- # space
29
+ # skip
30
30
  #
31
31
  # body "#dummy" do
32
32
  # properties background_color: "f7f7f7".to_rgb
@@ -145,22 +145,22 @@ module Hermeneutics
145
145
  def comment str
146
146
  @out << "/*"
147
147
  str = mask_comment str
148
- ml = str =~ %r(#$/)
148
+ ml = str =~ %r(\n)
149
149
  if ml then
150
- @out << $/
150
+ @out << "\n"
151
151
  str.each_line { |l|
152
152
  l.chomp!
153
- @out << " * " << l << $/
153
+ @out << " * " << l << "\n"
154
154
  }
155
155
  else
156
156
  @out << " " << str
157
157
  end
158
158
  @out << " */"
159
- ml and @out << $/
159
+ ml and @out << "\n"
160
160
  end
161
161
 
162
- def space
163
- @out << $/
162
+ def skip
163
+ @out << "\n"
164
164
  end
165
165
 
166
166
  def tag *args
@@ -182,6 +182,8 @@ module Hermeneutics
182
182
  protected_instance_methods + instance_methods)
183
183
  undef_method *m
184
184
 
185
+ private
186
+
185
187
  def method_missing sym, *args, &block
186
188
  if Html::TAGS[ sym] then
187
189
  if args.any? and not Hash === args.first then
@@ -198,6 +200,8 @@ module Hermeneutics
198
200
  end
199
201
  end
200
202
 
203
+ public
204
+
201
205
  def properties *args
202
206
  write @selector.to_s, *args
203
207
  end
@@ -228,15 +232,15 @@ module Hermeneutics
228
232
  args.each { |a| p.update a }
229
233
  @out << sel << " {"
230
234
  nl, ind = if p.size > 1 then
231
- @out << $/
232
- [ $/, INDENT]
235
+ @out << "\n"
236
+ [ "\n", INDENT]
233
237
  else
234
238
  [ " ", " "]
235
239
  end
236
240
  single p do |s|
237
241
  @out << ind << s << nl
238
242
  end
239
- @out << "}" << $/
243
+ @out << "}" << "\n"
240
244
  end
241
245
 
242
246
  def single hash
@@ -12,25 +12,25 @@ require "supplement"
12
12
  :section: Classes definied here
13
13
 
14
14
  Hermeneutics::Entities encodes to and decodes from HTML-Entities
15
- (<code>&amp;</code> etc.)
15
+ (+&amp;+ etc.)
16
16
 
17
17
  Hermeneutics::URLText encodes to and decodes from URLs
18
- (<code>%2d</code> etc.)
18
+ (+%2d+ etc.)
19
19
 
20
20
  Hermeneutics::HeaderExt encodes to and decodes from E-Mail Header fields
21
- (<code>=?UTF-8?Q?=C3=B6?=</code> etc.).
21
+ (+=?UTF-8?Q?=C3=B6?=+ etc.).
22
22
 
23
23
  =end
24
24
 
25
25
  module Hermeneutics
26
26
 
27
- # Translate HTML and XML character entities: <code>"&"</code> to
28
- # <code>"&amp;"</code> and vice versa.
27
+ # Translate HTML and XML character entities: +"&"+ to
28
+ # +"&amp;"+ and vice versa.
29
29
  #
30
30
  # == What actually happens
31
31
  #
32
- # HTML pages usually come in with characters encoded <code>&lt;</code>
33
- # for <code><</code> and <code>&euro;</code> for <code>€</code>.
32
+ # HTML pages usually come in with characters encoded +&lt;+ for +<+ and
33
+ # +&euro;+ for +€+.
34
34
  #
35
35
  # Further, they may contain a meta tag in the header like this:
36
36
  #
@@ -41,27 +41,25 @@ module Hermeneutics
41
41
  #
42
42
  # <?xml version="1.0" encoding="UTF-8" ?> (XHTML)
43
43
  #
44
- # When +charset+ is <code>utf-8</code> and the file contains the byte
45
- # sequence <code>"\303\244"</code>/<code>"\xc3\xa4"</code> then there will
46
- # be displayed a character <code>"ä"</code>.
44
+ # When +charset+ is +utf-8+ and the file contains the byte sequence
45
+ # +"\303\244"+/+"\xc3\xa4"+ then there will be displayed a character +"ä"+.
47
46
  #
48
- # When +charset+ is <code>iso8859-15</code> and the file contains the byte
49
- # sequence <code>"\344"</code>/<code>"\xe4"</code> then there will be
50
- # displayed a character <code>"ä"</code>, too.
47
+ # When +charset+ is +iso8859-15+ and the file contains the byte sequence
48
+ # +"\344"+/+"\xe4"+ then there will be displayed a character +"ä"+, too.
51
49
  #
52
- # The sequence <code>"&auml;"</code> will produce an <code>"ä"</code> in any
50
+ # The sequence +"&auml;"+ will produce an +"ä"+ in any
53
51
  # case.
54
52
  #
55
53
  # == What you should do
56
54
  #
57
55
  # Generating your own HTML pages you will always be safe when you only
58
- # produce entity tags as <code>&auml;</code> and <code>&euro;</code> or
59
- # <code>&#x00e4;</code> and <code>&#x20ac;</code> respectively.
56
+ # produce entity tags as +&auml;+ and +&euro;+ or +&#x00e4;+ and +&#x20ac;+
57
+ # respectively.
60
58
  #
61
59
  # == What this module does
62
60
  #
63
- # This module translates strings to a HTML-masked version. The encoding will
64
- # not be changed and you may demand to keep 8-bit-characters.
61
+ # This module translates strings to a HTML-masked version. The encoding
62
+ # will not be changed and you may demand to keep 8-bit-characters.
65
63
  #
66
64
  # == Examples
67
65
  #
@@ -118,7 +116,7 @@ module Hermeneutics
118
116
  # :call-seq:
119
117
  # new( keep_8bit: bool) -> ent
120
118
  #
121
- # Creates an <code>Entities</code> converter.
119
+ # Creates an +Entities+ converter.
122
120
  #
123
121
  # ent = Entities.new keep_8bit: true
124
122
  #
@@ -184,9 +182,8 @@ module Hermeneutics
184
182
  # Entities.decode "&lt;" #=> "<"
185
183
  # Entities.decode "&auml;&ouml;&uuml;" #=> "äöü"
186
184
  #
187
- # Unmasked 8-bit-characters (<code>"ä"</code> instead of
188
- # <code>"&auml;"</code>) will be kept but translated to
189
- # a unique encoding.
185
+ # Unmasked 8-bit-characters (+"ä"+ instead of +"&auml;"+) will be kept
186
+ # but translated to a unique encoding.
190
187
  #
191
188
  # s = "ä &ouml; ü"
192
189
  # s.encode! "utf-8"
@@ -259,7 +256,7 @@ module Hermeneutics
259
256
  # :call-seq:
260
257
  # new( hash) -> urltext
261
258
  #
262
- # Creates a <code>URLText</code> converter.
259
+ # Creates a +URLText+ converter.
263
260
  #
264
261
  # The parameters may be given as values or as a hash.
265
262
  #
@@ -276,7 +273,7 @@ module Hermeneutics
276
273
  # :call-seq:
277
274
  # encode( str) -> str
278
275
  #
279
- # Create a string that contains <code>%XX</code>-encoded bytes.
276
+ # Create a string that contains +%XX+-encoded bytes.
280
277
  #
281
278
  # utx = URLText.new
282
279
  # utx.encode "'Stop!' said Fred." #=> "%27Stop%21%27+said+Fred."
@@ -292,15 +289,14 @@ module Hermeneutics
292
289
  # s = "< ä >".encode "ISO-8859-1"
293
290
  # utx.encode s #=> "%3C+\xe4+%3E" in ISO-8859-1
294
291
  #
295
- # A space <code>" "</code> will not be replaced by a plus <code>"+"</code>
296
- # if +keep_space+ is set.
292
+ # A space +" "+ will not be replaced by a plus +"\+"+ if +keep_space+ is
293
+ # set.
297
294
  #
298
295
  # utx = URLText.new keep_space: true
299
296
  # s = "< x >"
300
297
  # utx.encode s #=> "%3C x %3E"
301
298
  #
302
- # When +mask_space+ is set, then a space will be represented as
303
- # <code>"%20"</code>,
299
+ # When +mask_space+ is set, then a space will be represented as +"%20"+,
304
300
  #
305
301
  def encode str
306
302
  r = str.new_string
@@ -347,6 +343,7 @@ module Hermeneutics
347
343
  else val.to_s.notempty?
348
344
  end
349
345
  end
346
+ private
350
347
  def method_missing sym, *args
351
348
  if args.empty? and not sym =~ /[!?=]\z/ then
352
349
  self[ sym]
@@ -369,7 +366,7 @@ module Hermeneutics
369
366
  # :call-seq:
370
367
  # encode_hash( hash) -> str
371
368
  #
372
- # Encode a <code>Hash</code> to a URL-style string.
369
+ # Encode a +Hash+ to a URL-style string.
373
370
  #
374
371
  # utx = URLText.new
375
372
  #
@@ -469,8 +466,8 @@ module Hermeneutics
469
466
  # decode_hash( str) -> hash
470
467
  # decode_hash( str) { |key,val| ... } -> nil or int
471
468
  #
472
- # Decode a URL-style encoded string to a <code>Hash</code>.
473
- # In case a block is given, the number of key-value pairs is returned.
469
+ # Decode a URL-style encoded string to a +Hash+. In case a block is
470
+ # given, the number of key-value pairs is returned.
474
471
  #
475
472
  # str = "a=%3B%3B%3B&x=%26auml%3B%26ouml%3B%26uuml%3B"
476
473
  # URLText.decode_hash str do |k,v|
@@ -527,7 +524,7 @@ module Hermeneutics
527
524
  # :call-seq:
528
525
  # new( [ parameters] ) -> con
529
526
  #
530
- # Creates a <code>HeaderExt</code> converter.
527
+ # Creates a +HeaderExt+ converter.
531
528
  #
532
529
  # See the +encode+ method for an explanation of the parameters.
533
530
  #
@@ -571,8 +568,8 @@ module Hermeneutics
571
568
  # The result will not contain any 8-bit characters. The encoding will
572
569
  # be kept although it won't have a meaning.
573
570
  #
574
- # The parameter <code>:mask</code> will have no influence on the masking
575
- # itself but will guarantee characters to be masked.
571
+ # The parameter +:mask+ will have no influence on the masking itself but
572
+ # will guarantee characters to be masked.
576
573
  #
577
574
  # == Examples
578
575
  #
@@ -121,6 +121,10 @@ module Hermeneutics
121
121
  @out.path
122
122
  rescue NoMethodError
123
123
  end
124
+ def merge str
125
+ do_ind
126
+ @out << str
127
+ end
124
128
  def plain str
125
129
  do_ind
126
130
  @out << (@ent.encode str)
@@ -147,7 +151,7 @@ module Hermeneutics
147
151
  @out << tag
148
152
  mkattrs attrs
149
153
  end
150
- if nls >3 then
154
+ if nls>3 then
151
155
  verbose_block yield
152
156
  else
153
157
  indent_if nls>2 do
@@ -209,9 +213,9 @@ module Hermeneutics
209
213
  @out << "/* "
210
214
  brace false do
211
215
  @out << "![CDATA["
212
- @out << " */" << $/
216
+ @out << " */\n"
213
217
  @out << str
214
- @out << $/ << "/* "
218
+ @out << "\n/* "
215
219
  @out << "]]"
216
220
  end
217
221
  @out << " */"
@@ -223,7 +227,7 @@ module Hermeneutics
223
227
  def brk
224
228
  unless @nl then
225
229
  @nl = true
226
- @out << $/
230
+ @out << "\n"
227
231
  end
228
232
  end
229
233
  def out_brk str
@@ -319,6 +323,8 @@ module Hermeneutics
319
323
  TAGS[ name]
320
324
  end
321
325
 
326
+ private
327
+
322
328
  def method_missing name, *args, &block
323
329
  t = tag? name
324
330
  t or super
@@ -330,10 +336,16 @@ module Hermeneutics
330
336
  end
331
337
  end
332
338
 
339
+ public
340
+
341
+ def merge str
342
+ @generator.merge str
343
+ nil
344
+ end
345
+
333
346
  def pcdata *strs
334
347
  strs.each { |s|
335
- s or next
336
- @generator.plain s
348
+ @generator.plain s if s.notempty?
337
349
  }
338
350
  nil
339
351
  end
@@ -343,9 +355,13 @@ module Hermeneutics
343
355
  self
344
356
  end
345
357
 
346
- def _ str = nil
347
- @generator.plain str||yield
348
- nil
358
+ def _ *strs
359
+ if strs.notempty? then
360
+ pcdata *strs
361
+ else
362
+ @generator.plain yield
363
+ nil
364
+ end
349
365
  end
350
366
 
351
367
  def comment str
@@ -362,64 +378,26 @@ module Hermeneutics
362
378
  method_missing :html, **attrs do yield end
363
379
  end
364
380
 
365
- def head attrs = nil
366
- method_missing :head, attrs do
381
+ def head **attrs
382
+ method_missing :head, **attrs do
367
383
  meta charset: @generator.encoding
368
384
  yield
369
385
  end
370
386
  end
371
387
 
372
- def form attrs, &block
373
- attrs[ :method] ||= if attrs[ :enctype] == "multipart/form-data" then
374
- "post"
375
- else
376
- "get"
377
- end
378
- @tabindex = 0
379
- method_missing :form, attrs, &block
380
- ensure
381
- @tabindex = nil
388
+ def h i, **attrs, &block
389
+ method_missing :"h#{i.to_i}", **attrs, &block
382
390
  end
383
391
 
384
- Field = Struct[ :type, :attrs]
385
-
386
- def field type, attrs
387
- attrs[ :id] ||= attrs[ :name]
388
- @tabindex += 1
389
- attrs[ :tabindex] ||= @tabindex
390
- Field[ type, attrs]
392
+ def form **attrs, &block
393
+ attrs[ :method] ||=
394
+ attrs[ :enctype] == "multipart/form-data" ? "post" : "get"
395
+ method_missing :form, **attrs, &block
391
396
  end
392
397
 
393
- def label field = nil, attrs = nil, &block
394
- if String === attrs then
395
- label field do attrs end
396
- else
397
- if Field === field or attrs then
398
- attrs = attrs.merge for: field.attrs[ :id]
399
- else
400
- attrs = field
401
- end
402
- method_missing :label, attrs, &block
403
- end
404
- end
405
-
406
- def input arg, &block
407
- if Field === arg then
408
- case arg.type
409
- when /select/i then
410
- method_missing :select, arg.attrs, &block
411
- when /textarea/i then
412
- block and
413
- raise ArgumentError, "Field textarea: use the value attribute."
414
- v = arg.attrs.delete :value
415
- method_missing :textarea, arg.attrs do v end
416
- else
417
- arg.attrs[ :type] ||= arg.type
418
- method_missing :input, arg.attrs, &block
419
- end
420
- else
421
- method_missing :input, arg, &block
422
- end
398
+ def input **attrs, &block
399
+ attrs[ :id] ||= attrs[ :name]
400
+ method_missing :input, **attrs, &block
423
401
  end
424
402
 
425
403
  end
@@ -433,8 +411,8 @@ module Hermeneutics
433
411
  super
434
412
  end
435
413
 
436
- def a attrs = nil
437
- attrs[ :name] ||= attrs[ :id] if attrs
414
+ def a **attrs
415
+ attrs[ :name] ||= attrs[ :id]
438
416
  super
439
417
  end
440
418