manveru-innate 2009.04 → 2009.04.01
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +0 -258
- data/MANIFEST +22 -23
- data/README.md +9 -1
- data/Rakefile +6 -6
- data/example/app/retro_games.rb +8 -8
- data/example/app/todo/layout/{default.xhtml → default.erb} +1 -1
- data/example/app/todo/view/{index.xhtml → index.erb} +11 -11
- data/example/app/whywiki_erb/start.rb +1 -2
- data/example/app/whywiki_erb/view/{edit.erb → edit.html.erb} +0 -0
- data/example/app/whywiki_erb/view/{index.erb → index.html.erb} +0 -0
- data/example/howto_spec.rb +1 -1
- data/example/provides.rb +6 -9
- data/example/session.rb +3 -3
- data/innate.gemspec +14 -6
- data/lib/innate.rb +18 -12
- data/lib/innate/action.rb +11 -22
- data/lib/innate/cache/file_based.rb +0 -2
- data/lib/innate/core_compatibility/basic_object.rb +10 -0
- data/lib/innate/core_compatibility/string.rb +3 -0
- data/lib/innate/dynamap.rb +0 -5
- data/lib/innate/helper.rb +29 -20
- data/lib/innate/helper/cgi.rb +19 -32
- data/lib/innate/helper/link.rb +2 -2
- data/lib/innate/helper/partial.rb +93 -0
- data/lib/innate/helper/redirect.rb +1 -1
- data/lib/innate/helper/send_file.rb +1 -9
- data/lib/innate/mock.rb +3 -2
- data/lib/innate/node.rb +51 -78
- data/lib/innate/options.rb +1 -1
- data/lib/innate/request.rb +23 -3
- data/lib/innate/response.rb +7 -0
- data/lib/innate/session.rb +2 -1
- data/lib/innate/spec.rb +50 -6
- data/lib/innate/version.rb +1 -1
- data/lib/innate/view/erb.rb +1 -1
- data/lib/innate/view/etanni.rb +2 -2
- data/lib/innate/view/none.rb +1 -1
- data/spec/example/session.rb +14 -8
- data/spec/innate/action/layout.rb +1 -1
- data/spec/innate/action/layout/file_layout.erb +1 -0
- data/spec/innate/helper/aspect.rb +6 -6
- data/spec/innate/helper/flash.rb +47 -28
- data/spec/innate/helper/link.rb +0 -8
- data/spec/innate/helper/partial.rb +101 -0
- data/spec/innate/helper/redirect.rb +43 -58
- data/spec/innate/helper/view/aspect_hello.erb +1 -0
- data/spec/innate/helper/view/locals.erb +1 -0
- data/spec/innate/helper/view/loop.erb +4 -0
- data/spec/innate/helper/view/num.erb +1 -0
- data/spec/innate/helper/view/partial.erb +1 -0
- data/spec/innate/helper/view/recursive.erb +8 -0
- data/spec/innate/node/node.rb +13 -5
- data/spec/innate/node/view/another_layout/{another_layout.xhtml → another_layout.erb} +1 -1
- data/spec/innate/node/view/{bar.xhtml → bar.erb} +0 -0
- data/spec/innate/node/view/foo.html.erb +1 -0
- data/spec/innate/node/view/{only_view.xhtml → only_view.erb} +0 -0
- data/spec/innate/node/view/with_layout.erb +1 -0
- data/spec/innate/provides.rb +2 -2
- data/spec/innate/provides/list.html.erb +1 -0
- data/spec/innate/provides/list.txt.erb +1 -0
- data/spec/innate/session.rb +15 -14
- data/spec/innate/state/fiber.rb +7 -8
- data/tasks/bacon.rake +21 -38
- data/tasks/install_dependencies.rake +4 -2
- data/tasks/release.rake +9 -48
- metadata +57 -29
- data/lib/innate/helper/render.rb +0 -87
- data/spec/example/app/retro_games.rb +0 -30
- data/spec/example/provides.rb +0 -16
- data/spec/innate/action/layout/file_layout.xhtml +0 -1
- data/spec/innate/helper/render.rb +0 -133
- data/spec/innate/helper/view/aspect_hello.xhtml +0 -1
- data/spec/innate/helper/view/locals.xhtml +0 -1
- data/spec/innate/helper/view/loop.xhtml +0 -4
- data/spec/innate/helper/view/num.xhtml +0 -1
- data/spec/innate/helper/view/partial.xhtml +0 -1
- data/spec/innate/helper/view/recursive.xhtml +0 -7
- data/spec/innate/node/view/foo.html.xhtml +0 -1
- data/spec/innate/node/view/with_layout.xhtml +0 -1
- data/spec/innate/provides/list.html.xhtml +0 -1
- data/spec/innate/provides/list.txt.xhtml +0 -1
- data/tasks/setup.rake +0 -28
@@ -1,4 +1,4 @@
|
|
1
|
-
<form method="post" action="
|
1
|
+
<form method="post" action="<%= r :create %>">
|
2
2
|
<fieldset>
|
3
3
|
<legend>Create new task</legend>
|
4
4
|
|
@@ -10,30 +10,30 @@
|
|
10
10
|
</form>
|
11
11
|
|
12
12
|
<table>
|
13
|
-
|
13
|
+
<% @list.each do |title, done| %>
|
14
14
|
<tr>
|
15
|
-
<form method="post" action="
|
16
|
-
<input type="hidden" name="id" value="
|
15
|
+
<form method="post" action="<%= r :update %>">
|
16
|
+
<input type="hidden" name="id" value="<%= h title %>" />
|
17
17
|
<td>
|
18
|
-
<input type="text" name="title" value="
|
18
|
+
<input type="text" name="title" value="<%= h title %>" />
|
19
19
|
</td>
|
20
20
|
<td>
|
21
|
-
|
21
|
+
<% if done %>
|
22
22
|
<input type="checkbox" name="done" checked="checked" />
|
23
|
-
|
23
|
+
<% else %>
|
24
24
|
<input type="checkbox" name="done" />
|
25
|
-
|
25
|
+
<% end %>
|
26
26
|
</td>
|
27
27
|
<td>
|
28
28
|
<input type="submit" value="Update" />
|
29
29
|
</td>
|
30
30
|
</form>
|
31
|
-
<form method="post" action="
|
32
|
-
<input type="hidden" name="id" value="
|
31
|
+
<form method="post" action="<%= r :delete %>">
|
32
|
+
<input type="hidden" name="id" value="<%= h title %>" />
|
33
33
|
<td>
|
34
34
|
<input type="submit" value="Delete" />
|
35
35
|
</td>
|
36
36
|
</form>
|
37
37
|
</tr>
|
38
|
-
|
38
|
+
<% end %>
|
39
39
|
</table>
|
@@ -7,7 +7,6 @@ DB = YAML::Store.new('wiki.yaml') unless defined?(DB)
|
|
7
7
|
class Wiki
|
8
8
|
Innate.node '/'
|
9
9
|
layout 'wiki'
|
10
|
-
provide :html, :engine => :ERB
|
11
10
|
|
12
11
|
def index(page = 'Home')
|
13
12
|
@page = page
|
@@ -39,4 +38,4 @@ class Wiki
|
|
39
38
|
end
|
40
39
|
end
|
41
40
|
|
42
|
-
Innate.start
|
41
|
+
Innate.start :adapter => :mongrel
|
File without changes
|
File without changes
|
data/example/howto_spec.rb
CHANGED
data/example/provides.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'innate'
|
3
|
-
require 'yaml'
|
4
3
|
|
5
4
|
ARTICLES = {
|
6
5
|
'hello' => {
|
@@ -14,17 +13,15 @@ class BlogArticles
|
|
14
13
|
Innate.node('/')
|
15
14
|
|
16
15
|
# provide a content representation for requests to /<action>.yaml
|
17
|
-
# If you request `/list.yaml`, you will get the `ARTICLES object serialized
|
18
|
-
# to YAML.
|
19
16
|
provide(:yaml, :type => 'text/yaml'){|action, value| value.to_yaml }
|
20
17
|
|
21
|
-
#
|
22
|
-
#
|
23
|
-
|
24
|
-
|
25
|
-
#
|
18
|
+
# the return value of this method is the `value` in the provide above
|
19
|
+
# Since ruby has implicit returns, `ARTICLES` will be the return value.
|
20
|
+
#
|
21
|
+
# If you request `/list.yaml` you will get the `ARTICLES` object serialized
|
22
|
+
# to YAML.
|
26
23
|
def list
|
27
|
-
|
24
|
+
@articles = ARTICLES
|
28
25
|
end
|
29
26
|
end
|
30
27
|
|
data/example/session.rb
CHANGED
@@ -11,9 +11,9 @@ class Hello
|
|
11
11
|
<body>
|
12
12
|
<h1>Session example</h1>
|
13
13
|
<p>
|
14
|
-
Value is:
|
15
|
-
|
16
|
-
|
14
|
+
Value is: <%= session[:value] %><br />
|
15
|
+
<%= a :increment %><br />
|
16
|
+
<%= a :decrement %>
|
17
17
|
</p>
|
18
18
|
</body>
|
19
19
|
</html>
|
data/innate.gemspec
CHANGED
@@ -2,28 +2,36 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{innate}
|
5
|
-
s.version = "2009.04"
|
5
|
+
s.version = "2009.04.01"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Michael 'manveru' Fellinger"]
|
9
|
-
s.date = %q{2009-04-
|
9
|
+
s.date = %q{2009-04-01}
|
10
10
|
s.description = %q{Simple, straight-forward base for web-frameworks.}
|
11
11
|
s.email = %q{m.fellinger@gmail.com}
|
12
|
-
s.files = ["CHANGELOG", "COPYING", "MANIFEST", "README.md", "Rakefile", "example/app/retro_games.rb", "example/app/todo/layout/default.
|
12
|
+
s.files = ["CHANGELOG", "COPYING", "MANIFEST", "README.md", "Rakefile", "example/app/retro_games.rb", "example/app/todo/layout/default.erb", "example/app/todo/spec/todo.rb", "example/app/todo/start.rb", "example/app/todo/view/index.erb", "example/app/whywiki_erb/layout/wiki.html.erb", "example/app/whywiki_erb/spec/wiki.rb", "example/app/whywiki_erb/start.rb", "example/app/whywiki_erb/view/edit.html.erb", "example/app/whywiki_erb/view/index.html.erb", "example/custom_middleware.rb", "example/hello.rb", "example/howto_spec.rb", "example/link.rb", "example/provides.rb", "example/session.rb", "innate.gemspec", "lib/innate.rb", "lib/innate/action.rb", "lib/innate/adapter.rb", "lib/innate/cache.rb", "lib/innate/cache/api.rb", "lib/innate/cache/drb.rb", "lib/innate/cache/file_based.rb", "lib/innate/cache/marshal.rb", "lib/innate/cache/memory.rb", "lib/innate/cache/yaml.rb", "lib/innate/core_compatibility/basic_object.rb", "lib/innate/core_compatibility/string.rb", "lib/innate/current.rb", "lib/innate/dynamap.rb", "lib/innate/helper.rb", "lib/innate/helper/aspect.rb", "lib/innate/helper/cgi.rb", "lib/innate/helper/flash.rb", "lib/innate/helper/link.rb", "lib/innate/helper/partial.rb", "lib/innate/helper/redirect.rb", "lib/innate/helper/send_file.rb", "lib/innate/log.rb", "lib/innate/log/color_formatter.rb", "lib/innate/log/hub.rb", "lib/innate/middleware_compiler.rb", "lib/innate/mock.rb", "lib/innate/node.rb", "lib/innate/options.rb", "lib/innate/options/dsl.rb", "lib/innate/options/stub.rb", "lib/innate/request.rb", "lib/innate/response.rb", "lib/innate/route.rb", "lib/innate/session.rb", "lib/innate/session/flash.rb", "lib/innate/spec.rb", "lib/innate/state.rb", "lib/innate/state/accessor.rb", "lib/innate/state/fiber.rb", "lib/innate/state/thread.rb", "lib/innate/traited.rb", "lib/innate/trinity.rb", "lib/innate/version.rb", "lib/innate/view.rb", "lib/innate/view/erb.rb", "lib/innate/view/etanni.rb", "lib/innate/view/none.rb", "spec/example/hello.rb", "spec/example/link.rb", "spec/example/session.rb", "spec/helper.rb", "spec/innate/action/layout.rb", "spec/innate/action/layout/file_layout.erb", "spec/innate/cache/common.rb", "spec/innate/cache/marshal.rb", "spec/innate/cache/memory.rb", "spec/innate/cache/yaml.rb", "spec/innate/dynamap.rb", "spec/innate/helper.rb", "spec/innate/helper/aspect.rb", "spec/innate/helper/cgi.rb", "spec/innate/helper/flash.rb", "spec/innate/helper/link.rb", "spec/innate/helper/partial.rb", "spec/innate/helper/redirect.rb", "spec/innate/helper/send_file.rb", "spec/innate/helper/view/aspect_hello.erb", "spec/innate/helper/view/locals.erb", "spec/innate/helper/view/loop.erb", "spec/innate/helper/view/num.erb", "spec/innate/helper/view/partial.erb", "spec/innate/helper/view/recursive.erb", "spec/innate/mock.rb", "spec/innate/node/mapping.rb", "spec/innate/node/node.rb", "spec/innate/node/resolve.rb", "spec/innate/node/view/another_layout/another_layout.erb", "spec/innate/node/view/bar.erb", "spec/innate/node/view/foo.html.erb", "spec/innate/node/view/only_view.erb", "spec/innate/node/view/with_layout.erb", "spec/innate/node/wrap_action_call.rb", "spec/innate/options.rb", "spec/innate/parameter.rb", "spec/innate/provides.rb", "spec/innate/provides/list.html.erb", "spec/innate/provides/list.txt.erb", "spec/innate/request.rb", "spec/innate/route.rb", "spec/innate/session.rb", "spec/innate/state/fiber.rb", "spec/innate/state/thread.rb", "spec/innate/traited.rb", "tasks/bacon.rake", "tasks/changelog.rake", "tasks/gem.rake", "tasks/gem_installer.rake", "tasks/grancher.rake", "tasks/install_dependencies.rake", "tasks/manifest.rake", "tasks/rcov.rake", "tasks/release.rake", "tasks/reversion.rake"]
|
13
13
|
s.has_rdoc = true
|
14
14
|
s.homepage = %q{http://github.com/manveru/innate}
|
15
15
|
s.require_paths = ["lib"]
|
16
|
-
s.
|
17
|
-
s.rubygems_version = %q{1.3.2}
|
16
|
+
s.rubygems_version = %q{1.3.1}
|
18
17
|
s.summary = %q{Powerful web-framework wrapper for Rack.}
|
19
18
|
|
20
19
|
if s.respond_to? :specification_version then
|
21
20
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
22
|
-
s.specification_version =
|
21
|
+
s.specification_version = 2
|
23
22
|
|
24
23
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
24
|
+
s.add_runtime_dependency(%q<rack>, [">= 0.9.1"])
|
25
|
+
s.add_development_dependency(%q<bacon>, [">= 1.0"])
|
26
|
+
s.add_development_dependency(%q<json>, ["~> 1.1.3"])
|
25
27
|
else
|
28
|
+
s.add_dependency(%q<rack>, [">= 0.9.1"])
|
29
|
+
s.add_dependency(%q<bacon>, [">= 1.0"])
|
30
|
+
s.add_dependency(%q<json>, ["~> 1.1.3"])
|
26
31
|
end
|
27
32
|
else
|
33
|
+
s.add_dependency(%q<rack>, [">= 0.9.1"])
|
34
|
+
s.add_dependency(%q<bacon>, [">= 1.0"])
|
35
|
+
s.add_dependency(%q<json>, ["~> 1.1.3"])
|
28
36
|
end
|
29
37
|
end
|
data/lib/innate.rb
CHANGED
@@ -3,7 +3,11 @@
|
|
3
3
|
#
|
4
4
|
# Name-space of Innate, just about everything goes in here.
|
5
5
|
#
|
6
|
-
#
|
6
|
+
# Exceptions are:
|
7
|
+
#
|
8
|
+
# * Logger::ColorFormatter
|
9
|
+
# * In 1.8, we define ::BasicObject
|
10
|
+
# * In 1.9, we define ::String#each
|
7
11
|
#
|
8
12
|
module Innate
|
9
13
|
ROOT = File.expand_path(File.dirname(__FILE__))
|
@@ -26,6 +30,10 @@ module Innate
|
|
26
30
|
# 3rd party
|
27
31
|
require 'rack'
|
28
32
|
|
33
|
+
# innates ruby core patches
|
34
|
+
require 'innate/core_compatibility/string'
|
35
|
+
require 'innate/core_compatibility/basic_object'
|
36
|
+
|
29
37
|
# innate core
|
30
38
|
require 'innate/version'
|
31
39
|
require 'innate/traited'
|
@@ -89,7 +97,7 @@ module Innate
|
|
89
97
|
# Port for the server
|
90
98
|
# @option param :started [boolean] (false)
|
91
99
|
# Indicate that calls Innate::start will be ignored
|
92
|
-
# @option param :
|
100
|
+
# @option param :handler [Symbol] (:webrick)
|
93
101
|
# Web server to run on
|
94
102
|
# @option param :setup [Array] ([Innate::Cache, Innate::Node])
|
95
103
|
# Will send ::setup to each element during Innate::start
|
@@ -105,14 +113,14 @@ module Innate
|
|
105
113
|
root = given_options.delete(:root)
|
106
114
|
file = given_options.delete(:file)
|
107
115
|
|
108
|
-
found_root = go_figure_root(caller, :root => root, :file => file)
|
109
|
-
|
116
|
+
if found_root = go_figure_root(caller, :root => root, :file => file)
|
117
|
+
$0 = found_root
|
118
|
+
Innate.options.roots = [found_root]
|
119
|
+
end
|
110
120
|
|
111
|
-
# Convert some top-level option keys to the internal ones that we use.
|
112
121
|
PROXY_OPTIONS.each{|k,v| given_options[v] = given_options.delete(k) }
|
113
122
|
given_options.delete_if{|k,v| v.nil? }
|
114
123
|
|
115
|
-
# Merge the user's given options into our existing set, which contains defaults.
|
116
124
|
options.merge!(given_options)
|
117
125
|
|
118
126
|
setup_dependencies
|
@@ -177,10 +185,10 @@ module Innate
|
|
177
185
|
# Innate.start :root => File.dirname(__FILE__)
|
178
186
|
#
|
179
187
|
# Either setting will surpress the warning that might show up on startup
|
180
|
-
# and tells you it
|
188
|
+
# and tells you it coldn't find an explicit root.
|
181
189
|
#
|
182
190
|
# In case these options are not passed we will try to figure out a file named
|
183
|
-
# `start.rb` in the
|
191
|
+
# `start.rb` in the processes working directory and assumes it's a valid point.
|
184
192
|
def go_figure_root(backtrace, options)
|
185
193
|
if root = options[:root]
|
186
194
|
root
|
@@ -255,15 +263,13 @@ module Innate
|
|
255
263
|
# @see Rack::MiddlewareCompiler
|
256
264
|
middleware :dev do |m|
|
257
265
|
m.apps(Rack::Lint, Rack::CommonLogger, Rack::ShowExceptions,
|
258
|
-
Rack::ShowStatus, Rack::ConditionalGet, Rack::
|
259
|
-
Rack::Head)
|
260
|
-
m.use(Rack::Reloader, 2)
|
266
|
+
Rack::ShowStatus, Rack::ConditionalGet, Rack::Head, Rack::Reloader)
|
261
267
|
m.innate
|
262
268
|
end
|
263
269
|
|
264
270
|
middleware :live do |m|
|
265
271
|
m.apps(Rack::CommonLogger, Rack::ShowStatus, Rack::ConditionalGet,
|
266
|
-
Rack::
|
272
|
+
Rack::Head)
|
267
273
|
m.innate
|
268
274
|
end
|
269
275
|
end
|
data/lib/innate/action.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Innate
|
2
|
-
ACTION_MEMBERS = [ :node, :
|
3
|
-
:
|
2
|
+
ACTION_MEMBERS = [ :node, :method, :params, :view, :layout, :instance, :exts,
|
3
|
+
:wish, :options, :variables, :value, :view_value, :engine ]
|
4
4
|
|
5
5
|
class Action < Struct.new(*ACTION_MEMBERS)
|
6
6
|
# Create a new Action instance.
|
@@ -32,7 +32,10 @@ module Innate
|
|
32
32
|
# @api stable
|
33
33
|
# @author manveru
|
34
34
|
def call
|
35
|
-
Current.actions
|
35
|
+
Current.actions << self
|
36
|
+
render
|
37
|
+
ensure
|
38
|
+
Current.actions.delete(self)
|
36
39
|
end
|
37
40
|
|
38
41
|
# @return [Binding] binding of the instance for this Action
|
@@ -97,12 +100,12 @@ module Innate
|
|
97
100
|
self.variables[:content] ||= nil
|
98
101
|
|
99
102
|
instance.wrap_action_call(self) do
|
100
|
-
copy_variables # this might
|
101
|
-
self.
|
102
|
-
self.view_value =
|
103
|
+
copy_variables # this might another position after all
|
104
|
+
self.value = instance.__send__(method, *params) if method
|
105
|
+
self.view_value = File.read(view) if view
|
103
106
|
|
104
107
|
body, content_type = wrap_in_layout{
|
105
|
-
engine.call(self, view_value ||
|
108
|
+
engine.call(self, view_value || value || '') }
|
106
109
|
options[:content_type] ||= content_type if content_type
|
107
110
|
body
|
108
111
|
end
|
@@ -114,7 +117,6 @@ module Innate
|
|
114
117
|
action = dup
|
115
118
|
action.view, action.method = layout_view_or_method(*layout)
|
116
119
|
action.layout = nil
|
117
|
-
action.view_value = nil
|
118
120
|
action.sync_variables(self)
|
119
121
|
body, content_type = yield
|
120
122
|
action.variables[:content] = body
|
@@ -125,26 +127,13 @@ module Innate
|
|
125
127
|
[:layout, :view].include?(name) ? [arg, nil] : [nil, arg]
|
126
128
|
end
|
127
129
|
|
128
|
-
def wrap_in_current
|
129
|
-
Current.actions << self
|
130
|
-
yield
|
131
|
-
ensure
|
132
|
-
Current.actions.delete(self)
|
133
|
-
end
|
134
|
-
|
135
130
|
# Try to figure out a sane name for current action.
|
136
131
|
def name
|
137
132
|
File.basename((method || view).to_s).split('.').first
|
138
133
|
end
|
139
134
|
|
140
|
-
# Path to this action, including params, with the mapping of the current
|
141
|
-
# controller prepended.
|
142
|
-
def full_path
|
143
|
-
File.join(node.mapping, path)
|
144
|
-
end
|
145
|
-
|
146
135
|
def valid?
|
147
|
-
|
136
|
+
method || view
|
148
137
|
end
|
149
138
|
end
|
150
139
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# We define BasicObject for compatibility with 1.9 if it isn't there yet.
|
2
|
+
class BasicObject
|
3
|
+
# Remove all but these methods
|
4
|
+
# NOTE: __id__ is not there in 1.9, but would give a warning in 1.8
|
5
|
+
KEEP = %w[== equal? ! != instance_eval instance_exec __send__ __id__]
|
6
|
+
|
7
|
+
(instance_methods - KEEP).each do |im|
|
8
|
+
undef_method(im)
|
9
|
+
end
|
10
|
+
end unless defined?(BasicObject)
|
data/lib/innate/dynamap.rb
CHANGED
data/lib/innate/helper.rb
CHANGED
@@ -11,7 +11,6 @@ module Innate
|
|
11
11
|
def self.included(into)
|
12
12
|
into.extend(HelperAccess)
|
13
13
|
into.__send__(:include, Trinity)
|
14
|
-
into.helper(*HelpersHelper.options[:default])
|
15
14
|
end
|
16
15
|
end
|
17
16
|
|
@@ -64,27 +63,34 @@ module Innate
|
|
64
63
|
#
|
65
64
|
# p Innate::HelpersHelper.each(:cgi, :link, :aspect)
|
66
65
|
module HelpersHelper
|
67
|
-
|
66
|
+
EXTS = %w[rb so bundle]
|
68
67
|
|
69
|
-
|
70
|
-
|
71
|
-
|
68
|
+
# By default, lib/innate/ is added to the PATH, you may add your
|
69
|
+
# application root here so innate will look in your own helper/ directory.
|
70
|
+
PATH = []
|
72
71
|
|
73
|
-
|
74
|
-
|
72
|
+
# The namespaces that may container helper modules.
|
73
|
+
# Lookup is done from left to right.
|
74
|
+
POOL = []
|
75
75
|
|
76
|
-
|
77
|
-
:exts, %w[rb so bundle]
|
76
|
+
# all of the following are singleton methods
|
78
77
|
|
79
|
-
|
80
|
-
|
78
|
+
module_function
|
79
|
+
|
80
|
+
def add_pool(pool)
|
81
|
+
POOL.unshift(pool)
|
82
|
+
POOL.uniq!
|
81
83
|
end
|
82
84
|
|
83
|
-
|
85
|
+
add_pool(Helper)
|
84
86
|
|
85
|
-
|
87
|
+
def add_path(path)
|
88
|
+
PATH.unshift(File.expand_path(path))
|
89
|
+
PATH.uniq!
|
90
|
+
end
|
86
91
|
|
87
|
-
|
92
|
+
add_path(File.dirname(__FILE__))
|
93
|
+
add_path('')
|
88
94
|
|
89
95
|
# Yield all the modules we can find for the given names of helpers, try to
|
90
96
|
# require them if not available.
|
@@ -152,10 +158,10 @@ module Innate
|
|
152
158
|
# helper :foo_bar # => FooBar
|
153
159
|
# helper :foo # => Foo
|
154
160
|
def get(name)
|
155
|
-
|
161
|
+
name = name.to_s.split('_').map{|e| e.capitalize}.join
|
156
162
|
|
157
|
-
|
158
|
-
found = namespace.constants.grep(
|
163
|
+
POOL.each do |namespace|
|
164
|
+
found = namespace.constants.grep(/^#{name}$/i).first
|
159
165
|
return namespace.const_get(found) if found
|
160
166
|
end
|
161
167
|
|
@@ -175,9 +181,12 @@ module Innate
|
|
175
181
|
# Return a nice list of filenames in correct locations with correct
|
176
182
|
# filename-extensions.
|
177
183
|
def glob(name = '*')
|
178
|
-
|
179
|
-
|
180
|
-
|
184
|
+
"{#{paths.join(',')}}/helper/#{name}.{#{EXTS.join(',')}}"
|
185
|
+
end
|
186
|
+
|
187
|
+
# In case you want to do something better.
|
188
|
+
def paths
|
189
|
+
PATH
|
181
190
|
end
|
182
191
|
end
|
183
192
|
end
|