OSDN Git Service

ruby-1.9.1-rc1
[splhack/AndroidRuby.git] / lib / ruby-1.9.1-rc1 / sample / rdoc / markup / sample.rb
1 # This program illustrates the basic use of the SimpleMarkup
2 # class. It extracts the first comment block from the
3 # simple_markup.rb file and converts it into HTML on
4 # standard output. Run it using
5 #
6 #  % ruby sample.rb
7 #
8 # You should be in the sample/rdoc/markup/ directory when you do this,
9 # as it hardwires the path to the files it needs to require.
10 # This isn't necessary in the code you write once you've
11 # installed the package.
12 #
13 # For a better way of formatting code comment blocks (and more)
14 # see the rdoc package.
15 #
16
17 require 'rdoc/markup/simple_markup'
18 require 'rdoc/markup/simple_markup/to_html'
19
20 # Extract the comment block from the source file
21
22 input_string = ""
23
24 File.foreach("../../../lib/rdoc/markup/simple_markup.rb") do |line|
25   break unless line.gsub!(/^\# ?/, '')
26   input_string << line
27 end
28
29 # Create a markup object
30 markup = SM::SimpleMarkup.new
31
32 # Attach it to an HTML formatter
33 h = SM::ToHtml.new
34
35 # And convert out comment block to html. Wrap it a body
36 # tag pair to let browsers view it
37
38 puts "<html><body>"
39 puts markup.convert(input_string, h)
40 puts "</body></html>"