reflect changes from the last imported theme (enhancements + bugs fixed)

This commit is contained in:
dinedine 2010-10-31 00:30:30 +02:00
parent 89f106405d
commit a1d9a5d548
15 changed files with 91 additions and 28 deletions

View File

@ -7,7 +7,7 @@ module Admin::CustomFieldsHelper
end
def options_for_order_by(content_type, collection_name)
options = %w{updated_at _position_in_list}.map do |type|
options = %w{created_at updated_at _position_in_list}.map do |type|
[t("admin.content_types.form.order_by.#{type.gsub(/^_/, '')}"), type]
end
options + options_for_highlighted_field(content_type, collection_name)
@ -16,7 +16,7 @@ module Admin::CustomFieldsHelper
def options_for_highlighted_field(content_type, collection_name)
custom_fields_collection_name = "ordered_#{collection_name.singularize}_custom_fields".to_sym
collection = content_type.send(custom_fields_collection_name)
collection.delete_if { |f| f.label == 'field name' }
collection.delete_if { |f| f.label == 'field name' || f.kind == 'file' }
collection.map { |field| [field.label, field._name] }
end

View File

@ -94,7 +94,7 @@ class ContentType
protected
def set_default_values
self.order_by ||= 'updated_at'
self.order_by ||= 'created_at'
self.highlighted_field_name ||= self.content_custom_fields.first._name
end

View File

@ -44,10 +44,7 @@ module Models
end
def hacked_descendants
# workorund for mongoid unexpected behavior
_new_record_var = self.instance_variable_get(:@new_record)
_new_record = _new_record_var != false
return [] if _new_record
return [] if new_record?
self.class.all_in(path_field => [self._id]).order_by tree_order
end
@ -56,6 +53,7 @@ module Models
def change_parent
if self.parent_id_changed?
self.fix_position(false)
self.position = nil # make it move to bottom
self.add_to_list_bottom
self.instance_variable_set :@_will_move, true
end
@ -81,7 +79,7 @@ module Models
end
def add_to_list_bottom
self.position = (::Page.where(:_id.ne => self._id).and(:parent_id => self.parent_id).max(:position) || 0) + 1
self.position ||= (::Page.where(:_id.ne => self._id).and(:parent_id => self.parent_id).max(:position) || 0) + 1
end
def remove_from_list

View File

@ -220,6 +220,7 @@ en:
new_item: new item
form:
order_by:
created_at: 'By "created at" date'
updated_at: 'By "updated at" date'
position_in_list: Manually

View File

@ -219,6 +219,7 @@ fr:
new_item: nouvel élément
form:
order_by:
created_at: 'Par date création'
updated_at: 'Par date de mise à jour'
position_in_list: Manuellement

View File

@ -9,9 +9,6 @@ defaults: &defaults
development:
<<: *defaults
database: locomotive_dev
# database: locomotive_dev_tmp
# database: locomotive_hosting_production
test:
<<: *defaults

View File

