introduce the last_modified_at attribute of a site + set the response type of a request based on the page
did
committed Sep 24, 2015
commit 6a77241773c1ea56fdbb645f08eca14162e21cd7
Showing 6
changed files with
37 additions
and 7 deletions
locomotive/steam/entities/page.rb b/lib/locomotive/steam/entities/page.rb
+2
-0
| @@ | @@ -12,7 +12,9 @@ module Locomotive::Steam |
| listed: false, | |
| published: true, | |
| templatized: false, | |
| + | cache_enabled: true, |
| fullpath: {}, | |
| + | response_type: nil, |
| content_type: nil, | |
| target_klass_name: nil, | |
| position: 99, | |
locomotive/steam/entities/site.rb b/lib/locomotive/steam/entities/site.rb
+9
-3
| @@ | @@ -6,9 +6,11 @@ module Locomotive::Steam |
| def initialize(attributes = {}) | |
| super({ | |
| - | prefix_default_locale: false, |
| - | updated_at: nil, |
| - | template_version: nil |
| + | cache_enabled: false, |
| + | prefix_default_locale: false, |
| + | updated_at: nil, |
| + | content_version: nil, |
| + | template_version: nil |
| }.merge(attributes)) | |
| end | |
| @@ | @@ -32,6 +34,10 @@ module Locomotive::Steam |
| @timezone ||= ActiveSupport::TimeZone.new(timezone_name) | |
| end | |
| + | def last_modified_at |
| + | [self.content_version, self.template_version].compact.sort.last || self.updated_at |
| + | end |
| + | |
| def to_liquid | |
| Locomotive::Steam::Liquid::Drops::Site.new(self) | |
| end | |
locomotive/steam/middlewares/helpers.rb b/lib/locomotive/steam/middlewares/helpers.rb
+2
-2
| @@ | @@ -13,8 +13,8 @@ module Locomotive::Steam |
| self.request.content_type == 'application/json' || File.extname(self.request.path) == '.json' | |
| end | |
| - | def render_response(content, code = 200, type = 'text/html') |
| - | @next_response = [code, { 'Content-Type' => type }, [content]] |
| + | def render_response(content, code = 200, type = nil) |
| + | @next_response = [code, { 'Content-Type' => type || 'text/html' }, [content]] |
| end | |
| def redirect_to(location, type = 301) | |
locomotive/steam/middlewares/path.rb b/lib/locomotive/steam/middlewares/path.rb
+1
-1
| @@ | @@ -16,7 +16,7 @@ module Locomotive::Steam |
| protected | |
| def set_path!(env) | |
| - | path = env['steam.path'] || request.path_info |
| + | path = (env['steam.path'] || request.path_info).dup |
| path.gsub!(/\.[a-zA-Z][a-zA-Z0-9]{2,}$/, '') | |
| path.gsub!(/^\//, '') | |
locomotive/steam/middlewares/renderer.rb b/lib/locomotive/steam/middlewares/renderer.rb
+1
-1
| @@ | @@ -20,7 +20,7 @@ module Locomotive::Steam |
| redirect_to(page.redirect_url, page.redirect_type) | |
| else | |
| content = parse_and_render_liquid | |
| - | render_response(content, page.not_found? ? 404: 200) |
| + | render_response(content, page.not_found? ? 404: 200, page.response_type) |
| end | |
| end | |
spec/unit/entities/site_spec.rb
+22
-0
| @@ | @@ -60,4 +60,26 @@ describe Locomotive::Steam::Site do |
| end | |
| + | describe '#last_modified_at' do |
| + | |
| + | subject { site.last_modified_at } |
| + | |
| + | it { is_expected.to eq nil } |
| + | |
| + | context 'only updated_at is defined' do |
| + | |
| + | let(:attributes) { { updated_at: DateTime.parse('2015/10/16 00:00:00') } } |
| + | it { is_expected.to eq DateTime.parse('2015/10/16 00:00:00') } |
| + | |
| + | end |
| + | |
| + | context 'template_version or content_version are defined' do |
| + | |
| + | let(:attributes) { { updated_at: DateTime.parse('2015/10/16 00:00:00'), template_version: DateTime.parse('2007/06/29 00:00:00'), content_version: DateTime.parse('2009/09/10 00:00:00') } } |
| + | it { is_expected.to eq DateTime.parse('2009/09/10 00:00:00') } |
| + | |
| + | end |
| + | |
| + | end |
| + | |
| end | |