docgenerator 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. data/examples/creole_example_tabular.rb +95 -0
  2. data/examples/docgenerator_example.rb +5 -5
  3. data/lib/creole/creole2doc.rb +28 -18
  4. data/lib/creole/creole_inclusions.rb +4 -4
  5. data/lib/creole/creole_placeholder.rb +4 -1
  6. data/lib/creole/creole_tabular.rb +173 -155
  7. data/lib/creole/plugins/rail.rb +118 -119
  8. data/lib/creole/plugins/struktex.rb +35 -35
  9. data/lib/creole/plugins/todonotes.rb +8 -1
  10. data/lib/docgenerator/attribute.rb +160 -160
  11. data/lib/docgenerator/characters.rb +343 -311
  12. data/lib/docgenerator/css.rb +167 -167
  13. data/lib/docgenerator/document.rb +525 -511
  14. data/lib/docgenerator/element.rb +316 -316
  15. data/lib/docgenerator/element_meta.rb +114 -114
  16. data/lib/docgenerator/elements.rb +19 -9
  17. data/lib/docgenerator/environments.rb +3 -1
  18. data/lib/docgenerator/lists.rb +177 -174
  19. data/lib/docgenerator/packages/hyperref.rb +74 -70
  20. data/lib/docgenerator/packages/multicol.rb +33 -0
  21. data/lib/docgenerator/packages/scrlettr2.rb +152 -151
  22. data/lib/docgenerator/packages/todonotes.rb +1 -1
  23. data/lib/docgenerator/tabular.rb +463 -400
  24. data/lib/docgenerator/templates/docgenerator_template.rb +94 -84
  25. data/lib/docgenerator/templates/docgenerator_template.yaml +75 -15
  26. data/lib/docgenerator.rb +1 -1
  27. data/lib/wiki2doc/wiki2docgenerator.rb +1 -1
  28. data/meta_test_and_doc/build__meta.rb +125 -0
  29. data/meta_test_and_doc/build_doc.rb +333 -0
  30. data/meta_test_and_doc/build_test.rb +251 -0
  31. data/meta_test_and_doc/manpages/attachfile.rb +389 -0
  32. data/meta_test_and_doc/manpages/caption.rb +133 -0
  33. data/meta_test_and_doc/manpages/characters.rb +3738 -0
  34. data/meta_test_and_doc/manpages/elements.rb +6851 -0
  35. data/meta_test_and_doc/manpages/environments.rb +985 -0
  36. data/meta_test_and_doc/manpages/footnote.rb +439 -0
  37. data/meta_test_and_doc/manpages/hyperref.rb +605 -0
  38. data/meta_test_and_doc/manpages/listings.rb +988 -0
  39. data/meta_test_and_doc/manpages/lists.rb +1463 -0
  40. data/meta_test_and_doc/manpages/others.rb +129 -0
  41. data/meta_test_and_doc/manpages/packages.rb +13 -0
  42. data/meta_test_and_doc/manpages/pdfpages.rb +108 -0
  43. data/meta_test_and_doc/manpages/readme.rdoc +9 -0
  44. data/meta_test_and_doc/manpages/scrlettr2.rb +362 -0
  45. data/meta_test_and_doc/manpages/scrpage2.rb +2028 -0
  46. data/meta_test_and_doc/manpages/sectioning.rb +2467 -0
  47. data/meta_test_and_doc/manpages/tables.rb +2088 -0
  48. data/meta_test_and_doc/manpages/todonotes.rb +235 -0
  49. data/meta_test_and_doc/manpages/wiki2docgenerator.rb +64 -0
  50. data/{readme.rd → readme.rdoc} +18 -1
  51. data/unittest/expected/test_tabular.creole +33 -0
  52. data/unittest/expected_creole/test_creole_creole1.0test.html +3 -3
  53. data/unittest/expected_creole/test_creole_creole1.0test.latex +3 -3
  54. data/unittest/expected_creole/test_creole_creole1.0test.text +3 -3
  55. data/unittest/expected_creole/test_creole_inline_apostroph.html +6 -0
  56. data/unittest/expected_creole/test_creole_inline_apostroph.latex +8 -0
  57. data/unittest/expected_creole/test_creole_inline_apostroph.text +4 -0
  58. data/unittest/expected_creole/test_creole_input.normsource +12 -12
  59. data/unittest/expected_creole/test_creole_input.normsource_1.8 +23 -0
  60. data/unittest/expected_creole/test_creole_links_external_implicit.html +2 -2
  61. data/unittest/expected_creole/test_creole_links_external_implicit.latex +2 -2
  62. data/unittest/expected_creole/test_creole_links_external_implicit.text +2 -2
  63. data/unittest/expected_creole/test_creole_links_implicit_end.html +1 -1
  64. data/unittest/expected_creole/test_creole_links_implicit_end.latex +1 -1
  65. data/unittest/expected_creole/test_creole_list_ul.normsource +42 -42
  66. data/unittest/expected_creole/test_creole_list_ul.normsource_1.8 +83 -0
  67. data/unittest/expected_creole/test_creole_paragraphs.normsource +15 -15
  68. data/unittest/expected_creole/test_creole_paragraphs.normsource_1.8 +27 -0
  69. data/unittest/expected_creole/test_creole_tabular.creole +22 -0
  70. data/unittest/expected_creole/test_creole_tabular_creole.creole +19 -0
  71. data/unittest/expected_creole/test_creole_tabular_css.creole +24 -0
  72. data/unittest/expected_creole/test_creole_tabular_multicols.creole +16 -0
  73. data/unittest/expected_creole/test_creole_tabular_multicols.html +14 -0
  74. data/unittest/expected_creole/test_creole_tabular_multicols.latex +16 -0
  75. data/unittest/expected_creole/test_creole_tabular_with_cell_option.creole +21 -0
  76. data/unittest/expected_creole/test_creole_toc_level_text.html +2 -2
  77. data/unittest/expected_creole/test_creole_toc_level_text.latex +2 -2
  78. data/unittest/expected_packages/test_multicol_3.tex +2 -0
  79. data/unittest/expected_packages/test_multicol_3_titleline.tex +2 -0
  80. data/unittest/expected_templates/test_article.tex +23 -0
  81. data/unittest/expected_templates/test_article_utf8.tex +34 -0
  82. data/unittest/expected_templates/test_context.miv +18 -0
  83. data/unittest/expected_templates/test_creole.creole +8 -0
  84. data/unittest/expected_templates/test_html.html +12 -0
  85. data/unittest/expected_templates/test_html401_strict.html +14 -0
  86. data/unittest/expected_templates/test_html401_trans.html +14 -0
  87. data/unittest/expected_templates/test_html_utf8.html +14 -0
  88. data/unittest/expected_templates/test_include.tex +17 -0
  89. data/unittest/expected_templates/test_include_utf8.tex +17 -0
  90. data/unittest/expected_templates/test_text.txt +6 -0
  91. data/unittest/expected_templates/test_wiki.wiki +6 -0
  92. data/unittest/expected_templates/test_xhtml_strict.html +14 -0
  93. data/unittest/expected_templates/test_xhtml_trans.html +14 -0
  94. data/unittest/unittest_creole.rb +27 -6
  95. data/unittest/unittest_creole_placeholders.rb +1 -123
  96. data/unittest/unittest_creole_tabular.rb +174 -0
  97. data/unittest/unittest_docgenerator.rb +4 -3
  98. data/unittest/unittest_docgenerator_characters.rb +4769 -615
  99. data/unittest/unittest_packages_multicol.rb +84 -0
  100. data/unittest/unittest_rubycode4doc.rb +0 -1
  101. data/unittest/unittest_templates.rb +64 -0
  102. metadata +163 -77
  103. data/build_test_and_doc.rb +0 -505
  104. data/manpage_elements.rb +0 -10411
