2011-06-28 21:28:43 +02:00
|
|
|
$LOAD_PATH << File.expand_path(File.dirname(__FILE__)) + '/'
|
2011-06-24 13:28:19 +02:00
|
|
|
|
2011-08-10 19:49:02 +02:00
|
|
|
def require_files
|
|
|
|
require 'libs'
|
|
|
|
require 'rake/functions'
|
|
|
|
end
|
2011-06-24 13:28:19 +02:00
|
|
|
|
|
|
|
namespace :dm do
|
|
|
|
desc 'migrate to the database model'
|
|
|
|
task :migrate do
|
2011-08-10 19:49:02 +02:00
|
|
|
require_files
|
|
|
|
require 'dm-migrations'
|
2011-06-24 13:28:19 +02:00
|
|
|
DataMapper.auto_migrate!
|
|
|
|
end
|
|
|
|
|
|
|
|
desc 'upgrade the database to the latest model'
|
|
|
|
task :upgrade do
|
2011-08-10 19:49:02 +02:00
|
|
|
require_files
|
|
|
|
require 'dm-migrations'
|
2011-06-24 13:28:19 +02:00
|
|
|
DataMapper.auto_upgrade!
|
|
|
|
end
|
|
|
|
|
|
|
|
desc 'fill the database with dummy data from seeds.rb'
|
|
|
|
task :seed do
|
2011-08-10 19:49:02 +02:00
|
|
|
require_files
|
2011-06-24 13:28:19 +02:00
|
|
|
require 'seeds'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
desc 'open a console with all libs loaded and a database connection opened'
|
|
|
|
task :console do
|
|
|
|
sh "irb -rubygems -I#{File.expand_path(File.dirname(__FILE__))} -r libs"
|
|
|
|
end
|
2011-07-19 19:14:32 +02:00
|
|
|
|
2011-08-10 19:49:02 +02:00
|
|
|
namespace :account do
|
|
|
|
desc 'create a new account'
|
|
|
|
task :create do
|
|
|
|
require_files
|
|
|
|
require 'highline'
|
|
|
|
h = HighLine.new
|
|
|
|
acc = Account.new
|
|
|
|
acc.username = h.ask('username: ')
|
|
|
|
acc.password = h.ask('password: '){|q| q.echo = false }
|
|
|
|
acc.password_confirmation = h.ask('password again: '){|q| q.echo = false }
|
|
|
|
acc.email = h.ask('email: ')
|
|
|
|
acc.role = :admin
|
|
|
|
if acc.save
|
|
|
|
puts "account saved with id #{acc.id}"
|
|
|
|
else
|
|
|
|
puts "failure at saving the account: #{acc.errors.first}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-07-19 19:14:32 +02:00
|
|
|
namespace :import do
|
|
|
|
desc 'import all posts from this directory'
|
|
|
|
task :jekyll do
|
2011-08-10 19:49:02 +02:00
|
|
|
require_files
|
2011-07-19 19:14:32 +02:00
|
|
|
path = ask("Where are the jekyll posts?")
|
|
|
|
template = ask("What is the default template? (textile, markdown, ...?)")
|
|
|
|
if path.nil?
|
|
|
|
puts "no path given! - aborting"
|
|
|
|
else
|
|
|
|
posts = Dir[path + '/*'].sort
|
|
|
|
if posts.empty?
|
|
|
|
puts "no posts in this directory"
|
|
|
|
else
|
|
|
|
import_jekyll posts, template
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|