public
Description: Collection of Sinatra specific rake tasks
Homepage:
Clone URL: git://github.com/CarlosGabaldon/sinatra-rake-tasks.git
sinatra-rake-tasks / rakefile
100644 65 lines (53 sloc) 1.589 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
alias :original_directory :directory
def directory(dir)
  original_directory dir
  Rake::Task[dir]
end
 
 
namespace :sinatra do
  task :create_dir => [
    directory('db'),
    directory('public'),
    directory('views'),
  ]
  
  desc "Create the Sinatra project."
  task :create_project => :create_dir do
    view_files = ["edit.haml","error.haml","layout.haml",
            "list.haml", "not_found.haml", "view.haml"]
            
    rb_files = ["models.rb", "main.rb", "./db/seeds.rb"]
    
    puts "Creating the Sinatra project."
    view_files.each do |f|
      puts "Creating view file: #{f}"
      `touch ./views/#{f}`
    end
    rb_files.each do |f|
      puts "Creating ruby file: #{f}"
      `touch #{f}`
      
    end
    
    File.open('main.rb', 'w') do |file|
      file.puts "require 'rubygems'"
      file.puts "require 'sinatra'"
      file.puts "require 'sequel'"
      file.puts "require 'models'\n\n"
      file.puts "get '/' do"
      file.puts " haml :list"
      file.puts "end"
    end
    
    File.open('./views/layout.haml', 'w') do |file|
      file.puts "%html"
      file.puts " %head"
      file.puts " %title Let's go.."
      file.puts " %body"
      file.puts " #container"
      file.puts " = yield"
    end
    
    File.open('./views/list.haml', 'w') do |file|
      file.puts "%h2 Sinatra is taking orders.."
    end
  end
  
  desc 'Load the seed data from db/seeds.rb'
  task :seed_db do
    seed_file = "./db/seeds.rb"
    puts "Seeding database from: #{seed_file}"
    load(seed_file) if File.exist?(seed_file)
  end
  
  
end