ref: master
script/sample-articles
#!/usr/bin/env ruby require_relative '../config/environment' require_relative '../lib/sample_data' include SampleData profiles = $environment.profiles categories = $environment.categories SUBJECTS = ['got a new car', 'release a new version of project X', "doesn't like wales no more", "doesn't use free-software no more"] TAGS = ['free-software', 'noosfero', 'development', 'rails', 'ruby'] EVENT_SUBJECTS = ['International Conference on %s', '%s day', '%s World Congress', '%s World Forum', '%s Summit', '%s Week'] THEMES = ['Sustainability', 'Free Software', 'Climate Change', 'Environment', 'Agile Development', 'Solidarity Economy', 'Debian', 'Perl'] print "Creating some Text articles: " for subject in SUBJECTS rand(20).times do |i| profile = profiles.sample name = "%s #{subject}" % profile.name next if profile.articles.where(:slug => name.to_slug).first article = TextArticle.new( :name => name, :body => name, :tag_list => [TAGS.sample, TAGS.sample], :profile => profile ) save article do article.add_category categories.sample end end end done print "Creating some galleries: " for subject in SUBJECTS rand(20).times do |i| profile = profiles.sample name = "Gallery %s #{subject}" % profile.name next if profile.articles.where(:slug => name.to_slug).first save Gallery.new( :name => name, :body => name, :tag_list => [TAGS.sample, TAGS.sample], :profile => profile ) end end done print "Creating some events: " for subject in EVENT_SUBJECTS for theme in THEMES profile = profiles.sample name = subject % theme next if profile.articles.where(:slug => name.to_slug).first event = Event.new( :name => name, :profile => profile, :start_date => Date.today + (-30 + rand(60)).days, :tag_list => [TAGS.sample, TAGS.sample] ) save event do 3.times do category = categories.sample event.add_category category end end end end done print "Creating some posts: " for subject in SUBJECTS rand(20).times do |i| profile = profiles.sample name = "%s #{subject}" % profile.name article = TextArticle.new( :name => name, :body => name, :tag_list => [TAGS.sample, TAGS.sample], :profile => profile, :parent_id => profile.blog.id ) save article do article.add_category categories.sample end end end done