erbook 6.1.0 → 7.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. data/bin/erbook +29 -25
  2. data/doc/HelloWorld.spec +3 -1
  3. data/doc/api/classes/ERBook.html +86 -0
  4. data/doc/api/classes/ERBook/Document.html +399 -0
  5. data/doc/api/classes/ERBook/Document/Node.html +110 -0
  6. data/doc/api/classes/ERBook/Template.html +309 -0
  7. data/doc/api/classes/ERBook/Template/Sandbox.html +134 -0
  8. data/doc/api/classes/RDoc.html +69 -0
  9. data/doc/api/classes/RDoc/AnyMethod.html +249 -0
  10. data/doc/api/classes/RDoc/DummyMarkup.html +60 -0
  11. data/doc/api/classes/RDoc/DummyMixin.html +54 -0
  12. data/doc/api/classes/RDoc/DummyOptions.html +60 -0
  13. data/doc/api/classes/RDoc/TopLevel.html +344 -0
  14. data/doc/api/classes/String.html +212 -0
  15. data/doc/api/created.rid +1 -0
  16. data/doc/api/css/main.css +263 -0
  17. data/doc/api/css/panel.css +383 -0
  18. data/doc/api/css/reset.css +53 -0
  19. data/doc/api/files/ANN_eml.html +276 -0
  20. data/doc/api/files/ANN_html.html +407 -0
  21. data/doc/api/files/ANN_txt.html +271 -0
  22. data/doc/api/files/LICENSE.html +76 -0
  23. data/doc/api/files/lib/erbook/document_rb.html +74 -0
  24. data/doc/api/files/lib/erbook/rdoc_rb.html +77 -0
  25. data/doc/api/files/lib/erbook/template_rb.html +66 -0
  26. data/doc/api/files/lib/erbook/to_xhtml_rb.html +89 -0
  27. data/doc/api/files/lib/erbook_rb.html +70 -0
  28. data/doc/api/i/arrows.png +0 -0
  29. data/doc/api/i/results_bg.png +0 -0
  30. data/doc/api/i/tree_bg.png +0 -0
  31. data/doc/api/index.html +14 -18
  32. data/doc/api/js/jquery-1.3.2.min.js +19 -0
  33. data/doc/api/js/jquery-effect.js +593 -0
  34. data/doc/api/js/main.js +22 -0
  35. data/doc/api/js/searchdoc.js +605 -0
  36. data/doc/api/panel/index.html +63 -0
  37. data/doc/api/panel/search_index.js +1 -0
  38. data/doc/api/panel/tree.js +1 -0
  39. data/doc/formats.erb +63 -115
  40. data/doc/history.erb +125 -92
  41. data/doc/index.erb +12 -7
  42. data/doc/index.xhtml +1020 -1347
  43. data/doc/intro.erb +42 -40
  44. data/doc/setup.erb +18 -18
  45. data/doc/theory.erb +24 -31
  46. data/doc/usage.erb +14 -24
  47. data/fmt/xhtml.icons/index.yaml +16 -14
  48. data/fmt/xhtml.icons/rakefile +33 -0
  49. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/16x16/places/start-here.png +0 -0
  50. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/32x32/actions/go-down.png +0 -0
  51. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/32x32/actions/go-up.png +0 -0
  52. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/32x32/places/start-here.png +0 -0
  53. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/32x32/status/software-update-available.png +0 -0
  54. data/fmt/xhtml.icons/{tango-icon-theme-0.8.1 → tango-icon-theme-0.8.90}/48x48/apps/accessories-text-editor.png +0 -0
  55. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/48x48/apps/internet-group-chat.png +0 -0
  56. data/fmt/xhtml.icons/{tango-icon-theme-0.8.1 → tango-icon-theme-0.8.90}/48x48/emblems/emblem-important.png +0 -0
  57. data/fmt/xhtml.icons/{tango-icon-theme-0.8.1 → tango-icon-theme-0.8.90}/48x48/status/dialog-error.png +0 -0
  58. data/fmt/xhtml.icons/{tango-icon-theme-0.8.1 → tango-icon-theme-0.8.90}/48x48/status/dialog-information.png +0 -0
  59. data/fmt/xhtml.icons/{tango-icon-theme-0.8.1 → tango-icon-theme-0.8.90}/48x48/status/dialog-warning.png +0 -0
  60. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/COPYING +1 -0
  61. data/fmt/xhtml.icons/{tango-icon-theme-0.8.1 → tango-icon-theme-0.8.90}/README +0 -0
  62. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/scalable/actions/bookmark-new.svg +672 -0
  63. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/scalable/actions/go-down.svg +200 -0
  64. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/scalable/actions/go-home.svg +445 -0
  65. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/scalable/actions/go-up.svg +196 -0
  66. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/scalable/actions/view-refresh.svg +393 -0
  67. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/scalable/apps/accessories-text-editor.svg +554 -0
  68. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/scalable/apps/internet-group-chat.svg +312 -0
  69. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/scalable/emblems/emblem-favorite.svg +242 -0
  70. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/scalable/emblems/emblem-important.svg +164 -0
  71. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/scalable/mimetypes/application-certificate.svg +443 -0
  72. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/scalable/places/start-here.svg +492 -0
  73. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/scalable/status/dialog-error.svg +330 -0
  74. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/scalable/status/dialog-information.svg +1159 -0
  75. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/scalable/status/dialog-warning.svg +373 -0
  76. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/scalable/status/software-update-available.svg +209 -0
  77. data/fmt/xhtml.scripts/jquery-1.3.2.min.js +19 -0
  78. data/fmt/xhtml.scripts/jquery.localscroll-1.2.7-min.js +9 -0
  79. data/fmt/xhtml.scripts/jquery.scrollTo-1.4.1-min.js +11 -0
  80. data/fmt/xhtml.yaml +470 -454
  81. data/lang/de.yaml +5 -5
  82. data/lang/el.yaml +4 -4
  83. data/lang/es.yaml +5 -5
  84. data/lang/fr.yaml +5 -5
  85. data/lang/it.yaml +5 -5
  86. data/lang/ja.yaml +4 -4
  87. data/lang/ko.yaml +4 -4
  88. data/lang/nl.yaml +4 -4
  89. data/lang/phrases.yaml +4 -4
  90. data/lang/pt.yaml +5 -5
  91. data/lang/ru.yaml +5 -5
  92. data/lang/zh.yaml +5 -5
  93. data/lang/zt.yaml +5 -5
  94. data/lib/erbook.rb +12 -5
  95. data/lib/erbook/document.rb +127 -107
  96. data/lib/erbook/rdoc.rb +18 -11
  97. data/lib/erbook/template.rb +86 -176
  98. data/lib/erbook/to_xhtml.rb +98 -25
  99. data/{Rakefile → rakefile} +1 -0
  100. metadata +106 -53
  101. data/doc/api/ERBook.html +0 -35
  102. data/doc/api/ERBook/Document.html +0 -669
  103. data/doc/api/ERBook/Document/Node.html +0 -102
  104. data/doc/api/ERBook/Template.html +0 -670
  105. data/doc/api/RDoc.html +0 -23
  106. data/doc/api/RDoc/AnyMethod.html +0 -302
  107. data/doc/api/RDoc/DummyMarkup.html +0 -73
  108. data/doc/api/RDoc/DummyMixin.html +0 -23
  109. data/doc/api/RDoc/DummyOptions.html +0 -140
  110. data/doc/api/RDoc/TopLevel.html +0 -465
  111. data/doc/api/String.html +0 -372
  112. data/doc/api/all-methods.html +0 -253
  113. data/doc/api/all-namespaces.html +0 -42
  114. data/doc/api/app.js +0 -18
  115. data/doc/api/jquery.js +0 -11
  116. data/doc/api/readme.html +0 -38
  117. data/doc/api/style.css +0 -68
  118. data/doc/api/syntax_highlight.css +0 -21
  119. data/fmt/xhtml.icons/tango-icon-theme-0.8.1/48x48/README +0 -2
  120. data/fmt/xhtml.icons/tango-icon-theme-0.8.1/48x48/apps/internet-group-chat.png +0 -0
  121. data/fmt/xhtml.icons/tango-icon-theme-0.8.1/COPYING +0 -67
