use absolute urls for the pagination links + allow developers to access the http params within a liquid template + the with_scope handles category fields
This commit is contained in:
parent
5654924e0b
commit
ea050afd5e
@ -82,8 +82,15 @@ class ContentType
|
|||||||
# convert alias (key) to name
|
# convert alias (key) to name
|
||||||
field = self.content_custom_fields.detect { |f| f._alias == key }
|
field = self.content_custom_fields.detect { |f| f._alias == key }
|
||||||
|
|
||||||
|
case field.kind.to_sym
|
||||||
|
when :category
|
||||||
|
if (category_item = field.category_items.where(:name => value).first).present?
|
||||||
|
conditions_with_names[field._name.to_sym] = category_item._id
|
||||||
|
end
|
||||||
|
else
|
||||||
conditions_with_names[field._name.to_sym] = value
|
conditions_with_names[field._name.to_sym] = value
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
self.contents.where(conditions_with_names)
|
self.contents.where(conditions_with_names)
|
||||||
end).sort { |a, b| (a.send(column) || 0) <=> (b.send(column) || 0) }
|
end).sort { |a, b| (a.send(column) || 0) <=> (b.send(column) || 0) }
|
||||||
|
@ -82,13 +82,13 @@ module Locomotive
|
|||||||
previous_link = (if paginate['previous'].blank?
|
previous_link = (if paginate['previous'].blank?
|
||||||
"<span class=\"disabled prev_page\">#{previous_label}</span>"
|
"<span class=\"disabled prev_page\">#{previous_label}</span>"
|
||||||
else
|
else
|
||||||
"<a href=\"/#{paginate['previous']['url']}\" class=\"prev_page\">#{previous_label}</a>"
|
"<a href=\"#{absolute_url(paginate['previous']['url'])}\" class=\"prev_page\">#{previous_label}</a>"
|
||||||
end)
|
end)
|
||||||
|
|
||||||
links = ""
|
links = ""
|
||||||
paginate['parts'].each do |part|
|
paginate['parts'].each do |part|
|
||||||
links << (if part['is_link']
|
links << (if part['is_link']
|
||||||
"<a href=\"/#{part['url']}\">#{part['title']}</a>"
|
"<a href=\"#{absolute_url(part['url'])}\">#{part['title']}</a>"
|
||||||
elsif part['hellip_break']
|
elsif part['hellip_break']
|
||||||
"<span class=\"gap\">#{part['title']}</span>"
|
"<span class=\"gap\">#{part['title']}</span>"
|
||||||
else
|
else
|
||||||
@ -99,7 +99,7 @@ module Locomotive
|
|||||||
next_link = (if paginate['next'].blank?
|
next_link = (if paginate['next'].blank?
|
||||||
"<span class=\"disabled next_page\">#{next_label}</span>"
|
"<span class=\"disabled next_page\">#{next_label}</span>"
|
||||||
else
|
else
|
||||||
"<a href=\"/#{paginate['next']['url']}\" class=\"next_page\">#{next_label}</a>"
|
"<a href=\"#{absolute_url(paginate['next']['url'])}\" class=\"next_page\">#{next_label}</a>"
|
||||||
end)
|
end)
|
||||||
|
|
||||||
%{<div class="pagination #{options[:css]}">
|
%{<div class="pagination #{options[:css]}">
|
||||||
@ -140,6 +140,10 @@ module Locomotive
|
|||||||
ThemeAssetUploader.url_for(@context.registers[:site], path)
|
ThemeAssetUploader.url_for(@context.registers[:site], path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def absolute_url(url)
|
||||||
|
url.starts_with('/') ? url : "/#{url}"
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
::Liquid::Template.register_filter(Html)
|
::Liquid::Template.register_filter(Html)
|
||||||
|
@ -13,21 +13,21 @@ module Locomotive
|
|||||||
|
|
||||||
def render(context)
|
def render(context)
|
||||||
context.stack do
|
context.stack do
|
||||||
context['with_scope'] = decode(@attributes)
|
context['with_scope'] = decode(@attributes, context)
|
||||||
render_all(@nodelist, context)
|
render_all(@nodelist, context)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def decode(attributes)
|
def decode(attributes, context)
|
||||||
attributes.each_pair do |key, value|
|
attributes.each_pair do |key, value|
|
||||||
attributes[key] = (case value
|
attributes[key] = (case value
|
||||||
when /true|false/ then value == 'true'
|
when /true|false/ then value == 'true'
|
||||||
when /[0-9]+/ then value.to_i
|
when /[0-9]+/ then value.to_i
|
||||||
when /'(\S+)'/ then $1
|
when /'(\S+)'/ then $1
|
||||||
else
|
else
|
||||||
value
|
context[value]
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -61,7 +61,8 @@ module Locomotive
|
|||||||
'page' => @page,
|
'page' => @page,
|
||||||
'asset_collections' => Locomotive::Liquid::Drops::AssetCollections.new,
|
'asset_collections' => Locomotive::Liquid::Drops::AssetCollections.new,
|
||||||
'contents' => Locomotive::Liquid::Drops::Contents.new,
|
'contents' => Locomotive::Liquid::Drops::Contents.new,
|
||||||
'current_page' => self.params[:page]
|
'current_page' => self.params[:page],
|
||||||
|
'params' => self.params
|
||||||
}.merge(flash.stringify_keys) # data from api
|
}.merge(flash.stringify_keys) # data from api
|
||||||
|
|
||||||
if @page.templatized? # add instance from content type
|
if @page.templatized? # add instance from content type
|
||||||
|
@ -2,15 +2,21 @@ require 'spec_helper'
|
|||||||
|
|
||||||
describe Locomotive::Liquid::Tags::WithScope do
|
describe Locomotive::Liquid::Tags::WithScope do
|
||||||
|
|
||||||
it 'should decode options (boolean, interger, ...)' do
|
it 'should decode basic options (boolean, interger, ...)' do
|
||||||
scope = Locomotive::Liquid::Tags::WithScope.new('with_scope', 'active:true price:42 title:\'foo\' hidden:false', ["{% endwith_scope %}"], {})
|
scope = Locomotive::Liquid::Tags::WithScope.new('with_scope', 'active:true price:42 title:\'foo\' hidden:false', ["{% endwith_scope %}"], {})
|
||||||
attributes = scope.send(:decode, scope.instance_variable_get(:@attributes))
|
attributes = scope.send(:decode, scope.instance_variable_get(:@attributes), {})
|
||||||
attributes['active'].should == true
|
attributes['active'].should == true
|
||||||
attributes['price'].should == 42
|
attributes['price'].should == 42
|
||||||
attributes['title'].should == 'foo'
|
attributes['title'].should == 'foo'
|
||||||
attributes['hidden'].should == false
|
attributes['hidden'].should == false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should decode context variable' do
|
||||||
|
scope = Locomotive::Liquid::Tags::WithScope.new('with_scope', 'category: params.type', ["{% endwith_scope %}"], {})
|
||||||
|
attributes = scope.send(:decode, scope.instance_variable_get(:@attributes), { 'params.type' => 'posts' })
|
||||||
|
attributes['category'].should == 'posts'
|
||||||
|
end
|
||||||
|
|
||||||
it 'should store attributes in the context' do
|
it 'should store attributes in the context' do
|
||||||
template = ::Liquid::Template.parse("{% with_scope active:true title:'foo' %}{{ with_scope.active }}-{{ with_scope.title }}{% endwith_scope %}")
|
template = ::Liquid::Template.parse("{% with_scope active:true title:'foo' %}{{ with_scope.active }}-{{ with_scope.title }}{% endwith_scope %}")
|
||||||
text = template.render
|
text = template.render
|
||||||
|
Loading…
Reference in New Issue
Block a user