Class: AutomaticUpdateCrossLinks
- Inherits:
-
Object
- Object
- AutomaticUpdateCrossLinks
- Defined in:
- lib/helpers/default-helpers.rb
Instance Method Summary collapse
- #delete_page(page) ⇒ Object
-
#initialize(wiki, view, banned_titles = []) ⇒ AutomaticUpdateCrossLinks
constructor
A new instance of AutomaticUpdateCrossLinks.
- #new_page(page) ⇒ Object
- #page_revised(page) ⇒ Object
- #title_banned?(title) ⇒ Boolean
- #update_all_pages ⇒ Object
Constructor Details
#initialize(wiki, view, banned_titles = []) ⇒ AutomaticUpdateCrossLinks
Returns a new instance of AutomaticUpdateCrossLinks.
6 7 8 9 10 11 12 |
# File 'lib/helpers/default-helpers.rb', line 6 def initialize( wiki, view, banned_titles = [] ) @wiki, @view, @banned_titles = wiki, view, banned_titles @wiki.watch_for( :page_created ) { |event, page| new_page( page ) } @wiki.watch_for( :page_deleted ) { |event, page| delete_page( page ) } @wiki.watch_for( :page_revised ) { |event, page| page_revised( page ) } update_all_pages end |
Instance Method Details
#delete_page(page) ⇒ Object
28 29 30 31 |
# File 'lib/helpers/default-helpers.rb', line 28 def delete_page( page ) @view.rollingmatch.delete( page.name ) page.links_to.each { |linkedpage| @view.refresh_redcloth( linkedpage ) } end |
#new_page(page) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/helpers/default-helpers.rb', line 14 def new_page( page ) return if title_banned? page.name @view.rollingmatch[ page.name ] = page titleregex = Regexp.new( Regexp.escape(page.name), Regexp::IGNORECASE ) # Refresh any page that might mention the title of the new page @wiki.each do |name, linkedpage | next if linkedpage.is_a? UploadPage next unless linkedpage.textile =~ titleregex @view.refresh_redcloth( linkedpage ) # Pages can be inserted into other pages, so need to refresh those as well linkedpage.inserted_into.each { |insert| @view.refresh_redcloth( insert ) } end end |
#page_revised(page) ⇒ Object
33 34 35 |
# File 'lib/helpers/default-helpers.rb', line 33 def page_revised( page ) page.inserted_into.each { |including_page| @view.refresh_redcloth( including_page ) } end |
#title_banned?(title) ⇒ Boolean
48 49 50 |
# File 'lib/helpers/default-helpers.rb', line 48 def title_banned?( title ) @banned_titles.include? title end |
#update_all_pages ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/helpers/default-helpers.rb', line 37 def update_all_pages @wiki.each do |pagename, page| @view.rollingmatch[ page.name ] = page unless title_banned?( page.name ) @view.links.links[ page ] = page.links_from end # Not needed now, because notife d #@wiki.each do |pagename, page| # @view.redcloth( page ) #end end |