Skip to content

Commit

Permalink
Merge branch 'master' of github.com:locomotivecms/engine
Browse files Browse the repository at this point in the history
  • Loading branch information
did committed Feb 4, 2013
2 parents 9f14068 + 64c02cf commit 2a48ed0
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 109 deletions.
5 changes: 5 additions & 0 deletions Gemfile.lock
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion app/controllers/locomotive/translations_controller.rb
Expand Up @@ -35,6 +35,5 @@ def destroy
@translation.destroy
respond_with @translation, location: translations_path
end

end
end
2 changes: 1 addition & 1 deletion app/views/locomotive/translations/index.html.haml
Expand Up @@ -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
= link_to_icon :trash, translation_url(translation), :title => t('.remove', key: translation.key), :class => 'remove', :data => { :confirm => t('locomotive.messages.confirm') }, :method => :delete
1 change: 1 addition & 0 deletions config/locales/admin_ui.en.yml
Expand Up @@ -234,6 +234,7 @@ en:
title: Translations
new: new translation
no_items: "There are no translations for now. Just click <a href=\"%{url}\">here</a> 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 <b>translate</b> liquid tag."
Expand Down
4 changes: 3 additions & 1 deletion features/backoffice/translations.feature
Expand Up @@ -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"
Then I should see "Translation was successfully created"
When I follow "Remove example_key"
Then I should see "Translation was successfully deleted"
5 changes: 5 additions & 0 deletions lib/generators/locomotive/install/install_generator.rb
Expand Up @@ -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 %(
Expand Down
1 change: 1 addition & 0 deletions 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'
Expand Down
1 change: 1 addition & 0 deletions lib/locomotive/engine.rb
Expand Up @@ -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|
Expand Down
106 changes: 0 additions & 106 deletions lib/tasks/locomotive.rake
Expand Up @@ -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'
Expand Down
2 changes: 2 additions & 0 deletions locomotive_cms.gemspec
Expand Up @@ -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'

Expand Down
107 changes: 107 additions & 0 deletions 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

0 comments on commit 2a48ed0

Please sign in to comment.