emerald 0.0.1.alpha1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,80 @@
1
+ <!DOCTYPE HTML>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
5
+ <link rel="stylesheet" type="text/css" href="<%= root_path + 'stylesheets' + 'rdoc.css' %>"/>
6
+ <script src="<%= root_path + 'javascripts' + 'jquery.js' %>"></script>
7
+ <script src="<%= root_path + 'javascripts' + 'emerald.js' %>"></script>
8
+ <script src="<%= root_path + 'javascripts' + 'toc.js' %>"></script>
9
+ <title><%= title %></title>
10
+ </head>
11
+ <body>
12
+ <div id="indices">
13
+ <form id="search">
14
+ <p style="margin-top: 0px"><input style="width: 100%" type="text" placeholder="Regexp Search"/></p>
15
+ </form>
16
+
17
+ <div class="index" id="file-index">
18
+ <div class="header">
19
+ <p>File Index</p>
20
+ </div>
21
+
22
+ <ul>
23
+ <% @toplevels.each do |tl| %>
24
+ <% target = root_path + rdocize_toplevel(tl) %>
25
+ <% if tl.name.end_with?(".rdoc") %>
26
+ <li class="rdoc-file"><a href="<%= target %>"><%= tl.name %></a></li>
27
+ <% else %>
28
+ <%# Usually you don’t want to see the code files %>
29
+ <li class="code-file" style="display: none"><a href="<%= target %>"><%= tl.name %></a></li>
30
+ <% end %>
31
+ <% end %>
32
+ <li><a style="font-style: italic" id="toggle-all-files" href="#">Show all</a></li>
33
+ </ul>
34
+ </div>
35
+
36
+ <div class="index" id="class-index">
37
+ <div class="header">
38
+ <p>Class Index</p>
39
+ </div>
40
+
41
+ <ul>
42
+ <% @classes_and_modules.each do |classmod| %>
43
+ <li>
44
+ <a href="<%= root_path + rdocize_classmod(classmod) %>"><%= classmod.full_name %></a>
45
+ </li>
46
+ <% end %>
47
+ </ul>
48
+ </div>
49
+
50
+ <div class="index" id="method-index">
51
+ <div class="header">
52
+ <p>Method Index</p>
53
+ </div>
54
+
55
+ <ul>
56
+ <% @methods.each do |method| %>
57
+ <li><a href="<%= root_path +
58
+ "#{rdocize_classmod(method.parent)}##{method.aref}"
59
+ %>"><%= method.pretty_name %></a>&nbsp;<span class="method-classname">(<%= method.parent.full_name %>)</span></li>
60
+ <% end %>
61
+ </ul>
62
+ </div>
63
+ </div>
64
+
65
+ <div id="content">
66
+ <%= yield %>
67
+ <div id="footer">
68
+ <p style="width: 49%; float: left">Time: <%= Time.now %></p>
69
+ <p style="width: 49%; float: right; text-align: right">
70
+ Generated by
71
+ <a href="https://github.com/Quintus/emerald">
72
+ Emerald generator for RDoc
73
+ </a>
74
+ </p>
75
+ </div>
76
+ </div>
77
+
78
+ <div class="clear"></div>
79
+ </body>
80
+ </html>
@@ -0,0 +1,13 @@
1
+ <p class="toplevel-name"><%= toplevel.full_name %></p>
2
+
3
+ <%= toplevel.description %>
4
+
5
+ <% if @options.generate_toc %>
6
+ <script>
7
+ html = "<div class=\"toc\"><p>Contents</p>";
8
+ html += generate_toc();
9
+ html += "</div>";
10
+
11
+ $(html).insertAfter("h1");
12
+ </script>
13
+ <% end %>
@@ -0,0 +1,4 @@
1
+ # Discovery file for RDoc to recognise this
2
+ # generator.
3
+
4
+ require_relative "generator/emerald"
@@ -0,0 +1,260 @@
1
+ # -*- coding: utf-8 -*-
2
+ gem "rdoc"
3
+
4
+ require "pathname"
5
+ require "fileutils"
6
+ require "erb"
7
+ require "rdoc/rdoc"
8
+ require "rdoc/generator"
9
+
10
+ # This is the main generator class that is instanciated by RDoc when
11
+ # you order it to use the _emerald_ generator. It mainly works on
12
+ # ERB template files you can find in the <b>data/templates</b> directory,
13
+ # where each major component (read: classes and toplevel files) has a
14
+ # template file that is evaluated for it. The result is then injected
15
+ # into the layout template, <b>data/templates/layout.html.erb</b>, which
16
+ # is then evaluated as well.
17
+ #
18
+ # == About relative paths
19
+ # As the output generated by RDoc is supposed to be viewable by both
20
+ # visiting the doc/ directory with a browser and providing the doc/
21
+ # directory to an HTTP server, effectively making it the root directory,
22
+ # care has been taken to only use relative links in all the static HTML
23
+ # files. The key component for this to work is the #root_path method,
24
+ # which is called to set the relative path to the root directory (i.e.
25
+ # the output directory). When called without an argument, #root_path
26
+ # returns the value previously remembered (usually it contains a good
27
+ # number of <b>../</b> entries). This way, the root directory can be
28
+ # set whenever a new HTML file is going to be outputted and can then
29
+ # be referenced from the ERB template.
30
+ #
31
+ # == Darkfish compatibility
32
+ # RDoc’s HTML formatter has a good number of helper methods that
33
+ # have a strong hint regarding "where what belongs". By using these
34
+ # helper methods itself when creating cross-references, the HTML
35
+ # formatter enforces both the directory structure of the output
36
+ # directory and the anchor names used for references inside a single
37
+ # HTML file. The only way to circumvent this is to write another
38
+ # formatter, which I don’t intend to as the standard HTML formatter
39
+ # does a good job for HTML stuff. A nice side effect is that Emerald’s
40
+ # documentation is compatible with Darkfish’s one when it comes to links
41
+ # to specific elements. For example, you can create a link to a method
42
+ # called Foo::Bar#baz somewhere on the web, and if the destinatinon
43
+ # website chooses to switch from Darkfish output to Emerald (which I
44
+ # hope!), the link will continue to work.
45
+ class RDoc::Generator::Emerald
46
+ include FileUtils
47
+
48
+ # Generic exception class for this generator.
49
+ class EmeraldError < StandardError
50
+ end
51
+
52
+ # Tell RDoc about the new generator
53
+ RDoc::RDoc.add_generator(self)
54
+
55
+ # Description displayed in RDoc’s help.
56
+ DESCRIPTION = "The only RDoc generator that makes your Ruby documentation a jewel, too"
57
+
58
+ # Root directory of this project.
59
+ ROOT_DIR = Pathname.new(__FILE__).dirname.parent.parent.parent
60
+
61
+ # Where to find the non-code stuff.
62
+ DATA_DIR = ROOT_DIR + "data"
63
+
64
+ # Main template used as the general layout.
65
+ LAYOUT_TEMPLATE = ERB.new(File.read(DATA_DIR + "templates" + "layout.html.erb"))
66
+
67
+ # Subtemplates injected into the main template.
68
+ TEMPLATES = {
69
+ :toplevel => ERB.new(File.read(DATA_DIR + "templates" + "toplevel.html.erb")),
70
+ :classmodule => ERB.new(File.read(DATA_DIR + "templates" + "classmodule.html.erb"))
71
+ }
72
+
73
+ # The version number.
74
+ VERSION = File.read(ROOT_DIR + "VERSION").chomp.freeze
75
+
76
+ # Add additional options to RDoc (see the
77
+ # RDoc::Generator::Emerald::Options module).
78
+ def self.setup_options(options)
79
+ options.extend(RDoc::Generator::Emerald::Options)
80
+ end
81
+
82
+ class << self
83
+
84
+ protected
85
+
86
+ # Protected foo.
87
+ def foo
88
+ end
89
+
90
+ private
91
+
92
+ # Private bar.
93
+ def bar
94
+ end
95
+
96
+ end
97
+
98
+ # Instanciates this generator. Automatically called
99
+ # by RDoc.
100
+ # ==Parameter
101
+ # [options]
102
+ # RDoc passed the current RDoc::Options instance.
103
+ def initialize(options)
104
+ @options = options
105
+ @op_dir = Pathname.pwd.expand_path + @options.op_dir
106
+ end
107
+
108
+ def generate(top_levels)
109
+ @toplevels = top_levels
110
+ @classes_and_modules = RDoc::TopLevel.all_classes_and_modules.sort_by{|klass| klass.full_name}
111
+ @methods = @classes_and_modules.map{|mod| mod.method_list}.flatten.sort
112
+
113
+ # Create the output directory
114
+ mkdir @op_dir unless @op_dir.exist?
115
+
116
+ copy_base_files
117
+ evaluate_toplevels
118
+ evaluate_classes_and_modules
119
+
120
+ unless @options.main_page # If set, #evaluate_toplevels creates the index.html for us
121
+ File.open(@op_dir + "index.html", "w") do |file|
122
+ file.write("<!DOCTYPE HTML>\n<html><head><title>RDoc documentation</title></head><body><p>This is the RDoc documentation.</p></body></html>")
123
+ end
124
+ end
125
+ end
126
+
127
+ # Darkfish returns +nil+, hence we do this as well.
128
+ def file_dir
129
+ nil
130
+ end
131
+
132
+ # Darkfish returns +nil+, hence we do this as well.
133
+ def class_dir
134
+ nil
135
+ end
136
+
137
+ protected
138
+
139
+ # Set/get the root directory.
140
+ # == Parameter
141
+ # [set_to (nil)]
142
+ # If passed, this method _sets_ the root directory rather
143
+ # than returning it.
144
+ # == Return value
145
+ # The current relative path to the root directory.
146
+ # == Remarks
147
+ # See the class’ introductory text for more information
148
+ # on this.
149
+ def root_path(set_to = nil)
150
+ if set_to
151
+ @root_path = Pathname.new(set_to)
152
+ else
153
+ @root_path ||= Pathname.new("./")
154
+ end
155
+ end
156
+
157
+ # Set/get the page title.
158
+ # == Parameter
159
+ # [set_to (nil)]
160
+ # If passed, this method _sets_ the title rather
161
+ # than returning it.
162
+ # == Return value
163
+ # The current page title.
164
+ # == Remarks
165
+ # Works the same way as #root_path.
166
+ def title(set_to = nil)
167
+ if set_to
168
+ @title = set_to
169
+ else
170
+ @title ||= ""
171
+ end
172
+ end
173
+
174
+ # Takes a RDoc::TopLevel and transforms it into a complete pathname
175
+ # relative to the output directory. Filename alterations
176
+ # done by RDoc’s crossref-HTML formatter are honoured. Note you
177
+ # have to prepend #root_path to get a complete href.
178
+ def rdocize_toplevel(toplevel)
179
+ Pathname.new("#{toplevel.relative_name.gsub(".", "_")}.html")
180
+ end
181
+
182
+ # Takes a RDoc::ClassModule and transforms it into a complete pathname
183
+ # relative to the output directory. Filename alterations
184
+ # done by RDoc’s crossref-HTML formatter are honoured. Note you
185
+ # have to prepend #root_path to get a complete href.
186
+ def rdocize_classmod(classmod)
187
+ Pathname.new(classmod.full_name.split("::").join("/") + ".html")
188
+ end
189
+
190
+ private
191
+
192
+ def copy_base_files
193
+ mkdir @op_dir + "stylesheets" unless File.directory?(@op_dir + "stylesheets")
194
+
195
+ cp Dir[DATA_DIR + "stylesheets" + "*.css"], @op_dir + "stylesheets"
196
+ cp_r DATA_DIR + "javascripts", @op_dir
197
+ cp_r DATA_DIR + "images", @op_dir
198
+ end
199
+
200
+ def evaluate_toplevels
201
+ @toplevels.each do |toplevel|
202
+ root_path("../" * (toplevel.relative_name.split("/").count - 1)) # Last component is a filename
203
+ title toplevel.relative_name
204
+
205
+ # Create the path to the file if necessary
206
+ path = @op_dir + rdocize_toplevel(toplevel)
207
+ mkdir_p path.parent unless path.parent.exist?
208
+
209
+ # Evaluate the actual file documentation
210
+ File.open(path, "w") do |file|
211
+ file.write(render(:toplevel, binding))
212
+ end
213
+
214
+ # If this toplevel is supposed to be the main file,
215
+ # copy it’s content to the index.html file.
216
+ if toplevel.relative_name == @options.main_page
217
+ root_path "./" # We *are* at the top here
218
+
219
+ File.open(@op_dir + "index.html", "w") do |file|
220
+ file.write(render(:toplevel, binding))
221
+ end
222
+ end
223
+ end
224
+ end
225
+
226
+ def evaluate_classes_and_modules
227
+ @classes_and_modules.each do |classmod|
228
+
229
+ path = @op_dir + rdocize_classmod(classmod)
230
+
231
+ mkdir_p path.parent unless path.parent.directory?
232
+ title classmod.full_name
233
+ root_path "../" * (classmod.full_name.split("::").count - 1) # Last element is a file
234
+
235
+
236
+ File.open(path, "w") do |file|
237
+ file.write(render(:classmodule, binding))
238
+ end
239
+ end
240
+ end
241
+
242
+ # Renders the subtemplate +template_name+ in the +context+ of the
243
+ # given binding, then injects it into the main template (which is
244
+ # evaluated in the same +context+).
245
+ #
246
+ # Returns the resulting string.
247
+ def render(template_name, context)
248
+ render_into_layout{TEMPLATES[template_name].result(context)}
249
+ end
250
+
251
+ # Renders into the main layout. The return value of the block
252
+ # passed to this method will be placed in the layout in place
253
+ # of the +yield+ expression.
254
+ def render_into_layout
255
+ LAYOUT_TEMPLATE.result(binding)
256
+ end
257
+
258
+ end
259
+
260
+ require_relative "emerald/options"
@@ -0,0 +1,37 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # This mixin module contains the extra options Emerald
4
+ # adds to the default RDoc ones. It is used in the
5
+ # RDoc::Generator::Emerald::setup_options method.
6
+ module RDoc::Generator::Emerald::Options
7
+
8
+ # Tells RDoc’s OptionParser about the new options when
9
+ # the RDoc::Options object is extended with this mixin.
10
+ def self.extended(options)
11
+ op = options.option_parser
12
+
13
+ op.separator ""
14
+ op.separator "Emerald generator options:"
15
+ op.separator ""
16
+
17
+ op.on("--[no-]generate-toc",
18
+ "Enables or disables generation of the",
19
+ "table of contents (ToC) for toplevel files."){|val| options.generate_toc = val}
20
+ end
21
+
22
+ # Whether or not to generate a Table of Contents (ToC) for
23
+ # toplevel files. Defaults to true.
24
+ #
25
+ # Note that the mechanism is implemented in JavaScript,
26
+ # which has therefore to be enabled in your browser.
27
+ def generate_toc
28
+ @generate_toc = true unless defined?(@generate_toc)
29
+ @generate_toc
30
+ end
31
+
32
+ # Setter for #generate_toc.
33
+ def generate_toc=(val)
34
+ @generate_toc = val
35
+ end
36
+
37
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: emerald
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.alpha1
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - Marvin Gülker
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rdoc
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '3.12'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '3.12'
30
+ - !ruby/object:Gem::Dependency
31
+ name: sass
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 3.2.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 3.2.0
46
+ description: ! 'Emerald is a generator for RDoc, like standard Darkfish, but looks
47
+
48
+ much better (and does not have this touch of green). It is inspired
49
+
50
+ by Hanna, but does not share any code with it (and does not use frames!).
51
+
52
+ '
53
+ email: quintus@quintilianus.eu
54
+ executables: []
55
+ extensions: []
56
+ extra_rdoc_files:
57
+ - COPYING.rdoc
58
+ - LEGAL.rdoc
59
+ - CHANGELOG.rdoc
60
+ - README.rdoc
61
+ files:
62
+ - lib/rdoc/discover.rb
63
+ - lib/rdoc/generator/emerald/options.rb
64
+ - lib/rdoc/generator/emerald.rb
65
+ - COPYING.rdoc
66
+ - LEGAL.rdoc
67
+ - CHANGELOG.rdoc
68
+ - README.rdoc
69
+ - data/javascripts/toc.js
70
+ - data/javascripts/jquery.js
71
+ - data/javascripts/emerald.js
72
+ - data/images/zoom.png
73
+ - data/images/tag_blue.png
74
+ - data/templates/layout.html.erb
75
+ - data/templates/classmodule.html.erb
76
+ - data/templates/toplevel.html.erb
77
+ - VERSION
78
+ homepage: https://github.com/Quintus/emerald
79
+ licenses: []
80
+ post_install_message:
81
+ rdoc_options:
82
+ - -t
83
+ - Emerald RDocs
84
+ - -m
85
+ - README.rdoc
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '1.9'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>'
98
+ - !ruby/object:Gem::Version
99
+ version: 1.3.1
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 1.8.24
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: The only RDoc generator that makes your Ruby documentation a jewel, too
106
+ test_files: []