Class: Strelka::CMS::Publisher
- Inherits:
-
App
- Object
- App
- Strelka::CMS::Publisher
- Extended by:
- Configurability, Loggability, MethodUtilities
- Defined in:
- lib/strelka/cms/publisher.rb
Constant Summary collapse
- ID =
Strelka App ID
'content-manager'
- DEFAULT_CONFIG =
The default directory to scan for pages
{ pageroot: Pathname( __FILE__ ).dirname.parent.parent.parent + 'public' }
- PAGE_PATH_PATTERN =
Pattern for untainting the page path
%r{ \A (?<path>(?: [\w\-/] # Allow word characters, slashes, and hyphens | \.(?!\.) # or periods not followed by another period )*) (?:\.(?<suffix>html|page))? # optional suffix \z }x
Instance Attribute Summary collapse
-
#catalog ⇒ Object
readonly
The Strelka::CMS::PageCatalog for the page root.
Class Method Summary collapse
-
.configure(config = nil) ⇒ Object
Configurability API – configure the CMS class once the config is loaded.
Instance Method Summary collapse
-
#get_html_path(path) ⇒ Object
Look for a static .html file in the catalog and return a Pathname for it if one exists.
-
#get_page_for(path) ⇒ Object
Find a page that corresponds to the specified
path
(a Pathname). -
#get_page_path(request) ⇒ Object
Return the page requested by the specified
request
as a Pathname relative to the application path. -
#initialize ⇒ Publisher
constructor
Create a new instance of the CMS handler application.
-
#make_page_response(page) ⇒ Object
Package up the specified
page
in the page template and return it. -
#make_raw_response(request, pagepath) ⇒ Object
Package up the page at the specified
path
in the response and return it. -
#pageroot ⇒ Object
The configured catalog root.
Constructor Details
#initialize ⇒ Publisher
Create a new instance of the CMS handler application.
78 79 80 81 |
# File 'lib/strelka/cms/publisher.rb', line 78 def initialize( * ) super @catalog = Strelka::CMS::PageCatalog.new( self.class.pageroot ) end |
Instance Attribute Details
#catalog ⇒ Object (readonly)
The Strelka::CMS::PageCatalog for the page root.
86 87 88 |
# File 'lib/strelka/cms/publisher.rb', line 86 def catalog @catalog end |
Class Method Details
.configure(config = nil) ⇒ Object
Configurability API – configure the CMS class once the config is loaded.
67 68 69 70 71 72 73 74 |
# 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 |
Instance Method Details
#get_html_path(path) ⇒ Object
Look for a static .html file in the catalog and return a Pathname for it if one exists.
145 146 147 148 149 |
# 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) ⇒ Object
Find a page that corresponds to the specified path
(a Pathname). Returns nil
if no matching page was found.
154 155 156 157 158 159 160 161 162 163 164 |
# 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) ⇒ Object
Return the page requested by the specified request
as a Pathname relative to the application path.
132 133 134 135 136 137 138 139 140 |
# 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) ⇒ Object
Package up the specified page
in the page template and return it.
168 169 170 171 172 |
# 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) ⇒ Object
Package up the page at the specified path
in the response and return it.
176 177 178 179 180 |
# 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 ⇒ Object
The configured catalog root
49 |
# File 'lib/strelka/cms/publisher.rb', line 49 singleton_attr_accessor :pageroot |