merb-gen 0.9.8 → 0.9.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. data/README +6 -3
  2. data/Rakefile +6 -4
  3. data/bin/merb-gen +1 -23
  4. data/lib/generators/controller.rb +4 -2
  5. data/lib/generators/helper.rb +0 -5
  6. data/lib/generators/merb/merb_core.rb +95 -0
  7. data/lib/generators/merb/merb_flat.rb +70 -69
  8. data/lib/generators/merb/merb_stack.rb +110 -0
  9. data/lib/generators/merb/merb_very_flat.rb +61 -64
  10. data/lib/generators/merb_plugin.rb +5 -0
  11. data/lib/generators/model.rb +5 -2
  12. data/lib/generators/resource.rb +7 -2
  13. data/lib/generators/resource_controller.rb +4 -4
  14. data/lib/generators/templates/application/common/Rakefile +2 -6
  15. data/lib/generators/templates/application/common/doc.thor +149 -0
  16. data/lib/generators/templates/application/common/dothtaccess +17 -0
  17. data/lib/generators/templates/application/common/jquery.js +32 -0
  18. data/lib/generators/templates/application/common/merb.thor +1550 -861
  19. data/lib/generators/templates/application/{merb → merb_core}/app/controllers/application.rb +0 -0
  20. data/lib/generators/templates/application/{merb → merb_core}/app/controllers/exceptions.rb +0 -0
  21. data/lib/generators/templates/application/{merb → merb_core}/app/helpers/global_helpers.rb +0 -0
  22. data/lib/generators/templates/application/{merb → merb_core}/app/views/exceptions/internal_server_error.html.erb +0 -0
  23. data/lib/generators/templates/application/{merb → merb_core}/app/views/exceptions/not_acceptable.html.erb +0 -0
  24. data/lib/generators/templates/application/{merb → merb_core}/app/views/exceptions/not_found.html.erb +0 -0
  25. data/lib/generators/templates/application/{merb → merb_core}/autotest/discover.rb +0 -0
  26. data/lib/generators/templates/application/{merb → merb_core}/autotest/merb.rb +0 -0
  27. data/lib/generators/templates/application/{merb → merb_core}/autotest/merb_rspec.rb +0 -0
  28. data/lib/generators/templates/application/{merb → merb_core}/config/environments/development.rb +7 -2
  29. data/lib/generators/templates/application/{merb → merb_core}/config/environments/production.rb +5 -2
  30. data/lib/generators/templates/application/{merb → merb_core}/config/environments/rake.rb +6 -2
  31. data/lib/generators/templates/application/merb_core/config/environments/staging.rb +10 -0
  32. data/lib/generators/templates/application/merb_core/config/environments/test.rb +12 -0
  33. data/lib/generators/templates/application/{merb → merb_core}/config/init.rb +6 -6
  34. data/lib/generators/templates/application/{merb → merb_core}/config/rack.rb +0 -0
  35. data/lib/generators/templates/application/{merb → merb_core}/config/router.rb +0 -0
  36. data/lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb +1362 -0
  37. data/lib/generators/templates/application/merb_core/doc/rdoc/generators/template/merb/api_grease.js +640 -0
  38. data/lib/generators/templates/application/merb_core/doc/rdoc/generators/template/merb/index.html.erb +37 -0
  39. data/lib/generators/templates/application/merb_core/doc/rdoc/generators/template/merb/merb.css +252 -0
  40. data/lib/generators/templates/application/merb_core/doc/rdoc/generators/template/merb/merb.rb +351 -0
  41. data/lib/generators/templates/application/merb_core/doc/rdoc/generators/template/merb/merb_doc_styles.css +492 -0
  42. data/lib/generators/templates/application/merb_core/doc/rdoc/generators/template/merb/prototype.js +2515 -0
  43. data/lib/generators/templates/application/{merb/app/models → merb_core/lib}/merb/session.rb +0 -0
  44. data/lib/generators/templates/application/{merb → merb_core}/public/favicon.ico +0 -0
  45. data/lib/generators/templates/application/{merb → merb_core}/public/images/merb.jpg +0 -0
  46. data/lib/generators/templates/application/merb_core/public/javascripts/application.js +1 -0
  47. data/lib/generators/templates/application/{merb → merb_core}/public/merb.fcgi +0 -0
  48. data/lib/generators/templates/application/{merb → merb_core}/public/robots.txt +0 -0
  49. data/lib/generators/templates/application/{merb → merb_core}/public/stylesheets/master.css +0 -0
  50. data/lib/generators/templates/application/{merb → merb_core}/spec/spec.opts +0 -0
  51. data/lib/generators/templates/application/{merb → merb_core}/spec/spec_helper.rb +0 -0
  52. data/lib/generators/templates/application/{merb → merb_core}/test/test_helper.rb +0 -0
  53. data/lib/generators/templates/application/merb_flat/application.rbt +1 -1
  54. data/lib/generators/templates/application/merb_flat/config/init.rb +8 -3
  55. data/lib/generators/templates/application/merb_plugin/LICENSE +1 -1
  56. data/lib/generators/templates/application/merb_stack/app/controllers/application.rb +2 -0
  57. data/lib/generators/templates/application/merb_stack/app/controllers/exceptions.rb +13 -0
  58. data/lib/generators/templates/application/merb_stack/app/helpers/global_helpers.rb +5 -0
  59. data/lib/generators/templates/application/merb_stack/app/models/user.rb +17 -0
  60. data/lib/generators/templates/application/merb_stack/app/views/exceptions/internal_server_error.html.erb +216 -0
  61. data/lib/generators/templates/application/merb_stack/app/views/exceptions/not_acceptable.html.erb +63 -0
  62. data/lib/generators/templates/application/merb_stack/app/views/exceptions/not_found.html.erb +47 -0
  63. data/lib/generators/templates/application/merb_stack/autotest/discover.rb +1 -0
  64. data/lib/generators/templates/application/merb_stack/autotest/merb.rb +149 -0
  65. data/lib/generators/templates/application/merb_stack/autotest/merb_rspec.rb +165 -0
  66. data/lib/generators/templates/application/merb_stack/config/database.yml +33 -0
  67. data/lib/generators/templates/application/merb_stack/config/dependencies.rb +15 -0
  68. data/lib/generators/templates/application/merb_stack/config/environments/development.rb +15 -0
  69. data/lib/generators/templates/application/merb_stack/config/environments/production.rb +10 -0
  70. data/lib/generators/templates/application/merb_stack/config/environments/rake.rb +11 -0
  71. data/lib/generators/templates/application/merb_stack/config/environments/staging.rb +10 -0
  72. data/lib/generators/templates/application/merb_stack/config/environments/test.rb +12 -0
  73. data/lib/generators/templates/application/merb_stack/config/init.rb +24 -0
  74. data/lib/generators/templates/application/merb_stack/config/rack.rb +12 -0
  75. data/lib/generators/templates/application/merb_stack/config/router.rb +44 -0
  76. data/lib/generators/templates/application/merb_stack/doc/rdoc/generators/merb_generator.rb +1362 -0
  77. data/lib/generators/templates/application/merb_stack/doc/rdoc/generators/template/merb/api_grease.js +640 -0
  78. data/lib/generators/templates/application/merb_stack/doc/rdoc/generators/template/merb/index.html.erb +37 -0
  79. data/lib/generators/templates/application/merb_stack/doc/rdoc/generators/template/merb/merb.css +252 -0
  80. data/lib/generators/templates/application/merb_stack/doc/rdoc/generators/template/merb/merb.rb +351 -0
  81. data/lib/generators/templates/application/merb_stack/doc/rdoc/generators/template/merb/merb_doc_styles.css +492 -0
  82. data/lib/generators/templates/application/merb_stack/doc/rdoc/generators/template/merb/prototype.js +2515 -0
  83. data/lib/generators/templates/application/merb_stack/merb/merb-auth/setup.rb +44 -0
  84. data/lib/generators/templates/application/merb_stack/merb/merb-auth/strategies.rb +11 -0
  85. data/lib/generators/templates/application/merb_stack/merb/session/session.rb +9 -0
  86. data/lib/generators/templates/application/merb_stack/public/favicon.ico +0 -0
  87. data/lib/generators/templates/application/merb_stack/public/images/merb.jpg +0 -0
  88. data/lib/generators/templates/application/merb_stack/public/javascripts/application.js +1 -0
  89. data/lib/generators/templates/application/merb_stack/public/merb.fcgi +22 -0
  90. data/lib/generators/templates/application/merb_stack/public/robots.txt +5 -0
  91. data/lib/generators/templates/application/merb_stack/public/stylesheets/master.css +119 -0
  92. data/lib/generators/templates/application/merb_stack/spec/spec.opts +0 -0
  93. data/lib/generators/templates/application/merb_stack/spec/spec_helper.rb +20 -0
  94. data/lib/generators/templates/application/merb_stack/test/test_helper.rb +19 -0
  95. data/lib/generators/templates/application/merb_very_flat/application.rbt +11 -5
  96. data/lib/generators/templates/component/layout/app/views/layout/%file_name%.html.erb +1 -0
  97. data/lib/generators/templates/component/resource_controller/spec/requests/%file_name%_spec.rb +53 -0
  98. data/lib/merb-gen/app_generator.rb +13 -0
  99. data/lib/merb-gen/generator.rb +36 -1
  100. data/lib/merb-gen/named_generator.rb +5 -2
  101. data/lib/merb-gen.rb +6 -8
  102. data/spec/controller_spec.rb +0 -20
  103. data/spec/{merb_full_spec.rb → merb_core_spec.rb} +11 -3
  104. data/spec/merb_stack_spec.rb +47 -0
  105. data/spec/part_controller_spec.rb +0 -39
  106. data/spec/resource_controller_spec.rb +1 -35
  107. data/spec/spec_helper.rb +4 -2
  108. metadata +133 -111
  109. data/lib/generators/merb/merb_full.rb +0 -85
  110. data/lib/generators/merb.rb +0 -24
  111. data/lib/generators/templates/application/merb/config/environments/staging.rb +0 -7
  112. data/lib/generators/templates/application/merb/config/environments/test.rb +0 -7
  113. data/lib/generators/templates/component/helper/spec/helpers/%file_name%_helper_spec.rb +0 -5
  114. data/lib/generators/templates/component/resource_controller/spec/controllers/%file_name%_spec.rb +0 -7
  115. data/spec/helper_spec.rb +0 -43
  116. data/spec/merb_spec.rb +0 -20
