Class: AutomaticAuthorIndex

Inherits:
Object
  • Object
show all
Defined in:
lib/helpers/default-helpers.rb

Instance Method Summary collapse

Constructor Details

#initialize(wiki, create_author_pages = true, author_include_regexp = /.*/, author_exclude_regexp = /^Automatic.*/, pagename = "authors", author = "AutomaticAuthorIndexer", author_page_tail = "s pages") ⇒ AutomaticAuthorIndex

Returns a new instance of AutomaticAuthorIndex.



362
363
364
365
366
367
368
369
# File 'lib/helpers/default-helpers.rb', line 362

def initialize( wiki, create_author_pages = true, author_include_regexp = /.*/, author_exclude_regexp = /^Automatic.*/, pagename = "authors", author = "AutomaticAuthorIndexer", author_page_tail = "s pages" )
	@wiki, @create_author_pages, @author_include_regexp, @author_exclude_regexp, @pagename, @author, @author_page_tail = wiki, create_author_pages, author_include_regexp, author_exclude_regexp, pagename, author, author_page_tail
	@authors = []
	find_all_authors( wiki )
	@wiki.watch_for( :page_revised ) { |event, page, revision| 
		$stderr.puts "Got a page revised message in AutomaticAuthorIndex"
		add_author( revision ) }
end

Instance Method Details

#add_author(revision) ⇒ Object



371
372
373
374
375
376
377
378
379
# File 'lib/helpers/default-helpers.rb', line 371

def add_author( revision )
	return if @authors.include? revision.author
	return unless revision.author =~ @author_include_regexp
	return unless revision.author !~ @author_exclude_regexp
	@authors << revision.author
	@authors.sort!
	create_author_page_for(revision.author) if @create_author_pages
	render_author_index
end

#create_author_page_for(author) ⇒ Object



402
403
404
405
406
407
408
409
410
411
412
413
# File 'lib/helpers/default-helpers.rb', line 402

def create_author_page_for( author ) 
AutomaticSummary.new( @wiki, {   :pagename => "#{author}#{@author_page_tail}" ,
								:regexp_for_author => /#{author}/,
								:author => @author,
								:only_new_pages => false,
								:sort_pages_by => :revised_on,
								:include_metadata => true,
								:summarise_revisions => true,
								:reverse_sort => true,
								:remove_deleted_pages => false,
							 } )		
end

#find_all_authors(wiki) ⇒ Object



381
382
383
384
385
386
387
# File 'lib/helpers/default-helpers.rb', line 381

def find_all_authors( wiki )
	wiki.each do |name, page|
		page.revisions.each do |revision|
			add_author( revision )
		end
	end
end

#render_author_indexObject



389
390
391
392
393
394
395
396
397
398
399
# File 'lib/helpers/default-helpers.rb', line 389

def render_author_index
	content = "h1. Index of Authors\n\n"
	@authors.each do |author|
		content << "* #{author}"
		if @create_author_pages
			content << " #{author}#{@author_page_tail}"
		end
		content << "\n"
	end
	@wiki.revise( @pagename, content, @author )
end