-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile.rb
93 lines (68 loc) · 1.62 KB
/
Rakefile.rb
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
require_relative "lib/habitat"
begin
require_relative "test/test"
rescue LoadError
end
require "fileutils"
require "pp"
def en(mod)
Dir.chdir(Habitat::Source.join("plugins", "backend")) do
["controllers", "templates", "views"].each do |bk|
target = "#{bk}/#{mod}"
unless File.exist?(target)
FileUtils.ln_s("../#{mod}/backend/#{bk}", target, :verbose => true)
end
end
end
end
def gen(mod, name, action)
cntrl = <<-HEREDOC
module Backend::Controllers::#{name.capitalize}
class #{action.capitalize}
include Backend::Action
def call(params)
end
end
end
HEREDOC
view = <<-HEREDOC
module Backend::Views::#{name.capitalize}
class #{action.capitalize}
include Backend::View
end
end
HEREDOC
template = <<-HEREDOC
#{action}
HEREDOC
Dir.chdir(Habitat::Source.join("plugins", mod, "backend")) do
{
"controllers/#{name}/#{action}.rb" => cntrl,
"views/#{name}/#{action}.rb" => view,
"templates/#{name}/#{action}.html.haml" => template
}.each_pair do |fn, fc|
if File.exist?(fn)
warn "existing: #{fn}"
else
FileUtils.mkdir_p(File.dirname(fn), :verbose => true)
File.open(fn, "w+"){|fp| fp.puts(fc)}
end
end
end
en(mod)
end
namespace :generate do
# rake "generate:action[snippet,snippet,index]"
task :action, [:module, :clz, :action] do |t, args|
mod, clz, action = args[:module], args[:clz], args[:action]
gen(mod, clz, action)
end
end
namespace :test do
task :test do
p Habitat::Quarters
end
task :plugins do
Habitat::Tests[:plugins].run_test(ENV["TEST"])
end
end