erbook 7.3.0 → 8.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/doc/usage.erb CHANGED
@@ -24,7 +24,7 @@
24
24
  In the above example, *YOUR\_PATH\_HERE* is the path of the file in which the output should be saved.
25
25
 
26
26
 
27
- %|important "Serve XHTML as HTML for Microsoft web browsers"
27
+ %|important! "Serve XHTML as HTML for Microsoft web browsers"
28
28
 
29
29
  If you do not care whether people can read your XHTML documents using Microsoft web browsers, please disregard this message. Otherwise, please heed the following instructions.
30
30
 
data/fmt/xhtml.yaml CHANGED
@@ -201,21 +201,31 @@ code: |
201
201
  atts[:src] = ERBook.base_64_embed_image_data(data, format)
202
202
  "<img#{atts.to_xml_atts}/>"
203
203
  end
204
- end
205
204
 
206
- class Document::Node
207
205
  ##
208
- # Returns the user-defined title for this node's content.
206
+ # Allows float nodes to be instantiated implicitly by name.
209
207
  #
210
- def title
211
- @title ||= args[0]
208
+ def method_missing name, *args, &block
209
+ if name.to_s =~ /!$/
210
+ args[2] = $` # the type of this float node
211
+ float(*args, &block)
212
+ else
213
+ super
214
+ end
212
215
  end
216
+ end
213
217
 
214
- ##
215
- # Returns the user-defined indentifer for this node.
216
- #
217
- def id
218
- @id ||= args[1]
218
+ class Document::Node
219
+ def index?
220
+ definition['index']
221
+ end
222
+
223
+ def index_toc?
224
+ Array(definition['index']).include? 'tree'
225
+ end
226
+
227
+ def index_lof?
228
+ Array(definition['index']).include? 'list'
219
229
  end
220
230
 
221
231
  # utility methods
@@ -242,6 +252,13 @@ code: |
242
252
  content.join.to_xhtml
243
253
  end
244
254
 
255
+ ##
256
+ # Returns the content of this node as inline XHTML.
257
+ #
258
+ def content_inline_xhtml
259
+ content.join.to_inline_xhtml
260
+ end
261
+
245
262
  ##
246
263
  # Returns the content of this node as XHTML inside a <div/>.
247
264
  #
@@ -257,34 +274,34 @@ code: |
257
274
  end
258
275
 
259
276
  ##
260
- # Returns a hyperlink to this node
261
- # containing its LaTeX-style index number.
277
+ # Returns a hyperlink to this node containing its section number.
262
278
  #
263
- def index_link
264
- index
279
+ def section_number_link
280
+ section_number
265
281
  end
266
282
 
267
283
  ##
268
- # Returns a hyperlink to this node containing its occurrence number.
284
+ # Returns a hyperlink to this node containing its ordinal number.
269
285
  #
270
- def number_link
271
- [type_label, number].compact.join(' ')
286
+ def ordinal_number_link
287
+ [type_label, ordinal_number].compact.join(' ')
272
288
  end
273
289
 
274
290
  ##
275
291
  # Returns a hyperlink to this node containing
276
292
  # its ocurrence number and its title.
277
293
  #
278
- def number_and_title_link #:nodoc:
279
- "#{number_link}.&nbsp;&nbsp;#{title_link}"
294
+ def ordinal_number_and_title_link #:nodoc:
295
+ "#{ordinal_number_link}.&nbsp;&nbsp;#{title_link}"
280
296
  end
281
297
 
282
298
  ##
283
- # Returns a hyperlink to this node containing
284
- # its LaTeX-style index number and its title.
299
+ # Returns a hyperlink to this
300
+ # node containing its section
301
+ # number and its title.
285
302
  #
286
- def index_and_title_link #:nodoc:
287
- "#{index_link}&nbsp;&nbsp;#{title_link}"
303
+ def section_number_and_title_link #:nodoc:
304
+ "#{section_number_link}&nbsp;&nbsp;#{title_link}"
288
305
  end
289
306
 
290
307
  ##
@@ -293,7 +310,7 @@ code: |
293
310
  def navigation
294
311
  self.class.navigation(
295
312
  here_frag,
296
- (list_frag if defn['toc'] || defn['lof']),
313
+ (list_frag if index?),
297
314
  (prev_node.here_frag if prev_node),
298
315
  (next_node.here_frag if next_node)
299
316
  )
@@ -322,7 +339,7 @@ code: |
322
339
  # configured to appear in the table of contents.
323
340
  #
324
341
  def toc_children
325
- children.select {|c| c.defn['toc'] }
342
+ children.select {|c| c.index_toc? }
326
343
  end
327
344
 
328
345
  HERE_TEXT = ERBook::PHRASES['Focus this segment']
@@ -358,7 +375,8 @@ code: |
358
375
  # this node will be used as the label instead.
359
376
  #
360
377
  def xref_link label = nil
361
- prefix = [type_label, index || number].compact.join(' ')
378
+ prefix = [type_label, section_number || ordinal_number].
379
+ compact.join(' ')
362
380
 
363
381
  caption =
364
382
  if type == 'reference'
@@ -386,7 +404,8 @@ code: |
386
404
 
387
405
  # make it unique
388
406
  while @@frags.include? frag
389
- frag = "#{frag} #{index || number || salt}".to_uri_fragment
407
+ frag = [frag, section_number || ordinal_number || salt].
408
+ join(' ').to_uri_fragment
390
409
  end
391
410
 
392
411
  @@frags << frag
@@ -408,37 +427,23 @@ code: |
408
427
 
409
428
 
410
429
  nodes:
411
- # object model
412
- node:
413
- toc: false
414
- lof: false
415
- depth: false
416
- index: false
430
+ # theory
431
+
432
+ node: &wrapper
433
+ index: false
417
434
  number: false
418
- silent: false
419
435
  inline: true
420
- bypass: true
436
+ silent: false
421
437
  output: <%= @node.content_xhtml %>
422
438
 
423
- # Structure
439
+ # structure
440
+
424
441
  header: &header
425
- toc: false
426
- lof: false
427
- depth: false
428
- index: false
429
- number: false
442
+ <<: *wrapper
430
443
  silent: true
431
- inline: true
432
- output: <%= @node.content_xhtml %>
433
444
 
434
445
  header_outside_above: &header_insert
435
- toc: false
436
- lof: false
437
- depth: false
438
- index: false
439
- number: false
440
- silent: true
441
- inline: true
446
+ <<: *header
442
447
  output: |
443
448
  <%= @node.parent_tabs_begin %>
444
449
  <div class="<%= @node.type %>" id="<%= @node.here_frag %>"><%= @node.content_xhtml %></div>
@@ -455,33 +460,27 @@ nodes:
455
460
  footer_outside_below: *header_insert
456
461
 
457
462
  abstract:
458
- toc: false
459
- lof: false
460
- depth: false
461
- index: false
462
- number: false
463
- silent: true
464
- bypass: false
463
+ <<: *wrapper
465
464
  output: |
466
465
  <div id="<%= @node.type_frag %>">
467
466
  <h1 class="title"><%= @node.type_label %></h1>
468
467
  <%= @node.content_xhtml_div %>
469
468
  </div>
470
469
 
471
- # Organization
470
+ # organization
471
+
472
472
  part: &latex
473
- toc: true
474
- lof: false
475
- depth: true
476
- index: true
477
- number: true
473
+ index: tree
474
+ number: section
475
+ inline: false
478
476
  silent: false
477
+ params: [title, id]
479
478
  output: |
480
479
  <%= @node.parent_tabs_begin %>
481
480
  <div class="<%= @node.type %>" id="<%= @node.here_frag %>">
482
481
  <%= @node.navigation %>
483
482
  <h1 class="title">
484
- <%= @node.type_label %>&nbsp;<%= @node.index_link %>
483
+ <%= @node.type_label %>&nbsp;<%= @node.section_number_link %>
485
484
  <br/>
486
485
  <big><%= @node.title_link %></big>
487
486
  </h1>
@@ -492,31 +491,22 @@ nodes:
492
491
  chapter: *latex
493
492
 
494
493
  section:
495
- toc: true
496
- lof: false
497
- depth: true
498
- index: true
499
- number: true
500
- silent: false
494
+ <<: *latex
501
495
  output: |
502
496
  <% depth = [6, @node.depth + 1].min %>
503
497
  <%= @node.parent_tabs_begin %>
504
498
  <div class="<%= @node.type %>" id="<%= @node.here_frag %>">
505
499
  <%= @node.navigation %>
506
500
  <h<%= depth %> class="title">
507
- <%= @node.index_and_title_link %>
501
+ <%= @node.section_number_and_title_link %>
508
502
  </h<%= depth %>>
509
503
  <%= @node.content_xhtml_div %>
510
504
  </div>
511
505
  <%= @node.parent_tabs_end %>
512
506
 
513
507
  paragraph:
514
- toc: true
515
- lof: false
516
- depth: false
517
- index: false
508
+ <<: *latex
518
509
  number: false
519
- silent: false
520
510
  output: |
521
511
  <%= @node.parent_tabs_begin %>
522
512
  <div class="<%= @node.type %>" id="<%= @node.here_frag %>">
@@ -526,107 +516,104 @@ nodes:
526
516
  </div>
527
517
  <%= @node.parent_tabs_end %>
528
518
 
529
- # Admonitions
530
- tip: &admonition
531
- toc: false
532
- lof: true
533
- depth: true
534
- index: false
535
- number: true
519
+ # arbitrary floats
520
+ # see also http://www.sagehill.net/docbookxsl/FormalTitles.html
521
+
522
+ float:
523
+ index: list
524
+ number: ordinal
525
+ inline: false
536
526
  silent: false
527
+ params: [title, id, type]
537
528
  output: |
538
529
  <%= @node.parent_tabs_begin %>
539
530
  <div class="<%= @node.type %>" id="<%= @node.here_frag %>">
540
531
  <%= @node.navigation %>
541
- <p class="title"><%= @node.number_and_title_link %></p>
542
- <div class="content">
543
- <%= ICON_BY_NAME[@node.type].to_xhtml %>
544
- <%= @node.content_xhtml %>
545
- </div>
532
+ <p class="title"><%= @node.ordinal_number_and_title_link %></p>
533
+ <% if ICON_BY_NAME.key? @node.type %>
534
+ <div class="content">
535
+ <%= ICON_BY_NAME[@node.type].to_xhtml %>
536
+ <%= @node.content_xhtml %>
537
+ </div>
538
+ <% else %>
539
+ <%= @node.content_xhtml_div %>
540
+ <% end %>
546
541
  </div>
547
542
  <%= @node.parent_tabs_end %>
548
543
 
549
- note: *admonition
550
- caution: *admonition
551
- warning: *admonition
552
- important: *admonition
553
-
554
- # Auxilary materials (formal blocks)
555
- # see http://www.sagehill.net/docbookxsl/FormalTitles.html
556
- figure: &formal
557
- toc: false
558
- lof: true
559
- depth: true
544
+ # tables
545
+
546
+ table: &table
560
547
  index: false
561
- number: true
548
+ number: false
549
+ inline: true
562
550
  silent: false
551
+ params: [xml_atts]
563
552
  output: |
564
- <%= @node.parent_tabs_begin %>
565
- <div class="<%= @node.type %>" id="<%= @node.here_frag %>">
566
- <%= @node.navigation %>
567
- <p class="title"><%= @node.number_and_title_link %></p>
568
- <%= @node.content_xhtml_div %>
569
- </div>
570
- <%= @node.parent_tabs_end %>
553
+ <table border="1"<%=
554
+ (@node.xml_atts || {}).to_xml_atts
555
+ %>><%= @node.content_xhtml %></table>
556
+
557
+ thead: &table_child
558
+ <<: *table
559
+ output: |
560
+ <<%= @node.type %><%=
561
+ (@node.xml_atts || {}).to_xml_atts
562
+ %>><%= @node.content_inline_xhtml %></<%= @node.type %>>
571
563
 
572
- table: *formal
573
- example: *formal
574
- equation: *formal
575
- procedure: *formal
564
+ tbody: *table_child
565
+ tfoot: *table_child
566
+ th: *table_child
567
+ tr: *table_child
568
+ td: *table_child
576
569
 
577
570
  # cross-references
578
571
  xref:
579
- toc: false
580
- lof: false
581
- depth: true
582
- index: false
572
+ index: false
583
573
  number: false
584
- silent: false
585
574
  inline: true
575
+ silent: false
576
+ params: [query, label]
586
577
  output: |
587
578
  <%=
588
- query, label = @node.args
589
-
590
579
  scope = @nodes.select {|n| n.content }
591
- target = scope.find {|n| n.id == query } || # id has 1st priority
592
- scope.find {|n| n.title == query }
580
+ target = scope.find {|n| n.id == @node.query } || # id has priority
581
+ scope.find {|n| n.title == @node.query }
593
582
 
594
583
  if target
595
- target.xref_link label
584
+ target.xref_link @node.label
596
585
  else
597
- raise ArgumentError, "invalid cross-reference to #{@node.title.inspect}", @node.trace
586
+ raise ArgumentError, "invalid cross-reference to #{@node.query.inspect}", @node.backtrace
598
587
  end
599
588
  %>
600
589
 
601
- # Bibliography
602
- reference:
603
- toc: false
604
- lof: false
605
- depth: false
606
- index: false
607
- number: true
590
+ # bibliography
591
+
592
+ reference: &reference
593
+ index: false
594
+ number: ordinal
595
+ inline: false
608
596
  silent: true
609
- bypass: true
597
+ params: [title, id]
610
598
 
611
599
  cite:
612
- toc: false
613
- lof: false
614
- depth: false
615
- index: false
600
+ index: false
616
601
  number: false
617
- silent: false
618
602
  inline: true
603
+ silent: false
604
+ params: [target]
619
605
  output: |
620
606
  <%=
621
- target = @nodes_by_type['reference'].find {|n| n.title == @node.title }
607
+ target = @nodes_by_type['reference'].find do |n|
608
+ n.title == @node.target
609
+ end
622
610
 
623
611
  if target
624
612
  '<sup>[%s]</sup>' % [
625
- target.xref_link(target.number),
626
- *@node.args[1..-1]
627
- ].join(', ')
613
+ target.xref_link(target.ordinal_number), *@node.arguments
614
+ ].compact.join(', ')
628
615
  else
629
- raise ArgumentError, "invalid citation for #{@node.title.inspect}", @node.trace
616
+ raise ArgumentError, "invalid citation for #{@node.target.inspect}", @node.backtrace
630
617
  end
631
618
  %>
632
619
 
@@ -652,9 +639,9 @@ output: |
652
639
  nested = n.children.inject('') {|s,c| s << toc_builder[c] }
653
640
  nested = nil if nested.empty?
654
641
 
655
- if n.defn['toc']
642
+ if n.index_toc?
656
643
  entry = '%s<a id="%s" href="#%s">%s</a>' % [
657
- (n.index.to_s + '&nbsp;&nbsp;' if n.index),
644
+ (n.section_number.to_s + '&nbsp;&nbsp;' if n.section_number),
658
645
  n.list_frag,
659
646
  n.here_frag,
660
647
  n.title.to_s.to_inline_xhtml
@@ -669,17 +656,19 @@ output: |
669
656
  toc = @roots.inject('') {|s,n| s << toc_builder[n] }
670
657
 
671
658
  # compute list of figures
672
- lof_enums = {} # type => nodes
673
-
674
- @format['nodes'].each_pair do |name, info|
675
- if info['lof']
676
- nodes = @nodes_by_type[name]
677
- lof_enums[name] = nodes unless nodes.empty?
659
+ lof_nodes_by_type = Hash.new {|h,k| h[k] = [] }
660
+ @nodes.each do |node|
661
+ if node.index_lof?
662
+ lof_nodes_by_type[node.type] << node
678
663
  end
679
664
  end
680
665
 
681
- lof_sections_frag_and_label = []
666
+ lof_enums = {} # type => nodes
667
+ lof_nodes_by_type.each do |type, nodes|
668
+ lof_enums[type] = nodes unless nodes.empty?
669
+ end
682
670
 
671
+ lof_sections_frag_and_label = []
683
672
  lof = lof_enums.sort.map do |type, nodes|
684
673
  nested = nodes.map do |n|
685
674
  %{<li><a id="#{n.list_frag}" href="##{n.here_frag}">#{n.title.to_s.to_inline_xhtml}</a></li>}
@@ -878,7 +867,7 @@ output: |
878
867
  <div id="__doc__" class="tabs">
879
868
  <h1 style="display: none"><%= ERBook::PHRASES['Document'] %></h1>
880
869
  <ul>
881
- % @roots.select {|n| n.defn['toc'] }.each do |n|
870
+ % @roots.select {|n| n.index_toc? }.each do |n|
882
871
  <li><a href="#<%= n.here_frag %>"><%= n.title.to_s.to_inline_xhtml %></a></li>
883
872
  </ul>
884
873