Module: PageNameToUrlNameConversion

Included in:
View
Defined in:
lib/soks-view.rb

Instance Method Summary collapse

Instance Method Details

#add_url_name_for_page_name(page_name) ⇒ Object



277
278
279
280
281
282
# File 'lib/soks-view.rb', line 277

def add_url_name_for_page_name( page_name )
	url_name = create_url_name( page_name )
	@pages_to_urls[ page_name.downcase ] = url_name
	@urls_to_pages[ url_name.downcase ] = page_name
	url_name 
end

#change_caps_for(page_name) ⇒ Object



284
285
286
287
# File 'lib/soks-view.rb', line 284

def change_caps_for( page_name )
	url_name = @pages_to_urls[ page_name.downcase ].downcase
	@urls_to_pages[ url_name  ] = page_name
end

#create_url_name(page_name) ⇒ Object

Turns text into a WikiWord by changing the capitalization and then dumping the punctuation



290
291
292
293
294
295
# File 'lib/soks-view.rb', line 290

def create_url_name( page_name )
	url_name = page_name.capitalize.gsub(/(\W+(\w))/) { |m| $1.upcase }.gsub(/\W+/,'')
	url_name = "PunctuationOnlyInTitle" if url_name == ""
	url_name = increment_url_name( url_name ) while @urls_to_pages.has_key? url_name.downcase
	url_name
end

#increment_url_name(url_name) ⇒ Object



297
298
299
300
301
302
303
# File 'lib/soks-view.rb', line 297

def increment_url_name( url_name )
	if url_name =~ /(\w+)-(\d+)/
		"#{$1}-#{$2.to_i.succ}"
	else
		url_name+"-2"
	end 
end

#page_name_for_url_name(url_name) ⇒ Object



273
274
275
# File 'lib/soks-view.rb', line 273

def page_name_for_url_name( url_name )
	@urls_to_pages[ url_name.downcase ] || url_name 
end

#setup_page_name_to_url_name_conversionObject



261
262
263
264
265
266
# File 'lib/soks-view.rb', line 261

def setup_page_name_to_url_name_conversion
	@urls_to_pages, @pages_to_urls = {}, {}
	@wiki.each { |name,page| url_name_for_page_name( page.name ) }
	@wiki.watch_attentively_for(:page_created) {|event,page,revision| url_name_for_page_name( page.name )}
	@wiki.watch_attentively_for(:page_title_recapitalized) {|event,page| change_caps_for( page.name )}
end

#url_name_for_page_name(page_name) ⇒ Object

To allow punctuation in page titles and not mess up urls



269
270
271
# File 'lib/soks-view.rb', line 269

def url_name_for_page_name( page_name )
	@pages_to_urls[ page_name.downcase ] || add_url_name_for_page_name( page_name )
end