-
Notifications
You must be signed in to change notification settings - Fork 51
/
Rakefile
executable file
·176 lines (148 loc) · 5.34 KB
/
Rakefile
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
require 'rake'
require 'rake/tasklib'
require 'rake/testtask'
require 'rake/rdoctask'
require 'test/behaviors'
desc 'Default: run unit tests.'
task :default => :test
desc 'Test the Comatose plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.pattern = 'test/**/*_test.rb'
t.verbose = false
end
Behaviors::ReportTask.new :specs do |t|
t.pattern = 'test/**/*_test.rb'
end
desc 'Generate documentation for Comatose.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'Comatose'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README')
rdoc.rdoc_files.include('lib/**/*.rb')
end
def manifest_files
Dir.glob("**/*").delete_if do |item|
item.include?(".git") or item =~ /gem(?:spec)?$/ or File.directory?(item)
end
end
desc "Generate a MANIFEST files"
task :manifest do
File.open('MANIFEST', 'w') do |f|
f.write manifest_files.join("\n")
end
puts 'Created MANIFEST'
end
desc "Update GEMSPEC"
task :gemspec=>:manifest do
$: << 'lib'
require 'comatose/version'
gemspec_src =<<-EOGS
# Generated on #{ Time.now.to_s }
Gem::Specification.new do |s|
s.name = "comatose"
s.version = "#{ Comatose::VERSION }"
s.date = "#{ Time.now.strftime('%Y-%m-%d') }" # 2008-05-20
s.summary = "Micro CMS designed for being embedded into existing Rails applications"
s.email = "[email protected]"
s.rubyforge_project = 'comatose'
s.homepage = "http://comatose.rubyforge.org"
s.description = "Comatose is a micro CMS designed for being embedded into existing Rails applications."
s.has_rdoc = true
s.authors = ["M@ McCray"]
s.bindir = 'bin'
s.executables = ['comatose']
s.files = ["#{ manifest_files.join('", "') }"]
s.test_files = ["#{ manifest_files.delete_if{ |f| !f.include?('test/') }.join('", "') }"]
s.rdoc_options = ["--main", "README.rdoc"]
s.extra_rdoc_files = %w(README.rdoc CHANGELOG SPECS LICENSE)
#s.add_dependency("mime-types", ["> 0.0.0"])
end
EOGS
File.open("comatose.gemspec", 'w') do |f|
f.write gemspec_src
end
puts "Update GEMSPEC"
end
desc "Builds the admin customizable layout, the embedded layout have the JS and CSS inlined"
task :build do
require 'erb'
# Javascript
script_path = File.join('resources', 'public', 'javascripts', 'comatose_admin.js')
script_contents = ''
# Stylesheet
style_path = File.join('resources', 'public', 'stylesheets', 'comatose_admin.css')
style_contents = ''
# Layout Template
tmpl_path = File.join('resources', 'layouts', 'comatose_admin_template.html.erb')
tmpl_contents = ''
# Layout Target
layout_path = File.join('views', 'layouts', 'comatose_admin.html.erb')
layout_contents = ''
# Customizable Target
customizable_path = File.join('views', 'layouts', 'comatose_admin_customize.html.erb')
# Read the file contents...
File.open(script_path, 'r') {|f| script_contents = "<script>\n#{f.read}\n</script>" }
File.open(style_path, 'r') {|f| style_contents = "<style>\n#{f.read}\n</style>" }
File.open(tmpl_path, 'r') {|f| tmpl_contents = f.read }
# Create the final layout...
layout_contents = ERB.new( tmpl_contents ).result(binding)
# Write it out...
File.open(layout_path, 'w') {|f| f.write layout_contents }
# Now let's create the customizable one...
style_contents = "<%= stylesheet_link_tag 'comatose_admin' %>"
script_contents = "<%= javascript_include_tag 'comatose_admin' %>"
# Create the final layout...
layout_contents = ERB.new( tmpl_contents ).result(binding)
# Write it out...
File.open(customizable_path, 'w') {|f| f.write layout_contents }
# That's it -- we're done.
puts "Finished."
end
desc "Creates an empty rails application for use as a test harness"
task :test_harness do
target = ENV['TARGET']
sym_link = (ENV['LINK'].to_s == 'true')
if target.nil?
puts "You must specify a TARGET for the test harness"
exit(1)
else
target = File.expand_path target
if target == File.expand_path(File.dirname(__FILE__))
puts "You must specify a folder other than this one."
exit(1)
end
end
comatose_plugin_path = target / 'vendor' / 'plugins' / 'comatose'
puts "Creating test harness at #{ target }"
run_sh "rails -d sqlite3 #{target}"
if sym_link
run_sh "ln -s #{ File.dirname(__FILE__) } #{ comatose_plugin_path }"
else
run_sh "cp -r #{ File.dirname(__FILE__) }/ #{ comatose_plugin_path }"
end
run_sh "ruby #{ comatose_plugin_path / 'install.rb' }"
run_sh "ruby #{ target / 'script' / 'generate' } comatose_migration"
run_sh "ruby #{ comatose_plugin_path / 'bin' / 'comatose' } --plugin #{ target }"
run_sh "cd #{ target } && rake db:migrate"
run_sh "cp #{ target / 'db' / 'development.sqlite3' } #{target / 'db' / 'test.sqlite3'}"
run_sh "rm #{ target / 'public' / 'index.html' }"
run_sh "cp #{ comatose_plugin_path / 'views' / 'layouts' / 'comatose_content.html.erb' } #{ target / 'app' / 'views' / 'layouts' / 'comatose_content.html.erb' }"
# Remove me soon!
run_sh "cd #{ target } && ruby #{ target / 'script' / 'plugin' } install acts_as_tree"
run_sh "cd #{ target } && ruby #{ target / 'script' / 'plugin' } install acts_as_list"
puts "Done."
end
class String
def /(str)
File.join(self, str)
end
end
def run_sh(command)
puts "-------------------------------------------------------------------------------"
puts "Running `#{command}`:"
sh command
puts
puts
end