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.
Files changed (44) hide show
  1. data/README.rdoc +6 -3
  2. data/app/tanuki/attribute/attribute.rb +19 -0
  3. data/app/tanuki/base/base.rb +3 -0
  4. data/app/tanuki/controller/controller.rb +1 -1
  5. data/app/tanuki/controller/link.thtml +6 -6
  6. data/app/tanuki/meta_model/manager.ttxt +2 -0
  7. data/app/tanuki/meta_model/manager_base.ttxt +2 -0
  8. data/app/tanuki/meta_model/meta_model.rb +3 -0
  9. data/app/tanuki/meta_model/model.ttxt +2 -0
  10. data/app/tanuki/meta_model/model_base.ttxt +12 -0
  11. data/app/tanuki/model/model.rb +3 -0
  12. data/app/tanuki/page/missing/default.thtml +61 -2
  13. data/app/user/page/index/default.thtml +120 -120
  14. data/app/user/page/index/index.rb +1 -1
  15. data/bin/tanuki +185 -53
  16. data/config/common.rb +7 -0
  17. data/config/common_application.rb +31 -0
  18. data/config/development_application.rb +8 -0
  19. data/config/production_application.rb +2 -0
  20. data/lib/tanuki/application.rb +15 -19
  21. data/lib/tanuki/argument/base.rb +2 -2
  22. data/lib/tanuki/argument/integer.rb +2 -2
  23. data/lib/tanuki/argument/integer_range.rb +3 -3
  24. data/lib/tanuki/argument/string.rb +2 -2
  25. data/lib/tanuki/argument.rb +3 -3
  26. data/lib/tanuki/{controller_behavior.rb → behavior/controller_behavior.rb} +22 -21
  27. data/lib/tanuki/behavior/meta_model_behavior.rb +43 -0
  28. data/lib/tanuki/behavior/model_behavior.rb +112 -0
  29. data/lib/tanuki/{object_behavior.rb → behavior/object_behavior.rb} +6 -6
  30. data/lib/tanuki/configurator.rb +39 -76
  31. data/lib/tanuki/context.rb +31 -19
  32. data/lib/tanuki/{module_extensions.rb → extensions/module.rb} +3 -3
  33. data/lib/tanuki/extensions/object.rb +12 -0
  34. data/lib/tanuki/extensions/rack/static_dir.rb +18 -0
  35. data/lib/tanuki/i18n.rb +3 -1
  36. data/lib/tanuki/launcher.rb +3 -2
  37. data/lib/tanuki/loader.rb +37 -46
  38. data/lib/tanuki/template_compiler.rb +8 -7
  39. data/lib/tanuki/version.rb +1 -1
  40. data/lib/tanuki.rb +14 -8
  41. data/schema/tanuki/models/controller.yml +2 -3
  42. data/schema/tanuki/models/page.yml +7 -8
  43. metadata +35 -27
  44. 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 create test
13
- $ ruby test/main.rb
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://bitbucket.org/dimituri/tanuki]
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
@@ -0,0 +1,3 @@
1
+ class Tanuki_Base
2
+ include Tanuki::BaseBehavior
3
+ end
@@ -1,3 +1,3 @@
1
- class Tanuki_Controller < Tanuki_Object
1
+ class Tanuki_Controller < Tanuki_Base
2
2
  include Tanuki::ControllerBehavior
3
3
  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
@@ -0,0 +1,2 @@
1
+ class <%= class_name_for :manager %> < <%= class_name_for :manager_base %>
2
+ end
@@ -0,0 +1,2 @@
1
+ class <%= class_name_for :manager_base %> < Tanuki_Controller
2
+ end
@@ -0,0 +1,3 @@
1
+ class Tanuki_MetaModel < Tanuki_Base
2
+ include Tanuki::MetaModelBehavior
3
+ end
@@ -0,0 +1,2 @@
1
+ class <%= class_name_for :model %> < <%= class_name_for :model_base %>
2
+ end
@@ -0,0 +1,12 @@
1
+ class <%= class_name_for :model_base %> < Tanuki_Base
2
+ extend Tanuki::ModelBehavior
3
+
4
+ class << self
5
+ def extract_key(data)
6
+ [<% key.each do |field_name| %>data[:<%= field_name.inspect %>], <% end %>]
7
+ end
8
+
9
+ def get(ctx,*args)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ class Tanuki_Model
2
+ include Tanuki::ModelBehavior
3
+ end
@@ -1,2 +1,61 @@
1
- <h1>Oh no!</h1>
2
- <p>Tanuki broke free at <%= ctx.env['REQUEST_URI'] %>!</p>
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, type <code>rake tanuki:models</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>
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
- class << self
4
- def create(name)
5
- require 'fileutils'
6
- version
7
- puts "\n creating #{name = name.downcase}"
8
- FileUtils.mkdir name
9
- puts " copying app/tanuki"
10
- FileUtils.mkdir_p File.join(name, 'app', 'tanuki')
11
- FileUtils.cp_r File.expand_path(File.join('..', '..', 'app', 'tanuki'), __FILE__), File.join(name, 'app')
12
- puts " copying app/user"
13
- FileUtils.mkdir_p File.join(name, 'app', 'user')
14
- FileUtils.cp_r File.expand_path(File.join('..', '..', 'app', 'user'), __FILE__), File.join(name, 'app')
15
- puts " creating cache"
16
- FileUtils.mkdir(File.join(name, 'cache'))
17
- puts " copying schema"
18
- FileUtils.mkdir(File.join(name, 'schema'))
19
- FileUtils.cp_r File.expand_path(File.join('..', '..', 'schema'), __FILE__), name
20
- puts " writing main"
21
- File.open(File.join(name, 'main.rb'), 'w') {|file| file.write "require 'tanuki'\nTanuki.development_application" }
22
- end
23
-
24
- def help
25
- version
26
- puts "\nbasic commands:\n"
27
- {
28
- 'help' => 'show help (this text)',
29
- 'create' => 'create a new app with the given name',
30
- 'version' => 'show framework version'
31
- }.each_pair {|k, v| puts ' %-7s %s' % [k, v] }
32
- end
33
-
34
- def init
35
- case ARGV[0]
36
- when /\Ac(r(e(a(te?)?)?)?)?\Z/, '--create', '-c' then create(ARGV[1])
37
- when /\Ah(e(lp?)?)?\Z/, '--help', '-h', nil then help
38
- when /\Av(e(r(s(i(on?)?)?)?)?)?\Z/, '--version', '-v' then version
39
- else create(ARGV[0])
40
- end
41
- end
42
-
43
- def version
44
- begin
45
- require 'tanuki/version'
46
- rescue LoadError
47
- $:.unshift File.expand_path(File.join('..', '..', 'lib'), __FILE__)
48
- require 'tanuki/version'
49
- end
50
- puts "Tanuki version #{VERSION}"
51
- end
52
- end
53
- end
54
-
55
- Tanuki.init if File.basename(__FILE__) == File.basename($0)
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)
data/config/common.rb ADDED
@@ -0,0 +1,7 @@
1
+ # Paths
2
+ set :app_root, proc { File.join(root, 'app') }
3
+ set :gen_root, proc { File.join(root, 'gen') }
4
+ set :schema_root, proc { File.join(root, 'schema') }
5
+
6
+ # Cache
7
+ set :templates, {}