bee_java 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/bin/beedoc DELETED
@@ -1,800 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # Copyright 2006-2010 Michel Casabianca <michel.casabianca@gmail.com>
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
-
17
- # Script to generate documentation from various sources.
18
-
19
- $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
20
- require 'rubygems'
21
- require 'erb'
22
- require 'fileutils'
23
- require 'yaml'
24
- require 'rexml/document'
25
- require 'rdoc/markup/simple_markup'
26
- require 'rdoc/markup/simple_markup/to_html'
27
- require 'singleton'
28
- require 'syntax/convertors/html'
29
-
30
- module Bee
31
-
32
- # Module for Bee documentation generation.
33
- module Doc
34
-
35
- # Console help.
36
- HELP = 'beedoc [-h] [-o dir] menu
37
- -h Print help about usage and exit.
38
- -o Output directory for documentation.
39
- menu Menu file to process.'
40
- # Exit value on error parsing command line
41
- EXIT_PARSING_CMDLINE = 1
42
- # Exit value on doc error
43
- EXIT_DOC_ERROR = 2
44
- # Exit value on unknown error
45
- EXIT_UNKNOWN_ERROR = 3
46
-
47
- #########################################################################
48
- # CLASS DOCERROR #
49
- #########################################################################
50
-
51
- class DocError < RuntimeError; end
52
-
53
- module DocErrorMixin
54
-
55
- # Convenient method to raise a DocError.
56
- # - message: error message.
57
- def error(message)
58
- raise DocError.new(message)
59
- end
60
-
61
- end
62
-
63
- #########################################################################
64
- # PARSE COMMAND LINE #
65
- #########################################################################
66
-
67
- # Parse command line and return arguments.
68
- def self.parse_command_line
69
- help = false
70
- output = nil
71
- require 'getoptlong'
72
- begin
73
- opts = GetoptLong.new(['--help', '-h', GetoptLong::NO_ARGUMENT ],
74
- ['--output', '-o', GetoptLong::REQUIRED_ARGUMENT])
75
- opts.each do |opt, arg|
76
- case opt
77
- when '--help'
78
- help = true
79
- when '--output'
80
- output = arg
81
- end
82
- end
83
- help = true if ARGV.length > 1
84
- menu = ARGV[0]
85
- return [help, output, menu]
86
- end
87
- end
88
-
89
- # Run BeeDoc from command line.
90
- def self.start_command_line
91
- STDOUT.sync = true
92
- begin
93
- help, output, menu = parse_command_line
94
- rescue
95
- puts "ERROR: parsing command line (type 'beedoc -h' for help): #{$!}"
96
- exit(EXIT_PARSING_CMDLINE)
97
- end
98
- begin
99
- if help
100
- puts COPYRIGHT
101
- puts HELP
102
- else
103
- raise DocError.new("No menu file") if not menu
104
- Bee::Doc::Menu.new(menu).generate(output)
105
- puts "OK"
106
- end
107
- rescue DocError
108
- puts "ERROR: #{$!}"
109
- exit(EXIT_DOC_ERROR)
110
- rescue Exception => e
111
- puts "ERROR: #{$!}"
112
- puts e.backtrace.join("\n")
113
- exit(EXIT_UNKNOWN_ERROR)
114
- end
115
- end
116
-
117
- #########################################################################
118
- # CLASS MENU #
119
- #########################################################################
120
-
121
- class Menu
122
-
123
- include DocErrorMixin
124
-
125
- # Title for documentation.
126
- attr_reader :title
127
- # Generation date.
128
- attr_reader :date
129
- # List of menu entries.
130
- attr_reader :entries
131
- # Base directory.
132
- attr_reader :base
133
- # Contents for page being generated.
134
- attr_reader :contents
135
- # Processor for PI.
136
- attr_reader :processor
137
-
138
- # Constructor.
139
- # - file: menu file to load.
140
- def initialize(file)
141
- begin
142
- @base = File.dirname(file)
143
- @processor = Processor.new(self)
144
- source = File.read(file)
145
- menu = YAML::load(source)
146
- @entries = []
147
- error "Menu must be a list" unless menu.kind_of?(Array)
148
- error "Menu description must be first entry" unless
149
- menu[0].kind_of?(Hash) and menu[0]['menu']
150
- @title = menu[0]['menu']
151
- @date = Time.now
152
- for entry in menu[1..-1]
153
- @entries << Entry.new(entry, self)
154
- end
155
- rescue
156
- error "Error loading menu file: #{$!}"
157
- end
158
- end
159
-
160
- # Generate documentation.
161
- # - output: output directory.
162
- def generate(output)
163
- error "Destination directory '#{output}' already exists" if
164
- File.exists?(output)
165
- FileUtils.makedirs(output)
166
- for entry in @entries
167
- entry.generate(output, @date)
168
- end
169
- # write stylesheet
170
- File.open(File.join(output, 'stylesheet.css'), 'w') do |file|
171
- file.write(Entry::DEFAULT_STYLESHEET)
172
- end
173
- end
174
-
175
- # Get absolute path for file relative to menu file.
176
- # - file: file relative to menu file.
177
- def abs_file(file)
178
- return File.join(@base, file)
179
- end
180
-
181
- end
182
-
183
- #########################################################################
184
- # CLASS ENTRY #
185
- #########################################################################
186
-
187
- # A menu entry.
188
- class Entry
189
-
190
- include DocErrorMixin
191
-
192
- # Parent menu.
193
- attr_reader :menu
194
- # Title.
195
- attr_reader :title
196
- # Document type (text, html, dir or link).
197
- attr_reader :type
198
- # File.
199
- attr_reader :file
200
- # Source directory.
201
- attr_reader :dir
202
- # Destination file.
203
- attr_reader :dest
204
- # Generation date.
205
- attr_reader :date
206
-
207
- # Entry types.
208
- TYPES = ['yaml', 'rdoc', 'html', 'text', 'dir', 'link', 'section']
209
- # Default TOC level (header level parsed to generate TOC).
210
- DEFAULT_TOC_LEVEL = 2
211
- # Default TOC depth.
212
- DEFAULT_TOC_DEPTH = 1
213
-
214
- # Constructor.
215
- # - entry: menu entry as a Hash.
216
- # - menu: the root menu for the entry.
217
- def initialize(entry, menu)
218
- # check keys in entry
219
- error "Unknown entry type '#{entry['type']}'" unless
220
- TYPES.member?(entry['type'])
221
- error "A menu entry must be a Hash" unless entry.kind_of?(Hash)
222
- error "'title' key is mandatory in menu entries" unless entry['title']
223
- error "One of 'file' or 'dir' keys must be in a menu entry" unless
224
- (entry['file'] or entry['dir']) or entry['type'] == 'link' or
225
- entry['type'] == 'section'
226
- error "'file' and 'dir' keys can't be in a menu entry at the " +
227
- "same time" if entry['file'] and entry['dir']
228
- # save keys into fields
229
- @menu = menu
230
- @title = entry['title']
231
- @type = entry['type']
232
- @file = entry['file']
233
- @dir = entry['dir']
234
- @dest = entry['dest']
235
- @template = entry['template']
236
- @erb = entry['erb']
237
- @toc = entry['toc']
238
- @level = entry['level'] || DEFAULT_TOC_LEVEL
239
- @depth = entry['depth'] || DEFAULT_TOC_DEPTH
240
- @process = entry['process']
241
- end
242
-
243
- # Generate a menu entry.
244
- # - output: destination directory.
245
- # - date: generation date.
246
- def generate(output, date)
247
- @date = date
248
- case @type
249
- when 'yaml'
250
- # entry is a yaml file: process using an ERB
251
- puts "Generating '#{@dest}' from yaml..."
252
- template = load_template(output)
253
- erb = ERB.new(File.read(@menu.abs_file(@erb)), nil, '%')
254
- @data = YAML::load(File.read(@menu.abs_file(file)))
255
- @contents = erb.result(get_binding)
256
- @contents = process_instructions(@contents) if @process
257
- @table = generate_toc(@contents, @level, @depth) if @toc
258
- result = template.result(get_binding)
259
- File.open(File.join(output, @dest), 'w') do |file|
260
- file.write(result)
261
- end
262
- when 'rdoc'
263
- # entry is a rdoc file: process rdoc
264
- puts "Generating '#{@dest}' from rdoc..."
265
- template = load_template(output)
266
- markup = SM::SimpleMarkup.new
267
- tohtml = SM::ToHtml.new
268
- rdoc = File.read(@menu.abs_file(@file))
269
- @contents = markup.convert(rdoc, tohtml)
270
- @contents = process_instructions(@contents) if @process
271
- @table = generate_toc(@contents, @level, @depth) if @toc
272
- result = template.result(get_binding)
273
- File.open(File.join(output, @dest), 'w') do |file|
274
- file.write(result)
275
- end
276
- when 'text'
277
- # entry is a text file: process it to remove HTML entities
278
- puts "Generating '#{@dest}' from text..."
279
- template = load_template(output)
280
- @contents = File.read(@menu.abs_file(@file))
281
- @contents = Entry.escape_special_characters(@contents)
282
- @contents = process_instructions(@contents) if @process
283
- result = template.result(get_binding)
284
- File.open(File.join(output, @dest), 'w') do |file|
285
- file.write(result)
286
- end
287
- when 'html'
288
- # entry is an HTML file: put it verbatim
289
- puts "Generating '#{@dest}' from html..."
290
- template = load_template(output)
291
- @contents = File.read(@menu.abs_file(@file))
292
- @contents = process_instructions(@contents) if @process
293
- @table = generate_toc(@contents, @level, @depth) if @toc
294
- result = template.result(get_binding)
295
- File.open(File.join(output, @dest), 'w') do |file|
296
- file.write(result)
297
- end
298
- when 'dir'
299
- # entry is a directory: copy it to destination directory
300
- puts "Copying directory '#{@dir}'..."
301
- FileUtils.cp_r(File.join(@menu.base, @dir),
302
- File.join(output, @dest))
303
- when 'link'
304
- # entry is a link: nothing to do
305
- when 'section'
306
- # entry is a section: nothing to do
307
- else
308
- error "Unknown entry type '#{@type}'"
309
- end
310
- end
311
-
312
- private
313
-
314
- # Load template and write default stylesheet if necessary.
315
- # - output: output directory.
316
- def load_template(output)
317
- if @template
318
- template = ERB.new(File.read(@menu.abs_file(@template)))
319
- else
320
- template = ERB.new(DEFAULT_TEMPLATE)
321
- File.open(File.join(output, 'stylesheet.css'), 'w') do |file|
322
- file.write(DEFAULT_STYLESHEET)
323
- end
324
- end
325
- return template
326
- end
327
-
328
- # Generate table of contents as an Array.
329
- # - contents: HTML page contents.
330
- # - level: header level to scan.
331
- # - depth: toc depth.
332
- # Return: TOC as an Array with reference to link the page.
333
- def generate_toc(contents, level, depth)
334
- level = DEFAULT_TOC_LEVEL if not level
335
- levels = (level..(level+depth-1)).to_a.join
336
- toc = []
337
- contents.gsub!(/<[h|H][#{levels}]>.*?<\/[h|H][#{levels}]>/) do |tag|
338
- name = tag.match(/<[h|H][#{levels}]>(.*?)<\/[h|H][#{levels}]>/)[1]
339
- d = tag.match(/<[h|H]([#{levels}])>.*?<\/[h|H][#{levels}]>/)[1].to_i -
340
- level
341
- toc << { :title => name, :depth => d }
342
- "<a name=\"#{name}\">#{tag}</a>"
343
- end
344
- return toc
345
- end
346
-
347
- # Get a binding for ERB generation.
348
- def get_binding
349
- return binding
350
- end
351
-
352
- # Escape HTML special characters (such as & " ' < and >).
353
- # - string: string to process.
354
- # Return: processed string.
355
- def self.escape_special_characters(string)
356
- return string.gsub(/&/, '&amp;').gsub(/"/, '&quot;').
357
- gsub(/'/, '&apos;').gsub(/</, '&lt;').gsub(/>/, '&gt;')
358
- end
359
-
360
- # Process page contents using processing instructions.
361
- # - contents: contents to process.
362
- def process_instructions(contents)
363
- return contents.gsub(/<\?.*?\?>/m) do |instruction|
364
- call_processor(instruction)
365
- end
366
- end
367
-
368
- # Process a given processing instruction.
369
- # - instruction: processing instruction to process.
370
- def call_processor(instruction)
371
- begin
372
- xml = "<#{instruction[2..-3].strip}/>"
373
- document = REXML::Document.new(xml)
374
- root = document.root
375
- command = root.name
376
- args = {}
377
- for name in root.attributes.keys
378
- value = root.attributes[name]
379
- args[name] = value
380
- end
381
- error "Instruction '#{command}' not found" if
382
- not @menu.processor.respond_to?(command)
383
- return @menu.processor.send(command, args)
384
- rescue
385
- error "Error parsing instruction '#{instruction}': #{$!}"
386
- end
387
- end
388
-
389
- # Default ERB template to generate HTML.
390
- DEFAULT_TEMPLATE = '<html>
391
- <head>
392
- <meta http-equiv=Content-Type content="text/html; charset=utf-8">
393
- <title><%= @menu.title %></title>
394
- <link rel="stylesheet" type="text/css" href="stylesheet.css">
395
- <link rel="stylesheet" type="text/css" href="ruby.css">
396
- <link rel="stylesheet" type="text/css" href="yaml.css">
397
- <link rel="stylesheet" type="text/css" href="xml.css">
398
- </head>
399
- <body marginwidth="10" marginheight=10" bgcolor="#213449">
400
- <table class="page" width="850" height="100%" align="center">
401
- <tr class="title">
402
- <td class="title" colspan="2" height="100">
403
- <table class="title" width="100%">
404
- <tr class="title">
405
- <td class="title" align="left" width="75%">
406
- <img src="bee-icon.png">
407
- </td>
408
- <td class="title" align="center" width="25%">
409
- <img src="bee-logo.gif">
410
- </td>
411
- </tr>
412
- </table>
413
- </td>
414
- </tr>
415
- <tr>
416
- <td class="ruller" colspan="2"
417
- align="left" valign="middle"
418
- height="10">
419
- Last update: <%= @date.strftime("%Y-%m-%d") %>
420
- </td>
421
- </tr>
422
- <tr>
423
- <td class="menu"
424
- align="left" valign="top"
425
- width="130">
426
- <%
427
- for entry in @menu.entries
428
- link = entry.dest
429
- link += \'/index.html\' if entry.dir
430
- if entry.type != "section"
431
- %>
432
- <a class="menu" href="<%= link %>"><%= entry.title %></a><br>
433
- <%
434
- else
435
- %>
436
- <h2 class="menu"><%= entry.title %></h2>
437
- <%
438
- end
439
- if entry.title == @title
440
- if @table
441
- %>
442
- <table class="space"><tr class="space"><td class="space"></td></tr></table>
443
- <table class="toc" width="100%">
444
- <tr class="toc">
445
- <td class="toc">
446
- <% for section in @table %>
447
- <% indent = "&#x00A0;&#x00A0;"*section[:depth] %>
448
- <%= indent %><a class="toc" href="#<%= section[:title] %>"><font size="-<%= section[:depth]+1 %>"><%= section[:title] %></font></a><br/>
449
- <% end %>
450
- </td>
451
- </tr>
452
- </table>
453
- <table class="space"><tr class="space"><td class="space"></td></tr></table>
454
- <%
455
- end
456
- end
457
- end
458
- %>
459
- </td>
460
- <td class="page"
461
- align="left" valign="top">
462
- <h1><%= @title %></h1>
463
- <% if @type == "text" %>
464
- <pre class="page"><%= @contents %></pre>
465
- <% else %>
466
- <%= @contents %>
467
- <% end %>
468
- <br>
469
- </td>
470
- </tr>
471
- </table>
472
- <table class="footer" width="800" align="center">
473
- <tr class="footer">
474
- <td class="footer">
475
- (C) Michel Casabianca & Contributors - 2006-2010 - Pictures courtesy of
476
- <a class="footer" href="http://pdphoto.org/">PD Photo.org</a>
477
- </td>
478
- </tr>
479
- </table>
480
- </body>
481
- </html>'
482
-
483
- public
484
-
485
- # Default style sheet.
486
- DEFAULT_STYLESHEET = '
487
- /* Title style */
488
- table.title {
489
- border: solid Opx #FFFFFF;
490
- border-collapse: collapse;
491
- }
492
- tr.title {
493
- border: solid Opx #FFFFFF;
494
- }
495
- td.title {
496
- border: solid 0px #000000;
497
- padding: 0px;
498
- background-color: #F8DE5A;
499
- }
500
-
501
- /* Ruller style */
502
- td.ruller {
503
- border: solid 0px #000000;
504
- text-align: right;
505
- padding: 3px;
506
- background-color: #000000;
507
- color: #FFFFFF;
508
- font-family: Verdana, Helvetica, Arial, sans-serif;
509
- font-size: 8pt;
510
- }
511
-
512
- /* Menu style */
513
- td.menu {
514
- border: solid 0px #000000;
515
- padding: 10px;
516
- background-color: #FF9000;
517
- font-family: Verdana, Helvetica, Arial, sans-serif;
518
- font-size: 12pt;
519
- }
520
- h2.menu {
521
- font-family: Verdana, Helvetica, Arial, sans-serif;
522
- color: #000000;
523
- border-bottom: 1px dotted #FFFFFF;
524
- font-size: 12pt;
525
- }
526
- a.menu:link {
527
- text-decoration: none;
528
- color: #000000;
529
- }
530
- a.menu:visited {
531
- text-decoration: none;
532
- color: #000000;
533
- }
534
- a.menu:active {
535
- text-decoration: none;
536
- color: #000000;
537
- }
538
- a.menu:hover {
539
- text-decoration: underline;
540
- color: #000000;
541
- background-color: #FF9000;
542
- }
543
-
544
- /* TOC style */
545
- table.toc {
546
- border: solid 1px #A0A0A0;
547
- }
548
- td.toc {
549
- border: solid 0px #000000;
550
- padding: 5px;
551
- background-color: #F0F0A0;
552
- font-family: Verdana, Helvetica, Arial, sans-serif;
553
- font-size: 10pt;
554
- }
555
- a.toc:link {
556
- text-decoration: none;
557
- color: #000000;
558
- }
559
- a.toc:visited {
560
- text-decoration: none;
561
- color: #000000;
562
- }
563
- a.toc:active {
564
- text-decoration: none;
565
- color: #000000;
566
- }
567
- a.toc:hover {
568
- text-decoration: underline;
569
- color: #000000;
570
- }
571
-
572
- /* Page style */
573
- pre.page {
574
- font-family: Courier, Verdana, Helvetica, Arial, sans-serif;
575
- font-size: 10pt;
576
- background-color: #FFFFFF;
577
- border-width: 0px;
578
- border-color: #FFFFFF;
579
- border-style: solid;
580
- }
581
- table.page {
582
- border: solid 2px #000000;
583
- }
584
- td.page {
585
- padding: 10px;
586
- border: solid 0px #000000;
587
- font-family: Verdana, Helvetica, Arial, sans-serif;
588
- font-size: 10pt;
589
- background-color: #FFFFFF;
590
- }
591
-
592
- /* Footer style */
593
- table.footer {
594
- border: solid 0px #000000;
595
- }
596
- td.footer {
597
- padding: 5px;
598
- border: solid 0px #000000;
599
- font-family: Verdana, Helvetica, Arial, sans-serif;
600
- font-size: 8pt;
601
- color: #A0A0A0;
602
- text-align: center;
603
- }
604
- a.footer:link {
605
- text-decoration: none;
606
- color: #FF9000;
607
- }
608
- a.footer:visited {
609
- text-decoration: none;
610
- color: #A0A0A0;
611
- }
612
- a.footer:active {
613
- text-decoration: none;
614
- color: #FF9000;
615
- }
616
- a.footer:hover {
617
- text-decoration: underline;
618
- color: #FF9000;
619
- }
620
-
621
- /* Style that defines table elements for spacing */
622
- table.space {
623
- border: solid 0px #000000;
624
- }
625
- tr.space {
626
- border: solid 0px #000000;
627
- }
628
- td.space {
629
- border: solid 0px #000000;
630
- padding: 2px;
631
- }
632
-
633
- /* pre element for term output */
634
- pre.term {
635
- clear: both;
636
- overflow: auto;
637
- color: #FFFFFF;
638
- background-color: #555555;
639
- padding: 0;
640
- padding: 1.0em;
641
- border-width: 1px;
642
- border-color: #C0C0C0;
643
- border-style: solid;
644
- }
645
-
646
- /* Contents style (default element form) */
647
- h1 {
648
- font-family: Verdana, Helvetica, Arial, sans-serif;
649
- color: #FF9000;
650
- text-align: center;
651
- font-size: 30pt;
652
- }
653
- h2,h3,h4,h5 {
654
- font-family: Verdana, Helvetica, Arial, sans-serif;
655
- color: #FF9000;
656
- border-bottom: 2px dotted #000000;
657
- }
658
- p {
659
- font-family: Verdana, Helvetica, Arial, sans-serif;
660
- font-size: 10pt;
661
- }
662
- table {
663
- font-family: Verdana, Helvetica, Arial, sans-serif;
664
- font-size: 10pt;
665
- border: solid 0px #000000;
666
- border-collapse: collapse;
667
- }
668
- th {
669
- padding: 5px;
670
- background-color: #FF9000;
671
- border: solid 1px #000000;
672
- text-align: left;
673
- }
674
- td {
675
- padding: 5px;
676
- border: solid 1px #000000;
677
- text-align: left;
678
- }
679
- li {
680
- font-family: Verdana, Helvetica, Arial, sans-serif;
681
- font-size: 10pt;
682
- list-style: square;
683
- }
684
- a:link {
685
- text-decoration: none;
686
- color: #FF9000;
687
- }
688
- a:visited {
689
- text-decoration: none;
690
- color: #000000;
691
- }
692
- a:active {
693
- text-decoration: none;
694
- color: #000000;
695
- }
696
- a:hover {
697
- text-decoration: underline;
698
- color: #FF9000;
699
- }
700
- pre {
701
- clear: both;
702
- overflow: auto;
703
- background-color: #EFEFEF;
704
- padding: 0;
705
- padding: 1.0em;
706
- border-width: 1px;
707
- border-color: #C0C0C0;
708
- border-style: solid;
709
- }
710
- '
711
-
712
- end
713
-
714
- # Class for PI processing.
715
- class Processor
716
-
717
- include DocErrorMixin
718
-
719
- def initialize(menu)
720
- @menu = menu
721
- end
722
-
723
- def include(args)
724
- file = args['file']
725
- error "Missing argument 'file' for 'include' instruction" if not file
726
- abs_file = @menu.abs_file(file)
727
- error "File to include not found '#{abs_file}'" if
728
- not File.exists?(abs_file)
729
- return Bee::Doc::syntax_colorization(abs_file)
730
- end
731
-
732
- def bee(args)
733
- build = args['build']
734
- options = args['options']
735
- if build
736
- abs_file = @menu.abs_file(build)
737
- error "Build file not found '#{abs_file}'" if
738
- not File.exists?(abs_file)
739
- value = `bee #{options} -f #{abs_file}`
740
- else
741
- value = `bee #{options}`
742
- end
743
- escaped = Entry.escape_special_characters(value)
744
- return "<pre class='term'>#{escaped}</pre>"
745
- end
746
-
747
- def run(args)
748
- command = args['command']
749
- raise "Missing argument 'command' for 'run' instruction" if not command
750
- directory = args['directory']||'.'
751
- print = args['print']||command
752
- error = (args['error']=='true' or
753
- args['error']=='yes' or
754
- args['error']=='1')||false
755
- current_dir = Dir.pwd
756
- begin
757
- Dir.chdir(@menu.base)
758
- Dir.chdir(directory)
759
- output = `#{command} 2>&1`
760
- if $? != 0 and not error
761
- raise "Error running command '#{command}': exit value #{$?}"
762
- end
763
- if $? == 0 and error
764
- raise "Error running command '#{command}': error expected"
765
- end
766
- escaped = Entry.escape_special_characters(output)
767
- return "<pre class='term'>$ #{print}\n#{escaped}</pre>"
768
- ensure
769
- Dir.chdir(current_dir)
770
- end
771
- end
772
-
773
- end
774
-
775
- TYPES = {
776
- '.rb' => 'ruby',
777
- '.yml' => 'yaml',
778
- '.yaml' => 'yaml',
779
- '.xml' => 'xml'
780
- }
781
-
782
- def self.syntax_colorization(file)
783
- type = TYPES[File.extname(file)]
784
- if type
785
- convertor = Syntax::Convertors::HTML.for_syntax(type)
786
- body = convertor.convert(File.read(file), false)
787
- return "<pre class='#{type}'>#{body}</pre>"
788
- else
789
- return "<pre>#{Entry.escape_special_characters(File.read(file))}</pre>"
790
- end
791
- end
792
-
793
- end
794
-
795
- end
796
-
797
- # Start command line
798
- if $0 == __FILE__
799
- Bee::Doc.start_command_line
800
- end