data/bin/erbook CHANGED
@@ -13,36 +13,40 @@
13
13
  # erbook [Options] FormatFile [InputFile]
14
14
  #
15
15
 
16
+ #--
17
+ # Copyright 2007 Suraj N. Kurapati
18
+ # See the LICENSE file for details.
19
+ #++
20
+
16
21
  require 'rubygems'
22
+ gem 'inochi', '~> 1'
17
23
  require 'inochi'
18
24
 
19
- # command line
20
- options = Inochi.main :ERBook do
21
- # show list of available formats
22
- text 'FormatName:'
23
-
24
- require 'yaml'
25
- ERBook::FORMAT_FILES.each do |file|
26
- name = File.basename(file, '.yaml')
27
- desc = YAML.load_file(file)['desc'] rescue nil
28
- banner '%8s: %s' % [name, desc]
29
- end
30
- text ''
31
-
32
- # show list of command-line options
33
- text 'Options:'
34
- opt :unindent, 'Unindent node content hierarchically'
25
+ options = Inochi.main :ERBook do
26
+ # show list of available formats
27
+ text 'FormatName:'
28
+
29
+ require 'yaml'
30
+ ERBook::FORMAT_FILES.each do |file|
31
+ name = File.basename(file, '.yaml')
32
+ desc = YAML.load_file(file)['desc'] rescue nil
33
+ banner '%8s: %s' % [name, desc]
35
34
  end
35
+ text ''
36
36
 
37
- # program body
38
- format = ARGV.shift or
37
+ # show list of command-line options
38
+ text 'Options:'
39
+ opt :unindent, 'Unindent node content hierarchically'
40
+ end
41
+
42
+ format = ARGV.shift or
39
43
  raise ArgumentError, "Format was not specified. Run `#{$0} -h` for help."
