diff --git a/Gemfile.lock b/Gemfile.lock index 64384aa528..930ec33ab6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -11,6 +11,7 @@ PATH codemirror-rails (~> 2.21) custom_fields (~> 2.1.0.rc2) devise (~> 2.2.3) + devise (~> 2.2.3) devise-encryptable (~> 0.1.1) dragonfly (~> 0.9.8) flash_cookie_session (~> 1.1.1) @@ -23,6 +24,7 @@ PATH kaminari (~> 0.13.0) locomotive-aloha-rails (~> 0.20.1.4) locomotive-mongoid-tree (~> 0.6.2) + locomotive-mongoid_migration locomotive-tinymce-rails (~> 3.4.7.4) locomotive_liquid (~> 2.4.2) mimetype-fu (~> 0.1.2) @@ -197,6 +199,9 @@ GEM actionpack (~> 3.2.1) locomotive-mongoid-tree (0.6.2) mongoid (~> 2.0) + locomotive-mongoid_migration (0.0.5) + mongoid (~> 2.4) + rails (~> 3.2) locomotive-tinymce-rails (3.4.7.4) actionpack (~> 3.2) locomotive_liquid (2.4.2) diff --git a/app/controllers/locomotive/translations_controller.rb b/app/controllers/locomotive/translations_controller.rb index 7140242ab7..25ec6cda8f 100644 --- a/app/controllers/locomotive/translations_controller.rb +++ b/app/controllers/locomotive/translations_controller.rb @@ -35,6 +35,5 @@ def destroy @translation.destroy respond_with @translation, location: translations_path end - end end \ No newline at end of file diff --git a/app/views/locomotive/translations/index.html.haml b/app/views/locomotive/translations/index.html.haml index 58d151d8a0..c4a22d6982 100644 --- a/app/views/locomotive/translations/index.html.haml +++ b/app/views/locomotive/translations/index.html.haml @@ -25,4 +25,4 @@ %span!= t('.updated_at') = l translation.updated_at, :format => :short - = link_to_icon :trash, translation_url(translation), :class => 'remove', :data => { :confirm => t('locomotive.messages.confirm') }, :method => :delete \ No newline at end of file + = link_to_icon :trash, translation_url(translation), :title => t('.remove', key: translation.key), :class => 'remove', :data => { :confirm => t('locomotive.messages.confirm') }, :method => :delete diff --git a/config/locales/admin_ui.en.yml b/config/locales/admin_ui.en.yml index 8c0a5e7bc5..87fca34166 100644 --- a/config/locales/admin_ui.en.yml +++ b/config/locales/admin_ui.en.yml @@ -234,6 +234,7 @@ en: title: Translations new: new translation no_items: "There are no translations for now. Just click here to create the first one." + remove: Remove %{key} new: title: "New translation" help: "Pages/snippets can share the same template for all the locales except for some labels which can be handled by the translate liquid tag." diff --git a/features/backoffice/translations.feature b/features/backoffice/translations.feature index 796fb524c0..0acde684a4 100644 --- a/features/backoffice/translations.feature +++ b/features/backoffice/translations.feature @@ -39,4 +39,6 @@ Background: And I fill in "English" with "Example text" And I fill in "Spanish" with "Texto de ejemplo" And I press "Create" - Then I should see "Translation was successfully created" \ No newline at end of file + Then I should see "Translation was successfully created" + When I follow "Remove example_key" + Then I should see "Translation was successfully deleted" \ No newline at end of file diff --git a/lib/generators/locomotive/install/install_generator.rb b/lib/generators/locomotive/install/install_generator.rb index ee22a59953..6385ed9d7e 100644 --- a/lib/generators/locomotive/install/install_generator.rb +++ b/lib/generators/locomotive/install/install_generator.rb @@ -16,6 +16,11 @@ def copy_initializers template 'mongoid.yml', 'config/mongoid.yml' end + + def copy_migrations + rake("db:mongoid:migration:install") + rake("db:mongoid:migrate") + end def insert_engine_routes route %( diff --git a/lib/locomotive/dependencies.rb b/lib/locomotive/dependencies.rb index 7443447bf7..18dd5f2ed0 100644 --- a/lib/locomotive/dependencies.rb +++ b/lib/locomotive/dependencies.rb @@ -1,6 +1,7 @@ require 'mongoid' require 'mongoid/railtie' require 'mongoid/tree' +require 'mongoid_migration' require 'devise' require 'devise/orm/mongoid' require 'devise-encryptable' diff --git a/lib/locomotive/engine.rb b/lib/locomotive/engine.rb index ed636b48ba..9e46bb40e1 100644 --- a/lib/locomotive/engine.rb +++ b/lib/locomotive/engine.rb @@ -8,6 +8,7 @@ class Engine < Rails::Engine isolate_namespace Locomotive + paths['mongodb/migrate'] = 'mongodb/migrate' # config.autoload_once_paths += %W( #{config.root}/app/controllers #{config.root}/app/models #{config.root}/app/helpers #{config.root}/app/uploaders) initializer 'locomotive.cells' do |app| diff --git a/lib/tasks/locomotive.rake b/lib/tasks/locomotive.rake index 1ce4e85b5b..30ad1f5d20 100644 --- a/lib/tasks/locomotive.rake +++ b/lib/tasks/locomotive.rake @@ -56,112 +56,6 @@ namespace :locomotive do end end - desc 'Make blocks and editable_elements consistent' - task :make_editable_elements_consistent => :environment do - Locomotive::Site.all.each do |site| - # site = Locomotive::Site.find('50acd6f087f64350c9000010') - site.locales.each do |locale| - ::Mongoid::Fields::I18n.locale = locale - # page = Locomotive::Page.find('50acd6f087f64350c9000012') # home page - # page = Locomotive::Page.find('50ae35ff87f643f3df0000bc') # company - site.pages.each do |page| - puts "[#{site.name}] #{page.fullpath} (#{locale})" - - found_elements = [] - - page.template.walk do |node, memo| - case node - when Locomotive::Liquid::Tags::InheritedBlock - puts "found block ! #{node.name} --- #{memo[:parent_block_name]}" - - # set the new name based on a potential parent block - name = node.name.gsub(/[\"\']/o, '') - - if memo[:parent_block_name] && !name.starts_with?(memo[:parent_block_name]) - name = "#{memo[:parent_block_name]}/#{name}" - end - - puts "new_name = #{name}" - - # retrieve all the editable elements of this block and set them the new name - page.find_editable_elements(node.name).each do |el| - # puts "**> hurray found the element #{el.block} _ #{el.slug}" - el.block = name - puts "**> hurray found the element #{el.block} _ #{el.slug} | #{page.find_editable_element(name, el.slug).present?.inspect}" - end - - # assign the new name to the block - node.instance_variable_set :@name, name - - # record the new parent block name for children - memo[:parent_block_name] = name - - when Locomotive::Liquid::Tags::Editable::ShortText, - Locomotive::Liquid::Tags::Editable::LongText, - Locomotive::Liquid::Tags::Editable::Control, - Locomotive::Liquid::Tags::Editable::File - - puts "\tfound editable_element ! #{node.slug} --- #{memo[:parent_block_name]}" - - slug = node.slug.gsub(/[\"\']/o, '') - - # assign the new slug to the editable element - puts "\t\t...looking for #{node.slug} inside #{memo[:parent_block_name]}" - - options = node.instance_variable_get :@options - block = options[:block].blank? ? memo[:parent_block_name] : options[:block] - - if el = page.find_editable_element(block, node.slug) - puts "\t\t--> yep found the element" - - el.slug = slug - el.block = memo[:parent_block_name] # just to make sure - - node.instance_variable_set :@slug, slug - - options.delete(:block) - node.instance_variable_set :@block, nil # just to make sure - - found_elements << el._id - else - puts "\t\t[WARNING] el not found (#{block} - #{slug})" - end - - end - - memo - end # page walk - - puts "found elements = #{found_elements.join(', ')} / #{page.editable_elements.count}" - - # "hide" useless editable elements - page.editable_elements.each do |el| - next if found_elements.include?(el._id) - el.disabled = true - end - - # serialize - page.send(:_serialize_template) - - # puts page.template.inspect - - # save ? - page.instance_variable_set :@template_changed, false - page.save - - # TODO: - # x ", block: 'Asset #1'"" ???? les re-assigner a "main" d'une facon ou d'une autre - # => en fait, ce sont des editable elements qui n'ont pas vrais blocks - # x hide useless editable elements - # x re-serializer le template - # ? skipper la methode parse (quoique pas besoin car template non modifie) - # x snippets - # x sauvegarder (sans callbacks ??) - end # loop: pages - end # loop: locales - end # loop: sites - end # task: make_editable_elements_consistent - end # namespace: upgrade desc 'Generate the documentation about the REST API' diff --git a/locomotive_cms.gemspec b/locomotive_cms.gemspec index d9f9a6f957..d8ca9562fc 100755 --- a/locomotive_cms.gemspec +++ b/locomotive_cms.gemspec @@ -24,12 +24,14 @@ Gem::Specification.new do |s| s.add_dependency 'devise', '~> 2.2.3' s.add_dependency 'devise-encryptable', '~> 0.1.1' + s.add_dependency 'devise', '~> 2.2.3' s.add_dependency 'cancan', '1.6.7' s.add_dependency 'mongo', '~> 1.5.2' s.add_dependency 'bson_ext', '~> 1.5.2' s.add_dependency 'mongoid', '~> 2.4.12' s.add_dependency 'locomotive-mongoid-tree', '~> 0.6.2' + s.add_dependency 'locomotive-mongoid_migration' s.add_dependency 'custom_fields', '~> 2.1.0.rc2' diff --git a/mongodb/migrate/20130204072721_make_editable_elements_consistent.rb b/mongodb/migrate/20130204072721_make_editable_elements_consistent.rb new file mode 100644 index 0000000000..24ca95d075 --- /dev/null +++ b/mongodb/migrate/20130204072721_make_editable_elements_consistent.rb @@ -0,0 +1,107 @@ +class MakeEditableElementsConsistent < MongoidMigration::Migration + def self.up + Locomotive::Site.all.each do |site| + site.locales.each do |locale| + ::Mongoid::Fields::I18n.locale = locale + site.pages.each do |page| + puts "[#{site.name}] #{page.fullpath} (#{locale})" + + found_elements = [] + + page.template.walk do |node, memo| + case node + when Locomotive::Liquid::Tags::InheritedBlock + puts "found block ! #{node.name} --- #{memo[:parent_block_name]}" + + # set the new name based on a potential parent block + name = node.name.gsub(/[\"\']/o, '') + + if memo[:parent_block_name] && !name.starts_with?(memo[:parent_block_name]) + name = "#{memo[:parent_block_name]}/#{name}" + end + + puts "new_name = #{name}" + + # retrieve all the editable elements of this block and set them the new name + page.find_editable_elements(node.name).each do |el| + # puts "**> hurray found the element #{el.block} _ #{el.slug}" + el.block = name + puts "**> hurray found the element #{el.block} _ #{el.slug} | #{page.find_editable_element(name, el.slug).present?.inspect}" + end + + # assign the new name to the block + node.instance_variable_set :@name, name + + # record the new parent block name for children + memo[:parent_block_name] = name + + when Locomotive::Liquid::Tags::Editable::ShortText, + Locomotive::Liquid::Tags::Editable::LongText, + Locomotive::Liquid::Tags::Editable::Control, + Locomotive::Liquid::Tags::Editable::File + + puts "\tfound editable_element ! #{node.slug} --- #{memo[:parent_block_name]}" + + slug = node.slug.gsub(/[\"\']/o, '') + + # assign the new slug to the editable element + puts "\t\t...looking for #{node.slug} inside #{memo[:parent_block_name]}" + + options = node.instance_variable_get :@options + block = options[:block].blank? ? memo[:parent_block_name] : options[:block] + + if el = page.find_editable_element(block, node.slug) + puts "\t\t--> yep found the element" + + el.slug = slug + el.block = memo[:parent_block_name] # just to make sure + + node.instance_variable_set :@slug, slug + + options.delete(:block) + node.instance_variable_set :@block, nil # just to make sure + + found_elements << el._id + else + puts "\t\t[WARNING] el not found (#{block} - #{slug})" + end + + end + + memo + end # page walk + + puts "found elements = #{found_elements.join(', ')} / #{page.editable_elements.count}" + + # "hide" useless editable elements + page.editable_elements.each do |el| + next if found_elements.include?(el._id) + el.disabled = true + end + + # serialize + page.send(:_serialize_template) + + # puts page.template.inspect + + # save ? + page.instance_variable_set :@template_changed, false + page.save + + # TODO: + # x ", block: 'Asset #1'"" ???? les re-assigner a "main" d'une facon ou d'une autre + # => en fait, ce sont des editable elements qui n'ont pas vrais blocks + # x hide useless editable elements + # x re-serializer le template + # ? skipper la methode parse (quoique pas besoin car template non modifie) + # x snippets + # x sauvegarder (sans callbacks ??) + end # loop: pages + end # loop: locales + end # loop: sites + end + + def self.down + raise MongoidMigration::IrreversibleMigration + end +end \ No newline at end of file