fix bugs: missing leading slash in local assets urls + wrong cached snippets

did committed Feb 16, 2015
commit d0f72c3bef47b316549d0b59cbb98792d422109e
Showing 7 changed files with 37 additions and 28 deletions
locomotive/steam/liquid/tags/snippet.rb b/lib/locomotive/steam/liquid/tags/snippet.rb +11 -5
@@ @@ -10,24 +10,30 @@ module Locomotive
listener.emit(:include, page: options[:page], name: @template_name)
# look for editable elements
- if snippet = options[:snippet_finder].find(snippet_name)
- options[:parser]._parse(snippet, options.merge(snippet: @template_name))
+ name = evaluate_snippet_name
+ if snippet = options[:snippet_finder].find(name)
+ options[:parser]._parse(snippet, options.merge(snippet: name))
end
end
end
+ def render(context)
+ @template_name = evaluate_snippet_name(context)
+ super
+ end
+
private
def read_template_from_file_system(context)
service = context.registers[:services]
- snippet = service.snippet_finder.find(snippet_name)
+ snippet = service.snippet_finder.find(@template_name)
- raise SnippetNotFound.new("Snippet with slug '#{snippet_name}' was not found") if snippet.nil?
+ raise SnippetNotFound.new("Snippet with slug '#{@template_name}' was not found") if snippet.nil?
snippet.liquid_source
end
- def snippet_name(context = nil)
+ def evaluate_snippet_name(context = nil)
context.try(:evaluate, @template_name) ||
@template_name.send(:state).first
end
locomotive/steam/middlewares/locale.rb b/lib/locomotive/steam/middlewares/locale.rb +1 -1
@@ @@ -18,7 +18,7 @@ module Locomotive::Steam
protected
def set_locale
- _locale = site.default_locale
+ _locale = default_locale
_path = path
if _path =~ /^(#{site.locales.join('|')})+(\/|$)/
locomotive/steam/repositories/filesystem/theme_asset.rb b/lib/locomotive/steam/repositories/filesystem/theme_asset.rb +1 -1
@@ @@ -7,7 +7,7 @@ module Locomotive
# Engine: ['', 'sites', site._id.to_s, 'theme', path].join('/')
def url_for(path)
- path
+ '/' + path
end
# Engine: site.theme_assets.checksums
spec/integration/server/basic_spec.rb +21 -20
@@ @@ -19,21 +19,36 @@ describe Locomotive::Steam::Server do
it 'shows the 404 page' do
get '/void'
expect(last_response.status).to eq(404)
- expect(last_response.body).to match /page not found/
+ expect(last_response.body).to include 'page not found'
end
it 'shows the 404 page with a 404 status code when its called explicitly' do
get '/404'
expect(last_response.status).to eq(404)
- expect(last_response.body).to match /page not found/
+ expect(last_response.body).to include 'page not found'
end
end
- # it 'shows content' do
- # get '/about-us/jane-doe'
- # expect(last_response.body).to match /Lorem ipsum dolor sit amet/
- # end
+ it 'shows content' do
+ get '/about-us/jane-doe'
+ expect(last_response.body).to include '<link href="/stylesheets/application.css"'
+ expect(last_response.body).to include 'Lorem ipsum dolor sit amet'
+ end
+
+ describe 'snippets' do
+
+ it 'includes a basic snippet' do
+ get '/'
+ expect(last_response.body).to include 'All photos are licensed under Creative Commons.'
+ end
+
+ it 'includes a snippet whose name is composed of dash' do
+ get '/'
+ expect(last_response.body).to include '<p>A complicated one name indeed.</p>'
+ end
+
+ end
# it 'shows a content type template', pending: true do
# get '/songs/song-number-1'
@@ @@ -75,20 +90,6 @@ describe Locomotive::Steam::Server do
# last_response.body.should =~ /<li>A song template<\/li>/
# end
- # describe 'snippets', pending: true do
-
- # it 'includes a basic snippet' do
- # get '/'
- # last_response.body.should =~ /All photos are licensed under Creative Commons\./
- # end
-
- # it 'includes a snippet whose name is composed of dash' do
- # get '/'
- # last_response.body.should =~ /<p>A complicated one name indeed.<\/p>/
- # end
-
- # end
-
# describe 'nav', pending: true do
# subject { get '/all'; last_response.body }
spec/unit/liquid/tags/csrf_spec.rb +1 -0
@@ @@ -1,4 +1,5 @@
require 'spec_helper'
+ require 'rack/csrf'
describe Locomotive::Steam::Liquid::Tags::Csrf do
spec/unit/liquid/tags/model_form_spec.rb +1 -0
@@ @@ -1,4 +1,5 @@
require 'spec_helper'
+ require 'rack/csrf'
describe Locomotive::Steam::Liquid::Tags::ModelForm do
spec/unit/repositories/filesystem/theme_asset_spec.rb +1 -1
@@ @@ -10,7 +10,7 @@ describe Locomotive::Steam::Repositories::Filesystem::ThemeAsset do
let(:path) { 'main.css' }
subject { repository.url_for(path) }
- it { is_expected.to eq 'main.css' }
+ it { is_expected.to eq '/main.css' }
end