public
Description:
Homepage: http://www.michaelbarton.me.uk
Clone URL: git://github.com/michaelbarton/cost_in_evolution.git
cost_in_evolution / Rakefile
100644 94 lines (76 sloc) 2.539 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
PROJECT_ROOT = File.expand_path(File.dirname(__FILE__))
 
require File.dirname(__FILE__) + '/config/environment.rb'
load File.dirname(__FILE__) + '/analysis/project.rake'
 
namespace :log do
  desc 'Clears all log files'
  task :clear do
    Dir.glob(PROJECT_ROOT + '/log/*.log').each { |file| File.delete(file) }
  end
end
 
namespace :db do
 
  desc "Build database tables based on model defined proterties"
  task :create do
    ActiveRecord::Migrator.migrate(PROJECT_ROOT + '/model/migrations',nil)
  end
 
  desc "Clears all database tables"
  task :drop do
    ActiveRecord::Migrator.migrate(PROJECT_ROOT + '/model/migrations',0)
  end
 
  desc "Drops, then recreates the database tables"
  task :recreate => [:drop,:create]
end
 
Spec::Rake::SpecTask.new do |t|
    t.pattern = 'spec/**/*.spec.rb'
end
 
desc 'Reset then rebuild the project'
task :rebuild => [
  'log:clear',
  'db:drop',
  'db:create',
  'analysis:analysis_rebuild',
  'www_rebuild'
]
 
namespace 'www' do
 
  desc 'Clears website files and data'
  task :clear do
    Project.delete_all
    Stage.delete_all
    Dir.glob("www/site/*.html").each {|x| File.delete(x)}
  end
 
  desc 'Loads analysis descriptions'
  task :load => ['clear']do
    # Load project description
    file = PROJECT_ROOT + '/analysis/description.markdown'
    File.open(file) do |f|
      Project.create({
        :title => f.readline.gsub(/#\s+/,''),
        :description => f.read,
        :major_version => PROJECT_VERSION.split('.')[0].to_i,
        :minor_version => PROJECT_VERSION.split('.')[1].to_i,
        :tiny_version => PROJECT_VERSION.split('.')[2].to_i,
        :last_modified => Date.parse(File.mtime(file).to_s)
      })
    end
    # Load stage information
    dirs = Dir.glob(PROJECT_ROOT + '/analysis/*').select {|x| File.directory?(x) }
    dirs.each do |dir|
      n = File.basename(dir).split('-').first.to_i
      Stage.create_from_markdown_erb(n,dir + '/description.markdown.erb')
    end
  end
 
  desc 'Rebuilds website files'
  task :build => ['load'] do
    haml = Haml::Engine.new(File.read(PROJECT_ROOT + '/www/views/layout.haml'))
 
    # Hash of pages and corresponding renderable objects
    pages = {
      'index' => Project.first,
      'stages' => Stage
    }
  
    # Add each stage to pages hash
    Stage.all.each {|stage| pages.store("stage_" + stage.number.to_s,stage)}
 
    # Render each page
    pages.each do |page,renderable|
      File.open(PROJECT_ROOT + "/www/site/#{page}.html",'w') {|x| x.puts haml.render(renderable)}
    end
 
  end
 
end