padrino-core 0.9.4 → 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +13 -1
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/bin/padrino +3 -1
- data/lib/padrino-core/application.rb +1 -1
- data/lib/padrino-core/application/rendering.rb +28 -12
- data/lib/padrino-core/reloader.rb +2 -2
- data/lib/padrino-core/tasks.rb +0 -1
- data/padrino-core.gemspec +5 -5
- data/test/test_application.rb +100 -6
- metadata +5 -5
data/README.rdoc
CHANGED
@@ -161,7 +161,19 @@ and even configure the respond_to for each route:
|
|
161
161
|
end
|
162
162
|
end
|
163
163
|
end
|
164
|
-
|
164
|
+
|
165
|
+
or auto lookup for current locale or content_type
|
166
|
+
|
167
|
+
# app/controllers/example.rb
|
168
|
+
SimpleApp.controllers :admin do
|
169
|
+
get :show, :with => :id, :respond_to => [html, :js] do
|
170
|
+
render "admin/show"
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
When you visit :+show+ and your I18n.locale == :ru Padrino try to look for "admin/show.ru.js.*" if nothing match that path
|
175
|
+
they try "admin/show.ru.*" then "admin/show.js.*" if none match return "admin/show.erb" (or other engine i.e. haml)
|
176
|
+
|
165
177
|
For a complete overview of the routing and controller system, check out the
|
166
178
|
{Routing and Controller guide}[http://wiki.github.com/padrino/padrino-framework/controllers].
|
167
179
|
|
data/Rakefile
CHANGED
@@ -13,7 +13,7 @@ begin
|
|
13
13
|
gem.authors = ["Padrino Team", "Nathan Esquenazi", "Davide D'Agostino", "Arthur Chiu"]
|
14
14
|
gem.executables = ["padrino"]
|
15
15
|
gem.rubyforge_project = 'padrino-core'
|
16
|
-
gem.add_runtime_dependency "sinatra", ">= 0.9.
|
16
|
+
gem.add_runtime_dependency "sinatra", ">= 0.9.6"
|
17
17
|
gem.add_runtime_dependency "i18n", ">= 0.3.2"
|
18
18
|
gem.add_runtime_dependency "usher", ">= 0.6.2"
|
19
19
|
gem.add_runtime_dependency "thor", ">= 0.13.0"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.5
|
data/bin/padrino
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'rubygems'
|
3
|
-
|
3
|
+
|
4
|
+
padrino_core_path = File.expand_path('../../lib', __FILE__)
|
5
|
+
$:.unshift(padrino_core_path) if File.directory?(padrino_core_path) && !$:.include?(padrino_core_path)
|
4
6
|
|
5
7
|
require 'padrino-core/cli/base'
|
6
8
|
|
@@ -189,7 +189,7 @@ module Padrino
|
|
189
189
|
# Returns the load_paths for the application (relative to the application root)
|
190
190
|
#
|
191
191
|
def load_paths
|
192
|
-
@load_paths ||= ["urls.rb", "config/urls.rb", "mailers/*.rb", "controllers/**/*.rb", "controllers.rb", "helpers
|
192
|
+
@load_paths ||= ["urls.rb", "config/urls.rb", "mailers/*.rb", "mailers.rb", "controllers/**/*.rb", "controllers.rb", "helpers/**/*.rb", "helpers.rb"]
|
193
193
|
end
|
194
194
|
|
195
195
|
##
|
@@ -14,13 +14,16 @@ module Padrino
|
|
14
14
|
#
|
15
15
|
def render(engine, data=nil, options={}, locals={}, &block)
|
16
16
|
clear_template_cache!
|
17
|
+
|
17
18
|
# If engine is an hash we convert to json
|
18
19
|
return engine.to_json if engine.is_a?(Hash)
|
20
|
+
|
19
21
|
# If an engine is a string probably is a path so we try to resolve them
|
20
|
-
if data.nil?
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
data, engine = *resolve_template(engine, options) if data.nil?
|
23
|
+
|
24
|
+
# We need for Sinatra 1.0 an outvar for erb and erubis templates
|
25
|
+
options[:outvar] ||= '@_out_buf' if [:erb, :erubis].include?(engine)
|
26
|
+
|
24
27
|
# Use layout as rails do
|
25
28
|
if (options[:layout].nil? || options[:layout] == true) && !self.class.templates.has_key?(:layout)
|
26
29
|
layout = self.class.instance_variable_defined?(:@_layout) ? self.class.instance_variable_get(:@_layout) : :application
|
@@ -34,15 +37,28 @@ module Padrino
|
|
34
37
|
end
|
35
38
|
|
36
39
|
##
|
37
|
-
# Returns the template
|
38
|
-
#
|
39
|
-
#
|
40
|
-
|
40
|
+
# Returns the template path and engine that match (if presents) content_type, I18n.locale.
|
41
|
+
#
|
42
|
+
# ==== Example
|
43
|
+
#
|
44
|
+
# get "/foo", :respond_to => [:html, :js] do; render 'path/to/foo'; end
|
45
|
+
# # If you request "/foo.js" with I18n.locale == :ru => [:"/path/to/foo.ru.js", :erb]
|
46
|
+
# # If you request "/foo" with I18n.locale == :de => [:"/path/to/foo.de.haml", :haml]
|
47
|
+
#
|
48
|
+
def resolve_template(template_path, options={})
|
41
49
|
view_path = options.delete(:views) || self.options.views || self.class.views || "./views"
|
42
|
-
|
43
|
-
|
50
|
+
template_path = File.join(view_path, template_path.to_s)
|
51
|
+
regexs = [/^[^\.]+\.[^\.]+$/]
|
52
|
+
regexs.unshift(/^[^\.]+\.#{content_type}\.[^\.]+$/) if content_type.present?
|
53
|
+
if defined?(I18n) && I18n.locale.present?
|
54
|
+
regexs.unshift(/^[^\.]+\.#{I18n.locale}\.[^\.]+$/)
|
55
|
+
regexs.unshift(/^[^\.]+\.#{I18n.locale}\.#{content_type}\.[^\.]+$/) if content_type.present?
|
56
|
+
end
|
57
|
+
template_file = regexs.map { |regex| Dir[template_path + ".*"].find { |file| File.basename(file) =~ regex } }.compact.first
|
44
58
|
raise "Template path '#{template_path}' could not be located in views!" unless template_file
|
45
|
-
|
59
|
+
engine = File.extname(template_file)[1..-1]
|
60
|
+
template = template_file.gsub(view_path, '').gsub(/\.#{engine}$/, '')
|
61
|
+
[template.to_sym, engine.to_sym]
|
46
62
|
end
|
47
63
|
|
48
64
|
##
|
@@ -50,7 +66,7 @@ module Padrino
|
|
50
66
|
# clear_template_cache!
|
51
67
|
#
|
52
68
|
def clear_template_cache!
|
53
|
-
# TODO: remove
|
69
|
+
# TODO: remove @template_cache.respond_to?(:clear) when sinatra 1.0 will be released
|
54
70
|
can_clear_cache = @template_cache && @template_cache.respond_to?(:clear)
|
55
71
|
is_in_development = (defined?(Padrino) && Padrino.respond_to?(:env) && Padrino.env != :production)
|
56
72
|
@template_cache.clear if is_in_development && can_clear_cache
|
@@ -35,10 +35,10 @@ module Padrino
|
|
35
35
|
|
36
36
|
##
|
37
37
|
# You can exclude some folders from reload its contents.
|
38
|
-
# Defaults excluded directories of Padrino.root are: test, spec, features, tmp, config, lib and public
|
38
|
+
# Defaults excluded directories of Padrino.root are: test, spec, features, tmp, config, lib, db and public
|
39
39
|
#
|
40
40
|
def self.exclude
|
41
|
-
@_exclude ||= %w(test spec tmp features config lib public).map { |path| Padrino.root(path) }
|
41
|
+
@_exclude ||= %w(test spec tmp features config lib public db).map { |path| Padrino.root(path) }
|
42
42
|
end
|
43
43
|
|
44
44
|
##
|
data/lib/padrino-core/tasks.rb
CHANGED
data/padrino-core.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{padrino-core}
|
8
|
-
s.version = "0.9.
|
8
|
+
s.version = "0.9.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Padrino Team", "Nathan Esquenazi", "Davide D'Agostino", "Arthur Chiu"]
|
12
|
-
s.date = %q{2010-03-
|
12
|
+
s.date = %q{2010-03-11}
|
13
13
|
s.default_executable = %q{padrino}
|
14
14
|
s.description = %q{The Padrino core gem required for use of this framework}
|
15
15
|
s.email = %q{padrinorb@gmail.com}
|
@@ -78,7 +78,7 @@ Gem::Specification.new do |s|
|
|
78
78
|
s.specification_version = 3
|
79
79
|
|
80
80
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
81
|
-
s.add_runtime_dependency(%q<sinatra>, [">= 0.9.
|
81
|
+
s.add_runtime_dependency(%q<sinatra>, [">= 0.9.6"])
|
82
82
|
s.add_runtime_dependency(%q<i18n>, [">= 0.3.2"])
|
83
83
|
s.add_runtime_dependency(%q<usher>, [">= 0.6.2"])
|
84
84
|
s.add_runtime_dependency(%q<thor>, [">= 0.13.0"])
|
@@ -89,7 +89,7 @@ Gem::Specification.new do |s|
|
|
89
89
|
s.add_development_dependency(%q<rack-test>, [">= 0.5.0"])
|
90
90
|
s.add_development_dependency(%q<webrat>, [">= 0.5.1"])
|
91
91
|
else
|
92
|
-
s.add_dependency(%q<sinatra>, [">= 0.9.
|
92
|
+
s.add_dependency(%q<sinatra>, [">= 0.9.6"])
|
93
93
|
s.add_dependency(%q<i18n>, [">= 0.3.2"])
|
94
94
|
s.add_dependency(%q<usher>, [">= 0.6.2"])
|
95
95
|
s.add_dependency(%q<thor>, [">= 0.13.0"])
|
@@ -101,7 +101,7 @@ Gem::Specification.new do |s|
|
|
101
101
|
s.add_dependency(%q<webrat>, [">= 0.5.1"])
|
102
102
|
end
|
103
103
|
else
|
104
|
-
s.add_dependency(%q<sinatra>, [">= 0.9.
|
104
|
+
s.add_dependency(%q<sinatra>, [">= 0.9.6"])
|
105
105
|
s.add_dependency(%q<i18n>, [">= 0.3.2"])
|
106
106
|
s.add_dependency(%q<usher>, [">= 0.6.2"])
|
107
107
|
s.add_dependency(%q<thor>, [">= 0.13.0"])
|
data/test/test_application.rb
CHANGED
@@ -14,16 +14,33 @@ class TestApplication < Test::Unit::TestCase
|
|
14
14
|
FileUtils.rm_rf(File.dirname(__FILE__) + "/views")
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
18
|
-
# Build a temp layout
|
17
|
+
def create_view(name, content, options={})
|
19
18
|
FileUtils.mkdir_p(File.dirname(__FILE__) + "/views")
|
20
|
-
|
21
|
-
|
19
|
+
path = "/views/#{name}"
|
20
|
+
path += ".#{options.delete(:locale)}" if options[:locale].present?
|
21
|
+
path += ".#{options.delete(:format)}" if options[:format].present?
|
22
|
+
path += ".erb"
|
23
|
+
view = File.dirname(__FILE__) + path
|
24
|
+
File.open(view, 'wb') { |io| io.write content }
|
25
|
+
view
|
26
|
+
end
|
27
|
+
|
28
|
+
def remove_views
|
29
|
+
FileUtils.rm_rf(File.dirname(__FILE__) + "/views")
|
30
|
+
end
|
31
|
+
|
32
|
+
def with_view(name, content, options={})
|
33
|
+
# Build a temp layout
|
34
|
+
view = create_view(name, content, options)
|
22
35
|
yield
|
23
36
|
ensure
|
24
37
|
# Remove temp layout
|
25
|
-
File.unlink(
|
26
|
-
|
38
|
+
File.unlink(view) rescue nil
|
39
|
+
remove_views
|
40
|
+
end
|
41
|
+
|
42
|
+
def teardown
|
43
|
+
remove_views
|
27
44
|
end
|
28
45
|
|
29
46
|
class PadrinoTestApp < Padrino::Application; end
|
@@ -146,5 +163,82 @@ class TestApplication < Test::Unit::TestCase
|
|
146
163
|
assert_equal "3", body
|
147
164
|
end
|
148
165
|
end
|
166
|
+
|
167
|
+
should 'reslove template content type' do
|
168
|
+
create_view :foo, "Im Js", :format => :js
|
169
|
+
create_view :foo, "Im Erb"
|
170
|
+
mock_app do
|
171
|
+
get("/foo", :respond_to => :js) { render :foo }
|
172
|
+
get("/bar.js") { render :foo }
|
173
|
+
end
|
174
|
+
get "/foo.js"
|
175
|
+
assert_equal "Im Js", body
|
176
|
+
get "/bar.js"
|
177
|
+
assert_equal "Im Js", body
|
178
|
+
remove_views
|
179
|
+
end
|
180
|
+
|
181
|
+
should 'reslove template locale' do
|
182
|
+
create_view :foo, "Im English", :locale => :en
|
183
|
+
create_view :foo, "Im Italian", :locale => :it
|
184
|
+
mock_app do
|
185
|
+
get("/foo") { render :foo }
|
186
|
+
end
|
187
|
+
I18n.locale = :en
|
188
|
+
get "/foo"
|
189
|
+
assert_equal "Im English", body
|
190
|
+
I18n.locale = :it
|
191
|
+
get "/foo"
|
192
|
+
assert_equal "Im Italian", body
|
193
|
+
end
|
194
|
+
|
195
|
+
should 'resolve template content_type and locale' do
|
196
|
+
create_view :foo, "Im Js", :format => :js
|
197
|
+
create_view :foo, "Im Erb"
|
198
|
+
create_view :foo, "Im English Erb", :locale => :en
|
199
|
+
create_view :foo, "Im Italian Erb", :locale => :it
|
200
|
+
create_view :foo, "Im English Js", :format => :js, :locale => :en
|
201
|
+
create_view :foo, "Im Italian Js", :format => :js, :locale => :it
|
202
|
+
mock_app do
|
203
|
+
get("/foo", :respond_to => [:html, :js]) { render :foo }
|
204
|
+
end
|
205
|
+
I18n.locale = :none
|
206
|
+
get "/foo.js"
|
207
|
+
assert_equal "Im Js", body
|
208
|
+
get "/foo"
|
209
|
+
assert_equal "Im Erb", body
|
210
|
+
I18n.locale = :en
|
211
|
+
get "/foo"
|
212
|
+
assert_equal "Im English Erb", body
|
213
|
+
I18n.locale = :it
|
214
|
+
get "/foo"
|
215
|
+
assert_equal "Im Italian Erb", body
|
216
|
+
I18n.locale = :en
|
217
|
+
get "/foo.js"
|
218
|
+
assert_equal "Im English Js", body
|
219
|
+
I18n.locale = :it
|
220
|
+
get "/foo.js"
|
221
|
+
assert_equal "Im Italian Js", body
|
222
|
+
I18n.locale = :en
|
223
|
+
get "/foo.pk"
|
224
|
+
assert_equal 404, status
|
225
|
+
end
|
226
|
+
|
227
|
+
should 'renders erb with blocks' do
|
228
|
+
mock_app do
|
229
|
+
def container
|
230
|
+
@_out_buf << "THIS."
|
231
|
+
yield
|
232
|
+
@_out_buf << "SPARTA!"
|
233
|
+
end
|
234
|
+
def is; "IS." end
|
235
|
+
get '/' do
|
236
|
+
render :erb, '<% container do %> <%= is %> <% end %>'
|
237
|
+
end
|
238
|
+
end
|
239
|
+
get '/'
|
240
|
+
assert ok?
|
241
|
+
assert_equal 'THIS. IS. SPARTA!', body
|
242
|
+
end
|
149
243
|
end
|
150
244
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 9
|
8
|
-
-
|
9
|
-
version: 0.9.
|
8
|
+
- 5
|
9
|
+
version: 0.9.5
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Padrino Team
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2010-03-
|
20
|
+
date: 2010-03-11 00:00:00 +01:00
|
21
21
|
default_executable: padrino
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
@@ -30,8 +30,8 @@ dependencies:
|
|
30
30
|
segments:
|
31
31
|
- 0
|
32
32
|
- 9
|
33
|
-
-
|
34
|
-
version: 0.9.
|
33
|
+
- 6
|
34
|
+
version: 0.9.6
|
35
35
|
type: :runtime
|
36
36
|
version_requirements: *id001
|
37
37
|
- !ruby/object:Gem::Dependency
|