~ubuntu-branches/ubuntu/trusty/ruby1.9/trusty

« back to all changes in this revision

Viewing changes to lib/rdoc/markup/sample/sample.rb

  • Committer: Bazaar Package Importer
  • Author(s): Stephan Hermann
  • Date: 2008-05-16 12:37:06 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20080516123706-r4llcdfd35aobrjv
Tags: 1.9.0.1-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Robustify check for target_os, fixing build failure on lpia.
* debian/control:
  - ruby1.9 pkg: moved rdoc1.9 suggestion to depends. (LP: #228345)

Show diffs side-by-side

added added

removed removed

Lines of Context:
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/ 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
 
$:.unshift "../../.."
18
 
 
19
 
require 'rdoc/markup/simple_markup'
20
 
require 'rdoc/markup/simple_markup/to_html'
21
 
 
22
 
# Extract the comment block from the source file
23
 
 
24
 
input_string = ""
25
 
 
26
 
File.foreach("../simple_markup.rb") do |line|
27
 
  break unless line.gsub!(/^\# ?/, '')
28
 
  input_string << line
29
 
end
30
 
 
31
 
# Create a markup object
32
 
markup = SM::SimpleMarkup.new
33
 
 
34
 
# Attach it to an HTML formatter
35
 
h = SM::ToHtml.new
36
 
 
37
 
# And convert out comment block to html. Wrap it a body
38
 
# tag pair to let browsers view it
39
 
 
40
 
puts "<html><body>"
41
 
puts markup.convert(input_string, h)
42
 
puts "</body></html>"