@@ -0,0 +1,95 @@
1
+ #encoding: cp1252
2
+ =begin rdoc
3
+ Example for creole/creole2doc
4
+ =end
5
+
6
+
7
+ require 'rubygems'
8
+ $:.unshift("../lib") #for local tests with uninstalled gem
9
+ #~ require 'docgenerator'
10
+ require 'creole/creole2doc'
11
+ include Docgenerator
12
+
13
+ begin
14
+ require 'rake4latex_pdflatex'
15
+ rescue LoadError
16
+ puts "rake4latex not installed -> no translation of LaTeX-file"
17
+ end
18
+
19
+ #
20
+ # Move all results to anothe folder
21
+ #
22
+ Dir.chdir('results')
23
+
24
+
25
+ =begin
26
+ Create document
27
+ =end
28
+ doc = Document.new(
29
+ :title => 'creole2doc_example_tabular.rb: Test for tabulars with creole'
30
+ )
31
+
32
+ =begin
33
+ Add creole-content.
34
+ =end
35
+ doc.body << Creole::Creole.new(:content => DATA)
36
+
37
+ # ###############################
38
+ # Save the files
39
+ # ###############
40
+ doc.save( __FILE__.sub(/\.rb/, ".html"))
41
+ doc.save( __FILE__.sub(/\.rb/, ".tex"),
42
+ :runtex => [:statistic, :clean]
43
+ )
44
+
45
+
46
+ __END__
47
+ =Normal tabular
48
+
49
+ |one | two
50
+ |1 | 2
51
+ |1.0 | 2.0
52
+
53
+ ==tabular with heading
54
+ |=header col1|=header col2|
55
+ |col1|col2|
56
+ |you |can |
57
+ |also |align\\ it. |
58
+
59
+
60
+ =tabular as placeholder
61
+ <<<tabular
62
+ |!columns=3
63
+ |!columndescription=ccc
64
+ |=1
65
+ |=2
66
+ |=3
67
+ |-
68
+ |eins
69
+ |zwei
70
+ |drei
71
+ |-
72
+ |one
73
+ |two
74
+ |three
75
+ >>>
76
+
77
+ =tabular with cell option
78
+
79
+ After || you may define special data
80
+
81
+ <<<tabular
82
+ |!columns=3
83
+ |!columndescription=ccc
84
+ |eins||css=color: red
85
+ |css = zwei
86
+ |||class=empty
87
+ |-
88
+ |normal
89
+ |//italic//
90
+ |//italic//||class=it
91
+ |-
92
+ |text with | nice! ||class = it
93
+ |||css =
94
+ |
95
+ >>>
@@ -17,7 +17,7 @@ rescue LoadError
17
17
  end