@ -6,7 +6,6 @@ BOARD:
- edit images (upload new ones, ...etc) => wait for aloha or send them an email ?
- refactor slugify method (use parameterize + create a module)
- [content types] the "display column" selector should not include file types
- global regions: keyword in editable element (http://www.mongodb.org/display/DOCS/Updating)
- write my first tutorial about locomotive
@ -157,3 +156,13 @@ x installation guide
x welcome: domains, ...etc
x Create account
x Create new site (name, subdomain) / Import theme (worker or list of sites from fs)
x import:
x ordered pages ?
x order_by for content_types ? created_at, updated_at
x liquid:
x nav
x no_wrapper option
x regexp to get rid of some pages
x filters
x default_pagination: labels
x [content types] the "display column" selector should not include file types

View File

@ -48,6 +48,8 @@ module Locomotive
next if File.directory?(asset_path)
self.log "other asset = #{asset_path}"
name = File.basename(asset_path, File.extname(asset_path)).parameterize('_')
collection.assets.create! :name => name, :source => File.open(asset_path)

View File

@ -97,7 +97,7 @@ module Locomotive
order_by = (case content_type.order_by
when 'manually', '_position_in_list' then '_position_in_list'
when 'date', 'updated_at' then 'updated_at'
when 'default', 'created_at' then 'created_at'
else
content_type.content_custom_fields.detect { |f| f._alias == content_type.order_by }._name rescue nil
end)

View File

@ -26,6 +26,8 @@ module Locomotive
template = File.read(File.join(theme_path, 'templates', "#{fullpath}.liquid")) rescue "Unable to find #{fullpath}.liquid"
self.replace_images!(template)
self.build_parent_template(template)
parent = self.find_parent(fullpath)
@ -97,7 +99,11 @@ module Locomotive
template = File.read(File.join(theme_path, 'templates', "#{slug}.liquid"))
page.attributes = { :raw_template => template, :position => position }.merge(self.pages[slug] || {})
self.replace_images!(template)
page.attributes = { :raw_template => template }.merge(self.pages[slug] || {})
page.position = position
page.save! rescue nil # TODO better error handling
@ -107,8 +113,39 @@ module Locomotive
end
end
def replace_images!(template)
return if template.blank?
template.gsub!(/\/samples\/(.*\.[a-zA-Z0-9]{3})/) do |match|
name = $1
collection = AssetCollection.find_or_create_internal(site)
if asset = collection.assets.detect { |a| a.source_filename == name }
asset.source.url
else
match
end
end
end
def pages
context[:database]['site']['pages']
@pages ||= self.retrieve_pages
end
def retrieve_pages
pages = context[:database]['site']['pages']
if pages.is_a?(Array) # ordered list of pages
tmp = {}
pages.each_with_index do |data, position|
attributes = (data.values.first || {}).merge(:position => position)
tmp[data.keys.first.to_s] = attributes
end
pages = tmp
end
pages
end
end

View File

@ -83,10 +83,13 @@ module Locomotive
options = args_to_options(args)
previous_label = options[:previous_label] || I18n.t('pagination.previous')
next_label = options[:next_label] || I18n.t('pagination.next')
previous_link = (if paginate['previous'].blank?
"<span class=\"disabled prev_page\">#{I18n.t('pagination.previous')}</span>"
"<span class=\"disabled prev_page\">#{previous_label}</span>"
else
"<a href=\"#{paginate['previous']['url']}\" class=\"prev_page\">#{I18n.t('pagination.previous')}</a>"
"<a href=\"#{paginate['previous']['url']}\" class=\"prev_page\">#{previous_label}</a>"
end)
links = ""
@ -101,9 +104,9 @@ module Locomotive
end
next_link = (if paginate['next'].blank?
"<span class=\"disabled next_page\">#{I18n.t('pagination.next')}</span>"
"<span class=\"disabled next_page\">#{next_label}</span>"
else
"<a href=\"#{paginate['next']['url']}\" class=\"next_page\">#{I18n.t('pagination.next')}</a>"
"<a href=\"#{paginate['next']['url']}\" class=\"next_page\">#{next_label}</a>"
end)
%{<div class="pagination #{options[:css]}">

View File

@ -17,6 +17,8 @@ module Locomotive
@site_or_page = $1 || 'page'
@options = {}
markup.scan(::Liquid::TagAttributes) { |key, value| @options[key.to_sym] = value }
@options[:exclude] = Regexp.new(@options[:exclude].gsub(/"|'/, '')) if @options[:exclude]
else
raise ::Liquid::SyntaxError.new("Syntax Error in 'nav' - Valid syntax: nav <page|site> <options>")
end
@ -29,22 +31,33 @@ module Locomotive
source = context.registers[@site_or_page.to_sym]
# puts "#{@site_or_page.to_sym} / source = #{source.inspect}"
if source.respond_to?(:name) # site ?
source = source.pages.index.first # start from home page
else
source = source.parent || source
end
output = %{<ul id="nav">}
output += source.children.map { |p| render_child_link(p) }.join("\n")
output += %{</ul>}
output = source.children.map { |p| include_page?(p) ? render_child_link(p) : '' }.join("\n")
if @options[:no_wrapper] != 'true'
output = %{<ul id="nav">\n#{output}</ul>}
end
output
end
private
def include_page?(page)
if page.templatized?
false
elsif @options[:exclude]
(page.fullpath =~ @options[:exclude]).nil?
else
true
end
end
def render_child_link(page)
selected = @current_page._id == page._id ? ' on' : ''

View File

@ -18,14 +18,16 @@
#page-toolbar ul li.link {
float: left;
margin-right: 5px;
margin: 0 0 0 5px;
background: transparent;
padding: 0px;
}
#page-toolbar ul li.link a {
display: block;
background: transparent url('/images/admin/inline_editor/action-left.png') no-repeat 0 0;
height: 19px;
line-height: 19px;
height: 20px;
line-height: 20px;
padding-left: 24px;
text-decoration: none;
color: #fff;

Binary file not shown.

View File

@ -27,7 +27,7 @@ describe Locomotive::Import::Job do
it 'converts correctly the order_by option for content types' do
content_type = @site.content_types.where(:slug => 'messages').first
content_type.order_by.should == 'updated_at'
content_type.order_by.should == 'created_at'
end
it 'adds samples coming with content types' do