40
44
 
41
- if input_file = ARGV.shift
42
- input_text = File.read(input_file)
43
- else
44
- input_file = 'STDIN'
45
- input_text = STDIN.read
46
- end
45
+ if input_file = ARGV.shift
46
+ input_text = File.read(input_file)
47
+ else
48
+ input_file = 'STDIN'
49
+ input_text = STDIN.read
50
+ end
47
51
 
48
- puts ERBook::Document.new(format, input_text, input_file, options)
52
+ puts ERBook::Document.new(format, input_text, input_file, options)
data/doc/HelloWorld.spec CHANGED
@@ -1,7 +1,7 @@
1
1
  desc: An example format.
2
2
 
3
3
  code: |
4
- class ERBook::Node
4
+ class ERBook::Document::Node
5
5
  def name
6
6
  # dynamically compute (and store)
7
7
  # the name of this node on demand
@@ -60,5 +60,7 @@ nodes:
60
60
 
61
61
  output: |
62
62
  Welcome to the "<%= @format[:name] %>" format.
63
+
63
64
  <%= @content %>
65
+
64
66
  That's all folks!
@@ -0,0 +1,86 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
3
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <title>ERBook</title>
7
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
8
+ <link rel="stylesheet" href="../css/reset.css" type="text/css" media="screen" />
9
+ <link rel="stylesheet" href="../css/main.css" type="text/css" media="screen" />
10
+ <script src="../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
11
+ <script src="../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
12
+ <script src="../js/main.js" type="text/javascript" charset="utf-8"></script>
13
+ </head>
14
+
15
+ <body>
16
+ <div class="banner">
17
+ <h1>
18
+ <span class="type">Module</span>
19
+ ERBook
20
+
21
+ </h1>
22
+ <ul class="files">
23
+
24
+ <li><a href="../files/lib/erbook/template_rb.html">lib/erbook/template.rb</a></li>
25
+
26
+ <li><a href="../files/lib/erbook/document_rb.html">lib/erbook/document.rb</a></li>
27
+
28
+ <li><a href="../files/lib/erbook_rb.html">lib/erbook.rb</a></li>
29
+
30
+ </ul>
31
+ </div>
32
+ <div id="bodyContent">
33
+ <div id="content">
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+ <div class="sectiontitle">Classes and Modules</div>
50
+ <ul>
51
+
52
+ <li><span class="type">CLASS</span> <a href="ERBook/Document.html">ERBook::Document</a></li>
53
+
54
+ <li><span class="type">CLASS</span> <a href="ERBook/Template.html">ERBook::Template</a></li>
55
+
56
+ </ul>
57
+
58
+
59
+
60
+ <div class="sectiontitle">Constants</div>
61
+ <table border='0' cellpadding='5'>
62
+
63
+ <tr valign='top'>
64
+ <td class="attr-name">FORMATS_DIR</td>
65
+ <td>=</td>
66
+ <td class="attr-value">File.join(INSTALL, 'fmt')</td>
67
+ </tr>
68
+
69
+
70
+ <tr valign='top'>
71
+ <td class="attr-name">FORMAT_FILES</td>
72
+ <td>=</td>
73
+ <td class="attr-value">Dir[File.join(FORMATS_DIR, '*.yaml')]</td>
74
+ </tr>
75
+
76
+
77
+ </table>
78
+
79
+
80
+
81
+
82
+
83
+ </div>
84
+ </div>
85
+ </body>
86
+ </html>
@@ -0,0 +1,399 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
3
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <title>ERBook::Document</title>
7
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
8
+ <link rel="stylesheet" href="../../css/reset.css" type="text/css" media="screen" />
9
+ <link rel="stylesheet" href="../../css/main.css" type="text/css" media="screen" />
10
+ <script src="../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
11
+ <script src="../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
12
+ <script src="../../js/main.js" type="text/javascript" charset="utf-8"></script>
13
+ </head>
14
+
15
+ <body>
16
+ <div class="banner">
17
+ <h1>
18
+ <span class="type">Class</span>
19
+ ERBook::Document
20
+
21
+ <span class="parent">&lt;
22
+
23
+ Object
24
+
25
+ </span>
26
+
27
+ </h1>
28
+ <ul class="files">
29
+
30
+ <li><a href="../../files/lib/erbook/document_rb.html">lib/erbook/document.rb</a></li>
31
+
32
+ </ul>
33
+ </div>
34
+ <div id="bodyContent">
35
+ <div id="content">
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+ <div class="sectiontitle">Methods</div>
46
+ <dl class="methods">
47
+
48
+ <dt>N</dt>
49
+ <dd>
50
+ <ul>
51
+
52
+ <li><a href="#M000042">new</a></li>
53
+
54
+ </ul>
55
+ </dd>
56
+
57
+ <dt>T</dt>
58
+ <dd>
59
+ <ul>
60
+
61
+ <li><a href="#M000055">to_s</a></li>
62
+
63
+ </ul>
64
+ </dd>
65
+
66
+ </dl>
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+ <div class="sectiontitle">Classes and Modules</div>
75
+ <ul>
76
+
77
+ <li><span class="type">CLASS</span> <a href="Document/Node.html">ERBook::Document::Node</a></li>
78
+
79
+ </ul>
80
+
81
+
82
+
83
+
84
+
85
+ <div class="sectiontitle">Attributes</div>
86
+ <table border='0' cellpadding='5'>
87
+
88
+ <tr valign='top'>
89
+ <td class='attr-rw'>
90
+ [R]
91
+ </td>
92
+ <td class='attr-name'>format</td>
93
+ <td class='attr-desc'><p>
94
+ Data from the format specification file.
95
+ </p></td>
96
+ </tr>
97
+
98
+ <tr valign='top'>
99
+ <td class='attr-rw'>
100
+ [R]
101
+ </td>
102
+ <td class='attr-name'>roots</td>
103
+ <td class='attr-desc'><p>
104
+ All root nodes in the document.
105
+ </p></td>
106
+ </tr>
107
+
108
+ <tr valign='top'>
109
+ <td class='attr-rw'>
110
+ [R]
111
+ </td>
112
+ <td class='attr-name'>nodes</td>
113
+ <td class='attr-desc'><p>
114
+ All nodes in the document.
115
+ </p></td>
116
+ </tr>
117
+
118
+ <tr valign='top'>
119
+ <td class='attr-rw'>
120
+ [R]
121
+ </td>
122
+ <td class='attr-name'>nodes_by_type</td>
123
+ <td class='attr-desc'><p>
124
+ All nodes in the document arranged by node type.
125
+ </p></td>
126
+ </tr>
127
+
128
+ </table>
129
+
130
+
131
+
132
+ <div class="sectiontitle">Class Public methods</div>
133
+
134
+ <div class="method">
135
+ <div class="title" id="M000042">
136
+
137
+ <a name="M000042"></a><b>new</b>(format_name, input_text, input_file, options = {})
138
+
139
+ </div>
140
+
141
+ <div class="description">
142
+ <h4>Parameters</h4>
143
+ <dl>
144
+ <dt>format_name</dt><dd>Either the short-hand name of a built-in format or the path to a format
145
+ specification file.
146
+
147
+ </dd>
148
+ <dt>input_text</dt><dd>The body of the input document.
149
+
150
+ </dd>
151
+ <dt>input_file</dt><dd>Name of the file from which the input document originated.
152
+
153
+ </dd>
154
+ </dl>
155
+ <h4>Options</h4>
156
+ <dl>
157
+ <dt>:unindent</dt><dd>If true, all node content is unindented hierarchically.
158
+
159
+ </dd>
160
+ </dl>
161
+
162
+ </div>
163
+
164
+
165
+
166
+
167
+ <div class="sourcecode">
168
+ <p class="source-link">
169
+ Source: <a href="javascript:toggleSource('M000042_source')" id="l_M000042_source">show</a>
170
+
171
+ | <a href="http://github.com/sunaku/erbook/blob/a096a4140d3d9ea230c89aba50526af5e4613f82/lib/erbook/document.rb#L42" target="_blank" class="github_url">on GitHub</a>
172
+
173
+ </p>
174
+ <div id="M000042_source" class="dyn-source">
175
+ <pre><span class="ruby-comment cmt"># File lib/erbook/document.rb, line 42</span>
176
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span> <span class="ruby-identifier">format_name</span>, <span class="ruby-identifier">input_text</span>, <span class="ruby-identifier">input_file</span>, <span class="ruby-identifier">options</span> = {}
177
+ <span class="ruby-comment cmt"># process format specification</span>
178
+ <span class="ruby-ivar">@format_file</span> = <span class="ruby-identifier">format_name</span>.<span class="ruby-identifier">to_s</span>
179
+
180
+ <span class="ruby-constant">File</span>.<span class="ruby-identifier">file?</span> <span class="ruby-ivar">@format_file</span> <span class="ruby-keyword kw">or</span>
181
+ <span class="ruby-ivar">@format_file</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-constant">ERBook</span><span class="ruby-operator">::</span><span class="ruby-constant">FORMATS_DIR</span>, <span class="ruby-ivar">@format_file</span> <span class="ruby-operator">+</span> <span class="ruby-value str">'.yaml'</span>)
182
+
183
+ <span class="ruby-keyword kw">begin</span>
184
+ <span class="ruby-ivar">@format</span> = <span class="ruby-constant">YAML</span>.<span class="ruby-identifier">load_file</span>(<span class="ruby-ivar">@format_file</span>)
185
+ <span class="ruby-ivar">@format</span>[<span class="ruby-identifier">:file</span>] = <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-ivar">@format_file</span>)
186
+ <span class="ruby-ivar">@format</span>[<span class="ruby-identifier">:name</span>] = <span class="ruby-constant">File</span>.<span class="ruby-identifier">basename</span>(<span class="ruby-ivar">@format_file</span>).<span class="ruby-identifier">sub</span>(<span class="ruby-regexp re">/\..*?$/</span>, <span class="ruby-value str">''</span>)
187
+
188
+ <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@format</span>.<span class="ruby-identifier">key?</span> <span class="ruby-value str">'code'</span>
189
+ <span class="ruby-identifier">eval</span> <span class="ruby-ivar">@format</span>[<span class="ruby-value str">'code'</span>].<span class="ruby-identifier">to_s</span>, <span class="ruby-constant">TOPLEVEL_BINDING</span>, <span class="ruby-node">&quot;#{@format_file}:code&quot;</span>
190
+ <span class="ruby-keyword kw">end</span>
191
+
192
+ <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span>
193
+ <span class="ruby-identifier">error</span> <span class="ruby-node">&quot;Could not load format specification file #{@format_file.inspect}&quot;</span>
194
+ <span class="ruby-keyword kw">end</span>
195
+
196
+ <span class="ruby-ivar">@node_defs</span> = <span class="ruby-ivar">@format</span>[<span class="ruby-value str">'nodes'</span>]
197
+
198
+ <span class="ruby-comment cmt"># process input document</span>
199
+ <span class="ruby-keyword kw">begin</span>
200
+ <span class="ruby-comment cmt"># create sandbox for input evaluation</span>
201
+ <span class="ruby-identifier">template</span> = <span class="ruby-constant">Template</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">input_file</span>, <span class="ruby-identifier">input_text</span>, <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:unindent</span>])
202
+ <span class="ruby-identifier">sandbox</span> = <span class="ruby-identifier">template</span>.<span class="ruby-identifier">sandbox</span>
203
+
204
+ <span class="ruby-ivar">@template_vars</span> = {
205
+ <span class="ruby-identifier">:@format</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@format</span>,
206
+ <span class="ruby-identifier">:@roots</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@roots</span> = [], <span class="ruby-comment cmt"># root nodes of all trees</span>
207
+ <span class="ruby-identifier">:@nodes</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@nodes</span> = [], <span class="ruby-comment cmt"># all nodes in the forest</span>
208
+ <span class="ruby-identifier">:@nodes_by_type</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@nodes_by_type</span> = <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">h</span>,<span class="ruby-identifier">k</span><span class="ruby-operator">|</span> <span class="ruby-identifier">h</span>[<span class="ruby-identifier">k</span>] = [] },
209
+ <span class="ruby-identifier">:@stack</span> =<span class="ruby-operator">&gt;</span> [], <span class="ruby-comment cmt"># stack for all nodes</span>
210
+ }.<span class="ruby-identifier">each_pair</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-identifier">sandbox</span>.<span class="ruby-identifier">instance_variable_set</span>(<span class="ruby-identifier">k</span>, <span class="ruby-identifier">v</span>) }
211
+
212
+ <span class="ruby-comment cmt"># Handles the method call from a node</span>
213
+ <span class="ruby-comment cmt"># placeholder in the input document.</span>
214
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">sandbox</span>.<span class="ruby-identifier">__node_impl__</span> <span class="ruby-identifier">node_type</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">node_args</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">node_content</span>
215
+ <span class="ruby-identifier">node</span> = <span class="ruby-constant">Node</span>.<span class="ruby-identifier">new</span>(
216
+ <span class="ruby-identifier">:type</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">node_type</span>,
217
+ <span class="ruby-identifier">:defn</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@format</span>[<span class="ruby-value str">'nodes'</span>][<span class="ruby-identifier">node_type</span>],
218
+ <span class="ruby-identifier">:args</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">node_args</span>,
219
+ <span class="ruby-identifier">:children</span> =<span class="ruby-operator">&gt;</span> [],
220
+
221
+ <span class="ruby-comment cmt"># omit erbook internals from the stack trace</span>
222
+ <span class="ruby-identifier">:trace</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">caller</span>.<span class="ruby-identifier">reject</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">t</span><span class="ruby-operator">|</span>
223
+ [<span class="ruby-identifier">$0</span>, <span class="ruby-constant">ERBook</span><span class="ruby-operator">::</span><span class="ruby-constant">INSTALL</span>].<span class="ruby-identifier">any?</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span> <span class="ruby-identifier">t</span>.<span class="ruby-identifier">index</span>(<span class="ruby-identifier">f</span>) <span class="ruby-operator">==</span> <span class="ruby-value">0</span> }
224
+ }
225
+ )
226
+ <span class="ruby-ivar">@nodes</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">node</span>
227
+ <span class="ruby-ivar">@nodes_by_type</span>[<span class="ruby-identifier">node</span>.<span class="ruby-identifier">type</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">node</span>
228
+
229
+ <span class="ruby-comment cmt"># calculate occurrence number for this node</span>
230
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">node</span>.<span class="ruby-identifier">defn</span>[<span class="ruby-value str">'number'</span>]
231
+ <span class="ruby-ivar">@count</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">h</span>,<span class="ruby-identifier">k</span><span class="ruby-operator">|</span> <span class="ruby-identifier">h</span>[<span class="ruby-identifier">k</span>] = []}
232
+ <span class="ruby-identifier">node</span>.<span class="ruby-identifier">number</span> = (<span class="ruby-ivar">@count</span>[<span class="ruby-identifier">node</span>.<span class="ruby-identifier">type</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">node</span>).<span class="ruby-identifier">length</span>
233
+ <span class="ruby-keyword kw">end</span>
234
+
235
+ <span class="ruby-comment cmt"># assign node family</span>
236
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">parent</span> = <span class="ruby-ivar">@stack</span>.<span class="ruby-identifier">last</span>
237
+ <span class="ruby-identifier">parent</span>.<span class="ruby-identifier">children</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">node</span>
238
+ <span class="ruby-identifier">node</span>.<span class="ruby-identifier">parent</span> = <span class="ruby-identifier">parent</span>
239
+ <span class="ruby-identifier">node</span>.<span class="ruby-identifier">depth</span> = <span class="ruby-identifier">parent</span>.<span class="ruby-identifier">depth</span>
240
+ <span class="ruby-identifier">node</span>.<span class="ruby-identifier">depth</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">node</span>.<span class="ruby-identifier">defn</span>[<span class="ruby-value str">'depth'</span>]
241
+
242
+ <span class="ruby-comment cmt"># calculate latex-style index number for this node</span>
243
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">node</span>.<span class="ruby-identifier">defn</span>[<span class="ruby-value str">'index'</span>]
244
+ <span class="ruby-identifier">ancestry</span> = <span class="ruby-ivar">@stack</span>.<span class="ruby-identifier">reverse</span>.<span class="ruby-identifier">find</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">n</span><span class="ruby-operator">|</span> <span class="ruby-identifier">n</span>.<span class="ruby-identifier">defn</span>[<span class="ruby-value str">'index'</span>] }.<span class="ruby-identifier">index</span>
245
+ <span class="ruby-identifier">branches</span> = <span class="ruby-identifier">node</span>.<span class="ruby-identifier">parent</span>.<span class="ruby-identifier">children</span>.<span class="ruby-identifier">select</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">n</span><span class="ruby-operator">|</span> <span class="ruby-identifier">n</span>.<span class="ruby-identifier">index</span> }
246
+
247
+ <span class="ruby-identifier">node</span>.<span class="ruby-identifier">index</span> = [<span class="ruby-identifier">ancestry</span>, <span class="ruby-identifier">branches</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>].<span class="ruby-identifier">join</span>(<span class="ruby-value str">'.'</span>)
248
+ <span class="ruby-keyword kw">end</span>
249
+ <span class="ruby-keyword kw">else</span>
250
+ <span class="ruby-ivar">@roots</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">node</span>
251
+ <span class="ruby-identifier">node</span>.<span class="ruby-identifier">parent</span> = <span class="ruby-keyword kw">nil</span>
252
+ <span class="ruby-identifier">node</span>.<span class="ruby-identifier">depth</span> = <span class="ruby-value">0</span>
253
+
254
+ <span class="ruby-comment cmt"># calculate latex-style index number for this node</span>
255
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">node</span>.<span class="ruby-identifier">defn</span>[<span class="ruby-value str">'index'</span>]
256
+ <span class="ruby-identifier">branches</span> = <span class="ruby-ivar">@roots</span>.<span class="ruby-identifier">select</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">n</span><span class="ruby-operator">|</span> <span class="ruby-identifier">n</span>.<span class="ruby-identifier">index</span> }
257
+ <span class="ruby-identifier">node</span>.<span class="ruby-identifier">index</span> = (<span class="ruby-identifier">branches</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>).<span class="ruby-identifier">to_s</span>
258
+ <span class="ruby-keyword kw">end</span>
259
+ <span class="ruby-keyword kw">end</span>
260
+
261
+ <span class="ruby-comment cmt"># assign node content</span>
262
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
263
+ <span class="ruby-ivar">@stack</span>.<span class="ruby-identifier">push</span> <span class="ruby-identifier">node</span>
264
+ <span class="ruby-identifier">node</span>.<span class="ruby-identifier">content</span> = <span class="ruby-identifier">__block_content__</span>(<span class="ruby-identifier">node</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">node_content</span>)
265
+ <span class="ruby-ivar">@stack</span>.<span class="ruby-identifier">pop</span>
266
+ <span class="ruby-keyword kw">end</span>
267
+
268
+ <span class="ruby-ivar">@buffer</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">node</span>
269
+
270
+ <span class="ruby-keyword kw">nil</span>
271
+ <span class="ruby-keyword kw">end</span>
272
+
273
+ <span class="ruby-ivar">@node_defs</span>.<span class="ruby-identifier">each_key</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">type</span><span class="ruby-operator">|</span>
274
+ <span class="ruby-comment cmt"># XXX: using a string because define_method()</span>
275
+ <span class="ruby-comment cmt"># does not accept a block until Ruby 1.9</span>
276
+ <span class="ruby-identifier">file</span>, <span class="ruby-identifier">line</span> = <span class="ruby-keyword kw">__FILE__</span>, <span class="ruby-keyword kw">__LINE__</span>; <span class="ruby-identifier">eval</span> <span class="ruby-node">%{
277
+ def sandbox.#{type} *node_args, &amp;node_content
278
+ __node_impl__ #{type.inspect}, *node_args, &amp;node_content
279
+ end
280
+ }</span>, <span class="ruby-identifier">binding</span>, <span class="ruby-identifier">file</span>, <span class="ruby-identifier">line</span>
281
+ <span class="ruby-keyword kw">end</span>
282
+
283
+ <span class="ruby-comment cmt"># evaluate the input &amp; build the document tree</span>
284
+ <span class="ruby-identifier">template</span>.<span class="ruby-identifier">render</span>
285
+ <span class="ruby-ivar">@processed_document</span> = <span class="ruby-identifier">template</span>.<span class="ruby-identifier">buffer</span>
286
+
287
+ <span class="ruby-comment cmt"># chain block-level nodes together for local navigation</span>
288
+ <span class="ruby-identifier">block_nodes</span> = <span class="ruby-ivar">@nodes</span>.<span class="ruby-identifier">reject</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">n</span><span class="ruby-operator">|</span> <span class="ruby-identifier">n</span>.<span class="ruby-identifier">defn</span>[<span class="ruby-value str">'bypass'</span>] <span class="ruby-operator">||</span>
289
+ <span class="ruby-identifier">n</span>.<span class="ruby-identifier">defn</span>[<span class="ruby-value str">'inline'</span>] }
290
+
291
+ <span class="ruby-identifier">require</span> <span class="ruby-value str">'enumerator'</span>
292
+ <span class="ruby-identifier">block_nodes</span>.<span class="ruby-identifier">each_cons</span>(<span class="ruby-value">2</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span><span class="ruby-operator">|</span>
293
+ <span class="ruby-identifier">a</span>.<span class="ruby-identifier">next_node</span> = <span class="ruby-identifier">b</span>
294
+ <span class="ruby-identifier">b</span>.<span class="ruby-identifier">prev_node</span> = <span class="ruby-identifier">a</span>
295
+ <span class="ruby-keyword kw">end</span>
296
+
297
+ <span class="ruby-comment cmt"># calculate output for all nodes</span>
298
+ <span class="ruby-identifier">actual_output_by_node</span> = {}
299
+
300
+ <span class="ruby-identifier">visitor</span> = <span class="ruby-identifier">lambda</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">n</span><span class="ruby-operator">|</span>
301
+ <span class="ruby-comment cmt">#</span>
302
+ <span class="ruby-comment cmt"># allow child nodes to calculate their actual</span>
303
+ <span class="ruby-comment cmt"># output and to set their identifier as Node#output</span>
304
+ <span class="ruby-comment cmt">#</span>
305
+ <span class="ruby-comment cmt"># we do this nodes first because this node's</span>
306
+ <span class="ruby-comment cmt"># content contains the child nodes' output</span>
307
+ <span class="ruby-comment cmt">#</span>
308
+ <span class="ruby-identifier">n</span>.<span class="ruby-identifier">children</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span> <span class="ruby-identifier">visitor</span>.<span class="ruby-identifier">call</span> <span class="ruby-identifier">c</span> }
309
+
310
+ <span class="ruby-comment cmt"># calculate the output for this node</span>
311
+ <span class="ruby-identifier">actual_output</span> = <span class="ruby-constant">Template</span>.<span class="ruby-identifier">new</span>(
312
+ <span class="ruby-node">&quot;#{@format_file}:nodes:#{n.type}:output&quot;</span>,
313
+ <span class="ruby-identifier">n</span>.<span class="ruby-identifier">defn</span>[<span class="ruby-value str">'output'</span>].<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">chomp</span>
314
+ ).<span class="ruby-identifier">render_with</span>(<span class="ruby-ivar">@template_vars</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">:@node</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">n</span>))
315
+
316
+ <span class="ruby-comment cmt"># reveal child nodes' actual output in this node's actual output</span>
317
+ <span class="ruby-identifier">n</span>.<span class="ruby-identifier">children</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span>
318
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">defn</span>[<span class="ruby-value str">'inline'</span>] <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">!</span><span class="ruby-identifier">c</span>.<span class="ruby-identifier">defn</span>[<span class="ruby-value str">'bypass'</span>]
319
+ <span class="ruby-identifier">actual_output</span>[<span class="ruby-identifier">c</span>.<span class="ruby-identifier">output</span>] = <span class="ruby-identifier">actual_output_by_node</span>[<span class="ruby-identifier">c</span>]
320
+
321
+ <span class="ruby-keyword kw">else</span>
322
+ <span class="ruby-comment cmt"># pull block-level node out of paragraph tag added by Maruku</span>
323
+ <span class="ruby-identifier">actual_output</span>.<span class="ruby-identifier">sub!</span> <span class="ruby-node">%r/(&lt;p&gt;\s*)?#{Regexp.quote c.output}/</span> <span class="ruby-keyword kw">do</span>
324
+ <span class="ruby-identifier">actual_output_by_node</span>[<span class="ruby-identifier">c</span>] <span class="ruby-operator">+</span> <span class="ruby-identifier">$1</span>.<span class="ruby-identifier">to_s</span>
325
+ <span class="ruby-keyword kw">end</span>
326
+ <span class="ruby-keyword kw">end</span>
327
+ <span class="ruby-keyword kw">end</span>
328
+
329
+ <span class="ruby-identifier">actual_output_by_node</span>[<span class="ruby-identifier">n</span>] = <span class="ruby-identifier">actual_output</span>
330
+
331
+ <span class="ruby-comment cmt">#</span>
332
+ <span class="ruby-comment cmt"># allow the parent node to calculate its actual</span>
333
+ <span class="ruby-comment cmt"># output without interference from the output of</span>
334
+ <span class="ruby-comment cmt"># this node (Node#to_s is aliased to Node#output)</span>
335
+ <span class="ruby-comment cmt">#</span>
336
+ <span class="ruby-comment cmt"># this assumes that having this node's string</span>
337
+ <span class="ruby-comment cmt"># representation be a consecutive sequence of digits</span>
338
+ <span class="ruby-comment cmt"># will not interfere with the text-to-whatever</span>
339
+ <span class="ruby-comment cmt"># transformation defined by the format specification</span>
340
+ <span class="ruby-comment cmt">#</span>
341
+ <span class="ruby-identifier">n</span>.<span class="ruby-identifier">output</span> = <span class="ruby-constant">Digest</span><span class="ruby-operator">::</span><span class="ruby-constant">SHA1</span>.<span class="ruby-identifier">digest</span>(<span class="ruby-identifier">n</span>.<span class="ruby-identifier">object_id</span>.<span class="ruby-identifier">to_s</span>).<span class="ruby-identifier">unpack</span>(<span class="ruby-value str">'I*'</span>).<span class="ruby-identifier">join</span>
342
+ <span class="ruby-keyword kw">end</span>
343
+
344
+ <span class="ruby-ivar">@roots</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">n</span><span class="ruby-operator">|</span> <span class="ruby-identifier">visitor</span>.<span class="ruby-identifier">call</span> <span class="ruby-identifier">n</span> }
345
+
346
+ <span class="ruby-comment cmt"># replace the temporary identifier with each node's actual output</span>
347
+ <span class="ruby-ivar">@nodes</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">n</span><span class="ruby-operator">|</span> <span class="ruby-identifier">n</span>.<span class="ruby-identifier">output</span> = <span class="ruby-identifier">actual_output_by_node</span>[<span class="ruby-identifier">n</span>] }
348
+
349
+ <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span>
350
+ <span class="ruby-identifier">puts</span> <span class="ruby-identifier">input_text</span> <span class="ruby-comment cmt"># so the user can debug line numbers in stack trace</span>
351
+ <span class="ruby-identifier">error</span> <span class="ruby-node">&quot;Could not process input document #{input_file.inspect}&quot;</span>
352
+ <span class="ruby-keyword kw">end</span>
353
+ <span class="ruby-keyword kw">end</span></pre>
354
+ </div>
355
+ </div>
356
+
357
+ </div>
358
+
359
+ <div class="sectiontitle">Instance Public methods</div>
360
+
361
+ <div class="method">
362
+ <div class="title" id="M000055">
363
+
364
+ <a name="M000055"></a><b>to_s</b>()
365
+
366
+ </div>
367
+
368
+ <div class="description">
369
+ <p>
370
+ Returns the output of this document.
371
+ </p>
372
+
373
+ </div>
374
+
375
+
376
+
377
+
378
+ <div class="sourcecode">
379
+ <p class="source-link">
380
+ Source: <a href="javascript:toggleSource('M000055_source')" id="l_M000055_source">show</a>
381
+
382
+ | <a href="http://github.com/sunaku/erbook/blob/a096a4140d3d9ea230c89aba50526af5e4613f82/lib/erbook/document.rb#L224" target="_blank" class="github_url">on GitHub</a>
383
+
384
+ </p>
385
+ <div id="M000055_source" class="dyn-source">
386
+ <pre><span class="ruby-comment cmt"># File lib/erbook/document.rb, line 224</span>
387
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_s</span><span class="ruby-identifier">to_s</span>
388
+ <span class="ruby-constant">Template</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">&quot;#{@format_file}:output&quot;</span>, <span class="ruby-ivar">@format</span>[<span class="ruby-value str">'output'</span>].<span class="ruby-identifier">to_s</span>).
389
+ <span class="ruby-identifier">render_with</span>(<span class="ruby-ivar">@template_vars</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">:@content</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@processed_document</span>.<span class="ruby-identifier">join</span>))
390
+ <span class="ruby-keyword kw">end</span></pre>
391
+ </div>
392
+ </div>
393
+
394
+ </div>
395
+
396
+ </div>
397
+ </div>
398
+ </body>
399
+ </html>