rote 0.2.4.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CONTRIBUTORS +3 -2
- data/DONE +22 -0
- data/README +11 -2
- data/Rakefile +25 -4
- data/TODO +7 -9
- data/doc/layouts/page.html +3 -0
- data/doc/pages/COMMON.rb +0 -11
- data/doc/pages/guide/COMMON.rb +5 -3
- data/doc/pages/guide/index.html +373 -120
- data/doc/res/stylesheets/normal.css +63 -0
- data/lib/rote.rb +2 -3
- data/lib/rote/app.rb +1 -1
- data/lib/rote/builtin.rf +3 -33
- data/lib/rote/filters.rb +10 -0
- data/lib/rote/filters/base.rb +135 -0
- data/lib/rote/filters/rdoc.rb +25 -0
- data/lib/rote/filters/redcloth.rb +40 -0
- data/lib/rote/filters/syntax.rb +38 -0
- data/lib/rote/filters/tidy.rb +55 -0
- data/lib/rote/filters/toc.rb +74 -0
- data/lib/rote/format.rb +9 -0
- data/lib/rote/format/html.rb +49 -0
- data/lib/rote/page.rb +194 -141
- data/lib/rote/project/Rakefile +26 -5
- data/lib/rote/rotetasks.rb +133 -20
- data/test/gem_tests.rb +3 -1
- data/test/layouts/simple.rb +1 -0
- data/test/pages/markdown.txt +5 -1
- data/test/pages/rdoc.txt +4 -1
- data/test/pages/textile.rb +2 -0
- data/test/test_formatting.rb +140 -0
- data/test/test_html_page.rb +33 -0
- data/test/test_page.rb +72 -50
- metadata +15 -2
data/CONTRIBUTORS
CHANGED
@@ -6,9 +6,10 @@ Without the help and guidance of these people, Rote would almost certainly
|
|
6
6
|
suck like a hoover.
|
7
7
|
|
8
8
|
===== Jonathan Paisley <jp-www at dcs gla ac uk>
|
9
|
-
* Auto
|
9
|
+
* Auto _monitor tasks
|
10
10
|
* COMMON.rb inheritance (with BOC)
|
11
11
|
* Rake magic
|
12
12
|
* better resource management
|
13
|
-
*
|
13
|
+
* Page filters
|
14
|
+
* _Many_ other suggestions for improvements
|
14
15
|
|
data/DONE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
= Rote project -- Done list
|
2
|
+
|
3
|
+
These were TODO items, but are now not. Other things have been done too, of
|
4
|
+
course - these are just the ones that spent some time as a TODO before
|
5
|
+
being implemented.
|
6
|
+
|
7
|
+
* More flexible markup rendering
|
8
|
+
* Source monitoring / render on update
|
9
|
+
* Better COMMON.rb handling
|
10
|
+
* Proper page/resource/ruby dependencies
|
11
|
+
* Support layout-specific code.
|
12
|
+
* Remove implicit output filename restriction
|
13
|
+
* Support optional filtering post-layout
|
14
|
+
* Support macros, separate macro and text processing
|
15
|
+
* Support ordered regexp extension mapping
|
16
|
+
** Support per-extension-mapping blocks
|
17
|
+
* Support filters
|
18
|
+
** Syntax
|
19
|
+
** RedCloth
|
20
|
+
** RDoc
|
21
|
+
** TOC
|
22
|
+
** Tidy
|
data/README
CHANGED
@@ -118,8 +118,17 @@ though, so flame him if it breaks your day ;P
|
|
118
118
|
As you may have guessed, Rote's hosting and development services are provided
|
119
119
|
by http://RubyForge.org .
|
120
120
|
|
121
|
-
|
121
|
+
The people who have been instrumental in making Rote a better piece of
|
122
|
+
software, without direct involvement in the development process. Without the
|
123
|
+
ideas, suggestions, bug reports and guidance from these people, rote would
|
124
|
+
probably be totally useless to anyone but me. Keeping a list like this
|
125
|
+
accurate and up to date is a recipe for disaster, so I'll take the safe
|
126
|
+
option and say 'thanks, everyone' :)
|
127
|
+
|
128
|
+
Thanks also to Yukihiro Matsumoto for a remarkable platform, Masatoshi Seki for
|
122
129
|
embedding it in text, Jim Weirich for an elegant build tool, and Dean Allen
|
123
|
-
for making markup easy in Ruby. Thanks
|
130
|
+
for making markup easy in Ruby. Thanks to the authors of all the libraries and
|
131
|
+
tools used by Rote, and thanks too to the many people who've contributed
|
124
132
|
and improved these things over the years - as ever, we stand on the shoulders
|
125
133
|
of giants.
|
134
|
+
|
data/Rakefile
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
# This Rakefile is heavily based on Rake's own Rakefile.
|
7
7
|
# Portions copyright (c)2003, 2004 Jim Weirich (jim <AT> weirichhouse.org)
|
8
8
|
#
|
9
|
-
# $Id: Rakefile,v 1.
|
9
|
+
# $Id: Rakefile,v 1.12 2005/12/12 02:45:24 roscopeco Exp $
|
10
10
|
#
|
11
11
|
|
12
12
|
begin
|
@@ -22,11 +22,18 @@ require 'rake/rdoctask'
|
|
22
22
|
|
23
23
|
# This needs to go at the front of the libpath
|
24
24
|
# Otherwise, any pre-installed rote gets found,
|
25
|
-
# and used from there.
|
26
|
-
|
25
|
+
# and used from there. This is only necessary
|
26
|
+
# for Rote's build, to make sure we always unit-
|
27
|
+
# test and build doc with the working copy.
|
28
|
+
$LOAD_PATH.unshift 'lib'
|
27
29
|
require 'rote'
|
30
|
+
require 'rote/filters/redcloth'
|
31
|
+
require 'rote/filters/syntax'
|
32
|
+
require 'rote/filters/tidy'
|
33
|
+
require 'rote/format/html'
|
34
|
+
include Rote
|
28
35
|
|
29
|
-
|
36
|
+
CLEAN.include('tidy.log')
|
30
37
|
CLOBBER.include('TAGS')
|
31
38
|
CLOBBER.include('html')
|
32
39
|
|
@@ -111,6 +118,7 @@ rd = Rake::RDocTask.new("rdoc") { |rdoc|
|
|
111
118
|
rdoc.rdoc_files.include('README', 'LICENSE', 'TODO', 'CONTRIBUTORS')
|
112
119
|
rdoc.rdoc_files.include('lib/**/*.rb', 'doc/**/*.rdoc')
|
113
120
|
rdoc.rdoc_files.exclude(/\bcontrib\b/)
|
121
|
+
rdoc.rdoc_files.exclude('lib/rote/project/**/*')
|
114
122
|
}
|
115
123
|
|
116
124
|
# Create a task build the website / docs
|
@@ -120,6 +128,19 @@ ws = Rote::DocTask.new(:doc) { |site|
|
|
120
128
|
site.pages.dir = 'doc/pages'
|
121
129
|
site.pages.include('**/*')
|
122
130
|
|
131
|
+
site.ext_mapping(/(html)/, '$1') do |page|
|
132
|
+
# Let's use the HTML stuff everywhere ...
|
133
|
+
page.extend Rote::Format::HTML
|
134
|
+
|
135
|
+
# use 'page' layout, textile formatting, ruby syntax, Tidy to xhtml
|
136
|
+
page.layout 'page'
|
137
|
+
|
138
|
+
page.page_filter Filters::RedCloth.new(:textile)
|
139
|
+
page.page_filter Filters::Syntax.new
|
140
|
+
|
141
|
+
page.post_filter Filters::Tidy.new
|
142
|
+
end
|
143
|
+
|
123
144
|
site.res.dir = 'doc/res'
|
124
145
|
site.res.include('**/*.png')
|
125
146
|
site.res.include('**/*.gif')
|
data/TODO
CHANGED
@@ -5,16 +5,14 @@ Send any suggestions or patches (preferably as/with tests) to:
|
|
5
5
|
|
6
6
|
rosco <at> roscopeco <dot> co <dot> uk
|
7
7
|
|
8
|
-
|
8
|
+
== For 1.0
|
9
|
+
* CSS / XML / etc, maybe with the existing builders (integrated with
|
10
|
+
Format::CSS, Format::XML, so on)
|
9
11
|
* Nested layouts
|
10
|
-
*
|
11
|
-
|
12
|
+
* Could work as 'plugins', maybe allow pseudo-sections to be created
|
13
|
+
in COMMON.rb, that get their pages from some supplied code.
|
14
|
+
Anything else then stays out of Rote, which is what's needed.
|
12
15
|
* Ability to have multiple views of a section, e.g. user guide (separate
|
13
16
|
pages) and user guide (one page) generated from same source.
|
14
|
-
|
15
|
-
* Index and glossary support
|
16
|
-
* statistics
|
17
|
-
* (maybe?) Automatic navigation / TOC
|
17
|
+
** Maybe in concert with plugins?
|
18
18
|
* (maybe?) Rant integration
|
19
|
-
* Ability to define rules for input.ext -> output.ext
|
20
|
-
* Support ruby source templates (.rbt, auto rename to .rb on output).
|
data/doc/layouts/page.html
CHANGED
@@ -25,6 +25,9 @@
|
|
25
25
|
<a class='nav' href='<%= link_rel nav[:url] %>'><%= nav[:title] %></a>
|
26
26
|
<% unless i == (@navigation.length - 1) %>|<% end %>
|
27
27
|
<% end %>
|
28
|
+
<% unless @toc.nil? or @toc.links.empty? %>
|
29
|
+
<div id="subnav"><%= @toc.links.select { |l| l.tag == 'h3' }.join(' - ') %></div>
|
30
|
+
<% end %>
|
28
31
|
</td>
|
29
32
|
</tr>
|
30
33
|
|
data/doc/pages/COMMON.rb
CHANGED
@@ -2,20 +2,9 @@
|
|
2
2
|
#
|
3
3
|
# Instead of being executed once (as you might expect), this is evaluated
|
4
4
|
# for each Page's binding as the instance is created.
|
5
|
-
#
|
6
|
-
# At the moment, COMMON.rb code isn't automatically inherited from
|
7
|
-
# parent directories - you have to use the 'inherit_common' hack provided
|
8
|
-
# by Page to inherit from the immediate parent directory ONLY (setting
|
9
|
-
# up chains of COMMONs if you have deep nesting - Ugh!). This limitation
|
10
|
-
# will be removed very soon.
|
11
|
-
|
12
5
|
@site_title = 'Rote'
|
13
6
|
@base_url = 'http://rote.rubyforge.org/'
|
14
7
|
|
15
|
-
# default to 'page' layout and textile formatting
|
16
|
-
layout 'page'
|
17
|
-
format_opts << :textile
|
18
|
-
|
19
8
|
# this is used to construct the navbar and frontpage. Note that we use absolute
|
20
9
|
# (root-relative) URLs here, and fix them from each page with 'link_rel'.
|
21
10
|
@navigation = [
|
data/doc/pages/guide/COMMON.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
-
|
2
|
-
inherit_common
|
1
|
+
require 'rote/filters/toc'
|
3
2
|
|
3
|
+
page_filter @toc = Filters::TOC.new
|
4
|
+
|
5
|
+
# Some helpers for writing out links and sections within
|
6
|
+
# the text
|
4
7
|
def section_anchor(name)
|
5
8
|
name.downcase.gsub(/\s/,'_')
|
6
9
|
end
|
@@ -12,7 +15,6 @@ end
|
|
12
15
|
def section(level, name, toplink = true)
|
13
16
|
%Q{
|
14
17
|
#{"[#{section_link('Top')}]" if toplink}
|
15
|
-
<a name='#{section_anchor(name)}'></a>
|
16
18
|
h#{level}. #{name}
|
17
19
|
}
|
18
20
|
end
|
data/doc/pages/guide/index.html
CHANGED
@@ -1,30 +1,17 @@
|
|
1
1
|
<% @page_title = 'User guide' %>
|
2
2
|
|
3
|
-
*
|
3
|
+
p{color:red}. *The guide is still under construction*
|
4
|
+
|
5
|
+
p. It has not yet been fully updated to cover all new features in 0.3.x.
|
6
|
+
Although most features are mentioned, in many cases the documentation consists
|
7
|
+
soley of a link to the relevant "RDoc":<%= link_rel '/rdoc/index.html' %>
|
8
|
+
|
9
|
+
<a name='top'></a>
|
4
10
|
|
5
11
|
It is assumed that you have installed Rote already. If not, please
|
6
|
-
consult the
|
12
|
+
consult the "README":<%= link_rel '/rdoc/files/README.html' %>
|
7
13
|
for installation instructions.
|
8
14
|
|
9
|
-
<a name='top'></a>
|
10
|
-
h3. Contents
|
11
|
-
|
12
|
-
* <%= section_link 'Conventions' %>
|
13
|
-
* <%= section_link 'Starting out with Rote' %>
|
14
|
-
** <%= section_link 'Creating a project' %>
|
15
|
-
** <%= section_link 'From the command-line' %>
|
16
|
-
** <%= section_link 'From your Rakefile' %>
|
17
|
-
* <%= section_link 'Creating templates' %>
|
18
|
-
** <%= section_link 'Basics' %>
|
19
|
-
** <%= section_link 'Formatting' %>
|
20
|
-
** <%= section_link 'Template code and ERB' %>
|
21
|
-
** <%= section_link 'Applying layout' %>
|
22
|
-
* <%= section_link 'Resources' %>
|
23
|
-
* <%= section_link 'Source monitoring' %>
|
24
|
-
** <%= section_link 'Auto-refresh Task' %>
|
25
|
-
* <%= section_link 'Definining additional tasks' %>
|
26
|
-
* <%= section_link 'Publishing' %>
|
27
|
-
|
28
15
|
<%= section 3, 'Conventions', false %>
|
29
16
|
|
30
17
|
*Task names* - Rote's standard tasks are always referred to with the base-name
|
@@ -51,7 +38,7 @@ case). This directory will have the following layout:
|
|
51
38
|
<p><code><pre>
|
52
39
|
someproject
|
53
40
|
|
|
54
|
-
|--> Rakefile
|
41
|
+
|--> Rakefile
|
55
42
|
|
|
56
43
|
|--> doc
|
57
44
|
| |--> res
|
@@ -135,82 +122,44 @@ manpage available for the @rote@ command.
|
|
135
122
|
|
136
123
|
If you are wanting to build documentation as part of a larger build process, or
|
137
124
|
commandline setup, then you'll want to get started on integrating Rote with
|
138
|
-
your own (existing) @Rakefile@.
|
139
|
-
|
140
|
-
|
141
|
-
<pre><code>
|
142
|
-
# Rakefile
|
143
|
-
require 'rote'
|
125
|
+
your own (existing) @Rakefile@. If you bootstrap a project with the
|
126
|
+
@rote create@ command, you'll get a Rakefile which you can modify to suit
|
127
|
+
your requirements.
|
144
128
|
|
145
|
-
|
146
|
-
|
147
|
-
site.layout_dir = 'doc/layouts'
|
148
|
-
|
149
|
-
site.pages.dir = 'doc/pages'
|
150
|
-
site.pages.include('**/*')
|
151
|
-
|
152
|
-
site.res.dir = 'doc/res/'
|
153
|
-
site.res.include('**/*.png')
|
154
|
-
site.res.include('**/*.gif')
|
155
|
-
site.res.include('**/*.jpg')
|
156
|
-
site.res.include('**/*.css')
|
157
|
-
}
|
158
|
-
</code></pre>
|
159
|
-
|
160
|
-
Save this as @Rakefile@, and fire up:
|
129
|
+
There is nothing special about this Rakefile, and it can use any of the other
|
130
|
+
Rake tasks, or indeed any other Ruby code. It is run with a command like:
|
161
131
|
|
162
132
|
<pre><code> rake doc</code></pre>
|
163
133
|
|
164
134
|
If all goes well, you should see each command and transformation output to your
|
165
135
|
console as Rote runs.
|
166
136
|
|
167
|
-
|
168
|
-
|
137
|
+
See the main Rote @Rakefile@ for an example of integrating Rote with your
|
138
|
+
software project, including linking to Rdoc generation and so on. The
|
139
|
+
<%= section_link 'Rake task configuration' %> section has more information
|
140
|
+
on the options supported by Rote's task library.
|
169
141
|
|
170
142
|
<%= section 3, 'Creating templates' %>
|
171
143
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
also used to provide simple hierarchical structure to the common page code.
|
177
|
-
|
178
|
-
By default, any file with an extension other than @rb@ will be processed
|
179
|
-
as a page template (with it's associated ruby source). The output will have
|
180
|
-
the same filename and path, relative to the output directory.
|
144
|
+
p=. *Wherever directories and files are mentioned, they refer to the appropriate*
|
145
|
+
*path/name/etc supplied during <%= section_link 'rake task configuration' %>*.
|
146
|
+
*In all cases the default settings can be seen in the layout created by the*
|
147
|
+
*@rote create foo@ command.*
|
181
148
|
|
182
|
-
<%= section 4, '
|
183
|
-
|
184
|
-
If you're generating HTML, you'll probably want to use some plaintext
|
185
|
-
formatting, rather than writing HTML by hand. Rote directly supports
|
186
|
-
the Textile, Markdown and Rdoc textual formatting styles.
|
187
|
-
The formatting applied to a given page is controlled by that page's @format_opts@
|
188
|
-
array. All three are disabled by default - to enable formatting you must add
|
189
|
-
appropriate symbols to the array, for example in page code or COMMON.rb:
|
190
|
-
|
191
|
-
<p><pre><code> format_opts << :textile << :markdown << :rdoc</code></pre></p>
|
149
|
+
<%= section 4, 'The Basics', false %>
|
192
150
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
*Some additional notes on formatting*
|
151
|
+
As mentioned, templates are simply files in the specifed pages directory
|
152
|
+
(@doc/pages@ by default) that match the supplied glob (default: all files,
|
153
|
+
though ruby source is implicitly excluded). The directory layout beneath the
|
154
|
+
page root is retained when transforming pages, and is also used to provide
|
155
|
+
hierarchical structure to the common page code.
|
200
156
|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
This allows you to output formatting from your code and have it rendered
|
208
|
-
properly.
|
209
|
-
|
210
|
-
* that the options you supply are passed directly to RedCloth, so you can
|
211
|
-
exercise much more control over the formatting by using the feature-specific
|
212
|
-
symbols defined by RedCloth, rather than the blanket :textile and :markdown
|
213
|
-
symbols.
|
157
|
+
The default behaviour is to transform all matched pages with ERB, and
|
158
|
+
optionally apply a second render pass with a <%= section_link 'layout' %>,
|
159
|
+
before writing to the same base filename beneath the output directory.
|
160
|
+
You can customise this behaviour by specifying _extension mappings_ for
|
161
|
+
specific file extensions - see the <%= section_link 'Rake task configuration' %>
|
162
|
+
section for details.
|
214
163
|
|
215
164
|
<%= section 4, 'Template code and ERB' %>
|
216
165
|
|
@@ -218,19 +167,24 @@ All templates may contain embedded Ruby code (ERB), delimited by the standard
|
|
218
167
|
<% ... %> (for executed code) and <%= ... %> (for
|
219
168
|
output) tags. Any (valid) Ruby code may be placed in the templates, and
|
220
169
|
variables may be defined to allow information to be passed into templates.
|
221
|
-
There are
|
170
|
+
There are five places where you might define such variables. The following
|
222
171
|
is in order of evaluation:
|
223
172
|
|
224
|
-
*
|
225
|
-
|
173
|
+
* A block supplied to <%= section_link 'extension mappings' %> that matched
|
174
|
+
this page.
|
175
|
+
* Any COMMON.rb files from the filesystem root down to this directory.
|
226
176
|
* This page's ruby code, _basename_.rb
|
227
|
-
* In a block passed to Page.new
|
228
177
|
* In the template itself
|
229
178
|
|
230
|
-
When a @
|
231
|
-
|
232
|
-
|
233
|
-
|
179
|
+
When a @Page@ instance is created, Rote looks for these, and if found evaluates
|
180
|
+
them, in order, in the same binding as the template is later rendered in (i.e.
|
181
|
+
the @Page@ instance binding). Therefore, you can define instance variables to
|
182
|
+
pass data around, or even helper methods if you wish.
|
183
|
+
|
184
|
+
Template code is used to support a great deal of flexibility in Rote, from
|
185
|
+
selecting layouts to mixing in format helpers to controlling the filter chain.
|
186
|
+
You can find details of the methods available in the
|
187
|
+
"@Rote::Page@ RDoc":<%= link_rel '/rdoc/classes/Rote/Page.html' %>
|
234
188
|
|
235
189
|
<%= section 4, 'Layout' %>
|
236
190
|
|
@@ -262,6 +216,92 @@ This pattern shouldn't be unfamiliar. Again, note that Rote doesn't mandate
|
|
262
216
|
HTML, despite the appearance from the ERB tags - any (textual) format can
|
263
217
|
be templated and laid out.
|
264
218
|
|
219
|
+
<%= section 4, 'Filters' %>
|
220
|
+
|
221
|
+
As well as rendering ERB and applying layout (both universal features of @Page@),
|
222
|
+
Rote provides the ability to apply custom _filters_ to a page or set of pages.
|
223
|
+
Along with this ability, a number of filters are provided as standard:
|
224
|
+
|
225
|
+
For example If you're generating HTML, you'll probably want to use some plaintext
|
226
|
+
formatting, rather than writing HTML by hand. Rote directly supports this
|
227
|
+
(thanks for "RedCloth":http://whytheluckystiff.net/ruby/redcloth) via the
|
228
|
+
_RedCloth_ filter, which allows Textile or Markdown (or both if you really want)
|
229
|
+
to be applied to pages.
|
230
|
+
|
231
|
+
h5. Filter chaining
|
232
|
+
|
233
|
+
In order to filter a given page, filter instances are added to that page's
|
234
|
+
filter chain. There are actually two separate chains, for _page filtering_
|
235
|
+
and _post filtering_.
|
236
|
+
|
237
|
+
* *Page filtering* takes place on the page content itself, after any
|
238
|
+
ERB is executed, but before the layout pass is applied. Most of the
|
239
|
+
standard filters are pre-filters.
|
240
|
+
|
241
|
+
* *Post filtering* takes place on the final output of the render pass,
|
242
|
+
after layout is applied. The @Filters::Tidy@ filter is a post filter.
|
243
|
+
|
244
|
+
h5. Standard filters
|
245
|
+
|
246
|
+
Rote supplies the following filters 'out of the box':
|
247
|
+
|
248
|
+
* *"Filters::RDoc":<%= link_rel '/rdoc/classes/Rote/Filters/RDoc.html' %>* -
|
249
|
+
Supports RDoc formatting with optional custom markup, to any supported output format
|
250
|
+
(defaults to HTML).
|
251
|
+
|
252
|
+
* *"Filters::RedCloth":<%= link_rel '/rdoc/classes/Rote/Filters/RedCloth.html' %>* -
|
253
|
+
Supports both Textile and Markdown to HTML.
|
254
|
+
|
255
|
+
* *"Filters::Syntax":<%= link_rel '/rdoc/classes/Rote/Filters/Syntax.html' %>* -
|
256
|
+
Supports @code@ <%= section_link 'macros' %> with pluggable syntax highlighting
|
257
|
+
(via the "Syntax library":http://syntax.rubyforge.org/) and Ruby-code support
|
258
|
+
out of the box.
|
259
|
+
|
260
|
+
* *"Filters::Tidy":<%= link_rel '/rdoc/classes/Rote/Filters/Tidy.html' %>* -
|
261
|
+
Post filter that corrects markup and semantic errors in HTML markup to produce
|
262
|
+
valid HTML or XHTML using the "HTML Tidy":http://tidy.sourceforge.net/ command-line
|
263
|
+
tool.
|
264
|
+
|
265
|
+
* *"Filters::TOC":<%= link_rel '/rdoc/classes/Rote/Filters/TOC.html' %>* -
|
266
|
+
Supports automatic generation of navigation from headings in documents.
|
267
|
+
|
268
|
+
The first three are page filters, while the The latter two are not. Tidy is a simple
|
269
|
+
post filter (since HTML Tidy operates on full HTML documents), and should be used
|
270
|
+
with the @post_filter@ chain. TOC operates somewhat differently, requiring two
|
271
|
+
render passes - first to enumerate the sections and second to output the TOC. In practice
|
272
|
+
this means that the TOC is currently generated from layout at present.
|
273
|
+
|
274
|
+
Adding filters to a page's chain can be done anywhere you can call that page's filter-chain
|
275
|
+
methods. This could be page code, COMMON.rb, or even inside the template itself. Filters
|
276
|
+
can also be applied to all files with a matching extension by adding filters inside an
|
277
|
+
<%= section_link 'extension mapping' %> block. Bear in mind that the order in which filters
|
278
|
+
are added *is* important, since each filters output becomes input for the next. You
|
279
|
+
must ensure that filters are applied in a compatible order - should you need to prepend
|
280
|
+
filters or otherwise modify the chain prior to rendering you may do so by directly
|
281
|
+
accessing the @page_filters@ and @post_filters@ array attributes.
|
282
|
+
|
283
|
+
See <%= section_link 'template code and erb', 'the section on template code' %>
|
284
|
+
for more information on adding code to your pages.
|
285
|
+
|
286
|
+
Filters are of course very simple to write. See the 'Writing filters' subsection
|
287
|
+
(in <%= section_link 'Extending Rote' %>) for details.
|
288
|
+
|
289
|
+
<%= section 4, 'Macros' %>
|
290
|
+
|
291
|
+
There is one more aspect to filters - support for macros. Macro filters (derived from
|
292
|
+
the standard @Filters::MacroFilter@ class) support the insertion of delimited
|
293
|
+
sections of text that should be ignored by all filters except that which handles the
|
294
|
+
macro. The standard @Syntax@ filter is a macro filter.
|
295
|
+
|
296
|
+
See the <%= section_link 'extending rote' %> section for information on implementing
|
297
|
+
your own macros.
|
298
|
+
|
299
|
+
<%= section 4, 'Format helpers' %>
|
300
|
+
|
301
|
+
p{color:red}. *TODO* This section is under construction.
|
302
|
+
Please see "@Rote::Format::HTML@":<%= link_rel '/rdoc/classes/Rote/Format/HTML.html' %>
|
303
|
+
for currently available information.
|
304
|
+
|
265
305
|
<%= section 3, 'Resources' %>
|
266
306
|
|
267
307
|
Of course, you're likely to have resources for your site (images, sounds, etc)
|
@@ -274,6 +314,100 @@ output, and will be preserved during the copy. Resources are copied only if
|
|
274
314
|
necessary (determined by existence and last-modified timestamp), in a similar
|
275
315
|
way to pages.
|
276
316
|
|
317
|
+
<%= section 3, 'Rake task configuration' %>
|
318
|
+
|
319
|
+
<%= section 4, 'Reference Rakefile' %>
|
320
|
+
|
321
|
+
The following Rakefile demonstrates most of the methods you can use to customise
|
322
|
+
Rote's rake task configuration.
|
323
|
+
|
324
|
+
#:code#ruby#
|
325
|
+
# Rakefile
|
326
|
+
require 'rote'
|
327
|
+
include Rote
|
328
|
+
|
329
|
+
# This defines all our Rake tasks. The symbol we supply here (:doc is
|
330
|
+
# default) gives the base-prefix for the tasks that are generated.
|
331
|
+
ws = Rote::DocTask.new(:doc) { |doc|
|
332
|
+
# Output directory and layout sources
|
333
|
+
doc.output_dir = 'html'
|
334
|
+
doc.layout_dir = 'doc/layouts'
|
335
|
+
|
336
|
+
# Page directory and include globs.
|
337
|
+
doc.pages.dir = 'doc/pages'
|
338
|
+
doc.pages.include('**/*')
|
339
|
+
|
340
|
+
# Resource directory and include globs. This directory
|
341
|
+
# could be the same as the pages directory.
|
342
|
+
doc.res.dir = 'doc/res/'
|
343
|
+
doc.res.include('**/*.png')
|
344
|
+
doc.res.include('**/*.gif')
|
345
|
+
doc.res.include('**/*.jpg')
|
346
|
+
doc.res.include('**/*.css')
|
347
|
+
|
348
|
+
# Define an extension mapping
|
349
|
+
doc.ext_mapping(/(html)/, '$1') do |page|
|
350
|
+
# Let's use the HTML helpers everywhere ...
|
351
|
+
page.extend Format::HTML
|
352
|
+
|
353
|
+
# use 'page' layout on all html files
|
354
|
+
# This can also be set from COMMON.rb
|
355
|
+
page.layout 'page'
|
356
|
+
|
357
|
+
# textile formatting, ruby syntax
|
358
|
+
page.page_filter Filters::RedCloth.new(:textile)
|
359
|
+
page.page_filter Filters::Syntax.new
|
360
|
+
|
361
|
+
# To valid xhtml with Tidy postfilter
|
362
|
+
page.post_filter Filters::Tidy
|
363
|
+
end
|
364
|
+
}
|
365
|
+
#:code#
|
366
|
+
|
367
|
+
Please refer to the "RDoc":<%= link_rel '/rdoc/classes/Rote/DocTask.html' %> for specific
|
368
|
+
information on each method.
|
369
|
+
|
370
|
+
<%= section 4, 'Extension mappings' %>
|
371
|
+
|
372
|
+
The default behaviour when transforming pages is to make each filename
|
373
|
+
matched by the @pages.include@s relative to the output directory, using
|
374
|
+
the same extension as the input file.
|
375
|
+
|
376
|
+
If you want to change this behaviour, you may supply an _extension mapping_
|
377
|
+
as demonstrated above. The general form is:
|
378
|
+
|
379
|
+
#:code#ruby#
|
380
|
+
# Define an extension mapping
|
381
|
+
doc.ext_mapping(/regexp/, 'replacement') do |page|
|
382
|
+
|
383
|
+
# call page methods
|
384
|
+
|
385
|
+
end
|
386
|
+
#:code#
|
387
|
+
|
388
|
+
The regexp is matched against processed page extensions (not resources) and
|
389
|
+
the replacement supplies the output extension. The optional block is executed
|
390
|
+
for each page when it's first instantiated, before any COMMON or page code.
|
391
|
+
Note that you must not include the '.' in either the regexp or replacement.
|
392
|
+
|
393
|
+
For more advanced mappings, you can supply a capturing regexp, and use the
|
394
|
+
@$n@ notation in the replacement to extract the catures. As shown in the
|
395
|
+
(contrived) example above:
|
396
|
+
|
397
|
+
#:code#ruby#
|
398
|
+
doc.ext_mapping(/(html)/, '$1') do |page|
|
399
|
+
#:code#
|
400
|
+
|
401
|
+
<%= section 4, 'Defining additional tasks' %>
|
402
|
+
|
403
|
+
The command-line build will automatically look for a file in the top-level
|
404
|
+
directory (above @doc@) named @local.rf@. If found, this file will be
|
405
|
+
evaluated by Rake, making any tasks defined within it available to your
|
406
|
+
build. This can be used to define an <%= section_link 'auto refresh task' %>
|
407
|
+
for the <%= section_link 'source monitoring', 'monitor' %> feature, for example,
|
408
|
+
or to define tasks to publish your site (most likely using one of Rake's
|
409
|
+
directory publishers).
|
410
|
+
|
277
411
|
<%= section 3, 'Source monitoring' %>
|
278
412
|
|
279
413
|
When making changes to a documentation set, you frequently need to render out
|
@@ -310,7 +444,7 @@ because it just might make me reconsider.
|
|
310
444
|
When you're done with Rote simply hit CTRL-C (or use @kill@) to stop monitoring
|
311
445
|
and exit.
|
312
446
|
|
313
|
-
<%= section 4, 'Auto
|
447
|
+
<%= section 4, 'Auto refresh task' %>
|
314
448
|
|
315
449
|
When using Source monitoring, it's often handy to be able to inform some other
|
316
450
|
program that something has changed. For example, you may want to automatically
|
@@ -320,27 +454,18 @@ in your source set (_after_ rendering, of course).
|
|
320
454
|
|
321
455
|
The following (Mac) example uses OSA script to refresh the Safari browser when
|
322
456
|
your rendered documentation changes:
|
323
|
-
|
324
|
-
|
457
|
+
|
458
|
+
#:code#ruby#
|
459
|
+
require 'osx/aeosa'
|
325
460
|
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
461
|
+
task :doc_refresh do
|
462
|
+
OSX.do_osascript('tell application "Safari" to do javascript "window.location.reload();" in document 1')
|
463
|
+
end
|
464
|
+
#:code#ruby#
|
330
465
|
|
331
466
|
As with all rake tasks, multiple actions can be associated, and you can of course
|
332
467
|
add prerequisites to the @refresh@ task as with any other Rake task.
|
333
468
|
|
334
|
-
<%= section 3, 'Defining additional tasks' %>
|
335
|
-
|
336
|
-
The command-line build will automatically look for a file in the top-level
|
337
|
-
directory (above @doc@) named @local.rf@. If found, this file will be
|
338
|
-
evaluated by Rake, making any tasks defined within it available to your
|
339
|
-
build. This can be used to define an <%= section_link 'auto-refresh task' %>
|
340
|
-
for the <%= section_link 'source monitoring', 'monitor' %> feature, for example,
|
341
|
-
or to define tasks to publish your site (most likely using one of Rake's
|
342
|
-
directory publishers).
|
343
|
-
|
344
469
|
<%= section 3, 'Publishing' %>
|
345
470
|
|
346
471
|
Rote does not provide any direct support for publishing your site at present,
|
@@ -349,20 +474,148 @@ the publishers supplied with Rake (in @rake/contrib@), or your own. This
|
|
349
474
|
allows maximum flexibility, and allows Rote to concentrate on creating your
|
350
475
|
documents.
|
351
476
|
|
477
|
+
See the <%= section_link 'rake task configuration' %> section for more details.
|
478
|
+
|
479
|
+
<%= section 3, 'Extending Rote' %>
|
480
|
+
|
481
|
+
Although Rote is designed to be as quick and easy to use as possible,
|
482
|
+
with sensible default configuration and reasonable convention throughout,
|
483
|
+
it also has ample flexibility when it comes to generating more complex
|
484
|
+
documentation sets. Thanks to it's 'option for every default' and simple
|
485
|
+
extension points, Rote should scale to even complex documentation sets
|
486
|
+
quite easily.
|
487
|
+
|
488
|
+
<%= section 4, 'Writing filters' %>
|
489
|
+
|
490
|
+
*Filters* do exactly what they say on the tin - they filter the output of
|
491
|
+
a page, perhaps rendering markup or inserting additional text. Filters
|
492
|
+
can be divided into two general categories: *Text filters* and *Macro filters*.
|
493
|
+
Either type can be a page or post filter - it depends only on the design
|
494
|
+
of the filter and the job it will perform as to which chain it should
|
495
|
+
be used with.
|
496
|
+
|
497
|
+
h5. Text filters
|
498
|
+
|
499
|
+
Text filters process the text in a page, with all macros replaced by a
|
500
|
+
standard plain-text marker. The purpose of this is to allow macros
|
501
|
+
to coexist with plain-text formatting without causing markup clashes.
|
502
|
+
|
503
|
+
Most of the standard filters are text filters. The RedCloth filter
|
504
|
+
is representative:
|
505
|
+
|
506
|
+
#:code#ruby#
|
507
|
+
class RedCloth < TextFilter
|
508
|
+
def initialize(*redcloth_opts)
|
509
|
+
super()
|
510
|
+
@redcloth_opts = redcloth_opts
|
511
|
+
end
|
512
|
+
|
513
|
+
def handler(text,page)
|
514
|
+
rc = ::RedCloth.new(text)
|
515
|
+
# hack around a RedCloth warning
|
516
|
+
rc.instance_eval { @lite_mode = false }
|
517
|
+
rc.to_html(*@redcloth_opts)
|
518
|
+
end
|
519
|
+
end
|
520
|
+
#:code#
|
521
|
+
|
522
|
+
(again, this example is slightly simplified with respect to auxiliary
|
523
|
+
functionality for the sake of clarity).
|
524
|
+
|
525
|
+
As mentioned above, @TextFilter@ also provides help with writing non-macro
|
526
|
+
filters that removes much of the headache of working around macros (which
|
527
|
+
must not be modified by any filter except that which handles the macro).
|
528
|
+
|
529
|
+
Text filters can optionally access the macro data using the @macros@ array.
|
530
|
+
|
531
|
+
If you want to implement a one-off filter quickly, there's no need to
|
532
|
+
create a new subclass - you can supply a block directly to TextFilter,
|
533
|
+
which is executed to render the textual content:
|
534
|
+
|
535
|
+
#:code#ruby#
|
536
|
+
page.page_filter Rote::Filters::TextFilter.new { |page, text|
|
537
|
+
text.gsub(/foo/,'bar')
|
538
|
+
}
|
539
|
+
#:code#
|
540
|
+
|
541
|
+
For text filters, a convenience in the implementation of @page_filter@
|
542
|
+
allows the above to be shortened to:
|
543
|
+
|
544
|
+
#:code#ruby#
|
545
|
+
page.page_filter do |page, text|
|
546
|
+
text.gsub(/foo/,'bar')
|
547
|
+
end
|
548
|
+
#:code#
|
549
|
+
|
550
|
+
Note the curly braces in the first example, which cause the block to bind
|
551
|
+
to the filter rather than the method. If @do..end@ were used, the second
|
552
|
+
form would actually be called and a new filter created. The filter you
|
553
|
+
supplied would be discarded.
|
554
|
+
|
555
|
+
The @post_filter@ method supports the same convenience.
|
556
|
+
|
557
|
+
h5. Macro filters
|
558
|
+
|
559
|
+
The standard Syntax filter is a typical macro filter. The following is
|
560
|
+
slightly simplified for brevity (the actual one allows custom macro tags
|
561
|
+
to be supplied):
|
562
|
+
|
563
|
+
#:code#ruby#
|
564
|
+
class Syntax < MacroFilter
|
565
|
+
def macro_code(lang, body)
|
566
|
+
converter = ::Syntax::Convertors::HTML.for_syntax(lang)
|
567
|
+
"<pre class='#{lang}'><code>#{converter.convert(body,false)}</code></pre>"
|
568
|
+
end
|
569
|
+
end
|
570
|
+
#:code#
|
571
|
+
|
572
|
+
As you can see, a macro filter simply inherits @Rote::Filters::MacroFilter@
|
573
|
+
and implements one or more @macro_XXXX@ methods, which is passed the arguments
|
574
|
+
supplied to the macro (used here to indicate the code language) and the
|
575
|
+
raw macro body.
|
576
|
+
|
577
|
+
If you want to implement a macro quickly, perhaps across a section or set of
|
578
|
+
pages, you can use @MacroFilter@ itself, supplying a block:
|
579
|
+
|
580
|
+
#:code#ruby#
|
581
|
+
page.page_filter Rote::Filters::MacroFilter.new([:foomacro]) { |tag, args, body
|
582
|
+
"FooMacro Replacement!"
|
583
|
+
}
|
584
|
+
#:code#
|
585
|
+
|
586
|
+
This can be done from any page code, a COMMON.rb (see
|
587
|
+
<%= section_link 'Template code and ERB' %>), or on a per-extension basis
|
588
|
+
with <%= section_link 'extension mappings' %>.
|
589
|
+
|
590
|
+
*Note* that macro data is passed raw, and excluded from rendering by
|
591
|
+
<%= section_link 'text filters' %>. The output, however, *will* be processed
|
592
|
+
by any filters that follow the macro filter in the chain.
|
593
|
+
|
594
|
+
h5. Duck filters
|
595
|
+
|
596
|
+
This being Ruby, you don't _have_ to inherit one of the above filters to create
|
597
|
+
your own - a filter is just an object with a @filter(text,page)@ method.
|
598
|
+
|
599
|
+
The standard TOC filter takes this route.
|
600
|
+
|
352
601
|
<%= section 3, 'Final notes' %>
|
353
602
|
|
354
|
-
|
355
|
-
|
356
|
-
|
603
|
+
<%= section 4, 'Layout dependencies' %>
|
604
|
+
|
605
|
+
Because of the way Rote is implemented, it is currently not possible for a
|
606
|
+
page's file task to depend upon the page's layout, or resources embedded in
|
607
|
+
it in a format-specific way (as opposed to merely referenced from it as with
|
608
|
+
HTML/images). When changing these resources it's highly recommended to first
|
609
|
+
run:
|
357
610
|
|
358
611
|
<p><pre><code> rote clobber</code></pre></p>
|
359
612
|
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
"Rake's Documentation":http://rake.rubyforge.org/ for information on
|
366
|
-
|
613
|
+
<%= section 4, 'Rake magic' %>
|
614
|
+
|
615
|
+
Rake is a *very* flexible tool, and supports a wide variety of configuration
|
616
|
+
options and advanced features you can use to fit Rote to your needs. Such
|
617
|
+
configuration is beyond the scope of this manual - see
|
618
|
+
"Rake's Documentation":http://rake.rubyforge.org/ for information on the
|
619
|
+
features supported by Rake.
|
367
620
|
|
368
621
|
[<%= section_link 'Top' %>]
|