Sha256: f65d2278f25ea7287a2b5ae1830c099ed8621522261f21126107b3043e754891

Contents?: true

Size: 1.26 KB

Versions: 2

Compression:

Stored size: 1.26 KB

Contents

namespace :db do
  namespace :sample do
    desc "Create admin username and password"
    task :cms => :environment do
    
      # dependent on spree_core
      require 'faker'
      
      unless Page.count == 0
        require 'highline/import'
        continue = ask("Sample data will destroy existing data. Continue? [y/n]", String) do |q|
          q.echo = true
          q.whitespace = :strip
        end
        exit unless continue =~ /y/i
        Page.destroy_all
      end
          
      images = Dir[File.expand_path("../sample", __FILE__) + "/*.jpg"]
      
      home = Page.create(:title => "Home", :path => "/")
      home.contents.first.update_attributes(:body => Faker::Lorem.paragraphs().join("\n\n"), :context => "main")
      home.contents.create(:title => Faker::Lorem.words(3 + rand(3)).join(" "), :body => Faker::Lorem.sentence, :context => "intro")
      
      images.each {|image| 
        PageImage.create(:viewable => home, :attachment => File.open(image), :alt => "Sailing") 
      }
      
      %w(About Contact).each do |title|
        page = Page.create(:title => title, :path => title.downcase)
        page.contents.first.update_attributes(:body => Faker::Lorem.paragraphs().join("\n\n"))
      end
      
      puts "done."
            
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spree_essential_cms-0.2.1 lib/tasks/sample.rake
spree_essential_cms-0.2.0 lib/tasks/sample.rake