Commits

Michael Granger committed a319491

Fixes for path translation

  • Participants
  • Parent commits 45bf3dd

Comments (0)

Files changed (2)

File data/strelka-cms/apps/content-manager

 		end
 
 		# Try a literal HTML page
-		htmlpage = self.class.pageroot + "#{path}.html"
+		htmlpage = self.class.pageroot + path.sub_ext( '.html' )
 		if htmlpage.exist?
 			return self.raw_response( request, htmlpage )
 		end
 	### Package up the page at the specified +path+ in the response and return it.
 	def raw_response( request, pagepath )
 		response = request.response
-		response.body = pagepath.read
+		response.body = pagepath.open( 'r', encoding: 'utf-8' )
 		return response
 	end
 

File lib/strelka/cms/page.rb

 require 'nokogiri'
 require 'summarize'
 require 'loggability'
+require 'inversion'
 
 require 'strelka/cms' unless defined?( Strelka::CMS )
 
 		@tags     = options.delete( 'tags' ) || options.delete( 'keywords' )
 		@title    = options.delete( 'title' )
 		@filters  = options.delete( 'filters' )
+		@template = options.delete( 'template' )
 		@options  = options
 		@created  = Time.now
 
 	# the order they will be applied.
 	attr_reader :filters
 
+	# The path to the Inversion template to wrap the page content in
+	attr_reader :template
+
 	# The path to the page (if loaded from a file, nil otherwise)
 	attr_reader :path
 
 	end
 
 
-	### Return the page rendered as HTML after applying filters.
+	### Return the page rendered as HTML after applying filters and wrapping
+	### it in its configured template if it has one.
+	def render( * )
+		if path = self.template
+			tmpl = Inversion::Template.load( path )
+			tmpl.page = self
+			return tmpl
+		else
+			return self.to_s
+		end
+	end
+
+
+	### Render the page content, filtering it with its configured filters. Note
+	### that this does not wrap it in its template.
 	def to_s
 		return self.apply_filters( self.content )
-
-		self.log.debug "  returning %d bytes" % [ content.length ]
-		return content
 	end
 	alias_method :to_html, :to_s