diff --git a/app/helpers/admin/custom_fields_helper.rb b/app/helpers/admin/custom_fields_helper.rb index 2ae107f9..7bd022ff 100644 --- a/app/helpers/admin/custom_fields_helper.rb +++ b/app/helpers/admin/custom_fields_helper.rb @@ -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 diff --git a/app/models/content_type.rb b/app/models/content_type.rb index 37e848ca..3943d0a6 100644 --- a/app/models/content_type.rb +++ b/app/models/content_type.rb @@ -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 diff --git a/app/models/extensions/page/tree.rb b/app/models/extensions/page/tree.rb index 8e69341c..ea38f3fc 100644 --- a/app/models/extensions/page/tree.rb +++ b/app/models/extensions/page/tree.rb @@ -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 diff --git a/config/locales/admin_ui_en.yml b/config/locales/admin_ui_en.yml index cad6cfe7..a303c712 100644 --- a/config/locales/admin_ui_en.yml +++ b/config/locales/admin_ui_en.yml @@ -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 diff --git a/config/locales/admin_ui_fr.yml b/config/locales/admin_ui_fr.yml index 89143adb..ebebc3c4 100644 --- a/config/locales/admin_ui_fr.yml +++ b/config/locales/admin_ui_fr.yml @@ -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 diff --git a/config/mongoid.yml b/config/mongoid.yml index 6f8a2978..c4c29b91 100644 --- a/config/mongoid.yml +++ b/config/mongoid.yml @@ -9,9 +9,6 @@ defaults: &defaults development: <<: *defaults database: locomotive_dev - # database: locomotive_dev_tmp - # database: locomotive_hosting_production - test: <<: *defaults diff --git a/doc/TODO b/doc/TODO index 597bb634..abadf994 100644 --- a/doc/TODO +++ b/doc/TODO @@ -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 diff --git a/lib/locomotive/import/assets.rb b/lib/locomotive/import/assets.rb index 18e85315..216850bf 100644 --- a/lib/locomotive/import/assets.rb +++ b/lib/locomotive/import/assets.rb @@ -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) diff --git a/lib/locomotive/import/content_types.rb b/lib/locomotive/import/content_types.rb index dd36827e..89c2640d 100644 --- a/lib/locomotive/import/content_types.rb +++ b/lib/locomotive/import/content_types.rb @@ -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) diff --git a/lib/locomotive/import/pages.rb b/lib/locomotive/import/pages.rb index fd8ebe59..4930c4c8 100644 --- a/lib/locomotive/import/pages.rb +++ b/lib/locomotive/import/pages.rb @@ -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 diff --git a/lib/locomotive/liquid/filters/html.rb b/lib/locomotive/liquid/filters/html.rb index e3d04141..5da6cf2b 100644 --- a/lib/locomotive/liquid/filters/html.rb +++ b/lib/locomotive/liquid/filters/html.rb @@ -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? - "#{I18n.t('pagination.previous')}" + "#{previous_label}" else - "#{I18n.t('pagination.previous')}" + "#{previous_label}" end) links = "" @@ -101,9 +104,9 @@ module Locomotive end next_link = (if paginate['next'].blank? - "#{I18n.t('pagination.next')}" + "#{next_label}" else - "#{I18n.t('pagination.next')}" + "#{next_label}" end) %{