linkparser 1.0.4 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/ChangeLog +134 -506
- data/LICENSE +1 -1
- data/README.md +95 -0
- data/Rakefile +145 -95
- data/Rakefile.local +31 -39
- data/ext/dictionary.c +103 -37
- data/ext/extconf.rb +79 -32
- data/ext/linkage.c +245 -210
- data/ext/linkparser.c +3 -2
- data/ext/linkparser.h +21 -17
- data/ext/parseoptions.c +65 -65
- data/ext/sentence.c +75 -64
- data/lib/linkparser.rb +16 -26
- data/lib/linkparser/linkage.rb +68 -50
- data/lib/linkparser/mixins.rb +38 -0
- data/lib/linkparser/sentence.rb +15 -40
- data/rake/dependencies.rb +1 -1
- data/rake/documentation.rb +123 -0
- data/rake/helpers.rb +400 -310
- data/rake/hg.rb +318 -0
- data/rake/manual.rb +84 -79
- data/rake/packaging.rb +33 -37
- data/rake/publishing.rb +166 -146
- data/rake/style.rb +1 -1
- data/rake/svn.rb +577 -549
- data/rake/testing.rb +55 -106
- data/spec/bugfixes_spec.rb +12 -6
- data/spec/linkparser/dictionary_spec.rb +45 -29
- data/spec/linkparser/linkage_spec.rb +90 -94
- data/spec/linkparser/mixins_spec.rb +67 -0
- data/spec/linkparser/parseoptions_spec.rb +19 -22
- data/spec/linkparser/sentence_spec.rb +19 -17
- data/spec/linkparser_spec.rb +11 -5
- metadata +64 -147
- metadata.gz.sig +0 -0
- data/README +0 -61
- data/rake/rdoc.rb +0 -40
- data/rake/win32.rb +0 -186
data/rake/hg.rb
ADDED
@@ -0,0 +1,318 @@
|
|
1
|
+
#
|
2
|
+
# Mercurial Rake Tasks
|
3
|
+
|
4
|
+
require 'enumerator'
|
5
|
+
|
6
|
+
#
|
7
|
+
# Authors:
|
8
|
+
# * Michael Granger <ged@FaerieMUD.org>
|
9
|
+
#
|
10
|
+
|
11
|
+
unless defined?( HG_DOTDIR )
|
12
|
+
|
13
|
+
# Mercurial constants
|
14
|
+
HG_DOTDIR = BASEDIR + '.hg'
|
15
|
+
HG_STORE = HG_DOTDIR + 'store'
|
16
|
+
|
17
|
+
IGNORE_FILE = BASEDIR + '.hgignore'
|
18
|
+
|
19
|
+
|
20
|
+
###
|
21
|
+
### Helpers
|
22
|
+
###
|
23
|
+
|
24
|
+
module MercurialHelpers
|
25
|
+
require './helpers.rb' unless defined?( RakefileHelpers )
|
26
|
+
include RakefileHelpers
|
27
|
+
|
28
|
+
###############
|
29
|
+
module_function
|
30
|
+
###############
|
31
|
+
|
32
|
+
### Generate a commit log from a diff and return it as a String.
|
33
|
+
def make_commit_log
|
34
|
+
diff = read_command_output( 'hg', 'diff' )
|
35
|
+
fail "No differences." if diff.empty?
|
36
|
+
|
37
|
+
return diff
|
38
|
+
end
|
39
|
+
|
40
|
+
### Generate a commit log and invoke the user's editor on it.
|
41
|
+
def edit_commit_log
|
42
|
+
diff = make_commit_log()
|
43
|
+
|
44
|
+
File.open( COMMIT_MSG_FILE, File::WRONLY|File::TRUNC|File::CREAT ) do |fh|
|
45
|
+
fh.print( diff )
|
46
|
+
end
|
47
|
+
|
48
|
+
edit( COMMIT_MSG_FILE )
|
49
|
+
end
|
50
|
+
|
51
|
+
### Generate a changelog.
|
52
|
+
def make_changelog
|
53
|
+
log = read_command_output( 'hg', 'log', '--style', 'compact' )
|
54
|
+
return log
|
55
|
+
end
|
56
|
+
|
57
|
+
### Get the 'tip' info and return it as a Hash
|
58
|
+
def get_tip_info
|
59
|
+
data = read_command_output( 'hg', 'tip' )
|
60
|
+
return YAML.load( data )
|
61
|
+
end
|
62
|
+
|
63
|
+
### Return the ID for the current rev
|
64
|
+
def get_current_rev
|
65
|
+
id = read_command_output( 'hg', '-q', 'identify' )
|
66
|
+
return id.chomp
|
67
|
+
end
|
68
|
+
|
69
|
+
### Read the list of existing tags and return them as an Array
|
70
|
+
def get_tags
|
71
|
+
taglist = read_command_output( 'hg', 'tags' )
|
72
|
+
return taglist.split( /\n/ )
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
### Read any remote repo paths known by the current repo and return them as a hash.
|
77
|
+
def get_repo_paths
|
78
|
+
paths = {}
|
79
|
+
pathspec = read_command_output( 'hg', 'paths' )
|
80
|
+
pathspec.split.each_slice( 3 ) do |name, _, url|
|
81
|
+
paths[ name ] = url
|
82
|
+
end
|
83
|
+
return paths
|
84
|
+
end
|
85
|
+
|
86
|
+
### Return the list of files which are not of status 'clean'
|
87
|
+
def get_uncommitted_files
|
88
|
+
list = read_command_output( 'hg', 'status', '-n', '--color', 'never' )
|
89
|
+
list = list.split( /\n/ )
|
90
|
+
|
91
|
+
trace "Changed files: %p" % [ list ]
|
92
|
+
return list
|
93
|
+
end
|
94
|
+
|
95
|
+
### Return the list of files which are of status 'unknown'
|
96
|
+
def get_unknown_files
|
97
|
+
list = read_command_output( 'hg', 'status', '-un', '--color', 'never' )
|
98
|
+
list = list.split( /\n/ )
|
99
|
+
|
100
|
+
trace "New files: %p" % [ list ]
|
101
|
+
return list
|
102
|
+
end
|
103
|
+
|
104
|
+
### Returns a human-scannable file list by joining and truncating the list if it's too long.
|
105
|
+
def humanize_file_list( list, indent=FILE_INDENT )
|
106
|
+
listtext = list[0..5].join( "\n#{indent}" )
|
107
|
+
if list.length > 5
|
108
|
+
listtext << " (and %d other/s)" % [ list.length - 5 ]
|
109
|
+
end
|
110
|
+
|
111
|
+
return listtext
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
### Add the list of +pathnames+ to the .hgignore list.
|
116
|
+
def hg_ignore_files( *pathnames )
|
117
|
+
patterns = pathnames.flatten.collect do |path|
|
118
|
+
'^' + Regexp.escape(path) + '$'
|
119
|
+
end
|
120
|
+
trace "Ignoring %d files." % [ pathnames.length ]
|
121
|
+
|
122
|
+
IGNORE_FILE.open( File::CREAT|File::WRONLY|File::APPEND, 0644 ) do |fh|
|
123
|
+
fh.puts( patterns )
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
|
128
|
+
### Delete the files in the given +filelist+ after confirming with the user.
|
129
|
+
def delete_extra_files( filelist )
|
130
|
+
description = humanize_file_list( filelist, ' ' )
|
131
|
+
log "Files to delete:\n ", description
|
132
|
+
ask_for_confirmation( "Really delete them?", false ) do
|
133
|
+
filelist.each do |f|
|
134
|
+
rm_rf( f, :verbose => true )
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
end # module MercurialHelpers
|
140
|
+
|
141
|
+
|
142
|
+
### Rakefile support
|
143
|
+
def get_vcs_rev( dir='.' )
|
144
|
+
return MercurialHelpers.get_current_rev
|
145
|
+
end
|
146
|
+
def make_changelog
|
147
|
+
return MercurialHelpers.make_changelog
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
###
|
152
|
+
### Tasks
|
153
|
+
###
|
154
|
+
|
155
|
+
desc "Mercurial tasks"
|
156
|
+
namespace :hg do
|
157
|
+
include MercurialHelpers
|
158
|
+
|
159
|
+
desc "Prepare for a new release"
|
160
|
+
task :prep_release do
|
161
|
+
uncommitted_files = get_uncommitted_files()
|
162
|
+
unless uncommitted_files.empty?
|
163
|
+
log "Uncommitted files:\n",
|
164
|
+
*uncommitted_files.map {|fn| " #{fn}\n" }
|
165
|
+
ask_for_confirmation( "\nRelease anyway?", true ) do
|
166
|
+
log "Okay, releasing with uncommitted versions."
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
tags = get_tags()
|
171
|
+
rev = get_current_rev()
|
172
|
+
pkg_version_tag = "v#{PKG_VERSION}"
|
173
|
+
|
174
|
+
# Look for a tag for the current release version, and if it exists abort
|
175
|
+
if tags.include?( pkg_version_tag )
|
176
|
+
error "Version #{PKG_VERSION} already has a tag. Did you mean " +
|
177
|
+
"to increment the version in #{VERSION_FILE}?"
|
178
|
+
fail
|
179
|
+
end
|
180
|
+
|
181
|
+
# Sign the current rev
|
182
|
+
log "Signing rev #{rev}"
|
183
|
+
run 'hg', 'sign'
|
184
|
+
|
185
|
+
# Tag the current rev
|
186
|
+
log "Tagging rev #{rev} as #{pkg_version_tag}"
|
187
|
+
run 'hg', 'tag', pkg_version_tag
|
188
|
+
|
189
|
+
# Offer to push
|
190
|
+
Rake::Task['hg:push'].invoke
|
191
|
+
end
|
192
|
+
|
193
|
+
desc "Check for new files and offer to add/ignore/delete them."
|
194
|
+
task :newfiles do
|
195
|
+
log "Checking for new files..."
|
196
|
+
|
197
|
+
entries = get_unknown_files()
|
198
|
+
|
199
|
+
unless entries.empty?
|
200
|
+
files_to_add = []
|
201
|
+
files_to_ignore = []
|
202
|
+
files_to_delete = []
|
203
|
+
|
204
|
+
entries.each do |entry|
|
205
|
+
action = prompt_with_default( " #{entry}: (a)dd, (i)gnore, (s)kip (d)elete", 's' )
|
206
|
+
case action
|
207
|
+
when 'a'
|
208
|
+
files_to_add << entry
|
209
|
+
when 'i'
|
210
|
+
files_to_ignore << entry
|
211
|
+
when 'd'
|
212
|
+
files_to_delete << entry
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
unless files_to_add.empty?
|
217
|
+
run 'hg', 'add', *files_to_add
|
218
|
+
end
|
219
|
+
|
220
|
+
unless files_to_ignore.empty?
|
221
|
+
hg_ignore_files( *files_to_ignore )
|
222
|
+
end
|
223
|
+
|
224
|
+
unless files_to_delete.empty?
|
225
|
+
delete_extra_files( files_to_delete )
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
task :add => :newfiles
|
230
|
+
|
231
|
+
|
232
|
+
desc "Pull and update from the default repo"
|
233
|
+
task :pull do
|
234
|
+
paths = get_repo_paths()
|
235
|
+
if origin_url = paths['default']
|
236
|
+
ask_for_confirmation( "Pull and update from '#{origin_url}'?", false ) do
|
237
|
+
Rake::Task['hg:pull_without_confirmation'].invoke
|
238
|
+
end
|
239
|
+
else
|
240
|
+
trace "Skipping pull: No 'default' path."
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
|
245
|
+
desc "Pull and update without confirmation"
|
246
|
+
task :pull_without_confirmation do
|
247
|
+
run 'hg', 'pull', '-u'
|
248
|
+
end
|
249
|
+
|
250
|
+
|
251
|
+
desc "Update to tip"
|
252
|
+
task :update do
|
253
|
+
run 'hg', 'update'
|
254
|
+
end
|
255
|
+
|
256
|
+
|
257
|
+
desc "Clobber all changes (hg up -C)"
|
258
|
+
task :update_and_clobber do
|
259
|
+
run 'hg', 'update', '-C'
|
260
|
+
end
|
261
|
+
|
262
|
+
|
263
|
+
desc "Check the current code in if tests pass"
|
264
|
+
task :checkin => ['hg:pull', 'hg:newfiles', 'test', COMMIT_MSG_FILE] do
|
265
|
+
targets = get_target_args()
|
266
|
+
$stderr.puts '---', File.read( COMMIT_MSG_FILE ), '---'
|
267
|
+
ask_for_confirmation( "Continue with checkin?" ) do
|
268
|
+
run 'hg', 'ci', '-l', COMMIT_MSG_FILE, targets
|
269
|
+
rm_f COMMIT_MSG_FILE
|
270
|
+
end
|
271
|
+
Rake::Task['hg:push'].invoke
|
272
|
+
end
|
273
|
+
task :commit => :checkin
|
274
|
+
task :ci => :checkin
|
275
|
+
|
276
|
+
CLEAN.include( COMMIT_MSG_FILE )
|
277
|
+
|
278
|
+
desc "Push to the default origin repo (if there is one)"
|
279
|
+
task :push do
|
280
|
+
paths = get_repo_paths()
|
281
|
+
if origin_url = paths['default']
|
282
|
+
ask_for_confirmation( "Push to '#{origin_url}'?", false ) do
|
283
|
+
Rake::Task['hg:push_without_confirmation'].invoke
|
284
|
+
end
|
285
|
+
else
|
286
|
+
trace "Skipping push: No 'default' path."
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
desc "Push to the default repo without confirmation"
|
291
|
+
task :push_without_confirmation do
|
292
|
+
run 'hg', 'push'
|
293
|
+
end
|
294
|
+
|
295
|
+
end
|
296
|
+
|
297
|
+
if HG_DOTDIR.exist?
|
298
|
+
trace "Defining mercurial VCS tasks"
|
299
|
+
|
300
|
+
desc "Check in all the changes in your current working copy"
|
301
|
+
task :ci => 'hg:ci'
|
302
|
+
desc "Check in all the changes in your current working copy"
|
303
|
+
task :checkin => 'hg:ci'
|
304
|
+
|
305
|
+
desc "Tag and sign revision before a release"
|
306
|
+
task :prep_release => 'hg:prep_release'
|
307
|
+
|
308
|
+
file COMMIT_MSG_FILE do
|
309
|
+
edit_commit_log()
|
310
|
+
end
|
311
|
+
|
312
|
+
else
|
313
|
+
trace "Not defining mercurial tasks: no #{HG_DOTDIR}"
|
314
|
+
end
|
315
|
+
|
316
|
+
end
|
317
|
+
|
318
|
+
|
data/rake/manual.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# Manual-generation Rake tasks and classes
|
3
|
-
|
3
|
+
|
4
4
|
#
|
5
5
|
# Authors:
|
6
6
|
# * Michael Granger <ged@FaerieMUD.org>
|
@@ -55,7 +55,7 @@ module Manual
|
|
55
55
|
def export_resources( output_dir )
|
56
56
|
# No-op by default
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
|
60
60
|
### Process the +page+'s source with the filter and return the altered content.
|
61
61
|
def process( source, page, metadata )
|
@@ -69,7 +69,7 @@ module Manual
|
|
69
69
|
DEFAULT_CONFIG = {
|
70
70
|
'filters' => [ 'erb', 'links', 'textile' ],
|
71
71
|
'layout' => 'default.page',
|
72
|
-
'cleanup' =>
|
72
|
+
'cleanup' => false,
|
73
73
|
}.freeze
|
74
74
|
|
75
75
|
# Pattern to match a source page with a YAML header
|
@@ -118,28 +118,28 @@ module Manual
|
|
118
118
|
######
|
119
119
|
public
|
120
120
|
######
|
121
|
-
|
121
|
+
|
122
122
|
# The Manual::PageCatalog to which the page belongs
|
123
123
|
attr_reader :catalog
|
124
|
-
|
124
|
+
|
125
125
|
# The relative path to the base directory, for prepending to page paths
|
126
126
|
attr_reader :basepath
|
127
|
-
|
127
|
+
|
128
128
|
# The Pathname object that specifys the page source file
|
129
129
|
attr_reader :sourcefile
|
130
|
-
|
130
|
+
|
131
131
|
# The configured layouts directory as a Pathname object.
|
132
132
|
attr_reader :layouts_dir
|
133
|
-
|
133
|
+
|
134
134
|
# The page configuration, as read from its YAML header
|
135
135
|
attr_reader :config
|
136
|
-
|
136
|
+
|
137
137
|
# The raw source of the page
|
138
138
|
attr_reader :source
|
139
|
-
|
139
|
+
|
140
140
|
# The filters the page will use to render itself
|
141
141
|
attr_reader :filters
|
142
|
-
|
142
|
+
|
143
143
|
|
144
144
|
### Generate HTML output from the page and return it.
|
145
145
|
def generate( metadata )
|
@@ -147,16 +147,21 @@ module Manual
|
|
147
147
|
|
148
148
|
layout = self.config['layout'].sub( /\.page$/, '' )
|
149
149
|
templatepath = @layouts_dir + "#{layout}.page"
|
150
|
-
template =
|
151
|
-
|
150
|
+
template = nil
|
151
|
+
if Object.const_defined?( :Encoding )
|
152
|
+
template = ERB.new( templatepath.read(:encoding => 'UTF-8') )
|
153
|
+
else
|
154
|
+
template = ERB.new( templatepath.read )
|
155
|
+
end
|
152
156
|
|
157
|
+
page = self
|
153
158
|
html = template.result( binding() )
|
154
159
|
|
155
160
|
# Use Tidy to clean up the html if 'cleanup' is turned on, but remove the Tidy
|
156
161
|
# meta-generator propaganda/advertising.
|
157
162
|
html = self.cleanup( html ).sub( %r:<meta name="generator"[^>]*tidy[^>]*/>:im, '' ) if
|
158
163
|
self.config['cleanup']
|
159
|
-
|
164
|
+
|
160
165
|
return html
|
161
166
|
end
|
162
167
|
|
@@ -165,8 +170,8 @@ module Manual
|
|
165
170
|
def title
|
166
171
|
return self.config['title'] || self.sourcefile.basename
|
167
172
|
end
|
168
|
-
|
169
|
-
|
173
|
+
|
174
|
+
|
170
175
|
### Run the various filters on the given input and return the transformed
|
171
176
|
### content.
|
172
177
|
def generate_content( input, metadata )
|
@@ -182,13 +187,13 @@ module Manual
|
|
182
187
|
unless source =~ PAGE_WITH_YAML_HEADER
|
183
188
|
return DEFAULT_CONFIG.dup, source
|
184
189
|
end
|
185
|
-
|
190
|
+
|
186
191
|
pageconfig = YAML.load( $1 )
|
187
192
|
source = $2
|
188
|
-
|
193
|
+
|
189
194
|
return DEFAULT_CONFIG.merge( pageconfig ), source
|
190
195
|
end
|
191
|
-
|
196
|
+
|
192
197
|
|
193
198
|
### Clean up and return the given HTML +source+.
|
194
199
|
def cleanup( source )
|
@@ -208,7 +213,7 @@ module Manual
|
|
208
213
|
trace "No cleanup: " + err.message
|
209
214
|
return source
|
210
215
|
end
|
211
|
-
|
216
|
+
|
212
217
|
|
213
218
|
### Get (singleton) instances of the filters named in +filterlist+ and return them.
|
214
219
|
def load_filters( filterlist )
|
@@ -230,7 +235,7 @@ module Manual
|
|
230
235
|
items << %Q{<div class="section">}
|
231
236
|
items << %Q{<h2><a href="#{self.basepath + path}/">#{title}</a></h2>}
|
232
237
|
items << '<ul class="index-section">'
|
233
|
-
|
238
|
+
|
234
239
|
when :current_section
|
235
240
|
items << %Q{<div class="section current-section">}
|
236
241
|
items << %Q{<h2><a href="#{self.basepath + path}/">#{title}</a></h2>}
|
@@ -267,44 +272,44 @@ module Manual
|
|
267
272
|
def initialize( sourcedir, layoutsdir )
|
268
273
|
@sourcedir = sourcedir
|
269
274
|
@layoutsdir = layoutsdir
|
270
|
-
|
275
|
+
|
271
276
|
@pages = []
|
272
277
|
@path_index = {}
|
273
278
|
@uri_index = {}
|
274
279
|
@title_index = {}
|
275
280
|
@hierarchy = {}
|
276
|
-
|
281
|
+
|
277
282
|
self.find_and_load_pages
|
278
283
|
end
|
279
|
-
|
280
|
-
|
284
|
+
|
285
|
+
|
281
286
|
######
|
282
287
|
public
|
283
288
|
######
|
284
289
|
|
285
290
|
# An index of the pages in the catalog by Pathname
|
286
291
|
attr_reader :path_index
|
287
|
-
|
292
|
+
|
288
293
|
# An index of the pages in the catalog by title
|
289
294
|
attr_reader :title_index
|
290
|
-
|
295
|
+
|
291
296
|
# An index of the pages in the catalog by the URI of their source relative to the source
|
292
297
|
# directory
|
293
298
|
attr_reader :uri_index
|
294
|
-
|
299
|
+
|
295
300
|
# The hierarchy of pages in the catalog, suitable for generating an on-page index
|
296
301
|
attr_reader :hierarchy
|
297
|
-
|
302
|
+
|
298
303
|
# An Array of all Manual::Page objects found
|
299
304
|
attr_reader :pages
|
300
305
|
|
301
306
|
# The Pathname location of the .page files.
|
302
307
|
attr_reader :sourcedir
|
303
|
-
|
308
|
+
|
304
309
|
# The Pathname location of look and feel templates.
|
305
310
|
attr_reader :layoutsdir
|
306
311
|
|
307
|
-
|
312
|
+
|
308
313
|
### Traverse the catalog's #hierarchy, yielding to the given +builder+
|
309
314
|
### block for each entry, as well as each time a sub-hash is entered or
|
310
315
|
### exited, setting the +type+ appropriately. Valid values for +type+ are:
|
@@ -361,7 +366,7 @@ module Manual
|
|
361
366
|
trace "Using the path for the sort of directory %p" % [ subpath ]
|
362
367
|
subpath.to_s
|
363
368
|
end
|
364
|
-
|
369
|
+
|
365
370
|
# Page
|
366
371
|
else
|
367
372
|
if subpath == INDEX_PATH
|
@@ -376,7 +381,7 @@ module Manual
|
|
376
381
|
|
377
382
|
end # sort_by
|
378
383
|
end
|
379
|
-
|
384
|
+
|
380
385
|
|
381
386
|
INDEX_PATH = Pathname.new('index')
|
382
387
|
|
@@ -386,7 +391,7 @@ module Manual
|
|
386
391
|
from_current = false
|
387
392
|
trace "Section handler: path=%p, section keys=%p, from=%s" %
|
388
393
|
[ path, section.keys, from.sourcefile ]
|
389
|
-
|
394
|
+
|
390
395
|
# Call the callback with :section -- determine the section title from
|
391
396
|
# the 'index.page' file underneath it, or the directory name if no
|
392
397
|
# index.page exists.
|
@@ -401,10 +406,10 @@ module Manual
|
|
401
406
|
title = File.dirname( path ).gsub( /_/, ' ' )
|
402
407
|
builder.call( :section, title, path )
|
403
408
|
end
|
404
|
-
|
409
|
+
|
405
410
|
# Recurse
|
406
411
|
self.traverse_hierarchy( path, section, from, &builder )
|
407
|
-
|
412
|
+
|
408
413
|
# Call the callback with :section_end
|
409
414
|
if from_current
|
410
415
|
builder.call( :current_section_end, '', path )
|
@@ -412,8 +417,8 @@ module Manual
|
|
412
417
|
builder.call( :section_end, '', path )
|
413
418
|
end
|
414
419
|
end
|
415
|
-
|
416
|
-
|
420
|
+
|
421
|
+
|
417
422
|
### Yield the specified +page+ to the builder
|
418
423
|
def handle_page_callback( path, page, from=nil )
|
419
424
|
if from == page
|
@@ -422,10 +427,10 @@ module Manual
|
|
422
427
|
yield( :entry, page.title, path )
|
423
428
|
end
|
424
429
|
end
|
425
|
-
|
430
|
+
|
426
431
|
|
427
432
|
### Find and store
|
428
|
-
|
433
|
+
|
429
434
|
### Find all .page files under the configured +sourcedir+ and create a new
|
430
435
|
### Manual::Page object for each one.
|
431
436
|
def find_and_load_pages
|
@@ -439,7 +444,7 @@ module Manual
|
|
439
444
|
@path_index[ pagefile ] = page
|
440
445
|
@title_index[ page.title ] = page
|
441
446
|
@uri_index[ hierpath.to_s ] = page
|
442
|
-
|
447
|
+
|
443
448
|
# Place the page in the page hierarchy by using inject to find and/or create the
|
444
449
|
# necessary subhashes. The last run of inject will return the leaf hash in which
|
445
450
|
# the page will live
|
@@ -451,7 +456,7 @@ module Manual
|
|
451
456
|
section[ pagefile.basename('.page') ] = page
|
452
457
|
end
|
453
458
|
end
|
454
|
-
|
459
|
+
|
455
460
|
end
|
456
461
|
|
457
462
|
|
@@ -463,7 +468,7 @@ module Manual
|
|
463
468
|
require 'redcloth'
|
464
469
|
super
|
465
470
|
end
|
466
|
-
|
471
|
+
|
467
472
|
|
468
473
|
### Process the given +source+ as Textile and return the resulting HTML
|
469
474
|
### fragment.
|
@@ -493,7 +498,7 @@ module Manual
|
|
493
498
|
|
494
499
|
### Manual generation task library
|
495
500
|
class GenTask < Rake::TaskLib
|
496
|
-
|
501
|
+
|
497
502
|
# Default values for task config variables
|
498
503
|
DEFAULT_NAME = :manual
|
499
504
|
DEFAULT_BASE_DIR = Pathname.new( 'docs/manual' )
|
@@ -503,7 +508,7 @@ module Manual
|
|
503
508
|
DEFAULT_RESOURCE_DIR = 'resources'
|
504
509
|
DEFAULT_LIB_DIR = 'lib'
|
505
510
|
DEFAULT_METADATA = OpenStruct.new
|
506
|
-
|
511
|
+
|
507
512
|
|
508
513
|
### Define a new manual-generation task with the given +name+.
|
509
514
|
def initialize( name=:manual )
|
@@ -515,13 +520,13 @@ module Manual
|
|
515
520
|
@resource_dir = DEFAULT_RESOURCE_DIR
|
516
521
|
@lib_dir = DEFAULT_LIB_DIR
|
517
522
|
@metadata = DEFAULT_METADATA
|
518
|
-
|
523
|
+
|
519
524
|
yield( self ) if block_given?
|
520
|
-
|
525
|
+
|
521
526
|
self.define
|
522
527
|
end
|
523
|
-
|
524
|
-
|
528
|
+
|
529
|
+
|
525
530
|
######
|
526
531
|
public
|
527
532
|
######
|
@@ -555,7 +560,7 @@ module Manual
|
|
555
560
|
|
556
561
|
load_filter_libraries( libdir )
|
557
562
|
catalog = Manual::PageCatalog.new( sourcedir, layoutsdir )
|
558
|
-
|
563
|
+
|
559
564
|
# Declare the tasks outside the namespace that point in
|
560
565
|
task @name => "#@name:build"
|
561
566
|
task "clobber_#@name" => "#@name:clobber"
|
@@ -563,20 +568,20 @@ module Manual
|
|
563
568
|
namespace( self.name ) do
|
564
569
|
setup_resource_copy_tasks( resourcedir, outputdir )
|
565
570
|
manual_pages = setup_page_conversion_tasks( sourcedir, outputdir, catalog )
|
566
|
-
|
571
|
+
|
567
572
|
desc "Build the manual"
|
568
|
-
task :build => [ :
|
569
|
-
|
573
|
+
task :build => [ :apidocs, :copy_resources, :copy_apidocs, :generate_pages ]
|
574
|
+
|
570
575
|
task :clobber do
|
571
576
|
RakeFileUtils.verbose( $verbose ) do
|
572
577
|
rm_f manual_pages.to_a
|
573
578
|
end
|
574
579
|
remove_dir( outputdir ) if ( outputdir + '.buildtime' ).exist?
|
575
580
|
end
|
576
|
-
|
581
|
+
|
577
582
|
desc "Remove any previously-generated parts of the manual and rebuild it"
|
578
583
|
task :rebuild => [ :clobber, self.name ]
|
579
|
-
|
584
|
+
|
580
585
|
desc "Watch for changes to the source files and rebuild when they change"
|
581
586
|
task :autobuild do
|
582
587
|
scope = [ self.name ]
|
@@ -598,8 +603,8 @@ module Manual
|
|
598
603
|
end
|
599
604
|
|
600
605
|
end # def define
|
601
|
-
|
602
|
-
|
606
|
+
|
607
|
+
|
603
608
|
### Load the filter libraries provided in the given +libdir+
|
604
609
|
def load_filter_libraries( libdir )
|
605
610
|
Pathname.glob( libdir + '*.rb' ) do |filterlib|
|
@@ -617,7 +622,7 @@ module Manual
|
|
617
622
|
# dependency that causes the rule to be fired for each one when the task is invoked.
|
618
623
|
manual_sources = FileList[ catalog.path_index.keys.map {|pn| pn.to_s} ]
|
619
624
|
trace " found %d source files" % [ manual_sources.length ]
|
620
|
-
|
625
|
+
|
621
626
|
# Map .page files to their equivalent .html output
|
622
627
|
html_pathmap = "%%{%s,%s}X.html" % [ sourcedir, outputdir ]
|
623
628
|
manual_pages = manual_sources.pathmap( html_pathmap )
|
@@ -636,33 +641,33 @@ module Manual
|
|
636
641
|
proc {|name| name.sub(/\.[^.]+$/, '.page').sub( outputdir, sourcedir) },
|
637
642
|
outputdir.to_s
|
638
643
|
]) do |task|
|
639
|
-
|
644
|
+
|
640
645
|
source = Pathname.new( task.source )
|
641
646
|
target = Pathname.new( task.name )
|
642
647
|
log " #{ source } -> #{ target }"
|
643
|
-
|
648
|
+
|
644
649
|
page = catalog.path_index[ source ]
|
645
650
|
#trace " page object is: %p" % [ page ]
|
646
|
-
|
651
|
+
|
647
652
|
target.dirname.mkpath
|
648
653
|
target.open( File::WRONLY|File::CREAT|File::TRUNC ) do |io|
|
649
654
|
io.write( page.generate(metadata) )
|
650
655
|
end
|
651
656
|
end
|
652
|
-
|
657
|
+
|
653
658
|
# Group all the manual page output files targets into a containing task
|
654
659
|
desc "Generate any pages of the manual that have changed"
|
655
660
|
task :generate_pages => manual_pages
|
656
661
|
return manual_pages
|
657
662
|
end
|
658
|
-
|
659
|
-
|
663
|
+
|
664
|
+
|
660
665
|
### Copy method for resources -- passed as a block to the various file tasks that copy
|
661
666
|
### resources to the output directory.
|
662
667
|
def copy_resource( task )
|
663
668
|
source = task.prerequisites[ 1 ]
|
664
669
|
target = task.name
|
665
|
-
|
670
|
+
|
666
671
|
when_writing do
|
667
672
|
trace " #{source} -> #{target}"
|
668
673
|
mkpath File.dirname( target ), :verbose => $trace unless
|
@@ -670,24 +675,24 @@ module Manual
|
|
670
675
|
install source, target, :mode => 0644, :verbose => $trace
|
671
676
|
end
|
672
677
|
end
|
673
|
-
|
674
|
-
|
678
|
+
|
679
|
+
|
675
680
|
### Set up a rule for copying files from the resources directory to the output dir.
|
676
681
|
def setup_resource_copy_tasks( resourcedir, outputdir )
|
677
|
-
resources = FileList[ resourcedir + '**/*.{js,css,png,gif,jpg,html}' ]
|
682
|
+
resources = FileList[ resourcedir + '**/*.{js,css,png,gif,jpg,html,svg,svgz,swf}' ]
|
678
683
|
resources.exclude( /\.svn/ )
|
679
684
|
target_pathmap = "%%{%s,%s}p" % [ resourcedir, outputdir ]
|
680
685
|
targets = resources.pathmap( target_pathmap )
|
681
686
|
copier = self.method( :copy_resource ).to_proc
|
682
|
-
|
687
|
+
|
683
688
|
# Create a file task to copy each file to the output directory
|
684
689
|
resources.each_with_index do |resource, i|
|
685
690
|
file( targets[i] => [ outputdir.to_s, resource ], &copier )
|
686
691
|
end
|
687
692
|
|
688
693
|
desc "Copy API documentation to the manual output directory"
|
689
|
-
task :copy_apidocs => :
|
690
|
-
cp_r(
|
694
|
+
task :copy_apidocs => :apidocs do
|
695
|
+
cp_r( API_DOCSDIR, outputdir )
|
691
696
|
end
|
692
697
|
|
693
698
|
# Now group all the resource file tasks into a containing task
|
@@ -696,9 +701,9 @@ module Manual
|
|
696
701
|
log "Copying manual resources"
|
697
702
|
end
|
698
703
|
end
|
699
|
-
|
704
|
+
|
700
705
|
end # class Manual::GenTask
|
701
|
-
|
706
|
+
|
702
707
|
end
|
703
708
|
|
704
709
|
|
@@ -707,13 +712,13 @@ end
|
|
707
712
|
if MANUALDIR.exist?
|
708
713
|
MANUALOUTPUTDIR = MANUALDIR + 'output'
|
709
714
|
trace "Manual will be generated in: #{MANUALOUTPUTDIR}"
|
710
|
-
|
715
|
+
|
711
716
|
begin
|
712
717
|
directory MANUALOUTPUTDIR.to_s
|
713
718
|
|
714
719
|
Manual::GenTask.new do |manual|
|
715
720
|
manual.metadata.version = PKG_VERSION
|
716
|
-
manual.metadata.api_dir =
|
721
|
+
manual.metadata.api_dir = API_DOCSDIR
|
717
722
|
manual.output_dir = MANUALOUTPUTDIR
|
718
723
|
manual.base_dir = MANUALDIR
|
719
724
|
manual.source_dir = 'src'
|
@@ -740,14 +745,14 @@ else
|
|
740
745
|
log "No manual directory (#{MANUALDIR}) currently exists."
|
741
746
|
ask_for_confirmation( "Create a new manual directory tree from a template?" ) do
|
742
747
|
MANUALDIR.mkpath
|
743
|
-
|
748
|
+
|
744
749
|
%w[layouts lib output resources src].each do |dir|
|
745
750
|
FileUtils.mkpath( MANUALDIR + dir, :mode => 0755, :verbose => true, :noop => $dryrun )
|
746
751
|
end
|
747
|
-
|
752
|
+
|
748
753
|
Pathname.glob( TEMPLATEDIR + '**/*.{rb,css,png,js,erb,page}' ).each do |tmplfile|
|
749
754
|
trace "extname is: #{tmplfile.extname}"
|
750
|
-
|
755
|
+
|
751
756
|
# Render ERB files
|
752
757
|
if tmplfile.extname == '.erb'
|
753
758
|
rname = tmplfile.basename( '.erb' )
|
@@ -762,7 +767,7 @@ else
|
|
762
767
|
target.open( File::WRONLY|File::CREAT|File::EXCL, 0644 ) do |fh|
|
763
768
|
fh.print( html )
|
764
769
|
end
|
765
|
-
|
770
|
+
|
766
771
|
# Just copy anything else
|
767
772
|
else
|
768
773
|
target = MANUALDIR + tmplfile.relative_path_from( TEMPLATEDIR )
|