@@ -0,0 +1,1362 @@
1
+
2
+ # # We're responsible for generating all the HTML files
3
+ # from the object tree defined in code_objects.rb. We
4
+ # generate:
5
+ #
6
+ # [files] an html file for each input file given. These
7
+ # input files appear as objects of class
8
+ # TopLevel
9
+ #
10
+ # [classes] an html file for each class or module encountered.
11
+ # These classes are not grouped by file: if a file
12
+ # contains four classes, we'll generate an html
13
+ # file for the file itself, and four html files
14
+ # for the individual classes.
15
+ #
16
+ # Method descriptions appear in whatever entity (file, class,
17
+ # or module) that contains them.
18
+ #
19
+ # We generate files in a structure below a specified subdirectory,
20
+ # normally +doc+.
21
+ #
22
+ # opdir
23
+ # |
24
+ # |___ files
25
+ # | |__ per file summaries
26
+ # |
27
+ # |___ classes
28
+ # |__ per class/module descriptions
29
+ #
30
+ # HTML is generated using the Template class.
31
+ #
32
+
33
+ require 'ftools'
34
+
35
+ require 'rdoc/options'
36
+ require 'rdoc/template'
37
+ require 'rdoc/markup/simple_markup'
38
+ require 'rdoc/markup/simple_markup/to_html'
39
+ require 'cgi'
40
+
41
+ module Generators
42
+
43
+ # Name of sub-direcories that hold file and class/module descriptions
44
+
45
+ FILE_DIR = "files"
46
+ CLASS_DIR = "classes"
47
+ CSS_NAME = "stylesheet.css"
48
+
49
+
50
+ ##
51
+ # Build a hash of all items that can be cross-referenced.
52
+ # This is used when we output required and included names:
53
+ # if the names appear in this hash, we can generate
54
+ # an html cross reference to the appropriate description.
55
+ # We also use this when parsing comment blocks: any decorated
56
+ # words matching an entry in this list are hyperlinked.
57
+
58
+ class AllReferences
59
+ @@refs = {}
60
+
61
+ def AllReferences::reset
62
+ @@refs = {}
63
+ end
64
+
65
+ def AllReferences.add(name, html_class)
66
+ @@refs[name] = html_class
67
+ end
68
+
69
+ def AllReferences.[](name)
70
+ @@refs[name]
71
+ end
72
+
73
+ def AllReferences.keys
74
+ @@refs.keys
75
+ end
76
+ end
77
+
78
+
79
+ ##
80
+ # Subclass of the SM::ToHtml class that supports looking
81
+ # up words in the AllReferences list. Those that are
82
+ # found (like AllReferences in this comment) will
83
+ # be hyperlinked
84
+
85
+ class HyperlinkHtml < SM::ToHtml
86
+ # We need to record the html path of our caller so we can generate
87
+ # correct relative paths for any hyperlinks that we find
88
+ def initialize(from_path, context)
89
+ super()
90
+ @from_path = from_path
91
+
92
+ @parent_name = context.parent_name
93
+ @parent_name += "::" if @parent_name
94
+ @context = context
95
+ end
96
+
97
+ # We're invoked when any text matches the CROSSREF pattern
98
+ # (defined in MarkUp). If we fine the corresponding reference,
99
+ # generate a hyperlink. If the name we're looking for contains
100
+ # no punctuation, we look for it up the module/class chain. For
101
+ # example, HyperlinkHtml is found, even without the Generators::
102
+ # prefix, because we look for it in module Generators first.
103
+
104
+ def handle_special_CROSSREF(special)
105
+ name = special.text
106
+ if name[0,1] == '#'
107
+ lookup = name[1..-1]
108
+ name = lookup unless Options.instance.show_hash
109
+ else
110
+ lookup = name
111
+ end
112
+
113
+ if /([A-Z].*)[.\#](.*)/ =~ lookup
114
+ container = $1
115
+ method = $2
116
+ ref = @context.find_symbol(container, method)
117
+ else
118
+ ref = @context.find_symbol(lookup)
119
+ end
120
+
121
+ if ref and ref.document_self
122
+ "<a href=\"index.html?a=#{ref.aref}&name=#{name}\">#{name}</a>"
123
+ else
124
+ name #it does not need to be a link
125
+ end
126
+ end
127
+
128
+
129
+ # Generate a hyperlink for url, labeled with text. Handle the
130
+ # special cases for img: and link: described under handle_special_HYPEDLINK
131
+ def gen_url(url, text)
132
+ if url =~ /([A-Za-z]+):(.*)/
133
+ type = $1
134
+ path = $2
135
+ else
136
+ type = "http"
137
+ path = url
138
+ url = "http://#{url}"
139
+ end
140
+
141
+ if type == "link"
142
+ url = path
143
+ end
144
+
145
+ if (type == "http" || type == "link") && url =~ /\.(gif|png|jpg|jpeg|bmp)$/
146
+ "<img src=\"#{url}\">"
147
+ elsif (type == "http" || type == "link")
148
+ "<a href=\"#{url}\" target=\"_blank\">#{text}</a>"
149
+ else
150
+ "<a href=\"#\" onclick=\"jsHref('#{url}');\">#{text.sub(%r{^#{type}:/*}, '')}</a>"
151
+
152
+ end
153
+ end
154
+
155
+ # And we're invoked with a potential external hyperlink mailto:
156
+ # just gets inserted. http: links are checked to see if they
157
+ # reference an image. If so, that image gets inserted using an
158
+ # <img> tag. Otherwise a conventional <a href> is used. We also
159
+ # support a special type of hyperlink, link:, which is a reference
160
+ # to a local file whose path is relative to the --op directory.
161
+
162
+ def handle_special_HYPERLINK(special)
163
+ url = special.text
164
+ gen_url(url, url)
165
+ end
166
+
167
+ # HEre's a hypedlink where the label is different to the URL
168
+ # <label>[url]
169
+ #
170
+
171
+ def handle_special_TIDYLINK(special)
172
+ text = special.text
173
+ # unless text =~ /(\S+)\[(.*?)\]/
174
+ unless text =~ /\{(.*?)\}\[(.*?)\]/ or text =~ /(\S+)\[(.*?)\]/
175
+ return text
176
+ end
177
+ label = $1
178
+ url = $2
179
+ gen_url(url, label)
180
+ end
181
+
182
+ end
183
+
184
+
185
+
186
+ #####################################################################
187
+ #
188
+ # Handle common markup tasks for the various Html classes
189
+ #
190
+
191
+ module MarkUp
192
+
193
+ # Convert a string in markup format into HTML. We keep a cached
194
+ # SimpleMarkup object lying around after the first time we're
195
+ # called per object.
196
+
197
+ def markup(str, remove_para=false)
198
+ return '' unless str
199
+ unless defined? @markup
200
+ @markup = SM::SimpleMarkup.new
201
+
202
+ # class names, variable names, file names, or instance variables
203
+ @markup.add_special(/(
204
+ \b([A-Z]\w*(::\w+)*[.\#]\w+) # A::B.meth
205
+ | \b([A-Z]\w+(::\w+)*) # A::B..
206
+ | \#\w+[!?=]? # #meth_name
207
+ | \b\w+([_\/\.]+\w+)+[!?=]? # meth_name
208
+ )/x, :CROSSREF)
209
+
210
+ # external hyperlinks
211
+ @markup.add_special(/((link:|https?:|mailto:|ftp:|www\.)\S+\w)/, :HYPERLINK)
212
+
213
+ # and links of the form <text>[<url>]
214
+ @markup.add_special(/(((\{.*?\})|\b\S+?)\[\S+?\.\S+?\])/, :TIDYLINK)
215
+ # @markup.add_special(/\b(\S+?\[\S+?\.\S+?\])/, :TIDYLINK)
216
+
217
+ end
218
+ unless defined? @html_formatter
219
+ @html_formatter = HyperlinkHtml.new(self.path, self)
220
+ end
221
+
222
+ # Convert leading comment markers to spaces, but only
223
+ # if all non-blank lines have them
224
+
225
+ if str =~ /^(?>\s*)[^\#]/
226
+ content = str
227
+ else
228
+ content = str.gsub(/^\s*(#+)/) { $1.tr('#',' ') }
229
+ end
230
+
231
+ res = @markup.convert(content, @html_formatter)
232
+ if remove_para
233
+ res.sub!(/^<p>/, '')
234
+ res.sub!(/<\/p>$/, '')
235
+ end
236
+ res
237
+ end
238
+
239
+
240
+ def style_url(path, css_name=nil)
241
+ css_name ||= CSS_NAME
242
+ end
243
+
244
+ # Build a webcvs URL with the given 'url' argument. URLs with a '%s' in them
245
+ # get the file's path sprintfed into them; otherwise they're just catenated
246
+ # together.
247
+
248
+ def cvs_url(url, full_path)
249
+ if /%s/ =~ url
250
+ return sprintf( url, full_path )
251
+ else
252
+ return url + full_path
253
+ end
254
+ end
255
+ end
256
+
257
+
258
+ #####################################################################
259
+ #
260
+ # A Context is built by the parser to represent a container: contexts
261
+ # hold classes, modules, methods, require lists and include lists.
262
+ # ClassModule and TopLevel are the context objects we process here
263
+ #
264
+ class ContextUser
265
+
266
+ include MarkUp
267
+
268
+ attr_reader :context
269
+
270
+ def initialize(context, options)
271
+ @context = context
272
+ @options = options
273
+
274
+ end
275
+
276
+ # convenience method to build a hyperlink # Where's the DRY in this?? Put this in the template where it belongs
277
+ def href(link, cls, name)
278
+ %{"<a href=\"#\" onclick=\"jsHref('#{link}');\" class=\"#{cls}\">#{name}</a>"}
279
+ end
280
+
281
+ # Create a list of HtmlMethod objects for each method
282
+ # in the corresponding context object. If the @options.show_all
283
+ # variable is set (corresponding to the <tt>--all</tt> option,
284
+ # we include all methods, otherwise just the public ones.
285
+
286
+ def collect_methods
287
+ list = @context.method_list
288
+ unless @options.show_all
289
+ list = list.find_all {|m| m.visibility == :public || m.visibility == :protected || m.force_documentation }
290
+ end
291
+ @methods = list.collect {|m| HtmlMethod.new(m, self, @options) }
292
+ end
293
+
294
+ # Build a summary list of all the methods in this context
295
+ def build_method_summary_list(path_prefix="")
296
+ collect_methods unless @methods
297
+ meths = @methods.sort
298
+ res = []
299
+ meths.each do |meth|
300
+ res << {
301
+ "name" => CGI.escapeHTML(meth.name),
302
+ "aref" => meth.aref,
303
+ "href" => meth.path
304
+ }
305
+ end
306
+ res
307
+ end
308
+
309
+
310
+ # Build a list of aliases for which we couldn't find a
311
+ # corresponding method
312
+ def build_alias_summary_list(section)
313
+ values = []
314
+ @context.aliases.each do |al|
315
+ next unless al.section == section
316
+ res = {
317
+ 'old_name' => al.old_name,
318
+ 'new_name' => al.new_name,
319
+ }
320
+ if al.comment && !al.comment.empty?
321
+ res['desc'] = markup(al.comment, true)
322
+ end
323
+ values << res
324
+ end
325
+ values
326
+ end
327
+
328
+ # Build a list of constants
329
+ def build_constants_summary_list(section)
330
+ values = []
331
+ @context.constants.each do |co|
332
+ next unless co.section == section
333
+ res = {
334
+ 'name' => co.name,
335
+ 'value' => CGI.escapeHTML(co.value)
336
+ }
337
+ res['desc'] = markup(co.comment, true) if co.comment && !co.comment.empty?
338
+ values << res
339
+ end
340
+ values
341
+ end
342
+
343
+ def build_requires_list(context)
344
+ potentially_referenced_list(context.requires) {|fn| [fn + ".rb"] }
345
+ end
346
+
347
+ def build_include_list(context)
348
+ potentially_referenced_list(context.includes)
349
+ end
350
+
351
+ # Build a list from an array of <i>Htmlxxx</i> items. Look up each
352
+ # in the AllReferences hash: if we find a corresponding entry,
353
+ # we generate a hyperlink to it, otherwise just output the name.
354
+ # However, some names potentially need massaging. For example,
355
+ # you may require a Ruby file without the .rb extension,
356
+ # but the file names we know about may have it. To deal with
357
+ # this, we pass in a block which performs the massaging,
358
+ # returning an array of alternative names to match
359
+
360
+ def potentially_referenced_list(array)
361
+ res = []
362
+ array.each do |i|
363
+ ref = AllReferences[i.name]
364
+ # if !ref
365
+ # container = @context.parent
366
+ # while !ref && container
367
+ # name = container.name + "::" + i.name
368
+ # ref = AllReferences[name]
369
+ # container = container.parent
370
+ # end
371
+ # end
372
+
373
+ ref = @context.find_symbol(i.name)
374
+ ref = ref.viewer if ref
375
+
376
+ if !ref && block_given?
377
+ possibles = yield(i.name)
378
+ while !ref and !possibles.empty?
379
+ ref = AllReferences[possibles.shift]
380
+ end
381
+ end
382
+ h_name = CGI.escapeHTML(i.name)
383
+ if ref and ref.document_self
384
+ path = ref.path
385
+ res << { "name" => h_name, "href" => path }
386
+ else
387
+ res << { "name" => h_name, "href" => "" }
388
+ end
389
+ end
390
+ res
391
+ end
392
+
393
+ # Build an array of arrays of method details. The outer array has up
394
+ # to six entries, public, private, and protected for both class
395
+ # methods, the other for instance methods. The inner arrays contain
396
+ # a hash for each method
397
+
398
+ def build_method_detail_list(section)
399
+ outer = []
400
+
401
+ methods = @methods.sort
402
+ for singleton in [true, false]
403
+ for vis in [ :public, :protected, :private ]
404
+ res = []
405
+ methods.each do |m|
406
+ if m.section == section and
407
+ m.document_self and
408
+ m.visibility == vis and
409
+ m.singleton == singleton
410
+ row = {}
411
+ if m.call_seq
412
+ row["callseq"] = m.call_seq.gsub(/->/, '&rarr;')
413
+ else
414
+ row["name"] = CGI.escapeHTML(m.name)
415
+ row["params"] = m.params
416
+ end
417
+ desc = m.description.strip
418
+ row["m_desc"] = desc unless desc.empty?
419
+ row["aref"] = m.aref
420
+ row["href"] = m.path
421
+ row["m_seq"] = m.seq
422
+ row["visibility"] = m.visibility.to_s
423
+
424
+ alias_names = []
425
+ m.aliases.each do |other|
426
+ if other.viewer # won't be if the alias is private
427
+ alias_names << {
428
+ 'name' => other.name,
429
+ 'href' => other.viewer.path,
430
+ 'aref' => other.viewer.aref
431
+ }
432
+ end
433
+ end
434
+ unless alias_names.empty?
435
+ row["aka"] = alias_names
436
+ end
437
+
438
+ #if @options.inline_source
439
+ code = m.source_code
440
+ row["sourcecode"] = code if code
441
+ #else
442
+ # code = m.src_url
443
+ #if code
444
+ # row["codeurl"] = code
445
+ # row["imgurl"] = m.img_url
446
+ #end
447
+ #end
448
+ res << row
449
+ end
450
+ end
451
+ if res.size > 0
452
+ outer << {
453
+ "type" => vis.to_s.capitalize,
454
+ "category" => singleton ? "Class" : "Instance",
455
+ "methods" => res
456
+ }
457
+ end
458
+ end
459
+ end
460
+ outer
461
+ end
462
+
463
+ # Build the structured list of classes and modules contained
464
+ # in this context.
465
+
466
+ def build_class_list(level, from, section, infile=nil)
467
+ res = ""
468
+ prefix = "&nbsp;&nbsp;::" * level;
469
+
470
+ from.modules.sort.each do |mod|
471
+ next unless mod.section == section
472
+ next if infile && !mod.defined_in?(infile)
473
+ if mod.document_self
474
+ res <<
475
+ prefix <<
476
+ "Module " <<
477
+ href(mod.viewer.path, "link", mod.full_name) <<
478
+ "<br />\n" <<
479
+ build_class_list(level + 1, mod, section, infile)
480
+ end
481
+ end
482
+
483
+ from.classes.sort.each do |cls|
484
+ next unless cls.section == section
485
+ next if infile && !cls.defined_in?(infile)
486
+ if cls.document_self
487
+ res <<
488
+ prefix <<
489
+ "Class " <<
490
+ href(cls.viewer.path, "link", cls.full_name) <<
491
+ "<br />\n" <<
492
+ build_class_list(level + 1, cls, section, infile)
493
+ end
494
+ end
495
+
496
+ res
497
+ end
498
+
499
+ def document_self
500
+ @context.document_self
501
+ end
502
+
503
+ def diagram_reference(diagram)
504
+ res = diagram.gsub(/((?:src|href)=")(.*?)"/) {
505
+ $1 + $2 + '"'
506
+ }
507
+ res
508
+ end
509
+
510
+
511
+ # Find a symbol in ourselves or our parent
512
+ def find_symbol(symbol, method=nil)
513
+ res = @context.find_symbol(symbol, method)
514
+ if res
515
+ res = res.viewer
516
+ end
517
+ res
518
+ end
519
+
520
+ # create table of contents if we contain sections
521
+
522
+ def add_table_of_sections
523
+ toc = []
524
+ @context.sections.each do |section|
525
+ if section.title
526
+ toc << {
527
+ 'secname' => section.title,
528
+ 'href' => section.sequence
529
+ }
530
+ end
531
+ end
532
+
533
+ @values['toc'] = toc unless toc.empty?
534
+ end
535
+
536
+
537
+ end
538
+
539
+ #####################################################################
540
+ #
541
+ # Wrap a ClassModule context
542
+
543
+ class HtmlClass < ContextUser
544
+
545
+ @@c_seq = "C00000000"
546
+
547
+ attr_reader :path
548
+
549
+ def initialize(context, html_file, prefix, options)
550
+ super(context, options)
551
+ @@c_seq = @@c_seq.succ
552
+ @c_seq = @@c_seq
553
+ @html_file = html_file
554
+ @is_module = context.is_module?
555
+ @values = {}
556
+
557
+ context.viewer = self
558
+
559
+ @path = http_url(context.full_name, prefix)
560
+
561
+ collect_methods
562
+
563
+ AllReferences.add(name, self)
564
+ end
565
+
566
+ # return the relative file name to store this class in,
567
+ # which is also its url
568
+ def http_url(full_name, prefix)
569
+ path = full_name.dup
570
+ if path['<<']
571
+ path.gsub!(/<<\s*(\w*)/) { "from-#$1" }
572
+ end
573
+ File.join(prefix, path.split("::")) + ".html"
574
+ end
575
+
576
+ def seq
577
+ @c_seq
578
+ end
579
+
580
+ def aref
581
+ @c_seq
582
+ end
583
+
584
+ def scope
585
+ a = @context.full_name.split("::")
586
+ if a.length > 1
587
+ a.pop
588
+ a.join("::")
589
+ else
590
+ ""
591
+ end
592
+ end
593
+
594
+ def name
595
+ @context.full_name.gsub("#{scope}::", '')
596
+ end
597
+
598
+ def full_name
599
+ @context.full_name
600
+ end
601
+
602
+ def parent_name
603
+ @context.parent.full_name
604
+ end
605
+
606
+ def write_on(f)
607
+ value_hash
608
+ template = TemplatePage.new(RDoc::Page::BODY,
609
+ RDoc::Page::CLASS_PAGE,
610
+ RDoc::Page::METHOD_LIST)
611
+ template.write_html_on(f, @values)
612
+ end
613
+
614
+ def value_hash
615
+ class_attribute_values
616
+ add_table_of_sections
617
+
618
+ @values["charset"] = @options.charset
619
+ @values["style_url"] = style_url(path, @options.css)
620
+
621
+ # Convert README to html
622
+ unless File.exist?('files/README.html')
623
+ File.open('files/README.html', 'w') do |file|
624
+ file << markup(File.read(File.expand_path(@options.main_page)))
625
+ end
626
+ end
627
+
628
+ d = markup(@context.comment)
629
+ @values["description"] = d unless d.empty?
630
+
631
+ ml = build_method_summary_list
632
+ @values["methods"] = ml unless ml.empty?
633
+
634
+ il = build_include_list(@context)
635
+ @values["includes"] = il unless il.empty?
636
+
637
+ @values["sections"] = @context.sections.map do |section|
638
+
639
+ secdata = {
640
+ "sectitle" => section.title,
641
+ "secsequence" => section.sequence,
642
+ "seccomment" => markup(section.comment)
643
+ }
644
+
645
+ al = build_alias_summary_list(section)
646
+ secdata["aliases"] = al unless al.empty?
647
+
648
+ co = build_constants_summary_list(section)
649
+ secdata["constants"] = co unless co.empty?
650
+
651
+ al = build_attribute_list(section)
652
+ secdata["attributes"] = al unless al.empty?
653
+
654
+ cl = build_class_list(0, @context, section)
655
+ secdata["classlist"] = cl unless cl.empty?
656
+
657
+ mdl = build_method_detail_list(section)
658
+ secdata["method_list"] = mdl unless mdl.empty?
659
+
660
+ secdata
661
+ end
662
+
663
+ @values
664
+ end
665
+
666
+ def build_attribute_list(section)
667
+ atts = @context.attributes.sort
668
+ res = []
669
+ atts.each do |att|
670
+ next unless att.section == section
671
+ if att.visibility == :public || att.visibility == :protected || @options.show_all
672
+ entry = {
673
+ "name" => CGI.escapeHTML(att.name),
674
+ "rw" => att.rw,
675
+ "a_desc" => markup(att.comment, true)
676
+ }
677
+ unless att.visibility == :public || att.visibility == :protected
678
+ entry["rw"] << "-"
679
+ end
680
+ res << entry
681
+ end
682
+ end
683
+ res
684
+ end
685
+
686
+ def class_attribute_values
687
+ h_name = CGI.escapeHTML(name)
688
+
689
+ @values["classmod"] = @is_module ? "Module" : "Class"
690
+ @values["title"] = "#{@values['classmod']}: #{h_name}"
691
+
692
+ c = @context
693
+ c = c.parent while c and !c.diagram
694
+ if c && c.diagram
695
+ @values["diagram"] = diagram_reference(c.diagram)
696
+ end
697
+
698
+ @values["full_name"] = h_name
699
+ @values["class_seq"] = seq
700
+ parent_class = @context.superclass
701
+
702
+ if parent_class
703
+ @values["parent"] = CGI.escapeHTML(parent_class)
704
+
705
+ if parent_name
706
+ lookup = parent_name + "::" + parent_class
707
+ else
708
+ lookup = parent_class
709
+ end
710
+
711
+ parent_url = AllReferences[lookup] || AllReferences[parent_class]
712
+
713
+ if parent_url and parent_url.document_self
714
+ @values["par_url"] = parent_url.path
715
+ end
716
+ end
717
+
718
+ files = []
719
+ @context.in_files.each do |f|
720
+ res = {}
721
+ full_path = CGI.escapeHTML(f.file_absolute_name)
722
+
723
+ res["full_path"] = full_path
724
+ res["full_path_url"] = f.viewer.path if f.document_self
725
+
726
+ if @options.webcvs
727
+ res["cvsurl"] = cvs_url( @options.webcvs, full_path )
728
+ end
729
+
730
+ files << res
731
+ end
732
+
733
+ @values['infiles'] = files
734
+ end
735
+
736
+ def <=>(other)
737
+ self.name <=> other.name
738
+ end
739
+
740
+ end
741
+
742
+ #####################################################################
743
+ #
744
+ # Handles the mapping of a file's information to HTML. In reality,
745
+ # a file corresponds to a +TopLevel+ object, containing modules,
746
+ # classes, and top-level methods. In theory it _could_ contain
747
+ # attributes and aliases, but we ignore these for now.
748
+
749
+ class HtmlFile < ContextUser
750
+
751
+ @@f_seq = "F00000000"
752
+
753
+ attr_reader :path
754
+ attr_reader :name
755
+
756
+ def initialize(context, options, file_dir)
757
+ super(context, options)
758
+ @@f_seq = @@f_seq.succ
759
+ @f_seq = @@f_seq
760
+ @values = {}
761
+
762
+ @path = http_url(file_dir)
763
+ @source_file_path = File.expand_path(@context.file_relative_name).gsub("\/doc\/", "/")
764
+ @name = @context.file_relative_name
765
+
766
+ collect_methods
767
+ AllReferences.add(name, self)
768
+ context.viewer = self
769
+ end
770
+
771
+ def http_url(file_dir)
772
+ File.join(file_dir, @context.file_relative_name.tr('.', '_')) + ".html"
773
+ end
774
+
775
+ def filename_to_label
776
+ @context.file_relative_name.gsub(/%|\/|\?|\#/) {|s| '%' + ("%x" % s[0]) }
777
+ end
778
+
779
+ def seq
780
+ @f_seq
781
+ end
782
+
783
+ def aref
784
+ @f_seq
785
+ end
786
+
787
+ def name
788
+ full_path = @context.file_absolute_name
789
+ short_name = File.basename(full_path)
790
+ end
791
+
792
+ def full_name
793
+ @context.file_absolute_name
794
+ end
795
+
796
+ def scope
797
+ @context.file_relative_name.gsub(/\/#{name}$/, '')
798
+ end
799
+
800
+ def parent_name
801
+ nil
802
+ end
803
+
804
+ def full_file_source
805
+ ret_str = ""
806
+ File.open(@source_file_path, 'r') do |f|
807
+ while(!f.eof?) do
808
+ ret_str += f.readline()
809
+ end
810
+ end
811
+ ret_str
812
+ rescue
813
+ "file not found -#{@source_file_path}-"
814
+ #@source_file_path
815
+ end
816
+
817
+ def value_hash
818
+ file_attribute_values
819
+ add_table_of_sections
820
+
821
+ @values["charset"] = @options.charset
822
+ @values["href"] = path
823
+ @values["style_url"] = style_url(path, @options.css)
824
+ @values["file_seq"] = seq
825
+
826
+ #pulling in the source for this file
827
+ #@values["source_code"] = @context.token_stream
828
+
829
+ @values["file_source_code"] = CGI.escapeHTML(full_file_source)
830
+
831
+ if @context.comment
832
+ d = markup(@context.comment)
833
+ @values["description"] = d if d.size > 0
834
+ end
835
+
836
+ ml = build_method_summary_list
837
+ @values["methods"] = ml unless ml.empty?
838
+
839
+ il = build_include_list(@context)
840
+ @values["includes"] = il unless il.empty?
841
+
842
+ rl = build_requires_list(@context)
843
+ @values["requires"] = rl unless rl.empty?
844
+
845
+
846
+ file_context = @context
847
+
848
+ @values["sections"] = @context.sections.map do |section|
849
+
850
+ secdata = {
851
+ "sectitle" => section.title,
852
+ "secsequence" => section.sequence,
853
+ "seccomment" => markup(section.comment)
854
+ }
855
+
856
+ cl = build_class_list(0, @context, section, file_context)
857
+ @values["classlist"] = cl unless cl.empty?
858
+
859
+ mdl = build_method_detail_list(section)
860
+ secdata["method_list"] = mdl unless mdl.empty?
861
+
862
+ al = build_alias_summary_list(section)
863
+ secdata["aliases"] = al unless al.empty?
864
+
865
+ co = build_constants_summary_list(section)
866
+ @values["constants"] = co unless co.empty?
867
+
868
+ secdata
869
+ end
870
+
871
+ @values
872
+ end
873
+
874
+ def write_on(f)
875
+ value_hash
876
+ template = TemplatePage.new(RDoc::Page::SRC_BODY,RDoc::Page::FILE_PAGE, RDoc::Page::METHOD_LIST)
877
+ template.write_html_on(f, @values)
878
+ end
879
+
880
+ def file_attribute_values
881
+ full_path = @context.file_absolute_name
882
+ short_name = File.basename(full_path)
883
+
884
+ @values["title"] = CGI.escapeHTML("File: #{short_name}")
885
+
886
+ if @context.diagram
887
+ @values["diagram"] = diagram_reference(@context.diagram)
888
+ end
889
+
890
+ @values["short_name"] = CGI.escapeHTML(short_name)
891
+ @values["full_path"] = CGI.escapeHTML(full_path)
892
+ @values["dtm_modified"] = @context.file_stat.mtime.to_s
893
+
894
+ if @options.webcvs
895
+ @values["cvsurl"] = cvs_url( @options.webcvs, @values["full_path"] )
896
+ end
897
+ end
898
+
899
+ def <=>(other)
900
+ self.name <=> other.name
901
+ end
902
+ end
903
+
904
+ #####################################################################
905
+
906
+ class HtmlMethod
907
+ include MarkUp
908
+
909
+ attr_reader :context
910
+ attr_reader :src_url
911
+ attr_reader :img_url
912
+ attr_reader :source_code
913
+
914
+ @@m_seq = "M000000"
915
+
916
+ @@all_methods = []
917
+
918
+ def HtmlMethod::reset
919
+ @@all_methods = []
920
+ end
921
+
922
+ def initialize(context, html_class, options)
923
+ @context = context
924
+ @html_class = html_class
925
+ @options = options
926
+ @@m_seq = @@m_seq.succ
927
+ @m_seq = @@m_seq
928
+ @@all_methods << self
929
+
930
+ context.viewer = self
931
+
932
+ if (ts = @context.token_stream)
933
+ @source_code = markup_code(ts)
934
+ #unless @options.inline_source
935
+ # @src_url = create_source_code_file(@source_code)
936
+ # @img_url = MERBGenerator.gen_url(path, 'source.png')
937
+ #end
938
+ end
939
+ AllReferences.add(name, self)
940
+ end
941
+
942
+ def seq
943
+ @m_seq
944
+ end
945
+
946
+ def aref
947
+ @m_seq
948
+ end
949
+
950
+ def scope
951
+ @html_class.full_name
952
+ end
953
+
954
+ # return a reference to outselves to be used as an href=
955
+ # the form depends on whether we're all in one file
956
+ # or in multiple files
957
+
958
+ def name
959
+ @context.name
960
+ end
961
+
962
+ def section
963
+ @context.section
964
+ end
965
+
966
+ def parent_name
967
+ if @context.parent.parent
968
+ @context.parent.parent.full_name
969
+ else
970
+ nil
971
+ end
972
+ end
973
+
974
+ def path
975
+ @html_class.path
976
+ end
977
+
978
+ def description
979
+ markup(@context.comment)
980
+ end
981
+
982
+ def visibility
983
+ @context.visibility
984
+ end
985
+
986
+ def singleton
987
+ @context.singleton
988
+ end
989
+
990
+ def call_seq
991
+ cs = @context.call_seq
992
+ if cs
993
+ cs.gsub(/\n/, "<br />\n")
994
+ else
995
+ nil
996
+ end
997
+ end
998
+
999
+ def params
1000
+ # params coming from a call-seq in 'C' will start with the
1001
+ # method name
1002
+ p = @context.params
1003
+ if p !~ /^\w/
1004
+ p = @context.params.gsub(/\s*\#.*/, '')
1005
+ p = p.tr("\n", " ").squeeze(" ")
1006
+ p = "(" + p + ")" unless p[0] == ?(
1007
+
1008
+ if (block = @context.block_params)
1009
+ # If this method has explicit block parameters, remove any
1010
+ # explicit &block
1011
+
1012
+ p.sub!(/,?\s*&\w+/, '')
1013
+
1014
+ block.gsub!(/\s*\#.*/, '')
1015
+ block = block.tr("\n", " ").squeeze(" ")
1016
+ if block[0] == ?(
1017
+ block.sub!(/^\(/, '').sub!(/\)/, '')
1018
+ end
1019
+ p << " {|#{block.strip}| ...}"
1020
+ end
1021
+ end
1022
+ CGI.escapeHTML(p)
1023
+ end
1024
+
1025
+ def create_source_code_file(code_body)
1026
+ meth_path = @html_class.path.sub(/\.html$/, '.src')
1027
+ File.makedirs(meth_path)
1028
+ file_path = File.join(meth_path, seq) + ".html"
1029
+
1030
+ template = TemplatePage.new(RDoc::Page::SRC_PAGE)
1031
+ File.open(file_path, "w") do |f|
1032
+ values = {
1033
+ 'title' => CGI.escapeHTML(name),
1034
+ 'code' => code_body,
1035
+ 'style_url' => style_url(file_path, @options.css),
1036
+ 'charset' => @options.charset
1037
+ }
1038
+ template.write_html_on(f, values)
1039
+ end
1040
+ file_path
1041
+ end
1042
+
1043
+ def HtmlMethod.all_methods
1044
+ @@all_methods
1045
+ end
1046
+
1047
+ def <=>(other)
1048
+ @context <=> other.context
1049
+ end
1050
+
1051
+ ##
1052
+ # Given a sequence of source tokens, mark up the source code
1053
+ # to make it look purty.
1054
+
1055
+
1056
+ def markup_code(tokens)
1057
+ src = ""
1058
+ tokens.each do |t|
1059
+ next unless t
1060
+ # p t.class
1061
+ # style = STYLE_MAP[t.class]
1062
+ style = case t
1063
+ when RubyToken::TkCONSTANT then "ruby-constant"
1064
+ when RubyToken::TkKW then "ruby-keyword kw"
1065
+ when RubyToken::TkIVAR then "ruby-ivar"
1066
+ when RubyToken::TkOp then "ruby-operator"
1067
+ when RubyToken::TkId then "ruby-identifier"
1068
+ when RubyToken::TkNode then "ruby-node"
1069
+ when RubyToken::TkCOMMENT then "ruby-comment cmt"
1070
+ when RubyToken::TkREGEXP then "ruby-regexp re"
1071
+ when RubyToken::TkSTRING then "ruby-value str"
1072
+ when RubyToken::TkVal then "ruby-value"
1073
+ else
1074
+ nil
1075
+ end
1076
+
1077
+ text = CGI.escapeHTML(t.text)
1078
+
1079
+ if style
1080
+ src << "<span class=\"#{style}\">#{text}</span>"
1081
+ else
1082
+ src << text
1083
+ end
1084
+ end
1085
+
1086
+ add_line_numbers(src)
1087
+ src
1088
+ end
1089
+
1090
+ # we rely on the fact that the first line of a source code
1091
+ # listing has
1092
+ # # File xxxxx, line dddd
1093
+
1094
+ def add_line_numbers(src)
1095
+ if src =~ /\A.*, line (\d+)/
1096
+ first = $1.to_i - 1
1097
+ last = first + src.count("\n")
1098
+ size = last.to_s.length
1099
+ real_fmt = "%#{size}d: "
1100
+ fmt = " " * (size+2)
1101
+ src.gsub!(/^/) do
1102
+ res = sprintf(fmt, first)
1103
+ first += 1
1104
+ fmt = real_fmt
1105
+ res
1106
+ end
1107
+ end
1108
+ end
1109
+
1110
+ def document_self
1111
+ @context.document_self
1112
+ end
1113
+
1114
+ def aliases
1115
+ @context.aliases
1116
+ end
1117
+
1118
+ def find_symbol(symbol, method=nil)
1119
+ res = @context.parent.find_symbol(symbol, method)
1120
+ if res
1121
+ res = res.viewer
1122
+ end
1123
+ res
1124
+ end
1125
+ end
1126
+
1127
+ #####################################################################
1128
+
1129
+ class MERBGenerator
1130
+
1131
+ include MarkUp
1132
+
1133
+ # Generators may need to return specific subclasses depending
1134
+ # on the options they are passed. Because of this
1135
+ # we create them using a factory
1136
+
1137
+ def MERBGenerator.for(options)
1138
+ AllReferences::reset
1139
+ HtmlMethod::reset
1140
+
1141
+ MERBGenerator.new(options)
1142
+
1143
+ end
1144
+
1145
+ class <<self
1146
+ protected :new
1147
+ end
1148
+
1149
+ # Set up a new HTML generator. Basically all we do here is load
1150
+ # up the correct output temlate
1151
+
1152
+ def initialize(options) #:not-new:
1153
+ @options = options
1154
+ load_html_template
1155
+ end
1156
+
1157
+
1158
+ ##
1159
+ # Build the initial indices and output objects
1160
+ # based on an array of TopLevel objects containing
1161
+ # the extracted information.
1162
+
1163
+ def generate(toplevels)
1164
+ @toplevels = toplevels
1165
+ @files = []
1166
+ @classes = []
1167
+
1168
+ write_style_sheet
1169
+ write_javascript
1170
+ gen_sub_directories()
1171
+ build_indices
1172
+ generate_html
1173
+ end
1174
+
1175
+ private
1176
+
1177
+ ##
1178
+ # Load up the AJAX HTML template specified in the options.
1179
+ # If the template name contains a slash, use it literally
1180
+ #
1181
+ def load_html_template
1182
+ template = @options.template
1183
+ unless template =~ %r{/|\\}
1184
+ template = File.join("rdoc/generators/template", @options.generator.key, template)
1185
+ end
1186
+ require template
1187
+ extend RDoc::Page
1188
+ rescue LoadError
1189
+ $stderr.puts "Could not find AJAX template '#{template}'"
1190
+ exit 99
1191
+ end
1192
+
1193
+ ##
1194
+ # Write out the style sheet used by the main frames
1195
+ #
1196
+
1197
+ def write_style_sheet
1198
+ template = TemplatePage.new(RDoc::Page::STYLE)
1199
+ File.open(CSS_NAME, "w") do |f|
1200
+ values = { "font" => "helvetica"} #this is not used anywhere but the template function demands a hash of values
1201
+ template.write_html_on(f, values)
1202
+ end
1203
+ end
1204
+
1205
+ def write_javascript
1206
+ #Argh... I couldn't figure out how to copy these from the template dir so they were copied into
1207
+ # the template file "ajax.rb" and processed similarlly to the style sheets. Not exactly a good thing to do with
1208
+ # external library code. Not very DRY.
1209
+
1210
+ File.open("api_grease.js", "w") do |f|
1211
+ f << RDoc::Page::API_GREASE_JS
1212
+ end
1213
+
1214
+ File.open("prototype.js", "w") do |f|
1215
+ f << RDoc::Page::PROTOTYPE_JS
1216
+ end
1217
+
1218
+ rescue LoadError
1219
+ $stderr.puts "Could not find AJAX template"
1220
+ exit 99
1221
+ end
1222
+
1223
+ ##
1224
+ # See the comments at the top for a description of the
1225
+ # directory structure
1226
+
1227
+ def gen_sub_directories
1228
+ File.makedirs(FILE_DIR, CLASS_DIR)
1229
+ rescue
1230
+ $stderr.puts $!.message
1231
+ exit 1
1232
+ end
1233
+
1234
+ ##
1235
+ # Generate:
1236
+ #
1237
+ # * a list of HtmlFile objects for each TopLevel object.
1238
+ # * a list of HtmlClass objects for each first level
1239
+ # class or module in the TopLevel objects
1240
+ # * a complete list of all hyperlinkable terms (file,
1241
+ # class, module, and method names)
1242
+
1243
+ def build_indices
1244
+
1245
+ @toplevels.each do |toplevel|
1246
+ @files << HtmlFile.new(toplevel, @options, FILE_DIR)
1247
+ end
1248
+
1249
+ RDoc::TopLevel.all_classes_and_modules.each do |cls|
1250
+ build_class_list(cls, @files[0], CLASS_DIR)
1251
+ end
1252
+ end
1253
+
1254
+ def build_class_list(from, html_file, class_dir)
1255
+ @classes << HtmlClass.new(from, html_file, class_dir, @options)
1256
+ from.each_classmodule do |mod|
1257
+ build_class_list(mod, html_file, class_dir)
1258
+ end
1259
+ end
1260
+
1261
+ ##
1262
+ # Generate all the HTML
1263
+ #
1264
+ def generate_html
1265
+ # the individual descriptions for files and classes
1266
+ gen_into(@files)
1267
+ gen_into(@classes)
1268
+ # and the index files
1269
+ gen_file_index
1270
+ gen_class_index
1271
+ gen_method_index
1272
+ gen_main_index
1273
+
1274
+ # this method is defined in the template file
1275
+ write_extra_pages if defined? write_extra_pages
1276
+ end
1277
+
1278
+ def gen_into(list)
1279
+ list.each do |item|
1280
+ if item.document_self
1281
+ op_file = item.path
1282
+ File.makedirs(File.dirname(op_file))
1283
+ File.open(op_file, "w") { |file| item.write_on(file) }
1284
+ end
1285
+ end
1286
+
1287
+ end
1288
+
1289
+ def gen_file_index
1290
+ gen_an_index(@files, 'Files',
1291
+ RDoc::Page::FILE_INDEX,
1292
+ "fr_file_index.html")
1293
+ end
1294
+
1295
+ def gen_class_index
1296
+ gen_an_index(@classes, 'Classes',
1297
+ RDoc::Page::CLASS_INDEX,
1298
+ "fr_class_index.html")
1299
+ end
1300
+
1301
+ def gen_method_index
1302
+ gen_an_index(HtmlMethod.all_methods, 'Methods',
1303
+ RDoc::Page::METHOD_INDEX,
1304
+ "fr_method_index.html")
1305
+ end
1306
+
1307
+
1308
+ def gen_an_index(collection, title, template, filename)
1309
+ template = TemplatePage.new(RDoc::Page::FR_INDEX_BODY, template)
1310
+ res = []
1311
+ collection.sort.each do |f|
1312
+ if f.document_self
1313
+ res << { "href" => f.path, "name" => f.name, "scope" => f.scope, "seq_id" => f.seq }
1314
+ end
1315
+ end
1316
+
1317
+ values = {
1318
+ "entries" => res,
1319
+ 'list_title' => CGI.escapeHTML(title),
1320
+ 'index_url' => main_url,
1321
+ 'charset' => @options.charset,
1322
+ 'style_url' => style_url('', @options.css),
1323
+ }
1324
+
1325
+ File.open(filename, "w") do |f|
1326
+ template.write_html_on(f, values)
1327
+ end
1328
+ end
1329
+
1330
+ # The main index page is mostly a template frameset, but includes
1331
+ # the initial page. If the <tt>--main</tt> option was given,
1332
+ # we use this as our main page, otherwise we use the
1333
+ # first file specified on the command line.
1334
+
1335
+ def gen_main_index
1336
+ template = TemplatePage.new(RDoc::Page::INDEX)
1337
+ File.open("index.html", "w") do |f|
1338
+ tStr = ""
1339
+ #File.open(main_url, 'r') do |g|
1340
+ # tStr = markup(g)
1341
+ #end
1342
+ values = {
1343
+ "initial_page" => tStr,
1344
+ 'title' => CGI.escapeHTML(@options.title),
1345
+ 'charset' => @options.charset,
1346
+ 'content' => File.read('files/README.html')
1347
+ }
1348
+
1349
+ values['inline_source'] = true
1350
+ template.write_html_on(f, values)
1351
+ end
1352
+ end
1353
+
1354
+ # return the url of the main page
1355
+ def main_url
1356
+ "files/README.html"
1357
+ end
1358
+
1359
+
1360
+ end
1361
+
1362
+ end