Permalink
Browse files

Keep only necessary data in seeds.rb, and example on another file

  • Loading branch information...
nebirhos committed Mar 7, 2012
1 parent aa1f60d commit 3c8317376350708cdffd51aefd08f64b4e89f853
View
@@ -0,0 +1,51 @@
+# This will import some contents into the db just to have some example
+
+public
+
+def generate_page(parent, title, pretty_url, the_layout)
+ pg = parent.children.create :parent => parent, :title => title, :pretty_url => "#{pretty_url}#{"-"+parent.lang if parent.lang!='en'}", :lang => parent.lang, :visible_in_menu => true, :reserved => false, :published => true, :layout_name => the_layout, :publish_at => Time.now, :meta_title => title, :meta_description => title
+ pg.snippets.create :title => "Two levels menu", :area => "header", :cell_controller => "menu", :cell_action => "two_levels", :handler => "menu%two_levels%#{rand(99999).to_s.center(5, rand(9).to_s)}"
+ pg.snippets.create :title => "Footer menu", :area => "footer", :cell_controller => "menu", :cell_action => "footer", :handler => "menu%footer%#{rand(99999).to_s.center(5, rand(9).to_s)}"
+ if the_layout == "two_columns.html.erb" or the_layout == "three_columns.html.erb"
+ pg.snippets.create :title => "Siblings menu", :area => "left", :cell_controller => "menu", :cell_action => "siblings", :handler => "menu%siblings%#{rand(99999).to_s.center(5, rand(9).to_s)}"
+ end
+ pg
+end
+
+
+private
+
+# Creating pages
+home = "home.html.erb"
+single_column = "single_column.html.erb"
+two_columns = "two_columns.html.erb"
+three_columns = "three_columns.html.erb"
+
+Setting.first.update_attribute(:theme_name, "rough") # does not work if called from rake ry:init task
+
+Page.all.map do |p|
+ p.snippets.map{|s| s.update_attribute(:area, "limbo")}
+ p.update_attribute(:layout_name, home)
+end
+
+
+Language.all.each do |lang|
+ root = Page.find_by_title(lang.short)
+ # Adding some snippets to home pages
+ home = root.children.first
+ home.snippets.create :title => "Two levels menu", :area => "header", :cell_controller => "menu", :cell_action => "two_levels", :handler => "menu%two_levels%#{rand(99999).to_s.center(5, rand(9).to_s)}"
+ home.snippets.create :title => "Footer menu", :area => "footer", :cell_controller => "menu", :cell_action => "footer", :handler => "menu%footer%#{rand(99999).to_s.center(5, rand(9).to_s)}"
+
+ # Generating new pages
+ first = generate_page(root, "First Group", "first", single_column)
+ generate_page(first, "1st page", "sub-first", single_column)
+ generate_page(first, "2nd page", "sub-second", two_columns)
+ generate_page(first, "3d page", "sub-third", three_columns)
+ puts "Generated first group of pages for language \"#{lang.name}\""
+
+ second = generate_page(root, "Second Group", "second", single_column)
+ generate_page(second, "4th page", "sub-fourth", single_column)
+ generate_page(second, "5th page", "sub-fifth", two_columns)
+ generate_page(second, "6th page", "sub-sixth", three_columns)
+ puts "Generated second group of pages for language \"#{lang.name}\""
+end
@@ -24,26 +24,6 @@ def self.up
add_index :pages, :title
add_index :pages, :pretty_url
add_index :pages, :ancestry
-
- first_theme = Theme.all.first.short
- first_layout = Layout.all(first_theme).first.filename
-
- ["it", "en"].each do |lang|
- puts "------------------------- Creating root language page \'#{lang}\' -------------------------"
- root = Page.create :title => lang, :pretty_url => lang, :lang => lang
- root.children.create :title => "Home #{lang}",
- :pretty_url => "home_#{lang}",
- :lang => lang,
- :visible_in_menu => true,
- :reserved => false,
- :published => true,
- :layout_name => first_layout,
- :publish_at => Time.now,
- :meta_title => "Home #{lang}",
- :meta_description => "Home #{lang}"
-
- end
-
end
def self.down
@@ -3,13 +3,7 @@ def self.up
create_table :roles do |t|
t.column :name, :string
t.timestamps
- end
-
- ["admin", "article_writer", "premium_user", "registered_user"].each do |role|
- puts "------------------------- Creating role \'#{role}\' -------------------------"
- Role.create :name => role
- end
-
+ end
end
def self.down
@@ -4,13 +4,6 @@ def self.up
t.references :role, :user
t.timestamps
end
-
- admin_role = Role.find_by_name('admin')
- user = User.create :email => 'admin@example.com', :firstname => 'Admin', :lastname => 'Surname', :password => 'changeme', :password_confirmation => 'changeme'
- user.confirmed_at, user.lang, user.enabled = Time.now, 'en', true
- user.roles << admin_role
- user.save
- puts "------------------------- Creating user email \'#{user.email}\', password \'changeme\'-------------------------"
end
def self.down
@@ -11,7 +11,6 @@ def self.up
t.column :analytics, :string, :default => ""
t.timestamps
end
- Setting.create :site_name => "My new RailsYard site", :default_lang => "en", :homepage_id => 1
end
def self.down
@@ -9,7 +9,7 @@ def self.up
t.string :assetable_type, :limit => 30
t.string :type, :limit => 30
- # Uncomment it to save images dimensions, if your need it
+ # Uncomment it to save images dimensions, if you need it
# t.integer :width
# t.integer :height
@@ -4,9 +4,6 @@ def self.up
t.string :name
t.timestamps
end
-
- Category.create :name => "General"
- Category.create :name => "Nerdy stuff"
end
def self.down
@@ -1,23 +0,0 @@
-class AddGermanLanguage < ActiveRecord::Migration
- def self.up
- lang = 'de'
- first_theme = Theme.all.first.short
- first_layout = Layout.all(first_theme).first.filename
- root = Page.create :title => lang, :pretty_url => lang, :lang => lang
- root.children.create :title => "Home #{lang}",
- :pretty_url => "home_#{lang}",
- :lang => lang,
- :visible_in_menu => true,
- :reserved => false,
- :published => true,
- :layout_name => first_layout,
- :publish_at => Time.now,
- :meta_title => "Home #{lang}",
- :meta_description => "Home #{lang}"
- end
-
- def self.down
- german_pages = Page.where("lang = ?", "de")
- german_pages.map{|p| p.destroy}
- end
-end
@@ -7,14 +7,6 @@ def self.up
end
add_column :associations, :article_layout_id, :integer
-
- theme = Setting.first.theme_name
- first_layout = Layout.all(theme).first.filename
-
- ["it", "en", "de", "cn"].each do |lang|
- ArticleLayout.create(:layout_name => first_layout, :lang => lang )
- end
-
end
def self.down
@@ -8,13 +8,10 @@ def self.up
change_column :settings, :site_page_title, :string, :default => "My new RailsYard site"
rename_column :articles, :meta_keyword, :meta_keywords
rename_column :articles, :meta_desc, :meta_description
-
- settings = Setting.first
- settings.update_attribute(:site_page_title, "My new RailsYard site") if settings.site_page_title.blank?
end
def self.down
- #rename_column :articles, :meta_description, :meta_desc
+ rename_column :articles, :meta_description, :meta_desc
rename_column :articles, :meta_keywords, :meta_keyword
change_column :settings, :site_page_title, :string
rename_column :settings, :default_page_desc, :site_desc
View
@@ -1,52 +1,47 @@
-# This file should contain all the record creation needed to seed the database with its default values.
-# This will import some contents into the db just to have some example
-
-public
+# Pages
+first_theme = Theme.all.first.short
+first_layout = Layout.all(first_theme).first.filename
+
+["it", "en", "de"].each do |lang|
+ puts "------------------------- Creating root language page \'#{lang}\' -------------------------"
+ root = Page.create :title => lang, :pretty_url => lang, :lang => lang
+ root.children.create( :title => "Home #{lang}",
+ :pretty_url => "home_#{lang}",
+ :lang => lang,
+ :visible_in_menu => true,
+ :reserved => false,
+ :published => true,
+ :layout_name => first_layout,
+ :publish_at => Time.now,
+ :meta_title => "Home #{lang}",
+ :meta_description => "Home #{lang}" )
+end
-def generate_page(parent, title, pretty_url, the_layout)
- pg = parent.children.create :parent => parent, :title => title, :pretty_url => "#{pretty_url}#{"-"+parent.lang if parent.lang!='en'}", :lang => parent.lang, :visible_in_menu => true, :reserved => false, :published => true, :layout_name => the_layout, :publish_at => Time.now, :meta_title => title, :meta_description => title
- pg.snippets.create :title => "Two levels menu", :area => "header", :cell_controller => "menu", :cell_action => "two_levels", :handler => "menu%two_levels%#{rand(99999).to_s.center(5, rand(9).to_s)}"
- pg.snippets.create :title => "Footer menu", :area => "footer", :cell_controller => "menu", :cell_action => "footer", :handler => "menu%footer%#{rand(99999).to_s.center(5, rand(9).to_s)}"
- if the_layout == "two_columns.html.erb" or the_layout == "three_columns.html.erb"
- pg.snippets.create :title => "Siblings menu", :area => "left", :cell_controller => "menu", :cell_action => "siblings", :handler => "menu%siblings%#{rand(99999).to_s.center(5, rand(9).to_s)}"
- end
- pg
+# Roles
+["admin", "article_writer", "premium_user", "registered_user"].each do |role|
+ puts "------------------------- Creating role \'#{role}\' ------------------------------------"
+ Role.create :name => role
end
-private
-# Creating pages
-home = "home.html.erb"
-single_column = "single_column.html.erb"
-two_columns = "two_columns.html.erb"
-three_columns = "three_columns.html.erb"
+# Users
+admin_role = Role.find_by_name('admin')
+user = User.create( :email => 'admin@example.com', :firstname => 'Admin', :lastname => 'Surname', :password => 'changeme', :password_confirmation => 'changeme' )
+user.confirmed_at, user.lang, user.enabled = Time.now, 'en', true
+user.roles << admin_role
+user.save
+puts "------------------------- Creating user email \'#{user.email}\', password \'changeme\'-------------------------"
-Setting.first.update_attribute(:theme_name, "rough") # does not work if called from rake ry:init task
+# Settings
+Setting.create :site_page_title => "My new RailsYard site", :default_lang => "en"
-Page.all.map do |p|
- p.snippets.map{|s| s.update_attribute(:area, "limbo")}
- p.update_attribute(:layout_name, home)
-end
+# Categories
+Category.create :name => "General"
+Category.create :name => "Nerdy stuff"
+# Article Layouts
+theme = Setting.first.theme_name
+first_layout = Layout.all(theme).first.filename
-Language.all.each do |lang|
- root = Page.find_by_title(lang.short)
- # Adding some snippets to home pages
- home = root.children.first
- home.snippets.create :title => "Two levels menu", :area => "header", :cell_controller => "menu", :cell_action => "two_levels", :handler => "menu%two_levels%#{rand(99999).to_s.center(5, rand(9).to_s)}"
- home.snippets.create :title => "Footer menu", :area => "footer", :cell_controller => "menu", :cell_action => "footer", :handler => "menu%footer%#{rand(99999).to_s.center(5, rand(9).to_s)}"
-
- # Generating new pages
- first = generate_page(root, "First Group", "first", single_column)
- generate_page(first, "1st page", "sub-first", single_column)
- generate_page(first, "2nd page", "sub-second", two_columns)
- generate_page(first, "3d page", "sub-third", three_columns)
- puts "Generated first group of pages for language \"#{lang.name}\""
-
- second = generate_page(root, "Second Group", "second", single_column)
- generate_page(second, "4th page", "sub-fourth", single_column)
- generate_page(second, "5th page", "sub-fifth", two_columns)
- generate_page(second, "6th page", "sub-sixth", three_columns)
- puts "Generated second group of pages for language \"#{lang.name}\""
+["it", "en", "de", "cn"].each do |lang|
+ ArticleLayout.create(:layout_name => first_layout, :lang => lang )
end
-
-

0 comments on commit 3c83173

Please sign in to comment.