hoe-manns 1.0.1 → 1.0.2
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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/.codeclimate.yml +8 -0
- data/.coveralls.yml +2 -0
- data/.index +7 -15
- data/CONTRIBUTING.md +2 -2
- data/Gemfile +0 -2
- data/Gemfile.lock +2 -11
- data/History.rdoc +7 -1
- data/Manifest.txt +3 -40
- data/README.rdoc +8 -12
- data/Rakefile +13 -15
- data/VERSION +1 -1
- data/data/hoe-manns/rubygems.png +0 -0
- data/lib/hoe/manns.rb +12 -2
- data.tar.gz.sig +0 -0
- metadata +6 -72
- metadata.gz.sig +0 -0
- data/.idea/hoe-manns.iml +0 -93
- data/.idea/misc.xml +0 -14
- data/.idea/modules.xml +0 -8
- data/.idea/vcs.xml +0 -6
- data/.idea/workspace.xml +0 -948
- data/manual/layouts/default.erb +0 -87
- data/manual/lib/api-filter.rb +0 -96
- data/manual/lib/editorial-filter.rb +0 -59
- data/manual/lib/examples-filter.rb +0 -230
- data/manual/lib/links-filter.rb +0 -111
- data/manual/resources/css/manual.css +0 -764
- data/manual/resources/css/reset.css +0 -112
- data/manual/resources/fonts/GraublauWeb.otf +0 -0
- data/manual/resources/fonts/GraublauWebBold.otf +0 -0
- data/manual/resources/fonts/Inconsolata.otf +0 -0
- data/manual/resources/images/arrow_225_small.png +0 -0
- data/manual/resources/images/arrow_315_small.png +0 -0
- data/manual/resources/images/arrow_skip.png +0 -0
- data/manual/resources/images/cc-by.png +0 -0
- data/manual/resources/images/dialog-error.png +0 -0
- data/manual/resources/images/dialog-information.png +0 -0
- data/manual/resources/images/dialog-warning.png +0 -0
- data/manual/resources/images/emblem-important.png +0 -0
- data/manual/resources/images/help.png +0 -0
- data/manual/resources/images/information.png +0 -0
- data/manual/resources/images/magnifier.png +0 -0
- data/manual/resources/images/magnifier_left.png +0 -0
- data/manual/resources/images/page_white_code.png +0 -0
- data/manual/resources/images/page_white_copy.png +0 -0
- data/manual/resources/images/printer.png +0 -0
- data/manual/resources/images/question.png +0 -0
- data/manual/resources/images/scripts_code.png +0 -0
- data/manual/resources/images/wrap.png +0 -0
- data/manual/resources/images/wrapping.png +0 -0
- data/manual/resources/js/jquery-1.4.4.min.js +0 -167
- data/manual/resources/js/manual.js +0 -30
- data/manual/resources/js/sh.js +0 -580
- data/manual/resources/swf/clipboard.swf +0 -0
- data/manual/src/apidocs.page +0 -17
- data/manual/src/index.page +0 -71
data/manual/layouts/default.erb
DELETED
@@ -1,87 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<!--
|
3
|
-
|
4
|
-
Main Manual Layout
|
5
|
-
$Id: default.erb.erb,v 8077c9cdbac9 2011/01/26 02:15:09 ged $
|
6
|
-
|
7
|
-
Author: Michael Granger <ged@FaerieMUD.org>
|
8
|
-
Two column fluid layout adapted from Matthew James Taylor's "Perfect 'Left Menu'
|
9
|
-
2 Column Liquid Layout":
|
10
|
-
http://matthewjamestaylor.com/blog/perfect-2-column-left-menu.htm
|
11
|
-
|
12
|
-
-->
|
13
|
-
<html lang="en">
|
14
|
-
<head>
|
15
|
-
<meta charset="utf-8">
|
16
|
-
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
17
|
-
|
18
|
-
<title>hoe-manns Manual — <%= page.config['title'] || "untitled" %></title>
|
19
|
-
|
20
|
-
<link rel="stylesheet" href="css/manual.css">
|
21
|
-
|
22
|
-
<script src="js/jquery-1.4.4.min.js"></script>
|
23
|
-
<script src="js/sh.js"></script>
|
24
|
-
<script src="js/manual.js"></script>
|
25
|
-
|
26
|
-
</head>
|
27
|
-
<body>
|
28
|
-
<div id="page">
|
29
|
-
|
30
|
-
<header>
|
31
|
-
<hgroup>
|
32
|
-
<a href="/">
|
33
|
-
<h1>hoe-manns</h1>
|
34
|
-
</a>
|
35
|
-
<% if metadata.version %><h2 class="version"><%= metadata.version %></h2><% end %>
|
36
|
-
<% if page.config['tagline'] %><h2 class="tagline"><%= page.config['tagline'] %></h2><% end %>
|
37
|
-
</hgroup>
|
38
|
-
</header>
|
39
|
-
|
40
|
-
<div class="colmask leftmenu">
|
41
|
-
<div class="colleft">
|
42
|
-
|
43
|
-
<section id="content" class="col1">
|
44
|
-
<!-- Generated content -->
|
45
|
-
<%= content %>
|
46
|
-
<!-- end of generated content -->
|
47
|
-
</section>
|
48
|
-
|
49
|
-
<aside id="sidebar" class="col2">
|
50
|
-
<nav>
|
51
|
-
<%
|
52
|
-
@catalog.traverse_page_hierarchy( self ) do |type, title, path|
|
53
|
-
case type
|
54
|
-
when :section
|
55
|
-
%>
|
56
|
-
<div class="section">
|
57
|
-
<h3><a href="<%= self.basepath + path %>/"><%= title %></a></h3>
|
58
|
-
<ul class="index-section">
|
59
|
-
<% when :current_section %>
|
60
|
-
<div class="section current-section">
|
61
|
-
<h3><a href="<%= self.basepath + path %>/"><%= title %></a></h3>
|
62
|
-
<ul class="index-section current-index-section">
|
63
|
-
<% when :section_end, :current_section_end %>
|
64
|
-
</ul>
|
65
|
-
</div>
|
66
|
-
<% when :entry %>
|
67
|
-
<li><a href="<%= self.basepath + path %>.html"><%= title %></a></li>
|
68
|
-
<% when :current_entry %>
|
69
|
-
<li class="current-entry"><%= title %></li>
|
70
|
-
<% end
|
71
|
-
end
|
72
|
-
%>
|
73
|
-
</nav>
|
74
|
-
</aside>
|
75
|
-
|
76
|
-
</div>
|
77
|
-
</div>
|
78
|
-
|
79
|
-
<footer>
|
80
|
-
<div class="copyright">Copyright © 2008-<%= Time.now.year %> Sascha Manns.</div>
|
81
|
-
<div class="vcsrev">Rev: $Revision: 8077c9cdbac9 $</div>
|
82
|
-
<div class="timestamp">Built: <%= Time.now.strftime("%Y%m%d %H:%M:%S %Z") %></div>
|
83
|
-
</footer>
|
84
|
-
|
85
|
-
</body>
|
86
|
-
</html>
|
87
|
-
|
data/manual/lib/api-filter.rb
DELETED
@@ -1,96 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby
|
2
|
-
#
|
3
|
-
# A manual filter to generate links from the Darkfish API.
|
4
|
-
#
|
5
|
-
# Authors:
|
6
|
-
# * Michael Granger <ged@FaerieMUD.org>
|
7
|
-
# * Mahlon E. Smith <mahlon@martini.nu>
|
8
|
-
#
|
9
|
-
|
10
|
-
|
11
|
-
### A filter for generating links from the generated API documentation. This allows you to refer
|
12
|
-
### to class documentation by simply referencing a class name.
|
13
|
-
###
|
14
|
-
### Links are XML processing instructions. Pages can be referenced as such:
|
15
|
-
###
|
16
|
-
### <?api Class::Name ?>
|
17
|
-
### <?api Class::Name#instance_method ?>
|
18
|
-
### <?api Class::Name.class_method ?>
|
19
|
-
###
|
20
|
-
### Link text can be overridden, too:
|
21
|
-
###
|
22
|
-
### <?api "click here":Class::Name ?>
|
23
|
-
### <?api "click here":Class::Name#instance_method ?>
|
24
|
-
###
|
25
|
-
class Hoe::ManualGen::APIFilter < Hoe::ManualGen::PageFilter
|
26
|
-
|
27
|
-
# PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'
|
28
|
-
ApiPI = %r{
|
29
|
-
<\?
|
30
|
-
api # Instruction Target
|
31
|
-
\s+
|
32
|
-
(?:"
|
33
|
-
(.*?) # Optional link text [$1]
|
34
|
-
":)?
|
35
|
-
(.*?) # Class name [$2]
|
36
|
-
([\.#].*?)? # Method anchor [$3]
|
37
|
-
\s+
|
38
|
-
\?>
|
39
|
-
}x
|
40
|
-
|
41
|
-
|
42
|
-
######
|
43
|
-
public
|
44
|
-
######
|
45
|
-
|
46
|
-
### Process the given +source+ for <?api ... ?> processing-instructions, calling out
|
47
|
-
def process( source, page, metadata )
|
48
|
-
|
49
|
-
apipath = metadata.api_dir or
|
50
|
-
raise "The API output directory is not defined in the manual task."
|
51
|
-
|
52
|
-
return source.gsub( ApiPI ) do |match|
|
53
|
-
# Grab the tag values
|
54
|
-
link_text = $1
|
55
|
-
classname = $2
|
56
|
-
methodname = $3
|
57
|
-
|
58
|
-
self.generate_link( page, apipath, classname, methodname, link_text )
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
|
63
|
-
### Create an HTML link fragment from the parsed ApiPI.
|
64
|
-
def generate_link( current_page, apipath, classname, methodname=nil, link_text=nil )
|
65
|
-
|
66
|
-
classpath = "%s.html" % [ classname.gsub('::', '/') ]
|
67
|
-
classfile = apipath + classpath
|
68
|
-
classuri = current_page.basepath + 'api' + classpath
|
69
|
-
|
70
|
-
if classfile.exist?
|
71
|
-
return %{<a href="%s%s">%s</a>} % [
|
72
|
-
classuri,
|
73
|
-
make_anchor( methodname ),
|
74
|
-
link_text || (classname + (methodname || ''))
|
75
|
-
]
|
76
|
-
else
|
77
|
-
link_text ||= classname
|
78
|
-
error_message = "Could not find a link for class '%s'" % [ classname ]
|
79
|
-
$stderr.puts( error_message )
|
80
|
-
return %{<a href="#" title="#{error_message}" class="broken-link">#{link_text}</a>}
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
|
85
|
-
### Attach a method anchor.
|
86
|
-
def make_anchor( methodname )
|
87
|
-
return '' unless methodname
|
88
|
-
|
89
|
-
method_type = methodname[ 0, 1 ]
|
90
|
-
return "#method-%s-%s" % [
|
91
|
-
( method_type == '#' ? 'i' : 'c' ),
|
92
|
-
methodname[ 1..-1 ]
|
93
|
-
]
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
@@ -1,59 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby
|
2
|
-
#
|
3
|
-
# A manual filter to highlight content that needs editorial help.
|
4
|
-
#
|
5
|
-
# Authors:
|
6
|
-
# * Michael Granger <ged@FaerieMUD.org>
|
7
|
-
#
|
8
|
-
#
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
### A filter for making editorial marks in manual content.
|
13
|
-
###
|
14
|
-
### Editorial marks are XML processing instructions. There are several available types of
|
15
|
-
### marks:
|
16
|
-
###
|
17
|
-
### <?ed "This is an editor's note." ?>
|
18
|
-
### <?ed verify:"this content needs checking or verification" ?>
|
19
|
-
###
|
20
|
-
class Hoe::ManualGen::EditorialFilter < Hoe::ManualGen::PageFilter
|
21
|
-
|
22
|
-
# PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'
|
23
|
-
LinkPI = %r{
|
24
|
-
<\?
|
25
|
-
ed # Instruction Target
|
26
|
-
\s+
|
27
|
-
(\w+?) # type of editorial mark [$1]
|
28
|
-
:? # optional colon
|
29
|
-
"
|
30
|
-
(.*?) # content that should be edited [$2]
|
31
|
-
"
|
32
|
-
\s*
|
33
|
-
\?>
|
34
|
-
}x
|
35
|
-
|
36
|
-
|
37
|
-
######
|
38
|
-
public
|
39
|
-
######
|
40
|
-
|
41
|
-
### Process the given +source+ for <?ed ... ?> processing-instructions
|
42
|
-
def process( source, page, metadata )
|
43
|
-
return source.gsub( LinkPI ) do |match|
|
44
|
-
# Grab the tag values
|
45
|
-
mark_type = $1
|
46
|
-
content = $2
|
47
|
-
|
48
|
-
self.generate_mark( page, mark_type, content )
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
|
53
|
-
### Create an HTML fragment from the parsed LinkPI.
|
54
|
-
def generate_mark( current_page, mark_type, content )
|
55
|
-
return "%%(editorial %s-mark)%s%%" % [ mark_type, content ]
|
56
|
-
end
|
57
|
-
|
58
|
-
|
59
|
-
end
|
@@ -1,230 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby
|
2
|
-
#encoding: utf-8
|
3
|
-
#
|
4
|
-
# A collection of standard filters for the manual generation tasklib.
|
5
|
-
#
|
6
|
-
# Authors:
|
7
|
-
# Michael Granger <ged@FaerieMUD.org>
|
8
|
-
#
|
9
|
-
#
|
10
|
-
|
11
|
-
# Dependencies deferred until #initialize
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
### A filter for inline example code or command-line sessions -- does
|
16
|
-
### syntax-checking for some languages and captioning.
|
17
|
-
###
|
18
|
-
### Examples are enclosed in XML processing instructions like so:
|
19
|
-
###
|
20
|
-
### <?example {language: ruby, testable: true, caption: "A fine example"} ?>
|
21
|
-
### a = 1
|
22
|
-
### puts a
|
23
|
-
### <?end example ?>
|
24
|
-
###
|
25
|
-
### This will be pulled out into a preformatted section in the HTML,
|
26
|
-
### highlighted as Ruby source, checked for valid syntax, and annotated with
|
27
|
-
### the specified caption. Valid keys in the example PI are:
|
28
|
-
###
|
29
|
-
### language::
|
30
|
-
### Specifies which (machine) language the example is in.
|
31
|
-
### testable::
|
32
|
-
### If set and there is a testing function for the given language, run it and append
|
33
|
-
### any errors to the output.
|
34
|
-
### caption::
|
35
|
-
### A small blurb to put below the pulled-out example in the HTML.
|
36
|
-
class Hoe::ManualGen::ExamplesFilter < Hoe::ManualGen::PageFilter
|
37
|
-
|
38
|
-
DEFAULTS = {
|
39
|
-
:language => :ruby,
|
40
|
-
:line_numbers => :inline,
|
41
|
-
:tab_width => 4,
|
42
|
-
:hint => :debug,
|
43
|
-
:testable => false,
|
44
|
-
}
|
45
|
-
|
46
|
-
# PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'
|
47
|
-
ExamplePI = %r{
|
48
|
-
<\?
|
49
|
-
example # Instruction Target
|
50
|
-
(?: # Optional instruction body
|
51
|
-
\s+
|
52
|
-
((?: # [$1]
|
53
|
-
[^?]* # Run of anything but a question mark
|
54
|
-
| # -or-
|
55
|
-
\?(?!>) # question mark not followed by a closing angle bracket
|
56
|
-
)*)
|
57
|
-
)?
|
58
|
-
\?>
|
59
|
-
}x
|
60
|
-
|
61
|
-
EndPI = %r{ <\? end (?: \s+ example )? \s* \?> }x
|
62
|
-
|
63
|
-
|
64
|
-
### Defer loading of dependenies until the filter is loaded
|
65
|
-
def initialize( *args )
|
66
|
-
require 'pathname'
|
67
|
-
require 'strscan'
|
68
|
-
require 'yaml'
|
69
|
-
require 'rcodetools/xmpfilter'
|
70
|
-
require 'digest/md5'
|
71
|
-
require 'tmpdir'
|
72
|
-
require 'erb'
|
73
|
-
end
|
74
|
-
|
75
|
-
|
76
|
-
######
|
77
|
-
public
|
78
|
-
######
|
79
|
-
|
80
|
-
### Process the given +source+ for <?example ... ?> processing-instructions, calling out
|
81
|
-
def process( source, page, metadata )
|
82
|
-
scanner = StringScanner.new( source )
|
83
|
-
|
84
|
-
buffer = ''
|
85
|
-
until scanner.eos?
|
86
|
-
startpos = scanner.pos
|
87
|
-
|
88
|
-
# If we find an example
|
89
|
-
if scanner.skip_until( ExamplePI )
|
90
|
-
contents = ''
|
91
|
-
|
92
|
-
# Append the interstitial content to the buffer
|
93
|
-
if ( scanner.pos - startpos > scanner.matched.length )
|
94
|
-
offset = scanner.pos - scanner.matched.length - 1
|
95
|
-
buffer << scanner.string[ startpos..offset ]
|
96
|
-
end
|
97
|
-
|
98
|
-
# Append everything up to it to the buffer and save the contents of
|
99
|
-
# the tag
|
100
|
-
params = scanner[1]
|
101
|
-
|
102
|
-
# Now find the end of the example or complain
|
103
|
-
contentpos = scanner.pos
|
104
|
-
scanner.skip_until( EndPI ) or
|
105
|
-
raise "Unterminated example at line %d" %
|
106
|
-
[ scanner.string[0..scanner.pos].count("\n") ]
|
107
|
-
|
108
|
-
# Now build the example and append to the buffer
|
109
|
-
if ( scanner.pos - contentpos > scanner.matched.length )
|
110
|
-
offset = scanner.pos - scanner.matched.length - 1
|
111
|
-
contents = scanner.string[ contentpos..offset ]
|
112
|
-
end
|
113
|
-
|
114
|
-
trace "Processing with params: %p, contents: %p" % [ params, contents ]
|
115
|
-
buffer << self.process_example( params, contents, page )
|
116
|
-
else
|
117
|
-
break
|
118
|
-
end
|
119
|
-
|
120
|
-
end
|
121
|
-
buffer << scanner.rest
|
122
|
-
scanner.terminate
|
123
|
-
|
124
|
-
return buffer
|
125
|
-
end
|
126
|
-
|
127
|
-
|
128
|
-
### Filter out 'example' macros, doing syntax highlighting, and running
|
129
|
-
### 'testable' examples through a validation process appropriate to the
|
130
|
-
### language the example is in.
|
131
|
-
def process_example( params, body, page )
|
132
|
-
options = self.parse_options( params )
|
133
|
-
caption = options.delete( :caption )
|
134
|
-
content = ''
|
135
|
-
lang = options.delete( :language ).to_s
|
136
|
-
|
137
|
-
# Test it if it's testable
|
138
|
-
if options[:testable]
|
139
|
-
content = test_content( body, lang, page )
|
140
|
-
else
|
141
|
-
content = body
|
142
|
-
end
|
143
|
-
|
144
|
-
# Strip trailing blank lines and syntax-highlight
|
145
|
-
content = highlight( content.strip, options, lang )
|
146
|
-
caption = %{<div class="caption">} + caption.to_s + %{</div>} if caption
|
147
|
-
|
148
|
-
return %{<notextile><div class="example #{lang}-example">%s%s</div></notextile>} %
|
149
|
-
[content, caption || '']
|
150
|
-
end
|
151
|
-
|
152
|
-
|
153
|
-
### Parse an options hash for filtering from the given +args+, which can either
|
154
|
-
### be a plain String, in which case it is assumed to be the name of the language the example
|
155
|
-
### is in, or a Hash of configuration options.
|
156
|
-
def parse_options( args )
|
157
|
-
args = "{ #{args} }" unless args.strip[0] == ?{
|
158
|
-
args = YAML.load( args )
|
159
|
-
|
160
|
-
# Convert to Symbol keys and value
|
161
|
-
args.keys.each do |k|
|
162
|
-
newval = args.delete( k )
|
163
|
-
next if newval.nil? || (newval.respond_to?(:size) && newval.size == 0)
|
164
|
-
args[ k.to_sym ] = newval.respond_to?( :to_sym ) ? newval.to_sym : newval
|
165
|
-
end
|
166
|
-
return DEFAULTS.merge( args )
|
167
|
-
end
|
168
|
-
|
169
|
-
|
170
|
-
### Test the given +content+ with a rule specific to the given +language+.
|
171
|
-
def test_content( body, language, page )
|
172
|
-
case language.to_sym
|
173
|
-
when :ruby
|
174
|
-
return self.test_ruby_content( body, page )
|
175
|
-
|
176
|
-
when :yaml
|
177
|
-
return self.test_yaml_content( body, page )
|
178
|
-
|
179
|
-
else
|
180
|
-
return body
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
|
185
|
-
### Test the specified Ruby content for valid syntax
|
186
|
-
def test_ruby_content( source, page )
|
187
|
-
# $stderr.puts "Testing ruby content..."
|
188
|
-
libdir = Pathname.new( __FILE__ ).dirname.parent.parent.parent + 'lib'
|
189
|
-
extdir = Pathname.new( __FILE__ ).dirname.parent.parent.parent + 'ext'
|
190
|
-
|
191
|
-
options = Rcodetools::XMPFilter::INITIALIZE_OPTS.dup
|
192
|
-
options[:include_paths] |= [ libdir.to_s, extdir.to_s ]
|
193
|
-
options[:width] = 60
|
194
|
-
|
195
|
-
if page.config['example_prelude']
|
196
|
-
prelude = page.config['example_prelude']
|
197
|
-
trace " prepending prelude:\n#{prelude}"
|
198
|
-
source = prelude.strip + "\n" + source.strip
|
199
|
-
else
|
200
|
-
trace " no prelude; page config is: %p" % [ page.config ]
|
201
|
-
end
|
202
|
-
|
203
|
-
rval = Rcodetools::XMPFilter.run( source, options )
|
204
|
-
|
205
|
-
trace "test output: ", rval
|
206
|
-
return rval.join
|
207
|
-
rescue Exception => err
|
208
|
-
return "%s while testing: %s\n %s" %
|
209
|
-
[ err.class.name, err.message, err.backtrace.join("\n ") ]
|
210
|
-
end
|
211
|
-
|
212
|
-
|
213
|
-
### Test the specified YAML content for valid syntax
|
214
|
-
def test_yaml_content( source, metadata )
|
215
|
-
YAML.load( source )
|
216
|
-
rescue YAML::Error => err
|
217
|
-
return "# Invalid YAML: " + err.message + "\n" + source
|
218
|
-
else
|
219
|
-
return source
|
220
|
-
end
|
221
|
-
|
222
|
-
|
223
|
-
### Highlights the given +content+ in language +lang+.
|
224
|
-
def highlight( content, options, lang )
|
225
|
-
source = ERB::Util.html_escape( content )
|
226
|
-
return %Q{\n\n<pre class="brush:#{lang}">#{source}</pre>\n\n}
|
227
|
-
end
|
228
|
-
|
229
|
-
end
|
230
|
-
|
data/manual/lib/links-filter.rb
DELETED
@@ -1,111 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby
|
2
|
-
#
|
3
|
-
# A manual filter to generate links from the page catalog.
|
4
|
-
#
|
5
|
-
# Authors:
|
6
|
-
# * Michael Granger <ged@FaerieMUD.org>
|
7
|
-
# * Mahlon E. Smith <mahlon@martini.nu>
|
8
|
-
#
|
9
|
-
#
|
10
|
-
|
11
|
-
|
12
|
-
### A filter for generating links from the page catalog. This allows you to refer to other pages
|
13
|
-
### in the source and have them automatically updated as the structure of the manual changes.
|
14
|
-
###
|
15
|
-
### Links are XML processing instructions. Pages can be referenced in one of several ways:
|
16
|
-
###
|
17
|
-
### <?link Page Title ?>
|
18
|
-
### <?link "click here":Page Title ?>
|
19
|
-
### <?link Page Title #section_id ?>
|
20
|
-
### <?link "click here":Page Title#section_id ?>
|
21
|
-
###
|
22
|
-
### This first form links to a page by title. Link text defaults to the page title unless an
|
23
|
-
### optional quoted string is prepended. If you want to link to an anchor inside the page, include
|
24
|
-
### its ID with a hash mark after the title.
|
25
|
-
###
|
26
|
-
### <?link path/to/Catalog.page ?>
|
27
|
-
### <?link "click here":path/to/Catalog.page ?>
|
28
|
-
### <?link path/to/Catalog.page#section_id ?>
|
29
|
-
### <?link "click here":path/to/Catalog.page#section_id ?>
|
30
|
-
###
|
31
|
-
### The second form links to a page by its path relative to the base manual source directory.
|
32
|
-
### Again, the link text defaults to the page title, or can be overriden via a prepended string,
|
33
|
-
### and you can link into a page with an appended ID.
|
34
|
-
class Hoe::ManualGen::LinksFilter < Hoe::ManualGen::PageFilter
|
35
|
-
|
36
|
-
# PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'
|
37
|
-
LinkPI = %r{
|
38
|
-
<\?
|
39
|
-
link # Instruction Target
|
40
|
-
\s+
|
41
|
-
(?:"
|
42
|
-
(.*?) # Optional link text [$1]
|
43
|
-
":)?
|
44
|
-
(.*?) # Title or path [$2]
|
45
|
-
\s*
|
46
|
-
(\#\w+)? # Fragment [$3]
|
47
|
-
\s+
|
48
|
-
\?>
|
49
|
-
}x
|
50
|
-
|
51
|
-
|
52
|
-
######
|
53
|
-
public
|
54
|
-
######
|
55
|
-
|
56
|
-
### Process the given +source+ for <?link ... ?> processing-instructions, calling out
|
57
|
-
def process( source, page, metadata )
|
58
|
-
return source.gsub( LinkPI ) do |match|
|
59
|
-
# Grab the tag values
|
60
|
-
link_text = $1
|
61
|
-
reference = $2
|
62
|
-
fragment = $3
|
63
|
-
|
64
|
-
self.generate_link( page, reference, link_text, fragment )
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
|
69
|
-
### Create an HTML link fragment from the parsed LinkPI.
|
70
|
-
def generate_link( current_page, reference, link_text=nil, fragment=nil )
|
71
|
-
|
72
|
-
if other_page = self.find_linked_page( current_page, reference )
|
73
|
-
href_path = other_page.sourcefile.relative_path_from( current_page.sourcefile.dirname )
|
74
|
-
href = href_path.to_s.gsub( '.page', '.html' )
|
75
|
-
|
76
|
-
if link_text
|
77
|
-
return %{<a href="#{href}#{fragment}">#{link_text}</a>}
|
78
|
-
else
|
79
|
-
return %{<a href="#{href}#{fragment}">#{other_page.title}</a>}
|
80
|
-
end
|
81
|
-
else
|
82
|
-
link_text ||= reference
|
83
|
-
error_message = "Could not find a link for reference '%s'" % [ reference ]
|
84
|
-
$stderr.puts( error_message )
|
85
|
-
return %{<a href="#" title="#{error_message}" class="broken-link">#{link_text}</a>}
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
|
90
|
-
### Lookup a page +reference+ in the catalog. +reference+ can be either a
|
91
|
-
### path to the .page file, relative to the manual root path, or a page title.
|
92
|
-
### Returns a matching Page object, or nil if no match is found.
|
93
|
-
def find_linked_page( current_page, reference )
|
94
|
-
|
95
|
-
catalog = current_page.catalog
|
96
|
-
|
97
|
-
# Lookup by page path
|
98
|
-
if reference =~ /\.page$/
|
99
|
-
return catalog.uri_index[ reference ]
|
100
|
-
|
101
|
-
# Lookup by page title
|
102
|
-
else
|
103
|
-
return catalog.title_index[ reference ]
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|