forked from locomotivecms/engine
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:locomotivecms/engine
- Loading branch information
Showing
11 changed files
with
126 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,5 @@ def destroy | |
@translation.destroy | ||
respond_with @translation, location: translations_path | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
mongodb/migrate/20130204072721_make_editable_elements_consistent.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |