pluginfactory 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/rake/manual.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Manual-generation Rake tasks and classes
3
- # $Id: manual.rb 84 2009-02-10 07:38:42Z deveiant $
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' => true,
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 )
@@ -156,7 +156,7 @@ module Manual
156
156
  # meta-generator propaganda/advertising.
157
157
  html = self.cleanup( html ).sub( %r:<meta name="generator"[^>]*tidy[^>]*/>:im, '' ) if
158
158
  self.config['cleanup']
159
-
159
+
160
160
  return html
161
161
  end
162
162
 
@@ -165,8 +165,8 @@ module Manual
165
165
  def title
166
166
  return self.config['title'] || self.sourcefile.basename
167
167
  end
168
-
169
-
168
+
169
+
170
170
  ### Run the various filters on the given input and return the transformed
171
171
  ### content.
172
172
  def generate_content( input, metadata )
@@ -182,13 +182,13 @@ module Manual
182
182
  unless source =~ PAGE_WITH_YAML_HEADER
183
183
  return DEFAULT_CONFIG.dup, source
184
184
  end
185
-
185
+
186
186
  pageconfig = YAML.load( $1 )
187
187
  source = $2
188
-
188
+
189
189
  return DEFAULT_CONFIG.merge( pageconfig ), source
190
190
  end
191
-
191
+
192
192
 
193
193
  ### Clean up and return the given HTML +source+.
194
194
  def cleanup( source )
@@ -208,7 +208,7 @@ module Manual
208
208
  trace "No cleanup: " + err.message
209
209
  return source
210
210
  end
211
-
211
+
212
212
 
213
213
  ### Get (singleton) instances of the filters named in +filterlist+ and return them.
214
214
  def load_filters( filterlist )
@@ -230,7 +230,7 @@ module Manual
230
230
  items << %Q{<div class="section">}
