Class: View
Constant Summary
collapse
- REDCLOTH_CACHE_NAME =
'redcloth'
Instance Attribute Summary collapse
Attributes included from ErbHelper
#author_to_email_conversion, #description, #name
Instance Method Summary
collapse
-
#clear_redcloth_cache(page = :all_pages) ⇒ Object
-
#erb_filename(klass, view) ⇒ Object
-
#frame_erb ⇒ Object
-
#html(klass, view, _binding) ⇒ Object
-
#initialize(wiki, root_url, view_folder) ⇒ View
constructor
-
#load_frame_erb ⇒ Object
-
#method_missing(method, *args, &block) ⇒ Object
-
#path_for(klass, view) ⇒ Object
-
#redcloth(page) ⇒ Object
-
#refresh_redcloth(page) ⇒ Object
-
#render(pagename, view = 'view', person = 'Anon.', query = {}) ⇒ Object
-
#should_frame?(view) ⇒ Boolean
#add_url_name_for_page_name, #change_caps_for, #create_url_name, #increment_url_name, #page_name_for_url_name, #setup_page_name_to_url_name_conversion, #url_name_for_page_name
Methods included from ErbHelper
#file, #file2, #url
Constructor Details
#initialize(wiki, root_url, view_folder) ⇒ View
319
320
321
322
323
324
325
326
327
328
329
330
|
# File 'lib/soks-view.rb', line 319
def initialize( wiki, root_url, view_folder )
@wiki, @root_url, @view_folder = wiki, root_url, view_folder
@rollingmatch, @links = BruteMatch.new, Links.new
@redcloth_cache = wiki.load_cache(REDCLOTH_CACHE_NAME) || Hash.new
@erb_cache = Hash.new
@reload_erb_each_request = false
@dont_frame_views = []
@redcloth_hard_breaks = false
setup_page_name_to_url_name_conversion
wiki.watch_attentively_for( :page_revised ) { |event,page,revision| refresh_redcloth( page ) }
wiki.watch_for(:shutdown) { wiki.save_cache(REDCLOTH_CACHE_NAME,@redcloth_cache) }
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
395
396
397
398
|
# File 'lib/soks-view.rb', line 395
def method_missing( method, *args, &block )
@wiki.send( method, *args, &block )
end
|
Instance Attribute Details
#dont_frame_views ⇒ Object
Returns the value of attribute dont_frame_views.
316
317
318
|
# File 'lib/soks-view.rb', line 316
def dont_frame_views
@dont_frame_views
end
|
#links ⇒ Object
Returns the value of attribute links.
312
313
314
|
# File 'lib/soks-view.rb', line 312
def links
@links
end
|
#redcloth_hard_breaks ⇒ Object
Returns the value of attribute redcloth_hard_breaks.
317
318
319
|
# File 'lib/soks-view.rb', line 317
def redcloth_hard_breaks
@redcloth_hard_breaks
end
|
#reload_erb_each_request ⇒ Object
Returns the value of attribute reload_erb_each_request.
315
316
317
|
# File 'lib/soks-view.rb', line 315
def reload_erb_each_request
@reload_erb_each_request
end
|
#rollingmatch ⇒ Object
Returns the value of attribute rollingmatch.
312
313
314
|
# File 'lib/soks-view.rb', line 312
def rollingmatch
@rollingmatch
end
|
#root_url ⇒ Object
Returns the value of attribute root_url.
314
315
316
|
# File 'lib/soks-view.rb', line 314
def root_url
@root_url
end
|
#view_folder ⇒ Object
Returns the value of attribute view_folder.
313
314
315
|
# File 'lib/soks-view.rb', line 313
def view_folder
@view_folder
end
|
Instance Method Details
#clear_redcloth_cache(page = :all_pages) ⇒ Object
354
355
356
|
# File 'lib/soks-view.rb', line 354
def clear_redcloth_cache( page = :all_pages )
( page == :all_pages ) ? @redcloth_cache.clear : @redcloth_cache.delete( page )
end
|
#erb_filename(klass, view) ⇒ Object
363
364
365
366
367
368
369
370
371
372
373
374
|
# File 'lib/soks-view.rb', line 363
def erb_filename( klass, view )
$LOG.info "Looking for #{path_for( klass, view)}"
until File.exists?( path_for( klass, view ) )
if klass.superclass
klass = klass.superclass
else
$LOG.warn "Not found #{path_for( klass, view)}"
raise WEBrick::HTTPStatus::NotFound
end
end
path_for( klass, view )
end
|
#frame_erb ⇒ Object
382
383
384
385
|
# File 'lib/soks-view.rb', line 382
def frame_erb
@frame_erb = nil if reload_erb_each_request
@frame_erb ||= load_frame_erb
end
|
#html(klass, view, _binding) ⇒ Object
358
359
360
361
|
# File 'lib/soks-view.rb', line 358
def html( klass, view, _binding )
@erb_cache.clear if reload_erb_each_request
( @erb_cache[ path_for( klass, view ) ] ||= ERB.new( IO.readlines( erb_filename( klass, view ) ).join ) ).result( _binding )
end
|
#load_frame_erb ⇒ Object
387
388
389
390
391
392
393
|
# File 'lib/soks-view.rb', line 387
def load_frame_erb
if File.exists? "#{view_folder}/frame.rhtml"
ERB.new( IO.readlines( "#{view_folder}/frame.rhtml" ).join )
else
ERB.new( "<%= content_of_page %>" )
end
end
|
#path_for(klass, view) ⇒ Object
376
|
# File 'lib/soks-view.rb', line 376
def path_for( klass, view ) "#{view_folder}/#{klass}_#{view.downcase}.rhtml" end
|
#redcloth(page) ⇒ Object
349
350
351
352
|
# File 'lib/soks-view.rb', line 349
def redcloth( page )
textile = page.textile(self)
@redcloth_cache[ page.name ] || refresh_redcloth( page )
end
|
#refresh_redcloth(page) ⇒ Object
344
345
346
347
|
# File 'lib/soks-view.rb', line 344
def refresh_redcloth( page )
$LOG.info "Refreshing #{page}"
@redcloth_cache[ page.name ] = WikiRedCloth.new( self, page, page.textile(self), redcloth_hard_breaks).to_html
end
|
#render(pagename, view = 'view', person = 'Anon.', query = {}) ⇒ Object
332
333
334
335
336
337
338
339
340
341
342
|
# File 'lib/soks-view.rb', line 332
def render( pagename, view = 'view', person = 'Anon.', query = {} )
page = @wiki.page( pagename )
renderedview = redcloth( page )
content_of_page = html( page.class, view, binding )
@wiki.notify(:page_viewed, page, view, person)
if should_frame? view
return frame_erb.result(binding)
else
return content_of_page
end
end
|
#should_frame?(view) ⇒ Boolean
378
379
380
|
# File 'lib/soks-view.rb', line 378
def should_frame?( view )
not( dont_frame_views.include? view.downcase )
end
|