Skip to content

Commit

Permalink
Support multiple languages for seed data in extension and form genera…
Browse files Browse the repository at this point in the history
…ted seeds file.
  • Loading branch information
ugisozols committed May 25, 2012
1 parent 0179860 commit 33878c5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 39 deletions.
38 changes: 21 additions & 17 deletions core/lib/generators/refinery/engine/templates/db/seeds.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
if defined?(::Refinery::User)
::Refinery::User.all.each do |user|
if user.plugins.where(:name => 'refinerycms-<%= namespacing.underscore %>').blank?
user.plugins.create(:name => 'refinerycms-<%= namespacing.underscore %>',
:position => (user.plugins.maximum(:position) || -1) +1)
Refinery::I18n.frontend_locales.each do |lang|
I18n.locale = lang

if defined?(Refinery::User)
Refinery::User.all.each do |user|
if user.plugins.where(:name => 'refinerycms-<%= namespacing.underscore %>').blank?
user.plugins.create(:name => 'refinerycms-<%= namespacing.underscore %>',
:position => (user.plugins.maximum(:position) || -1) +1)
end
end
end
end

<% unless skip_frontend? -%>
url = "/<%= [(namespacing.underscore if namespacing.underscore != plural_name), plural_name].compact.join('/') %>"
if defined?(::Refinery::Page) && ::Refinery::Page.where(:link_url => url).empty?
page = ::Refinery::Page.create(
:title => '<%= class_name.pluralize.underscore.titleize %>',
:link_url => url,
:deletable => false,
:menu_match => "^#{url}(\/|\/.+?|)$"
)
Refinery::Pages.default_parts.each_with_index do |default_page_part, index|
page.parts.create(:title => default_page_part, :body => nil, :position => index)
url = "/<%= [(namespacing.underscore if namespacing.underscore != plural_name), plural_name].compact.join('/') %>"
if defined?(Refinery::Page) && Refinery::Page.where(:link_url => url).empty?
page = Refinery::Page.create(
:title => '<%= class_name.pluralize.underscore.titleize %>',
:link_url => url,
:deletable => false,
:menu_match => "^#{url}(\/|\/.+?|)$"
)
Refinery::Pages.default_parts.each_with_index do |default_page_part, index|
page.parts.create(:title => default_page_part, :body => nil, :position => index)
end
end
end
<% end -%>
end
48 changes: 26 additions & 22 deletions core/lib/generators/refinery/form/templates/db/seeds.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
if defined?(::Refinery::User)
::Refinery::User.all.each do |user|
if user.plugins.find_by_name('<%= plural_name %>').nil?
user.plugins.create(:name => "<%= plural_name %>",
:position => (user.plugins.maximum(:position) || -1) +1)
Refinery::I18n.frontend_locales.each do |lang|
I18n.locale = lang

if defined?(Refinery::User)
Refinery::User.all.each do |user|
if user.plugins.find_by_name('<%= plural_name %>').nil?
user.plugins.create(:name => "<%= plural_name %>",
:position => (user.plugins.maximum(:position) || -1) +1)
end
end
end
end

if defined?(::Refinery::Page)
page = ::Refinery::Page.create(
:title => "<%= class_name.pluralize.underscore.titleize %>",
:link_url => "/<%= plural_name %>/new",
:deletable => false,
:menu_match => "^/<%= plural_name %>(\/|\/.+?|)$"
)
thank_you_page = page.children.create(
:title => "Thank You",
:link_url => "/<%= plural_name %>/thank_you",
:deletable => false,
:show_in_menu => false
)
Refinery::Pages.default_parts.each do |default_page_part|
page.parts.create(:title => default_page_part, :body => nil)
thank_you_page.parts.create(:title => default_page_part, :body => nil)
if defined?(Refinery::Page)
page = Refinery::Page.create(
:title => "<%= class_name.pluralize.underscore.titleize %>",
:link_url => "/<%= plural_name %>/new",
:deletable => false,
:menu_match => "^/<%= plural_name %>(\/|\/.+?|)$"
)
thank_you_page = page.children.create(
:title => "Thank You",
:link_url => "/<%= plural_name %>/thank_you",
:deletable => false,
:show_in_menu => false
)
Refinery::Pages.default_parts.each do |default_page_part|
page.parts.create(:title => default_page_part, :body => nil)
thank_you_page.parts.create(:title => default_page_part, :body => nil)
end
end
end

0 comments on commit 33878c5

Please sign in to comment.