18
18
 
19
19
  #
20
- # Move all results to anothe folder
20
+ # Move all results to another folder
21
21
  #
22
22
  Dir.chdir('results')
23
23
 
@@ -34,18 +34,18 @@ doc = Docgenerator::Document.new(
34
34
  )
35
35
 
36
36
  #
37
- # Alternative psooibility to define settings:
37
+ # Alternative possibility to define settings:
38
38
  #~ doc.title ='Titel'
39
39
  #~ doc.author = 'Authorname'
40
40
  #~ doc.date = 'Datum'
41
41
  #~ doc.keywords = 'Test, DocGenerator.rb'
42
42
  #~ doc.description = 'Testdokument for DocGenerator.rb'
43
43
 
44
- doc.add_option('ngerman')
44
+ doc.add_option('english')
45
45
 
46
46
  #
47
47
  doc.body << element(:maketitle) #Only LaTeX
48
- doc.body[:lang] << 'de' #language flag for HTML
48
+ doc.body[:lang] << 'en' #language flag for HTML
49
49
 
50
50
  # ###############################
51
51
  doc.body << element(:h1, {}, 'Sections and paragraphs').cr
@@ -104,7 +104,7 @@ doc.body.insertbefore( par, 'This is inserted before the paragraph.' )
104
104
  doc.body.insertafter( par, 'This is inserted after the paragraph.' )
105
105
 
106
106
  #
107
- # This would give yo an error
107
+ # This would give you an error
108
108
  #
109
109
  #~ puts "!And now an error: insertbefore with a non-existing target"
110
110
  #~ doc.body.insertbefore( 'a', 'Before List' )
@@ -175,13 +175,16 @@ Define a creole document. The settings are forwarded to Document#new()
175
175
  Some settings are used only directly in Creole_document.
176
176
  - :with_toc: Add a table of contents at the beginning of the document.
177
177
  - :content: Wiki-text. Same as Creole_document#<<
178
+ - :logname: Name for Creole#log
178
179
  =end
179
180
  def initialize( settings = {} )
180
181
  @with_toc = settings[:with_toc ]
181
182
  settings.delete(:with_toc) #Avoid error message in Document.new
182
-
183
+ settings[:logname] ||= 'CreoleDoc' #Just a name for easier debugging/logging
184
+
183
185
  @creole = Creole.new(
184
186
  #Get content if available and delete setting to avoid error message in Document.new
187
+ :logname => settings.delete(:logname), #for logger
185
188
  :content => settings.delete(:content),
186
189
  :ignore => settings.delete(:ignore),
187
190
  :targetdir => settings.delete(:targetdir)
@@ -277,7 +280,7 @@ Options:
277
280
  =end
278
281
  def initialize( options = {} )
279
282
  @options = {
280
- :name => 'Creole', #Just a name for easier debugging/logging
283
+ :logname => 'Creole', #Just a name for easier debugging/logging
281
284
  :targetdir => '.',
282
285
  :wrap_at => 75, #Default line wrapping
283
286
  #~ :parsetest => false #Make an immediate test for parsing #fixme
@@ -309,7 +312,7 @@ Options:
309
312
  @targetdir = @options[:targetdir] if @options[:targetdir]
310
313
 
311
314
  @log = @options[:log]
312
- @log = Log4r::Logger.new(@options[:name], Log4r::INFO) unless @log
315
+ @log = Log4r::Logger.new(@options[:logname], Log4r::INFO) unless @log
313
316
  @log.outputters = Log4r::StdoutOutputter.new('log_stdout') if @log.outputters.empty?
314
317
 
315
318
  @creation_caller = caller.first
@@ -374,8 +377,12 @@ multiple paragraphs, lists...
374
377
  else
375
378
  raise InputError, "Don't know, how to handle #{input.class} in Creole#<<"
376
379
  end
377
-
378
- source_enc = source.encode(@options[:encoding])
380
+ begin
381
+ source_enc = source.encode(@options[:encoding])
382
+ rescue Encoding::UndefinedConversionError => err
383
+ @log.warn("Encoding conversion error <#{err}>") if @log.warn?
384
+ source_enc = source.encode(@options[:encoding], :undef => :replace)
385
+ end
379
386
  @source << source_enc
380
387
  #Parse the given source.
381
388
  #This is done immediate, so you have a chance to localize the line, where an error occurs.
@@ -549,12 +556,8 @@ Return a table of contents as a list.
549
556
 
550
557
  @toc.each{|tocentry|
551
558
  level = tocentry.add_info[:level]
552
-
553
- #
554
- #fixme:
555
- #Ebenenfehler (fehlende ebene resultiert in:
556
- # ERROR Creole: List ** with missing sublist
557
- # --> bessere meldung
559
+ #Skip deeper levels then wanted.
560
+ next if level > options[:level]
558
561
 
559
562
  #Build the label
560
563
  if level > toclabel.size
@@ -562,9 +565,12 @@ Return a table of contents as a list.
562
565
  elsif level < toclabel.size
563
566
  toclabel.pop
564
567
  end
568
+ #Happens if there is a jump gap on section levels (subsubsection inside section without subsection)
565
569
  if ! toclabel[level-1]
566
- @log.fatal("toclevel error: #{__FILE__}##{__LINE__}")
567
- return nil
570
+ @log.warn("Missing toclevel for <#{tocentry.content}> #{tocentry.add_info.inspect}")
571
+ #add dummy level
572
+ toclabel << 0
573
+ toclist << "#{listtype * ( level - 1)} ---"
568
574
  end
569
575
  toclabel[level-1] = toclabel[level-1] + 1
570
576
 
@@ -575,8 +581,6 @@ Return a table of contents as a list.
575
581
  else
576
582
  label = tocentry.add_info[:label] = toclabel.join('-')
577
583
  end
578
- #Skip deeper levels then wanted.
579
- next if level > options[:level]
580
584
 
581
585
  #Feature to create the toc if higher levels are missing /start at h3...)
582
586
  #~ if level < options[:startlevel]
@@ -602,6 +606,9 @@ toc
602
606
  Wrapping mechanism for texts.
603
607
 
604
608
  Don't do anything, if line_width is 0.
609
+
610
+ See also http://stackoverflow.com/questions/7548968/format-output-to-40-characters-long-per-line/7549032#7549032
611
+ and http://forum.ruby-portal.de/viewtopic.php?t=3844&p=24578
605
612
  =end
606
613
  def word_wrap(text, line_width = @options[:wrap_at] )
607
614
  return text if line_width <= 0
@@ -783,9 +790,10 @@ Options is a Hash and may contain:
783
790
  options[:log].error("Lost link <#{el}>") if options[:log].error?
784
791
  #fixme: there are obsolete 2 additional spaces in the result.
785
792
  when /^http/ #implicit link
786
- href = element(:a, {:href=>el.strip}, el.strip )
793
+ #~ href = element(:a, {:href=>el.strip}, el.strip ) #This makes problems with TeX (unmasked _,%...)
794
+ href = element(:url, {}, el.strip )
787
795
  el =~ /(\s|\Z)$/ #get the end-space/newline if available
788
- endspace = ( ! $1.empty? ? $1 : nil )
796
+ endspace = ( $1.empty? ? nil : $1 )
789
797
  if stack.last
790
798
  stack.last << href
791
799
  #~ stack.last << last_char #add again the
@@ -878,10 +886,12 @@ Check for links and pictures if the target exist.
878
886
 
879
887
  Absolute DOS-Pathes are detected (C:\...).
880
888
  Relative pathes are searched from @options[:targetdir] (default '.').
889
+
890
+ Different locations are not supported (e.g. to implement LaTeXs \graphicspath)
881
891
  =end
882
892
  def check_link_existence( filename, log )
883
893
  case filename
884
- when /^.:/#absolute DOS-path
894
+ when /^.:/#absolute DOS-path (e.g. c:\...)
885
895
  path = filename.dup
886
896
  else #relative path
887
897
  path = "#{@options[:targetdir]}/#{filename}".sub(/^\//, '')
@@ -50,7 +50,7 @@ Define an image.
50
50
  The existence of the picture is checked.
51
51
 
52
52
  Supported options:
53
- * alt (2nd parameter of {{picsrc|...}}
53
+ * alt (2nd parameter of {{picsrc|...}}
54
54
  * css or imgcss
55
55
  * class or imgclass
56
56
  * longdesc (can take a url, at leas opera offers to call the description)
@@ -73,9 +73,9 @@ Supported options:
73
73
  #* align
74
74
  #* border
75
75
  #* height
76
- #* hspace
77
- #* name
78
- #* vspace
76
+ #* hspace
77
+ #* name
78
+ #* vspace
79
79
  options.each{|option|
80
80
  case option
81
81
  when /^(img)?css\s*=\s*(.*)/
@@ -130,7 +130,10 @@ class Creole_latex < Placeholder
130
130
  end #Creole_latex
131
131
 
132
132
  #
133
- #Collect
133
+ #Usage:
134
+ # <<<comment
135
+ # This text is a comment.
136
+ # >>>
134
137
  #
135
138
  class Creole_comment < Placeholder
136
139
  set_placeholder_key 'comment'
@@ -1,4 +1,5 @@
1
- require 'creole2doc' if __FILE__ == $0
1
+ #encoding: UTF-8
2
+
2
3
 
3
4
  <<fixme
4
5
  taboptions:
@@ -17,8 +18,7 @@ fixme
17
18
 
18
19
 
19
20
  module Docgenerator
20
- module Creole
21
-
21
+ module Creole
22
22
  =begin
23
23
  "Original" creole tab.
24
24
 
@@ -35,55 +35,55 @@ Usage:
35
35
  |also |align\\ it. |
36
36
 
37
37
  =end
38
- class Creole_tab < Placeholder
39
- set_placeholder_key 'creole_tabular' #original creole-tab definition
38
+ class Creole_tab < Placeholder
39
+ set_placeholder_key 'creole_tabular' #original creole-tab definition
40
40
 
41
- #Extend the class by a little structure
42
- Cell = Struct.new('Cell', :content, :type )
41
+ #Extend the class by a little structure
42
+ Cell = Struct.new('Cell', :content, :type )
43
43
 
44
- #Finish the tabular.
45
- #Each cell is added left justified.
46
- def close(options)
47
- #~ @log.error("Standard creole tabulars not supported yet" )
48
-
49
- step = 0 #start
50
- head = []
51
- content = []
52
- @source.each{|line|
53
- content << []
54
- #delete trailing empty cells
55
- line.chomp.gsub(/\|\s*$/,'').split(/\|/)[1..-1].each{|cell|
56
- case cell
57
- when /^=/
58
- content.last << Cell.new(@wiki.inline($~.post_match.strip, options),:th)
59
- else
60
- content.last << Cell.new(@wiki.inline(cell.strip, options), :td)
61
- end
62
- }
63
- }
64
-
65
- max_size = 0
66
- content.each{|line|
67
- max_size = [max_size, line.size].max
68
- }
69
-
70
- @tab = element(:tabular, {#:style => tab_css,
71
- :columns => max_size,
72
- :columndescription => 'l' * max_size,
73
- }).cR
74
- content.each{|line|
75
- @tab << row = element(:row).cr
76
- line.each{|cell|
77
- #fixme cell to wiki/creole
78
- row << element(cell.type,{}, cell.content).cr
79
- }
80
- }
81
- end
82
- def to_doc( target, options = {})
83
- self.close(options) unless @tab
84
- @tab.to_doc( target, options )
85
- end
86
- end #Creole_tab
44
+ #Finish the tabular.
45
+ #Each cell is added left justified.
46
+ def close(options)
47
+ #~ @log.error("Standard creole tabulars not supported yet" )
48
+
49
+ step = 0 #start
50
+ head = []
51
+ content = []
52
+ @source.each{|line|
53
+ content << []
54
+ #delete trailing empty cells
55
+ line.chomp.gsub(/\|\s*$/,'').split(/\|/)[1..-1].each{|cell|
56
+ case cell
57
+ when /^=/
58
+ content.last << Cell.new(@wiki.inline($~.post_match.strip, options),:th)
59
+ else
60
+ content.last << Cell.new(@wiki.inline(cell.strip, options), :td)
61
+ end
62
+ }
63
+ }
64
+
65
+ max_size = 0
66
+ content.each{|line|
67
+ max_size = [max_size, line.size].max
68
+ }
69
+
70
+ @tab = element(:tabular, {#:style => tab_css,
71
+ :columns => max_size,
72
+ :columndescription => 'l' * max_size,
73
+ }).cR
74
+ content.each{|line|
75
+ @tab << row = element(:row).cr
76
+ line.each{|cell|
77
+ #fixme cell to wiki/creole
78
+ row << element(cell.type,{}, cell.content).cr
79
+ }
80
+ }
81
+ end
82
+ def to_doc( target, options = {})
83
+ self.close(options) unless @tab
84
+ @tab.to_doc( target, options )
85
+ end
86
+ end #Creole_tab
87
87
 
88
88
  =begin rdoc
89
89
  Create tabulars analog to Wikimedia.
@@ -117,11 +117,11 @@ You can add additional settings to cells:
117
117
  |||class=empty
118
118
  >>>
119
119
  =end
120
- class Creole_tabular < Placeholder
121
- set_placeholder_key 'tabular'
122
-
123
- #Extend the class by a little structure
124
- class Cell
120
+ class Creole_tabular < Placeholder
121
+ set_placeholder_key 'tabular'
122
+
123
+ #Extend the class by a little structure
124
+ class Cell
125
125
  =begin rdoc
126
126
  The content of a cell is separated from settings by two ||
127
127
 
@@ -132,107 +132,125 @@ Supported additional settings:
132
132
  * class= define HTML-class
133
133
  * title= define a title (results in popup during mouse-over)
134
134
  =end
135
- def initialize( content, type, wiki, local_options )
136
- @content, options = content.split(/\|\|/,2)
137
- @content = '' unless @content #just in case of empty content
138
- @options = {}
139
- options.split(/\|/).each{|option|
140
- case option
141
- when /class\s*=\s*/
142
- @options[:class] = $~.post_match
143
- when /css\s*=\s*/
144
- @options[:style] = $~.post_match
145
- when /title\s*=\s*/
146
- @options[:title] = $~.post_match
147
- when '' #ignore them
148
- else
149
- wiki.log.warn("Creole_tabular::Cell: Undefined option #{option.inspect}")
150
- end
151
- } if options
152
- @type = type #:td or :th
153
- @wiki = wiki
154
- @local_options = local_options
155
- end
156
- #Return the content as a element.
157
- def cell_element()
158
- element(@type,@options, @wiki.inline(@content, @local_options)).cr
159
- end
160
- end
161
-
162
- #Build the tabular.
163
- def close()
164
- #~ fixme:
165
- #~ *CSS-format
166
- #~ *generelle def
167
-
168
- step = 0 #start
169
- head = []
170
- content = [[]]
171
-
172
- options = { :log => @log }
173
- local_options = {
174
- :log => @log,
175
- :inclusions => @wiki.inclusions,
176
- :plugins => @wiki.plugins.dup
177
- }
178
- #No footnotes inside tabulars
179
- local_options[:plugins].delete('footnote')
180
- local_options[:plugins].delete('footnotes')
181
-
182
- tab_css = CSS.new( :log => @log )
183
- @source.each{|cell|
184
- case cell
185
- when /^\|!/ #generell cell definition
186
- case $~.post_match().strip
187
- when /columns\s*=\s*(.*)/
188
- options[:columns] = $1.to_i
189
- when /border\s*=\s*(.*)/
190
- options[:border] = $1
191
- when /columndescription\s*=\s*(.*)/
192
- options[:columndescription] = $1
193
- when /css\s*=\s*(.*)\s*:\s*(.*)/
194
- tab_css[$1] = $2
195
- when '' #
135
+ def initialize( content, type, wiki, local_options )
136
+ @content, options = content.split(/\|\|/,2)
137
+ @content = '' unless @content #just in case of empty content
138
+ @options = {}
139
+ options.split(/\|/).each{|option|
140
+ case option
141
+ when /class\s*=\s*/
142
+ @options[:class] = $~.post_match
143
+ when /css\s*=\s*/
144
+ @options[:style] = $~.post_match
145
+ when /title\s*=\s*/
146
+ @options[:title] = $~.post_match
147
+ when /pos\s*=\s*/ #only for multicol
148
+ @options[:pos] = $~.post_match
149
+ when /columns\s*=\s*/
150
+ wiki.log.debug("Creole_tabular::Cell #{type} converted to multicol")
151
+ type = :multicolumn #loose th/td-information -- fixme
152
+ @options[:colspan] = $~.post_match.to_i
153
+ when '' #ignore them
196
154
  else
197
- @log.warn("#{self}: Unknown tabular option #{$1}") if @log.warn?
198
- end
199
- when /^\|-(.*)/ #new line
200
- content << []
201
- when /^\|=/ #header cell
202
- #~ content.last << Cell.new(@wiki.inline($~.post_match.strip, local_options), :th)
203
- content.last << Cell.new($~.post_match.strip, :th, @wiki, local_options)
204
- when /^\|/ #content of a cell
205
- #~ content.last << Cell.new(@wiki.inline($~.post_match.strip, local_options), :td)
206
- content.last << Cell.new($~.post_match.strip, :td, @wiki, local_options)
207
- else #error!
208
- raise 'cell/log-warning'
209
- end
210
- }
211
-
212
- max_size = 0
213
- content.each{|line|
214
- max_size = [max_size, line.size].max
215
- }
216
-
217
- if options[:columns] and options[:columns] < max_size
218
- @log.warn("Creole-tabular: Defined size #{options[:columns]} < no of columns (#{max_size})") if @log.warn?
219
- end
155
+ wiki.log.warn("Creole_tabular::Cell: Undefined option #{option.inspect}")
156
+ end
157
+ } if options
158
+ @type = type #:td or :th
159
+ @wiki = wiki
160
+ @local_options = local_options
161
+ end
162
+ #Return the content as a element.
163
+ def cell_element()
164
+ element(@type,@options, @wiki.inline(@content, @local_options)).cr
165
+ end
166
+ end #class Cell
220
167
 
221
- @tab = element(:tabular, { :style => tab_css,
222
-
168
+ #Build the tabular.
169
+ def close()
170
+ #~ fixme:
171
+ #~ *CSS-format
172
+ #~ *generelle def
173
+
174
+ step = 0 #start
175
+ head = []
176
+ content = [[]]
177
+
178
+ options = { :log => @log }
179
+ local_options = {
180
+ :log => @log,
181
+ :inclusions => @wiki.inclusions,
182
+ :plugins => @wiki.plugins.dup
183
+ }
184
+ #No footnotes inside tabulars
185
+ local_options[:plugins].delete('footnote')
186
+ local_options[:plugins].delete('footnotes')
187
+
188
+ tab_css = CSS.new( :log => @log )
189
+ @source.each{|cell|
190
+ case cell
191
+ when /^\|!/ #generell cell definition
192
+ case $~.post_match().strip
193
+ when /columns\s*=\s*(.*)/
194
+ options[:columns] = $1.to_i
195
+ when /border\s*=\s*(.*)/
196
+ options[:border] = $1
197
+ when /columndescription\s*=\s*(.*)/
198
+ options[:columndescription] = $1
199
+ when /css\s*=\s*(.*)\s*:\s*(.*)/
200
+ tab_css[$1] = $2
201
+ when '' #
202
+ else
203
+ @log.warn("#{self}: Unknown tabular option #{$1}") if @log.warn?
204
+ end
205
+ when /^\|-(.*)/ #new line
206
+ content << []
207
+ when /^\|=/ #header cell
208
+ #~ content.last << Cell.new(@wiki.inline($~.post_match.strip, local_options), :th)
209
+ content.last << Cell.new($~.post_match.strip, :th, @wiki, local_options)
210
+ when /^\|/ #content of a cell
211
+ #~ content.last << Cell.new(@wiki.inline($~.post_match.strip, local_options), :td)
212
+ content.last << Cell.new($~.post_match.strip, :td, @wiki, local_options)
213
+ else #error!
214
+ raise "cell/log-warning in #{cell.inspect}"
215
+ end
216
+ }
217
+
218
+ max_size = 0
219
+ content.each{|line|
220
+ max_size = [max_size, line.size].max
221
+ }
222
+
223
+ if options[:columns] and options[:columns] < max_size
224
+ @log.warn("Creole-tabular: Defined size #{options[:columns]} < no of columns (#{max_size})") if @log.warn?
225
+ end
226
+
227
+ if self.is_a?(Docgenerator::Creole::Creole_longtable)
228
+ @tab = element(:longtable, { :style => tab_css,
223
229
  }.merge(options) ).cR
224
- content.each{|line|
225
- @tab << row = element(:row).cr
226
- line.each{|cell|
227
- row << cell.cell_element.cr
230
+ elsif self.is_a?(Docgenerator::Creole::Creole_tabular)
231
+ @tab = element(:tabular, { :style => tab_css,
232
+ }.merge(options) ).cR
233
+ else
234
+ raise ArgumentError, "Unsupported tabular-class #{self.class}"
235
+ end
236
+
237
+ content.each{|line|
238
+ @tab << row = element(:row).cr
239
+ line.each{|cell|
240
+ row << cell.cell_element.cr
241
+ }
228
242
  }
229
- }
230
- end
231
- def to_doc( target, options = {})
232
- @tab.to_doc( target, options )
243
+ end
244
+ def to_doc( target, options = {})
245
+ @tab.to_doc( target, options )
246
+ end
247
+ end #Creole_tabular
248
+
249
+ class Creole_longtable < Creole_tabular
250
+ set_placeholder_key 'longtable'
233
251
  end
234
- end
235
- end #module Creole
252
+
253
+ end #module Creole
236
254
  end #module Docgenerator
237
255
 
238
256
 
@@ -262,8 +280,8 @@ yy;yy;yy;
262
280
  <<<
263
281
 
264
282
 
265
- Die Syntax:
266
- *{| beginnt eine Tabelle. Hier k�nnen zus�tzliche Formatierungseigenschaften kommen.
283
+ Die Syntax:
284
+ *{| beginnt eine Tabelle. Hier können zusätzliche Formatierungseigenschaften kommen.
267
285
  **Zumindest columns==__ sollte gesetzt sein
268
286
  *! beginnt eine neue Zelle einer Titelzeile
269
287
  *| beginnt eine neue Zelle
@@ -272,6 +290,6 @@ yy;yy;yy;
272
290
  Dann sinnvoll, wenn im Text selbst ein | vorkommt
273
291
  (z.B. ein Macro verwendet wird)
274
292
  *|- trennt zwei Zeilen der Tabelle
275
- **hline: Zus�tzlicher Trennstrich �ber der Zeile
276
- **toprule, midrule, bottomrule: Zus�tzlicher Trennstrich �ber der Zeile (erfordert booktabs.sty)
293
+ **hline: Zusätzlicher Trennstrich über der Zeile
294
+ **toprule, midrule, bottomrule: Zusätzlicher Trennstrich über der Zeile (erfordert booktabs.sty)
277
295
  *|} beendet eine Tabelle