231
231
  items << %Q{<h2><a href="#{self.basepath + path}/">#{title}</a></h2>}
232
232
  items << '<ul class="index-section">'
233
-
233
+
234
234
  when :current_section
235
235
  items << %Q{<div class="section current-section">}
236
236
  items << %Q{<h2><a href="#{self.basepath + path}/">#{title}</a></h2>}
@@ -267,44 +267,44 @@ module Manual
267
267
  def initialize( sourcedir, layoutsdir )
268
268
  @sourcedir = sourcedir
269
269
  @layoutsdir = layoutsdir
270
-
270
+
271
271
  @pages = []
272
272
  @path_index = {}
273
273
  @uri_index = {}
274
274
  @title_index = {}
275
275
  @hierarchy = {}
276
-
276
+
277
277
  self.find_and_load_pages
278
278
  end
279
-
280
-
279
+
280
+
281
281
  ######
282
282
  public
283
283
  ######
284
284
 
285
285
  # An index of the pages in the catalog by Pathname
286
286
  attr_reader :path_index
287
-
287
+
288
288
  # An index of the pages in the catalog by title
289
289
  attr_reader :title_index
290
-
290
+
291
291
  # An index of the pages in the catalog by the URI of their source relative to the source
292
292
  # directory
293
293
  attr_reader :uri_index
294
-
294
+
295
295
  # The hierarchy of pages in the catalog, suitable for generating an on-page index
296
296
  attr_reader :hierarchy
297
-
297
+
298
298
  # An Array of all Manual::Page objects found
299
299
  attr_reader :pages
300
300
 
301
301
  # The Pathname location of the .page files.
302
302
  attr_reader :sourcedir
303
-
303
+
304
304
  # The Pathname location of look and feel templates.
305
305
  attr_reader :layoutsdir
306
306
 
307
-
307
+
308
308
  ### Traverse the catalog's #hierarchy, yielding to the given +builder+
309
309
  ### block for each entry, as well as each time a sub-hash is entered or
310
310
  ### exited, setting the +type+ appropriately. Valid values for +type+ are:
@@ -361,7 +361,7 @@ module Manual
361
361
  trace "Using the path for the sort of directory %p" % [ subpath ]
362
362
  subpath.to_s
363
363
  end
364
-
364
+
365
365
  # Page
366
366
  else
367
367
  if subpath == INDEX_PATH
@@ -376,7 +376,7 @@ module Manual
376
376
 
377
377
  end # sort_by
378
378
  end
379
-
379
+
380
380
 
381
381
  INDEX_PATH = Pathname.new('index')
382
382
 
@@ -386,7 +386,7 @@ module Manual
386
386
  from_current = false
387
387
  trace "Section handler: path=%p, section keys=%p, from=%s" %
388
388
  [ path, section.keys, from.sourcefile ]
389
-
389
+
390
390
  # Call the callback with :section -- determine the section title from
391
391
  # the 'index.page' file underneath it, or the directory name if no
392
392
  # index.page exists.
@@ -401,10 +401,10 @@ module Manual
401
401
  title = File.dirname( path ).gsub( /_/, ' ' )
402
402
  builder.call( :section, title, path )
403
403
  end
404
-
404
+
405
405
  # Recurse
406
406
  self.traverse_hierarchy( path, section, from, &builder )
407
-
407
+
408
408
  # Call the callback with :section_end
409
409
  if from_current
410
410
  builder.call( :current_section_end, '', path )
@@ -412,8 +412,8 @@ module Manual
412
412
  builder.call( :section_end, '', path )
413
413
  end
414
414
  end
415
-
416
-
415
+
416
+
417
417
  ### Yield the specified +page+ to the builder
418
418
  def handle_page_callback( path, page, from=nil )
419
419
  if from == page
@@ -422,10 +422,10 @@ module Manual
422
422
  yield( :entry, page.title, path )
423
423
  end
424
424
  end
425
-
425
+
426
426
 
427
427
  ### Find and store
428
-
428
+
429
429
  ### Find all .page files under the configured +sourcedir+ and create a new
430
430
  ### Manual::Page object for each one.
431
431
  def find_and_load_pages
@@ -439,7 +439,7 @@ module Manual
439
439
  @path_index[ pagefile ] = page
440
440
  @title_index[ page.title ] = page
441
441
  @uri_index[ hierpath.to_s ] = page
442
-
442
+
443
443
  # Place the page in the page hierarchy by using inject to find and/or create the
444
444
  # necessary subhashes. The last run of inject will return the leaf hash in which
445
445
  # the page will live
@@ -451,7 +451,7 @@ module Manual
451
451
  section[ pagefile.basename('.page') ] = page
452
452
  end
453
453
  end
454
-
454
+
455
455
  end
456
456
 
457
457
 
@@ -463,7 +463,7 @@ module Manual
463
463
  require 'redcloth'
464
464
  super
465
465
  end
466
-
466
+
467
467
 
468
468
  ### Process the given +source+ as Textile and return the resulting HTML
469
469
  ### fragment.
@@ -493,7 +493,7 @@ module Manual
493
493
 
494
494
  ### Manual generation task library
495
495
  class GenTask < Rake::TaskLib
496
-
496
+
497
497
  # Default values for task config variables
498
498
  DEFAULT_NAME = :manual
499
499
  DEFAULT_BASE_DIR = Pathname.new( 'docs/manual' )
@@ -503,7 +503,7 @@ module Manual
503
503
  DEFAULT_RESOURCE_DIR = 'resources'
504
504
  DEFAULT_LIB_DIR = 'lib'
505
505
  DEFAULT_METADATA = OpenStruct.new
506
-
506
+
507
507
 
508
508
  ### Define a new manual-generation task with the given +name+.
509
509
  def initialize( name=:manual )
@@ -515,13 +515,13 @@ module Manual
515
515
  @resource_dir = DEFAULT_RESOURCE_DIR
516
516
  @lib_dir = DEFAULT_LIB_DIR
517
517
  @metadata = DEFAULT_METADATA
518
-
518
+
519
519
  yield( self ) if block_given?
520
-
520
+
521
521
  self.define
522
522
  end
523
-
524
-
523
+
524
+
525
525
  ######
526
526
  public
527
527
  ######
@@ -555,7 +555,7 @@ module Manual
555
555
 
556
556
  load_filter_libraries( libdir )
557
557
  catalog = Manual::PageCatalog.new( sourcedir, layoutsdir )
558
-
558
+
559
559
  # Declare the tasks outside the namespace that point in
560
560
  task @name => "#@name:build"
561
561
  task "clobber_#@name" => "#@name:clobber"
@@ -563,20 +563,20 @@ module Manual
563
563
  namespace( self.name ) do
564
564
  setup_resource_copy_tasks( resourcedir, outputdir )
565
565
  manual_pages = setup_page_conversion_tasks( sourcedir, outputdir, catalog )
566
-
566
+
567
567
  desc "Build the manual"
568
568
  task :build => [ :rdoc, :copy_resources, :copy_apidocs, :generate_pages ]
569
-
569
+
570
570
  task :clobber do
571
571
  RakeFileUtils.verbose( $verbose ) do
572
572
  rm_f manual_pages.to_a
573
573
  end
574
574
  remove_dir( outputdir ) if ( outputdir + '.buildtime' ).exist?
575
575
  end
576
-
576
+
577
577
  desc "Remove any previously-generated parts of the manual and rebuild it"
578
578
  task :rebuild => [ :clobber, self.name ]
579
-
579
+
580
580
  desc "Watch for changes to the source files and rebuild when they change"
581
581
  task :autobuild do
582
582
  scope = [ self.name ]
@@ -598,8 +598,8 @@ module Manual
598
598
  end
599
599
 
600
600
  end # def define
601
-
602
-
601
+
602
+
603
603
  ### Load the filter libraries provided in the given +libdir+
604
604
  def load_filter_libraries( libdir )
605
605
  Pathname.glob( libdir + '*.rb' ) do |filterlib|
@@ -617,7 +617,7 @@ module Manual
617
617
  # dependency that causes the rule to be fired for each one when the task is invoked.
618
618
  manual_sources = FileList[ catalog.path_index.keys.map {|pn| pn.to_s} ]
619
619
  trace " found %d source files" % [ manual_sources.length ]
620
-
620
+
621
621
  # Map .page files to their equivalent .html output
622
622
  html_pathmap = "%%{%s,%s}X.html" % [ sourcedir, outputdir ]
623
623
  manual_pages = manual_sources.pathmap( html_pathmap )
@@ -636,33 +636,33 @@ module Manual
636
636
  proc {|name| name.sub(/\.[^.]+$/, '.page').sub( outputdir, sourcedir) },
637
637
  outputdir.to_s
638
638
  ]) do |task|
