tanuki 0.1.3 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +6 -3
- data/app/tanuki/attribute/attribute.rb +19 -0
- data/app/tanuki/base/base.rb +3 -0
- data/app/tanuki/controller/controller.rb +1 -1
- data/app/tanuki/controller/link.thtml +6 -6
- data/app/tanuki/meta_model/manager.ttxt +2 -0
- data/app/tanuki/meta_model/manager_base.ttxt +2 -0
- data/app/tanuki/meta_model/meta_model.rb +3 -0
- data/app/tanuki/meta_model/model.ttxt +2 -0
- data/app/tanuki/meta_model/model_base.ttxt +12 -0
- data/app/tanuki/model/model.rb +3 -0
- data/app/tanuki/page/missing/default.thtml +61 -2
- data/app/user/page/index/default.thtml +120 -120
- data/app/user/page/index/index.rb +1 -1
- data/bin/tanuki +185 -53
- data/config/common.rb +7 -0
- data/config/common_application.rb +31 -0
- data/config/development_application.rb +8 -0
- data/config/production_application.rb +2 -0
- data/lib/tanuki/application.rb +15 -19
- data/lib/tanuki/argument/base.rb +2 -2
- data/lib/tanuki/argument/integer.rb +2 -2
- data/lib/tanuki/argument/integer_range.rb +3 -3
- data/lib/tanuki/argument/string.rb +2 -2
- data/lib/tanuki/argument.rb +3 -3
- data/lib/tanuki/{controller_behavior.rb → behavior/controller_behavior.rb} +22 -21
- data/lib/tanuki/behavior/meta_model_behavior.rb +43 -0
- data/lib/tanuki/behavior/model_behavior.rb +112 -0
- data/lib/tanuki/{object_behavior.rb → behavior/object_behavior.rb} +6 -6
- data/lib/tanuki/configurator.rb +39 -76
- data/lib/tanuki/context.rb +31 -19
- data/lib/tanuki/{module_extensions.rb → extensions/module.rb} +3 -3
- data/lib/tanuki/extensions/object.rb +12 -0
- data/lib/tanuki/extensions/rack/static_dir.rb +18 -0
- data/lib/tanuki/i18n.rb +3 -1
- data/lib/tanuki/launcher.rb +3 -2
- data/lib/tanuki/loader.rb +37 -46
- data/lib/tanuki/template_compiler.rb +8 -7
- data/lib/tanuki/version.rb +1 -1
- data/lib/tanuki.rb +14 -8
- data/schema/tanuki/models/controller.yml +2 -3
- data/schema/tanuki/models/page.yml +7 -8
- metadata +35 -27
- data/app/tanuki/object/object.rb +0 -3
data/README.rdoc
CHANGED
@@ -4,16 +4,19 @@ Tanuki is a web application framework inspired by the MVVM pattern with focus
|
|
4
4
|
on DRY code and extensibility. Tanuki tries to keep its looks close to
|
5
5
|
idiomatic Ruby, so you would feel at home.
|
6
6
|
|
7
|
+
Right now it's very raw, so don't expect things to work properly.
|
8
|
+
|
7
9
|
== Quick Start
|
8
10
|
|
9
11
|
Fire up the terminal and type:
|
10
12
|
|
11
13
|
$ gem install tanuki
|
12
|
-
$ tanuki
|
13
|
-
|
14
|
+
$ tanuki
|
15
|
+
tanuki> create test
|
16
|
+
tanuki> server
|
14
17
|
|
15
18
|
View the result at: http://localhost:3000
|
16
19
|
|
17
20
|
== Resources
|
18
21
|
|
19
|
-
{Home Page}[http://
|
22
|
+
{Home Page}[http://withballs.org]
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class Tanuki_Attribute
|
2
|
+
def initialize(cfg, owner)
|
3
|
+
#--
|
4
|
+
# created on demand (first access)
|
5
|
+
# cfg is a parsed yaml hash
|
6
|
+
# attribute owner object
|
7
|
+
# all Object and Collection attrs are defined in relations
|
8
|
+
@cfg = cfg
|
9
|
+
@owner = owner
|
10
|
+
end
|
11
|
+
|
12
|
+
def required?
|
13
|
+
@cfg[:required]
|
14
|
+
end
|
15
|
+
|
16
|
+
def value
|
17
|
+
# value of data (scalar, array, or hash)
|
18
|
+
end
|
19
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
% if current?
|
2
|
-
<span class="active"><%= self %></span>
|
3
|
-
% elsif active?
|
4
|
-
<a class="active" href="<%= self.link %>"><%= self %></a>
|
5
|
-
% else
|
6
|
-
<a href="<%= self.link %>"><%= self %></a>
|
1
|
+
% if current?
|
2
|
+
<span class="active"><%= self %></span>
|
3
|
+
% elsif active?
|
4
|
+
<a class="active" href="<%= self.link %>"><%= self %></a>
|
5
|
+
% else
|
6
|
+
<a href="<%= self.link %>"><%= self %></a>
|
7
7
|
% end
|
@@ -1,2 +1,61 @@
|
|
1
|
-
|
2
|
-
<
|
1
|
+
<!DOCTYPE HTML>
|
2
|
+
<html lang="en">
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<title>404 Not Found</title>
|
6
|
+
<style type="text/css" media="screen">
|
7
|
+
body {
|
8
|
+
margin: 0;
|
9
|
+
padding: 0;
|
10
|
+
font-family: 'Trebuchet MS', Helvetica, sans-serif;
|
11
|
+
font-size: 11pt;
|
12
|
+
background-color: #f5f4ef;
|
13
|
+
color: #000305;
|
14
|
+
}
|
15
|
+
|
16
|
+
h1 {
|
17
|
+
margin: 30px 40px 20px 40px;
|
18
|
+
padding: 0;
|
19
|
+
font-size: 22pt;
|
20
|
+
}
|
21
|
+
|
22
|
+
div {
|
23
|
+
background-color: #fff;
|
24
|
+
margin: 20px 30px 30px 30px;
|
25
|
+
padding: 15px 20px;
|
26
|
+
border-radius: 10px;
|
27
|
+
-moz-border-radius: 10px;
|
28
|
+
-webkit-border-radius: 10px;
|
29
|
+
}
|
30
|
+
|
31
|
+
code {
|
32
|
+
font-family: 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Menlo, Monaco, Consolas, 'Courier New', monospace;
|
33
|
+
font-size: 10pt;
|
34
|
+
background-color: #fffccc;
|
35
|
+
padding: 1px 3px;
|
36
|
+
}
|
37
|
+
</style>
|
38
|
+
</head>
|
39
|
+
<body>
|
40
|
+
<h1>Page not found!</h1>
|
41
|
+
<div>
|
42
|
+
<p>It seems that the page <code><%= ctx.env['REQUEST_URI'] %></code> at <a href="/"><%= ctx.env['HTTP_HOST'] %></a></p>
|
43
|
+
<ul>
|
44
|
+
<li>has moved,</li>
|
45
|
+
<li>no longer exists,</li>
|
46
|
+
<li>or never existed.</li>
|
47
|
+
</ul>
|
48
|
+
% if ctx.development
|
49
|
+
Controller chain: <ul>
|
50
|
+
% ctrl = self
|
51
|
+
% traceback = []
|
52
|
+
% traceback << ctrl while ctrl = ctrl.logical_parent
|
53
|
+
% traceback.reverse_each do |ctrl|
|
54
|
+
<li><code><%= ctrl.class %> @ <%= ctrl.link %></code></li>
|
55
|
+
% end
|
56
|
+
<li><code><%= self.class %> @ <%= self.link %></code></li>
|
57
|
+
</ul>
|
58
|
+
% end
|
59
|
+
</div>
|
60
|
+
</body>
|
61
|
+
</html>
|
@@ -1,121 +1,121 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html lang="en">
|
3
|
-
<head>
|
4
|
-
<meta charset="utf-8" />
|
5
|
-
<title>Welcome to Tanuki</title>
|
6
|
-
<style type="text/css" media="screen">
|
7
|
-
body {
|
8
|
-
margin: 0;
|
9
|
-
padding: 0;
|
10
|
-
font-family: 'Trebuchet MS', Helvetica, sans-serif;
|
11
|
-
font-size: 11pt;
|
12
|
-
background-color: #f5f4ef;
|
13
|
-
color: #000305;
|
14
|
-
}
|
15
|
-
|
16
|
-
#header {
|
17
|
-
margin: 0 auto;
|
18
|
-
width: 540px;
|
19
|
-
}
|
20
|
-
|
21
|
-
div.top {
|
22
|
-
background-color: #fff;
|
23
|
-
margin: 0 auto 20px auto;
|
24
|
-
padding: 15px 20px 0 20px;
|
25
|
-
width: 540px;
|
26
|
-
border-radius: 10px;
|
27
|
-
-moz-border-radius: 10px;
|
28
|
-
-webkit-border-radius: 10px;
|
29
|
-
}
|
30
|
-
|
31
|
-
h1 {
|
32
|
-
margin: 20px 0;
|
33
|
-
padding: 0;
|
34
|
-
font-size: 22pt;
|
35
|
-
}
|
36
|
-
|
37
|
-
h1 em {
|
38
|
-
display: block;
|
39
|
-
font-style: normal;
|
40
|
-
font-size: 12pt;
|
41
|
-
color: #777a7c;
|
42
|
-
}
|
43
|
-
|
44
|
-
h2 {
|
45
|
-
margin: 0 0 15px 0;
|
46
|
-
padding: 0;
|
47
|
-
font-size: 16pt;
|
48
|
-
}
|
49
|
-
|
50
|
-
#next ol {
|
51
|
-
margin: 0;
|
52
|
-
padding-bottom: 25px;
|
53
|
-
}
|
54
|
-
|
55
|
-
#next li {
|
56
|
-
margin: 0;
|
57
|
-
padding: 0;
|
58
|
-
font-size: 16pt;
|
59
|
-
font-weight: bold;
|
60
|
-
color: #c74451;
|
61
|
-
}
|
62
|
-
|
63
|
-
#next li span {
|
64
|
-
font-size: 11pt;
|
65
|
-
font-weight: normal;
|
66
|
-
color: #000305;
|
67
|
-
}
|
68
|
-
|
69
|
-
code {
|
70
|
-
font-family: 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Menlo, Monaco, Consolas, 'Courier New', monospace;
|
71
|
-
font-size: 10pt;
|
72
|
-
background-color: #fffccc;
|
73
|
-
padding: 1px 3px;
|
74
|
-
}
|
75
|
-
|
76
|
-
#env div {
|
77
|
-
padding-bottom: 25px;
|
78
|
-
}
|
79
|
-
|
80
|
-
#env table {
|
81
|
-
margin: 0;
|
82
|
-
padding: 0;
|
83
|
-
border-collapse: collapse;
|
84
|
-
color: #444;
|
85
|
-
}
|
86
|
-
|
87
|
-
#env table th {
|
88
|
-
text-align: left;
|
89
|
-
}
|
90
|
-
|
91
|
-
#env table td {
|
92
|
-
padding-left: 20px;
|
93
|
-
font-size: 10pt;
|
94
|
-
}
|
95
|
-
</style>
|
96
|
-
</head>
|
97
|
-
<body>
|
98
|
-
<div id="header">
|
99
|
-
<h1>It Works! <em>You have been granted one Tanuki.</em></h1>
|
100
|
-
</div>
|
101
|
-
<div class="top" id="next">
|
102
|
-
<h2>What to do next</h2>
|
103
|
-
<div>
|
104
|
-
<p>Here's a few suggestions to get things going:</p>
|
105
|
-
<ol>
|
106
|
-
<li><span>To use a database, describe its contents in <code>schema/user</code>.</span></li>
|
107
|
-
<li><span>To generate models from your schema,
|
108
|
-
<li><span>To add or edit controllers, navigate to <code>app/user</code>.</span></li>
|
109
|
-
</ol>
|
110
|
-
</div>
|
111
|
-
</div>
|
112
|
-
<div class="top" id="env">
|
113
|
-
<h2>Your setup</h2>
|
114
|
-
<div><table>
|
115
|
-
<tr><th>Ruby</th><td><%= RUBY_VERSION %> (<%= RUBY_RELEASE_DATE %>) [<%= RUBY_PLATFORM %>]</td></tr>
|
116
|
-
<tr><th>Rack</th><td><%= Rack.version %> (on <%= ctx.env['SERVER_SOFTWARE'] %>)</td></tr>
|
117
|
-
<tr><th>Tanuki</th><td><%= Tanuki::VERSION %></td></tr>
|
118
|
-
</table></div>
|
119
|
-
</div>
|
120
|
-
</body>
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html lang="en">
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8" />
|
5
|
+
<title>Welcome to Tanuki</title>
|
6
|
+
<style type="text/css" media="screen">
|
7
|
+
body {
|
8
|
+
margin: 0;
|
9
|
+
padding: 0;
|
10
|
+
font-family: 'Trebuchet MS', Helvetica, sans-serif;
|
11
|
+
font-size: 11pt;
|
12
|
+
background-color: #f5f4ef;
|
13
|
+
color: #000305;
|
14
|
+
}
|
15
|
+
|
16
|
+
#header {
|
17
|
+
margin: 0 auto;
|
18
|
+
width: 540px;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.top {
|
22
|
+
background-color: #fff;
|
23
|
+
margin: 0 auto 20px auto;
|
24
|
+
padding: 15px 20px 0 20px;
|
25
|
+
width: 540px;
|
26
|
+
border-radius: 10px;
|
27
|
+
-moz-border-radius: 10px;
|
28
|
+
-webkit-border-radius: 10px;
|
29
|
+
}
|
30
|
+
|
31
|
+
h1 {
|
32
|
+
margin: 20px 0;
|
33
|
+
padding: 0;
|
34
|
+
font-size: 22pt;
|
35
|
+
}
|
36
|
+
|
37
|
+
h1 em {
|
38
|
+
display: block;
|
39
|
+
font-style: normal;
|
40
|
+
font-size: 12pt;
|
41
|
+
color: #777a7c;
|
42
|
+
}
|
43
|
+
|
44
|
+
h2 {
|
45
|
+
margin: 0 0 15px 0;
|
46
|
+
padding: 0;
|
47
|
+
font-size: 16pt;
|
48
|
+
}
|
49
|
+
|
50
|
+
#next ol {
|
51
|
+
margin: 0;
|
52
|
+
padding-bottom: 25px;
|
53
|
+
}
|
54
|
+
|
55
|
+
#next li {
|
56
|
+
margin: 0;
|
57
|
+
padding: 0;
|
58
|
+
font-size: 16pt;
|
59
|
+
font-weight: bold;
|
60
|
+
color: #c74451;
|
61
|
+
}
|
62
|
+
|
63
|
+
#next li span {
|
64
|
+
font-size: 11pt;
|
65
|
+
font-weight: normal;
|
66
|
+
color: #000305;
|
67
|
+
}
|
68
|
+
|
69
|
+
code {
|
70
|
+
font-family: 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Menlo, Monaco, Consolas, 'Courier New', monospace;
|
71
|
+
font-size: 10pt;
|
72
|
+
background-color: #fffccc;
|
73
|
+
padding: 1px 3px;
|
74
|
+
}
|
75
|
+
|
76
|
+
#env div {
|
77
|
+
padding-bottom: 25px;
|
78
|
+
}
|
79
|
+
|
80
|
+
#env table {
|
81
|
+
margin: 0;
|
82
|
+
padding: 0;
|
83
|
+
border-collapse: collapse;
|
84
|
+
color: #444;
|
85
|
+
}
|
86
|
+
|
87
|
+
#env table th {
|
88
|
+
text-align: left;
|
89
|
+
}
|
90
|
+
|
91
|
+
#env table td {
|
92
|
+
padding-left: 20px;
|
93
|
+
font-size: 10pt;
|
94
|
+
}
|
95
|
+
</style>
|
96
|
+
</head>
|
97
|
+
<body>
|
98
|
+
<div id="header">
|
99
|
+
<h1>It Works! <em>You have been granted one Tanuki.</em></h1>
|
100
|
+
</div>
|
101
|
+
<div class="top" id="next">
|
102
|
+
<h2>What to do next</h2>
|
103
|
+
<div>
|
104
|
+
<p>Here's a few suggestions to get things going:</p>
|
105
|
+
<ol>
|
106
|
+
<li><span>To use a database, describe its contents in <code>schema/user</code>.</span></li>
|
107
|
+
<li><span>To generate models from your schema, run <code>tanuki generate</code>.</span></li>
|
108
|
+
<li><span>To add or edit controllers, navigate to <code>app/user</code>.</span></li>
|
109
|
+
</ol>
|
110
|
+
</div>
|
111
|
+
</div>
|
112
|
+
<div class="top" id="env">
|
113
|
+
<h2>Your setup</h2>
|
114
|
+
<div><table>
|
115
|
+
<tr><th>Ruby</th><td><%= RUBY_VERSION %> (<%= RUBY_RELEASE_DATE %>) [<%= RUBY_PLATFORM %>]</td></tr>
|
116
|
+
<tr><th>Rack</th><td><%= Rack.version %> (on <%= ctx.env['SERVER_SOFTWARE'] %>)</td></tr>
|
117
|
+
<tr><th>Tanuki</th><td><%= Tanuki::VERSION %></td></tr>
|
118
|
+
</table></div>
|
119
|
+
</div>
|
120
|
+
</body>
|
121
121
|
</html>
|
@@ -1,2 +1,2 @@
|
|
1
|
-
class User_Page_Index < Tanuki_Controller
|
1
|
+
class User_Page_Index < Tanuki_Controller
|
2
2
|
end
|
data/bin/tanuki
CHANGED
@@ -1,55 +1,187 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
module Tanuki
|
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
|
-
require 'tanuki/
|
46
|
-
|
47
|
-
|
48
|
-
require 'tanuki/
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
3
|
+
|
4
|
+
module Utility
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def create(name)
|
9
|
+
unless name
|
10
|
+
puts "To use this command: `create <name>'"
|
11
|
+
return
|
12
|
+
end
|
13
|
+
require 'fileutils'
|
14
|
+
project_dir = File.expand_path(name)
|
15
|
+
if File.exists? project_dir
|
16
|
+
puts "File or directory `#{name}' already exists!"
|
17
|
+
return
|
18
|
+
end
|
19
|
+
version unless @in_repl
|
20
|
+
puts "\n creating #{name = name.downcase}"
|
21
|
+
FileUtils.mkdir project_dir
|
22
|
+
file_source = File.expand_path(File.join('..', '..'), __FILE__)
|
23
|
+
puts " creating #{File.join(name, 'app')}"
|
24
|
+
FileUtils.mkdir_p File.join(project_dir, 'app', 'user')
|
25
|
+
FileUtils.cp_r File.join(file_source, 'app', 'user'), File.join(project_dir, 'app')
|
26
|
+
puts " creating #{File.join(name, 'gen')}"
|
27
|
+
FileUtils.mkdir(gen_dir = File.join(project_dir, 'gen'))
|
28
|
+
FileUtils.chmod(0777, gen_dir)
|
29
|
+
puts " creating #{File.join(name, 'public')}"
|
30
|
+
FileUtils.mkdir(File.join(project_dir, 'public'))
|
31
|
+
puts " creating #{File.join(name, 'schema')}"
|
32
|
+
FileUtils.mkdir(File.join(project_dir, 'schema'))
|
33
|
+
Dir.chdir(project_dir) if @in_repl
|
34
|
+
end
|
35
|
+
|
36
|
+
def generate(cwd)
|
37
|
+
version unless @in_repl
|
38
|
+
cwd = File.expand_path(cwd ? cwd : '.')
|
39
|
+
puts "Working directory is: #{cwd}\nTo specify another: `generate <path>'"
|
40
|
+
require 'yaml'
|
41
|
+
require 'fileutils'
|
42
|
+
require 'tanuki/extensions/object'
|
43
|
+
require 'tanuki/behavior/meta_model_behavior'
|
44
|
+
require 'tanuki/behavior/model_behavior'
|
45
|
+
require 'tanuki/behavior/object_behavior'
|
46
|
+
require 'tanuki/configurator'
|
47
|
+
require 'tanuki/context'
|
48
|
+
require 'tanuki/loader'
|
49
|
+
require 'tanuki/template_compiler'
|
50
|
+
Loader.context = ctx = Context
|
51
|
+
cfg = Configurator.new(Context, cwd, File.expand_path(File.join('..', '..', 'config'), __FILE__))
|
52
|
+
cfg.load_config :common
|
53
|
+
cfg.config_root = File.join(cwd, 'config')
|
54
|
+
cfg.load_config :common, true
|
55
|
+
puts "\n looking for models"
|
56
|
+
@tried = {}
|
57
|
+
local_schema_root = File.expand_path(File.join('..', '..', 'schema'), __FILE__)
|
58
|
+
generate_in(ctx.schema_root, ctx)
|
59
|
+
generate_in(local_schema_root, ctx) if ctx.schema_root != local_schema_root
|
60
|
+
@tried.each_pair do |name, arys|
|
61
|
+
puts "\n found: #{name}"
|
62
|
+
arys.each_pair {|ary_name, ary| puts %{ #{ary_name}:\n - #{ary.join "\n - "}} unless ary.empty? }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def generate_in(schema_root, ctx)
|
67
|
+
Dir.entries(schema_root)[2..-1].each do |namespace_path|
|
68
|
+
namespace = namespace_path.capitalize
|
69
|
+
Dir.glob(File.join(schema_root, namespace_path, 'models', '*.yml')) do |file_path|
|
70
|
+
model_name = File.basename(file_path, '.yml').split('_').map {|s| s.capitalize }.join
|
71
|
+
if @tried.include? namespace_model_name = "#{namespace}.#{model_name}"
|
72
|
+
next
|
73
|
+
else
|
74
|
+
@tried[namespace_model_name] = {:generated => [], :failed => [], :skipped => []}
|
75
|
+
end
|
76
|
+
meta_model = Tanuki_MetaModel.new(namespace, model_name, YAML.load_file(file_path))
|
77
|
+
{
|
78
|
+
:model => false,
|
79
|
+
:model_base => true,
|
80
|
+
:manager => false,
|
81
|
+
:manager_base => true
|
82
|
+
}.each do |class_type, base|
|
83
|
+
class_name = meta_model.class_name_for class_type
|
84
|
+
path = Tanuki::Loader.class_path(class_name, base ? ctx.gen_root : ctx.app_root)
|
85
|
+
if base || !(File.exists? path)
|
86
|
+
begin
|
87
|
+
dirname = File.dirname(path)
|
88
|
+
FileUtils.mkdir_p dirname unless File.directory? dirname
|
89
|
+
File.open path, 'w' do |file|
|
90
|
+
writer = proc {|out| file.print out.to_s }
|
91
|
+
Loader.run_template({}, meta_model, class_type).call(writer, ctx)
|
92
|
+
end
|
93
|
+
@tried[namespace_model_name][:generated] << class_name unless base
|
94
|
+
rescue
|
95
|
+
@tried[namespace_model_name][:failed] << class_name unless base
|
96
|
+
end
|
97
|
+
else
|
98
|
+
@tried[namespace_model_name][:skipped] << class_name unless base
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def execute(args)
|
106
|
+
case args[0]
|
107
|
+
when 'create' then create(args[1])
|
108
|
+
when 'exit' then @in_repl ? (puts 'Bye bye!'; return false) : help
|
109
|
+
when 'generate' then generate(args[1])
|
110
|
+
when 'help' then help
|
111
|
+
when 'server' then return server(args[1])
|
112
|
+
when 'version' then version
|
113
|
+
when nil then start_repl unless @in_repl
|
114
|
+
else help
|
115
|
+
end
|
116
|
+
true
|
117
|
+
end
|
118
|
+
|
119
|
+
def help
|
120
|
+
version unless @in_repl
|
121
|
+
puts "\nbasic commands:\n"
|
122
|
+
commands = {}
|
123
|
+
commands['create'] = 'create a new app with the given name'
|
124
|
+
commands['exit'] = 'exit this utility' if @in_repl
|
125
|
+
commands['generate'] = 'generate models for application schema'
|
126
|
+
commands['help'] = 'show help (this text)'
|
127
|
+
commands['server'] = 'run application'
|
128
|
+
commands['version'] = 'show framework version'
|
129
|
+
commands.each_pair {|k, v| puts ' %-8s %s' % [k, v] }
|
130
|
+
end
|
131
|
+
|
132
|
+
def init
|
133
|
+
@in_repl = false
|
134
|
+
execute ARGV
|
135
|
+
end
|
136
|
+
|
137
|
+
def server(env=nil)
|
138
|
+
env = env ? env.to_sym : :development
|
139
|
+
puts %{Calling for a Tanuki in "#{pwd = Dir.pwd}"}
|
140
|
+
version unless @in_repl
|
141
|
+
require 'tanuki'
|
142
|
+
allow_run = false
|
143
|
+
begin
|
144
|
+
@cfg = Configurator.new(Context, pwd, File.expand_path(File.join('..', '..', 'config'), __FILE__))
|
145
|
+
@cfg.load_config(([:development, :production].include? env) ? :"#{env}_application" : :common_application)
|
146
|
+
@cfg.config_root = File.join(pwd, 'config')
|
147
|
+
@cfg.load_config :"#{env}_application", true
|
148
|
+
allow_run = true
|
149
|
+
rescue NameError => e
|
150
|
+
puts "Tanuki wanted `#{e.name}', but you didn't have any."
|
151
|
+
end
|
152
|
+
begin
|
153
|
+
Application.run
|
154
|
+
false
|
155
|
+
rescue Interrupt
|
156
|
+
puts 'Tanuki ran away!'
|
157
|
+
false
|
158
|
+
rescue SystemCallError
|
159
|
+
puts 'Tanuki ran away! Someone else is playing here.'
|
160
|
+
true
|
161
|
+
end if allow_run
|
162
|
+
end
|
163
|
+
|
164
|
+
def start_repl
|
165
|
+
@in_repl = true
|
166
|
+
version
|
167
|
+
print 'tanuki>'
|
168
|
+
print "\ntanuki>" while gets && execute($_.chomp.scan /(?<=")\w[\w\s]*(?=")|\w+/)
|
169
|
+
end
|
170
|
+
|
171
|
+
def version
|
172
|
+
begin
|
173
|
+
require 'tanuki/version'
|
174
|
+
rescue LoadError
|
175
|
+
$:.unshift File.expand_path(File.join('..', '..', 'lib'), __FILE__)
|
176
|
+
require 'tanuki/version'
|
177
|
+
end
|
178
|
+
puts "Tanuki version #{VERSION}"
|
179
|
+
end
|
180
|
+
|
181
|
+
end # end class << self
|
182
|
+
|
183
|
+
end # end Utility
|
184
|
+
|
185
|
+
end # end Tanuki
|
186
|
+
|
187
|
+
Tanuki::Utility.init if File.basename(__FILE__) == File.basename($0)
|