class Strelka::CMS::Publisher
Constants
Attributes
catalog[R]
The Strelka::CMS::PageCatalog
for the page root.
Public Class Methods
configure( config=nil )
click to toggle source
Configurability API – configure the CMS class once the config is loaded.
# File lib/strelka/cms/publisher.rb, line 67 def self::configure( config=nil ) if config && config.member?( :pageroot ) self.log.debug "Config is: %p" % [ config ] self.pageroot = Pathname( config.pageroot ) else self.pageroot = DEFAULT_CONFIG[:pageroot] end end
new( * )
click to toggle source
Create a new instance of the CMS handler application.
Calls superclass method
# File lib/strelka/cms/publisher.rb, line 78 def initialize( * ) super @catalog = Strelka::CMS::PageCatalog.new( self.class.pageroot ) end
Public Instance Methods
get_html_path( path )
click to toggle source
Look for a static .html file in the catalog and return a Pathname for it if one exists.
# File lib/strelka/cms/publisher.rb, line 145 def get_html_path( path ) path = self.class.pageroot + path.sub_ext( '.html' ) return path if path.exist? return nil end
get_page_for( path )
click to toggle source
Find a page that corresponds to the specified path
(a Pathname). Returns nil
if no matching page was found.
# File lib/strelka/cms/publisher.rb, line 154 def get_page_for( path ) self.log.debug "Page path is: %p" % [ path ] if path.to_s.empty? subcat = @catalog.matching_pattern( 'index.page' ) return subcat.first else subcat = @catalog.relative_to( path.dirname ). matching_pattern( "#{path.basename(path.extname)}{.page,/index.page}" ) return subcat.first end end
get_page_path( request )
click to toggle source
Return the page requested by the specified request
as a Pathname relative to the application path.
# File lib/strelka/cms/publisher.rb, line 132 def get_page_path( request ) unless path = request.app_path[ PAGE_PATH_PATTERN, :path ] self.log.error "Invalid app_path: %p" % [ request.app_path ] finish_with HTTP::NOT_FOUND end # Force the path to be relative and clean it up return Pathname( path.gsub(%r{\A\.?/+|/(?=/)|/+\z}, '') ) end
make_page_response( page )
click to toggle source
Package up the specified page
in the page template and return it.
# File lib/strelka/cms/publisher.rb, line 168 def make_page_response( page ) tmpl = self.template( :page ) tmpl.page = page return tmpl end
make_raw_response( request, pagepath )
click to toggle source
Package up the page at the specified path
in the response and return it.
# File lib/strelka/cms/publisher.rb, line 176 def make_raw_response( request, pagepath ) response = request.response response.body = pagepath.open( 'r', encoding: 'utf-8' ) return response end
pageroot()
click to toggle source
The configured catalog root
# File lib/strelka/cms/publisher.rb, line 49 singleton_attr_accessor :pageroot
text/html()
click to toggle source
The default content-type
# File lib/strelka/cms/publisher.rb, line 53 default_type 'text/html'