639
-
639
+
640
640
  source = Pathname.new( task.source )
641
641
  target = Pathname.new( task.name )
642
642
  log " #{ source } -> #{ target }"
643
-
643
+
644
644
  page = catalog.path_index[ source ]
645
645
  #trace " page object is: %p" % [ page ]
646
-
646
+
647
647
  target.dirname.mkpath
648
648
  target.open( File::WRONLY|File::CREAT|File::TRUNC ) do |io|
649
649
  io.write( page.generate(metadata) )
650
650
  end
651
651
  end
652
-
652
+
653
653
  # Group all the manual page output files targets into a containing task
654
654
  desc "Generate any pages of the manual that have changed"
655
655
  task :generate_pages => manual_pages
656
656
  return manual_pages
657
657
  end
658
-
659
-
658
+
659
+
660
660
  ### Copy method for resources -- passed as a block to the various file tasks that copy
661
661
  ### resources to the output directory.
662
662
  def copy_resource( task )
663
663
  source = task.prerequisites[ 1 ]
664
664
  target = task.name
665
-
665
+
666
666
  when_writing do
667
667
  trace " #{source} -> #{target}"
668
668
  mkpath File.dirname( target ), :verbose => $trace unless
@@ -670,16 +670,16 @@ module Manual
670
670
  install source, target, :mode => 0644, :verbose => $trace
671
671
  end
672
672
  end
673
-
674
-
673
+
674
+
675
675
  ### Set up a rule for copying files from the resources directory to the output dir.
676
676
  def setup_resource_copy_tasks( resourcedir, outputdir )
677
- resources = FileList[ resourcedir + '**/*.{js,css,png,gif,jpg,html}' ]
677
+ resources = FileList[ resourcedir + '**/*.{js,css,png,gif,jpg,html,svg,svgz,swf}' ]
678
678
  resources.exclude( /\.svn/ )
679
679
  target_pathmap = "%%{%s,%s}p" % [ resourcedir, outputdir ]
680
680
  targets = resources.pathmap( target_pathmap )
681
681
  copier = self.method( :copy_resource ).to_proc
682
-
682
+
683
683
  # Create a file task to copy each file to the output directory
684
684
  resources.each_with_index do |resource, i|
685
685
  file( targets[i] => [ outputdir.to_s, resource ], &copier )
@@ -696,9 +696,9 @@ module Manual
696
696
  log "Copying manual resources"
697
697
  end
698
698
  end
699
-
699
+
700
700
  end # class Manual::GenTask
701
-
701
+
702
702
  end
703
703
 
704
704
 
@@ -707,7 +707,7 @@ end
707
707
  if MANUALDIR.exist?
708
708
  MANUALOUTPUTDIR = MANUALDIR + 'output'
709
709
  trace "Manual will be generated in: #{MANUALOUTPUTDIR}"
710
-
710
+
711
711
  begin
712
712
  directory MANUALOUTPUTDIR.to_s
713
713
 
@@ -719,9 +719,7 @@ if MANUALDIR.exist?
719
719
  manual.source_dir = 'src'
720
720
  end
721
721
 
722
- task :clobber_manual do
723
- rmtree( MANUALOUTPUTDIR, :verbose => true )
724
- end
722
+ CLOBBER.include( MANUALOUTPUTDIR.to_s )
725
723
 
726
724
  rescue LoadError => err
727
725
  task :no_manual do
@@ -742,14 +740,14 @@ else
742
740
  log "No manual directory (#{MANUALDIR}) currently exists."
743
741
  ask_for_confirmation( "Create a new manual directory tree from a template?" ) do
744
742
  MANUALDIR.mkpath
745
-
743
+
746
744
  %w[layouts lib output resources src].each do |dir|
747
745
  FileUtils.mkpath( MANUALDIR + dir, :mode => 0755, :verbose => true, :noop => $dryrun )
748
746
  end
749
-
747
+
750
748
  Pathname.glob( TEMPLATEDIR + '**/*.{rb,css,png,js,erb,page}' ).each do |tmplfile|
751
749
  trace "extname is: #{tmplfile.extname}"
752
-
750
+
753
751
  # Render ERB files
754
752
  if tmplfile.extname == '.erb'
755
753
  rname = tmplfile.basename( '.erb' )
@@ -764,7 +762,7 @@ else
764
762
  target.open( File::WRONLY|File::CREAT|File::EXCL, 0644 ) do |fh|
765
763
  fh.print( html )
766
764
  end
767
-
765
+
768
766
  # Just copy anything else
769
767
  else
770
768
  target = MANUALDIR + tmplfile.relative_path_from( TEMPLATEDIR )