gerbil 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/fmt/latex.yaml ADDED
@@ -0,0 +1,2 @@
1
+ desc: high-quality typesetting
2
+ code: raise NotImplementedError, 'this format is not yet implemented'
data/fmt/man.yaml ADDED
@@ -0,0 +1,2 @@
1
+ desc: manual page for UNIX
2
+ code: raise NotImplementedError, 'this format is not yet implemented'
data/fmt/text.yaml ADDED
@@ -0,0 +1,2 @@
1
+ desc: plain text, nothing fancy
2
+ code: raise NotImplementedError, 'this format is not yet implemented'
data/lib/gerbil.rb ADDED
@@ -0,0 +1,11 @@
1
+ # project information
2
+
3
+ Gerbil = {
4
+ :name => 'Gerbil',
5
+ :version => '1.0.0',
6
+ :release => '2008-01-12',
7
+ :website => 'http://gerbil.rubyforge.org',
8
+ :home => File.expand_path(File.join(File.dirname(__FILE__), '..'))
9
+ }
10
+ Gerbil[:format_home] = File.join(Gerbil[:home], 'fmt')
11
+ Gerbil[:format_files] = Dir[File.join(Gerbil[:format_home], '*.yaml')]
@@ -0,0 +1,149 @@
1
+ # This file defines the String#to_html method, which is
2
+ # invoked to transform the content of a blog entry into HTML.
3
+ #
4
+ # It features the Textile formatting system (RedCloth), syntax coloring
5
+ # (CodeRay), and smart source code sizing (block versus inline display).
6
+ #--
7
+ # Copyright 2006 Suraj N. Kurapati
8
+ # See the file named LICENSE for details.
9
+
10
+ require 'cgi'
11
+ require 'digest/sha1'
12
+
13
+ begin
14
+ require 'rubygems'
15
+ rescue LoadError
16
+ end
17
+
18
+ require 'coderay'
19
+ require 'redcloth'
20
+
21
+ class String
22
+ # The content of these HTML tags will be preserved while
23
+ # they are being processed by Textile. By doing this, we
24
+ # avoid unwanted Textile transformations, such as quotation
25
+ # marks becoming curly ( ), in source code.
26
+ PROTECTED_TAGS = %w[tt code pre]
27
+
28
+ # The content of these HTML tags will
29
+ # be preserved *verbatim* throughout
30
+ # the text-to-HTML conversion process.
31
+ VERBATIM_TAGS = %w[noformat]
32
+
33
+ # Transforms this string into HTML.
34
+ def to_html
35
+ text = dup
36
+ protect_tags! text, VERBATIM_TAGS, verbatimStore = {}, true
37
+ protect_tags! text, PROTECTED_TAGS, protectedStore = {}, false
38
+
39
+ html = text.thru_redcloth
40
+ restore_tags! html, protectedStore
41
+
42
+ # collapse redundant <pre> elements -- a side effect of RedCloth
43
+ html.gsub! %r{(<pre>)\s*<pre>(.*?)</pre>\s*(</pre>)}m, '\1\2\3'
44
+
45
+ html = html.thru_coderay
46
+ restore_tags! html, verbatimStore
47
+
48
+ # ensure tables have a border (this GREATLY improves
49
+ # readability in text-mode web browsers like Lynx and w3m)
50
+ html.gsub! %r/<table/, '\& border="1"'
51
+
52
+ html
53
+ end
54
+
55
+ # Returns the result of running this string through RedCloth.
56
+ def thru_redcloth
57
+ text = dup
58
+
59
+ # redcloth does not correctly convert -- into &mdash;
60
+ text.gsub! %r{\b--\b}, '&mdash;'
61
+
62
+ html = RedCloth.new(text).to_html
63
+
64
+ # redcloth adds <span> tags around acronyms
65
+ html.gsub! %r{<span class="caps">([[:upper:][:digit:]]+)</span>}, '\1'
66
+
67
+ # redcloth wraps indented text within <pre><code> tags
68
+ html.gsub! %r{(<pre>)\s*<code>(.*?)\s*</code>\s*(</pre>)}m, '\1\2\3'
69
+
70
+ # redcloth wraps a single item within paragraph tags, which
71
+ # prevents the item's HTML from being validly injected within
72
+ # other block-level elements, such as headings (h1, h2, etc.)
73
+ html.sub! %r{^<p>(.*)</p>$}m do |match|
74
+ payload = $1
75
+
76
+ if payload =~ /<p>/
77
+ match
78
+ else
79
+ payload
80
+ end
81
+ end
82
+
83
+ html
84
+ end
85
+
86
+ # Adds syntax coloring to <code> elements in the given text. If the
87
+ # <code> tag has an attribute lang="...", then that is considered the
88
+ # programming language for which appropriate syntax coloring should be
89
+ # applied. Otherwise, the programming language is assumed to be ruby.
90
+ def thru_coderay
91
+ gsub %r{<(code)(.*?)>(.*?)</\1>}m do
92
+ atts, code = $2, CGI.unescapeHTML($3)
93
+
94
+ lang =
95
+ if $2 =~ /lang=('|")(.*?)\1/i
96
+ $2
97
+ else
98
+ :ruby
99
+ end
100
+
101
+ tag =
102
+ if code =~ /\n/
103
+ :pre
104
+ else
105
+ :code
106
+ end
107
+
108
+ html = CodeRay.scan(code, lang).html(:css => :style)
109
+
110
+ %{<#{tag} class="code"#{atts}>#{html}</#{tag}>}
111
+ end
112
+ end
113
+
114
+ private
115
+
116
+ def protect_tags! aText, aTags, aStore, aVerbatim #:nodoc:
117
+ aTags.each do |tag|
118
+ aText.gsub! %r{(<#{tag}.*?>)(.*?)(</#{tag}>)}m do
119
+ head, body, tail = $1, $2, $3
120
+
121
+ # XXX: when we restore protected tags later on, String.gsub! is
122
+ # removing all single backslashes for some reason... so we
123
+ # protect against this by doubling all single backslashes first
124
+ body.gsub! %r/\\/, '\&\&'
125
+
126
+ original =
127
+ if aVerbatim
128
+ body
129
+ else
130
+ head << CGI.escapeHTML(CGI.unescapeHTML(body)) << tail
131
+ end
132
+ escape = Digest::SHA1.hexdigest(original)
133
+
134
+ aStore[escape] = original
135
+ escape
136
+ end
137
+ end
138
+ end
139
+
140
+ def restore_tags! aText, aStore #:nodoc:
141
+ until aStore.empty?
142
+ aStore.each_pair do |escape, original|
143
+ if aText.gsub! %r{<p>#{escape}</p>|#{escape}}, original
144
+ aStore.delete escape
145
+ end
146
+ end
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,91 @@
1
+ # Workaround for: `rdoc --fmt xml` does not dump information about methods.
2
+ #--
3
+ # Copyright 2007 Suraj N. Kurapati
4
+ # See the file named LICENSE for details.
5
+
6
+ require 'rdoc/rdoc'
7
+
8
+ module RDoc
9
+ module DummyMixin
10
+ def method_missing *args
11
+ # ignore all messages
12
+ end
13
+ end
14
+
15
+ class DummyOptions
16
+ include DummyMixin
17
+
18
+ def quiet # supress '...c..m...' output on STDERR
19
+ true
20
+ end
21
+ end
22
+
23
+ class DummyMarkup
24
+ require 'rdoc/generators/html_generator'
25
+ include Generators::MarkUp
26
+ include DummyMixin
27
+ end
28
+
29
+ # Returns an array of RDoc parse trees for the given code.
30
+ # If the file name (which signifies the origin of the given
31
+ # code) is given, it MUST have a ".rb" file extension.
32
+ # Otherwise, RDoc will give you an empty parse tree! :-(
33
+ def self.gen_parse_trees aCode, aFileName = __FILE__
34
+ root = TopLevel.new(aFileName)
35
+ parser = ParserFactory.parser_for(root, aFileName, aCode, DummyOptions.new, Stats.new)
36
+ info = parser.scan
37
+
38
+ info.requires.map do |r|
39
+ f = r.name
40
+ f << '.rb' unless File.exist? f
41
+ gen_parse_tree f if File.exist? f
42
+ end.flatten.compact << info
43
+ end
44
+
45
+ # Returns an array of hashes describing all methods present in the
46
+ # given parse trees (which are produced by RDoc::gen_parse_trees).
47
+ def self.gen_method_infos *aParseTrees
48
+ meths = aParseTrees.map do |i|
49
+ i.method_list + i.classes.map { |c| c.method_list }
50
+ end.flatten.uniq
51
+
52
+ meths.map do |m|
53
+ # determine full path to method (Module::Class::...::method)
54
+ hier = []
55
+ root = m.parent
56
+ while root && root.parent
57
+ hier.unshift root
58
+ root = root.parent
59
+ end
60
+
61
+ if hier.empty?
62
+ path = m.name
63
+ else
64
+ path = hier.map {|n| n.name}.join('::')
65
+ path = [path, m.name].join(m.singleton ? '::' : '#')
66
+ end
67
+
68
+ # determine argument string for method
69
+ args = m.params
70
+ if m.block_params
71
+ args.sub! %r/\#.*(?=.$)/, ''
72
+ args << " { |#{m.block_params}| ... }"
73
+ end
74
+
75
+ {
76
+ :file => root.file_absolute_name,
77
+ :name => path,
78
+ :args => args,
79
+ :decl => path + args,
80
+ :docs => m.comment,
81
+ :docs_html => DummyMarkup.new.markup(m.comment),
82
+
83
+ # nodes in the parse tree
84
+ :node => m,
85
+ :root => root,
86
+ # for top level methods, info.parent == root
87
+ # for class methods, info.singleton == true
88
+ }
89
+ end
90
+ end
91
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gerbil
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors: []
7
+
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-01-12 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: RedCloth
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: coderay
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: "0"
32
+ version:
33
+ description: Extensible document generator based on eRuby.
34
+ email:
35
+ executables:
36
+ - gerbil
37
+ extensions: []
38
+
39
+ extra_rdoc_files: []
40
+
41
+ files:
42
+ - fmt
43
+ - fmt/html.icons
44
+ - fmt/html.icons/warning.png
45
+ - fmt/html.icons/tip.png
46
+ - fmt/html.icons/caution.png
47
+ - fmt/html.icons/important.png
48
+ - fmt/html.icons/note.png
49
+ - fmt/html.icons/LICENSE
50
+ - fmt/html.icons/README
51
+ - fmt/latex.yaml
52
+ - fmt/html.yaml
53
+ - fmt/man.yaml
54
+ - fmt/text.yaml
55
+ - lib
56
+ - lib/gerbil
57
+ - lib/gerbil/html.rb
58
+ - lib/gerbil/rdoc.rb
59
+ - lib/gerbil.rb
60
+ - Rakefile
61
+ - bin
62
+ - bin/gerbil
63
+ - LICENSE
64
+ - README
65
+ - doc
66
+ - doc/gerbil.png
67
+ - doc/gerbil.svg
68
+ - doc/HelloWorld.input
69
+ - doc/guide.html
70
+ - doc/guide.erb
71
+ - doc/HelloWorld.spec
72
+ has_rdoc: false
73
+ homepage: http://gerbil.rubyforge.org
74
+ post_install_message:
75
+ rdoc_options: []
76
+
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: "0"
84
+ version:
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: "0"
90
+ version:
91
+ requirements: []
92
+
93
+ rubyforge_project:
94
+ rubygems_version: 1.0.1
95
+ signing_key:
96
+ specification_version: 2
97
+ summary: Extensible document generator based on eRuby.
98
+ test_files: []
99
+