padrino-core 0.11.3 → 0.11.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/README.rdoc +5 -5
  3. data/lib/padrino-core.rb +3 -9
  4. data/lib/padrino-core/application.rb +39 -35
  5. data/lib/padrino-core/application/flash.rb +7 -7
  6. data/lib/padrino-core/application/rendering.rb +136 -139
  7. data/lib/padrino-core/application/rendering/extensions/erubis.rb +15 -6
  8. data/lib/padrino-core/application/routing.rb +371 -369
  9. data/lib/padrino-core/application/showexceptions.rb +13 -12
  10. data/lib/padrino-core/caller.rb +40 -40
  11. data/lib/padrino-core/cli/adapter.rb +4 -4
  12. data/lib/padrino-core/cli/base.rb +40 -39
  13. data/lib/padrino-core/cli/rake.rb +2 -2
  14. data/lib/padrino-core/cli/rake_tasks.rb +2 -4
  15. data/lib/padrino-core/command.rb +2 -2
  16. data/lib/padrino-core/loader.rb +14 -15
  17. data/lib/padrino-core/locale/cs.yml +0 -1
  18. data/lib/padrino-core/locale/da.yml +0 -1
  19. data/lib/padrino-core/locale/de.yml +0 -1
  20. data/lib/padrino-core/locale/en.yml +0 -1
  21. data/lib/padrino-core/locale/es.yml +1 -2
  22. data/lib/padrino-core/locale/fr.yml +2 -3
  23. data/lib/padrino-core/locale/hu.yml +1 -2
  24. data/lib/padrino-core/locale/it.yml +0 -1
  25. data/lib/padrino-core/locale/ja.yml +1 -2
  26. data/lib/padrino-core/locale/lv.yml +0 -1
  27. data/lib/padrino-core/locale/nl.yml +0 -1
  28. data/lib/padrino-core/locale/no.yml +0 -2
  29. data/lib/padrino-core/locale/pl.yml +0 -1
  30. data/lib/padrino-core/locale/pt_br.yml +0 -1
  31. data/lib/padrino-core/locale/ro.yml +0 -1
  32. data/lib/padrino-core/locale/ru.yml +0 -1
  33. data/lib/padrino-core/locale/sv.yml +0 -1
  34. data/lib/padrino-core/locale/tr.yml +0 -1
  35. data/lib/padrino-core/locale/uk.yml +0 -1
  36. data/lib/padrino-core/locale/zh_cn.yml +0 -1
  37. data/lib/padrino-core/locale/zh_tw.yml +0 -1
  38. data/lib/padrino-core/logger.rb +26 -27
  39. data/lib/padrino-core/module.rb +3 -3
  40. data/lib/padrino-core/mounter.rb +59 -59
  41. data/lib/padrino-core/reloader.rb +23 -23
  42. data/lib/padrino-core/router.rb +10 -13
  43. data/lib/padrino-core/server.rb +17 -19
  44. data/lib/padrino-core/tasks.rb +3 -3
  45. data/lib/padrino-core/version.rb +1 -1
  46. data/padrino-core.gemspec +1 -1
  47. data/test/test_application.rb +7 -7
  48. data/test/test_rendering.rb +15 -2
  49. data/test/test_routing.rb +34 -10
  50. metadata +13 -27
@@ -5,16 +5,17 @@ module Padrino
5
5
  # @private
6
6
  class ShowExceptions < Sinatra::ShowExceptions
7
7
  private
8
- def frame_class(frame)
9
- if frame.filename =~ /lib\/sinatra.*\.rb|lib\/padrino.*\.rb/
10
- "framework"
11
- elsif (defined?(Gem) && frame.filename.include?(Gem.dir)) ||
12
- frame.filename =~ /\/bin\/(\w+)$/ ||
13
- frame.filename =~ /Ruby\/Gems/
14
- "system"
15
- else
16
- "app"
17
- end
8
+
9
+ def frame_class(frame)
10
+ if frame.filename =~ /lib\/sinatra.*\.rb|lib\/padrino.*\.rb/
11
+ "framework"
12
+ elsif (defined?(Gem) && frame.filename.include?(Gem.dir)) ||
13
+ frame.filename =~ /\/bin\/(\w+)$/ ||
14
+ frame.filename =~ /Ruby\/Gems/
15
+ "system"
16
+ else
17
+ "app"
18
18
  end
19
- end # ShowExceptions
20
- end # Padrino
19
+ end
20
+ end
21
+ end
@@ -2,23 +2,23 @@ module Padrino
2
2
 
3
3
  # List of callers in a Padrino application that should be ignored as part of a stack trace.
4
4
  PADRINO_IGNORE_CALLERS = [
5
- %r{lib/padrino-.*$}, # all padrino code
6
- %r{/padrino-.*/(lib|bin)}, # all padrino code
7
- %r{/bin/padrino$}, # all padrino code
8
- %r{/sinatra(/(base|main|showexceptions))?\.rb$}, # all sinatra code
9
- %r{lib/tilt.*\.rb$}, # all tilt code
10
- %r{lib/rack.*\.rb$}, # all rack code
11
- %r{lib/mongrel.*\.rb$}, # all mongrel code
12
- %r{lib/shotgun.*\.rb$}, # all shotgun lib
13
- %r{bin/shotgun$}, # shotgun binary
14
- %r{\(.*\)}, # generated code
15
- %r{shoulda/context\.rb$}, # shoulda hacks
16
- %r{mocha/integration}, # mocha hacks
17
- %r{test/unit}, # test unit hacks
18
- %r{rake_test_loader\.rb}, # rake hacks
19
- %r{custom_require\.rb$}, # rubygems require hacks
20
- %r{active_support}, # active_support require hacks
21
- %r{/thor} # thor require hacks
5
+ %r{lib/padrino-.*$},
6
+ %r{/padrino-.*/(lib|bin)},
7
+ %r{/bin/padrino$},
8
+ %r{/sinatra(/(base|main|showexceptions))?\.rb$},
9
+ %r{lib/tilt.*\.rb$},
10
+ %r{lib/rack.*\.rb$},
11
+ %r{lib/mongrel.*\.rb$},
12
+ %r{lib/shotgun.*\.rb$},
13
+ %r{bin/shotgun$},
14
+ %r{\(.*\)},
15
+ %r{shoulda/context\.rb$},
16
+ %r{mocha/integration},
17
+ %r{test/unit},
18
+ %r{rake_test_loader\.rb},
19
+ %r{custom_require\.rb$},
20
+ %r{active_support},
21
+ %r{/thor}
22
22
  ] unless defined?(PADRINO_IGNORE_CALLERS)
23
23
 
24
24
  ##
@@ -27,27 +27,27 @@ module Padrino
27
27
  PADRINO_IGNORE_CALLERS.concat(RUBY_IGNORE_CALLERS) if defined?(RUBY_IGNORE_CALLERS)
28
28
 
29
29
  private
30
- ##
31
- # The filename for the file that is the direct caller (first caller).
32
- #
33
- # @return [String]
34
- # The file the caller method exists in.
35
- #
36
- def self.first_caller
37
- caller_files.first
38
- end
30
+ ##
31
+ # The filename for the file that is the direct caller (first caller).
32
+ #
33
+ # @return [String]
34
+ # The file the caller method exists in.
35
+ #
36
+ def self.first_caller
37
+ caller_files.first
38
+ end
39
39
 
40
- #
41
- # Like +Kernel#caller+ but excluding certain magic entries and without
42
- # line / method information; the resulting array contains filenames only.
43
- #
44
- # @return [Array<String>]
45
- # The files of the calling methods.
46
- #
47
- def self.caller_files
48
- caller(1).
49
- map { |line| line.split(/:(?=\d|in )/)[0,2] }.
50
- reject { |file,line| PADRINO_IGNORE_CALLERS.any? { |pattern| file =~ pattern } }.
51
- map { |file,line| file }
52
- end
53
- end # Padrino
40
+ #
41
+ # Like +Kernel#caller+ but excluding certain magic entries and without
42
+ # line / method information; the resulting array contains filenames only.
43
+ #
44
+ # @return [Array<String>]
45
+ # The files of the calling methods.
46
+ #
47
+ def self.caller_files
48
+ caller(1).
49
+ map { |line| line.split(/:(?=\d|in )/)[0,2] }.
50
+ reject { |file,line| PADRINO_IGNORE_CALLERS.any? { |pattern| file =~ pattern } }.
51
+ map { |file,line| file }
52
+ end
53
+ end
@@ -18,7 +18,7 @@ module Padrino
18
18
  puts "=> #{options[:pid]} not found!"
19
19
  end
20
20
  end
21
- end # self
22
- end # Adapter
23
- end # Cli
24
- end # Padrino
21
+ end
22
+ end
23
+ end
24
+ end
@@ -71,7 +71,6 @@ module Padrino
71
71
  desc "generate", "Executes the Padrino generator with given options (alternatively use 'gen' or 'g')."
72
72
  map ["gen", "g"] => :generate
73
73
  def generate(*args)
74
- # Build Padrino g as an alias of padrino-gen
75
74
  begin
76
75
  # We try to load the vendored padrino-gen if exist
77
76
  padrino_gen_path = File.expand_path('../../../../../padrino-gen/lib', __FILE__)
@@ -111,48 +110,50 @@ module Padrino
111
110
  end
112
111
 
113
112
  private
114
- def prepare(task)
115
- if options.help?
116
- help(task.to_s)
117
- raise SystemExit
118
- end
119
- ENV["PADRINO_ENV"] ||= ENV["RACK_ENV"] ||= options.environment.to_s
120
- chdir(options.chdir)
121
- unless File.exist?('config/boot.rb')
122
- puts "=> Could not find boot file in: #{options.chdir}/config/boot.rb !!!"
123
- raise SystemExit
124
- end
113
+
114
+ def prepare(task)
115
+ if options.help?
116
+ help(task.to_s)
117
+ raise SystemExit
118
+ end
119
+ ENV["PADRINO_ENV"] ||= ENV["RACK_ENV"] ||= options.environment.to_s
120
+ chdir(options.chdir)
121
+ unless File.exist?('config/boot.rb')
122
+ puts "=> Could not find boot file in: #{options.chdir}/config/boot.rb !!!"
123
+ raise SystemExit
125
124
  end
125
+ end
126
126
 
127
127
  protected
128
- def self.banner(task=nil, *args)
129
- "padrino #{task.name}"
130
- end
131
128
 
132
- def chdir(dir)
133
- return unless dir
134
- begin
135
- Dir.chdir(dir.to_s)
136
- rescue Errno::ENOENT
137
- puts "=> Specified Padrino root '#{dir}' does not appear to exist!"
138
- rescue Errno::EACCES
139
- puts "=> Specified Padrino root '#{dir}' cannot be accessed by the current user!"
140
- end
129
+ def self.banner(task=nil, *args)
130
+ "padrino #{task.name}"
131
+ end
132
+
133
+ def chdir(dir)
134
+ return unless dir
135
+ begin
136
+ Dir.chdir(dir.to_s)
137
+ rescue Errno::ENOENT
138
+ puts "=> Specified Padrino root '#{dir}' does not appear to exist!"
139
+ rescue Errno::EACCES
140
+ puts "=> Specified Padrino root '#{dir}' cannot be accessed by the current user!"
141
141
  end
142
+ end
142
143
 
143
- def capture(stream)
144
- begin
145
- stream = stream.to_s
146
- eval "$#{stream} = StringIO.new"
147
- yield
148
- result = eval("$#{stream}").string
149
- ensure
150
- eval("$#{stream} = #{stream.upcase}")
151
- end
152
-
153
- result
144
+ def capture(stream)
145
+ begin
146
+ stream = stream.to_s
147
+ eval "$#{stream} = StringIO.new"
148
+ yield
149
+ result = eval("$#{stream}").string
150
+ ensure
151
+ eval("$#{stream} = #{stream.upcase}")
154
152
  end
155
- alias :silence :capture
156
- end # Base
157
- end # Cli
158
- end # Padrino
153
+
154
+ result
155
+ end
156
+ alias :silence :capture
157
+ end
158
+ end
159
+ end
@@ -7,9 +7,9 @@ require 'padrino-gen'
7
7
 
8
8
  module PadrinoTasks
9
9
  def self.init(init=false)
10
- $LOAD_PATH.unshift(File.expand_path("lib")) # Adds "lib" to the load path
10
+ $LOAD_PATH.unshift(File.expand_path("lib"))
11
11
  Padrino::Tasks.files.flatten.uniq.each { |rakefile| Rake.application.add_import(rakefile) rescue puts "<= Failed load #{ext}" }
12
- load(File.expand_path('../rake_tasks.rb', __FILE__)) # Load default rake tasks
12
+ load(File.expand_path('../rake_tasks.rb', __FILE__))
13
13
  Rake.application.load_imports
14
14
  end
15
15
 
@@ -1,4 +1,3 @@
1
- # Load rake tasks from common rake task definition locations
2
1
  Dir["{lib/tasks/**,tasks/**,test,spec}/*.rake"].each do |file|
3
2
  begin
4
3
  load(file)
@@ -7,8 +6,8 @@ Dir["{lib/tasks/**,tasks/**,test,spec}/*.rake"].each do |file|
7
6
  end
8
7
  end
9
8
 
10
- # Loads the Padrino applications mounted within the project
11
- # setting up the required environment for Padrino
9
+ # Loads the Padrino applications mounted within the project.
10
+ # Setting up the required environment for Padrino.
12
11
  task :environment do
13
12
  require File.expand_path('config/boot.rb', Rake.application.original_dir)
14
13
 
@@ -22,7 +21,6 @@ task :secret do
22
21
  shell.say SecureRandom.hex(32)
23
22
  end
24
23
 
25
- # lists all routes of a given app
26
24
  def list_app_routes(app, args)
27
25
  app_routes = app.named_routes
28
26
  app_routes.reject! { |r| r.identifier.to_s !~ /#{args.query}/ } if args.query.present?
@@ -3,7 +3,7 @@ require 'rbconfig'
3
3
  module Padrino
4
4
  ##
5
5
  # This method return the correct location of padrino bin or
6
- # exec it using Kernel#system with the given args
6
+ # exec it using Kernel#system with the given args.
7
7
  #
8
8
  # @param [Array] args
9
9
  # command or commands to execute
@@ -35,4 +35,4 @@ module Padrino
35
35
  ruby
36
36
  end
37
37
  end
38
- end # Padrino
38
+ end
@@ -64,7 +64,7 @@ module Padrino
64
64
 
65
65
  @_called_from = first_caller
66
66
  Padrino.set_encoding
67
- Padrino.set_load_paths(*load_paths) # We set the padrino load paths
67
+ Padrino.set_load_paths(*load_paths)
68
68
  Padrino::Logger.setup! # Initialize our logger
69
69
  Padrino.require_dependencies("#{root}/config/database.rb", :nodeps => true) # Be sure to don't remove constants from dbs.
70
70
  Padrino::Reloader.lock! # Now we can remove constant from here to down
@@ -105,7 +105,7 @@ module Padrino
105
105
  end
106
106
 
107
107
  ##
108
- # This adds the ablity to instantiate {Padrino.load!} after
108
+ # This adds the ability to instantiate {Padrino.load!} after
109
109
  # {Padrino::Application} definition.
110
110
  #
111
111
  def called_from
@@ -135,7 +135,7 @@ module Padrino
135
135
  #
136
136
  # Dir["/models/*.rb"].each { |r| require r }
137
137
  #
138
- # we get an error, because we try to require first +a.rb+ that need
138
+ # We get an error, because we try to require first +a.rb+ that need
139
139
  # _something_ of +b.rb+.
140
140
  #
141
141
  # With this method we don't have this problem.
@@ -153,21 +153,19 @@ module Padrino
153
153
  files = paths.flatten.map { |path| Dir[path] }.flatten.uniq.sort
154
154
 
155
155
  while files.present?
156
- # List of errors and failed files
157
156
  errors, failed = [], []
158
157
 
159
- # We need a size to make sure things are loading
160
158
  size_at_start = files.size
161
159
 
162
160
  # Now we try to require our dependencies, we dup files
163
161
  # so we don't perform delete on the original array during
164
- # iteration, this prevent problems with rubinus
162
+ # iteration, this prevent problems with Rubinus
165
163
  files.dup.each do |file|
166
164
  begin
167
165
  Padrino::Reloader.safe_load(file, options.dup)
168
166
  files.delete(file)
169
167
  rescue NameError, LoadError => e
170
- Padrino.logger.devel "Problem while loading #{file}: #{e.to_s}"
168
+ Padrino.logger.devel "Problem while loading #{file}: #{e}"
171
169
  errors << e
172
170
  failed << file
173
171
  rescue Exception => e
@@ -182,7 +180,7 @@ module Padrino
182
180
  end
183
181
 
184
182
  ##
185
- # Returns default list of path globs to load as dependencies
183
+ # Returns default list of path globs to load as dependencies.
186
184
  # Appends custom dependency patterns to the be loaded for Padrino.
187
185
  #
188
186
  # @return [Array<String>]
@@ -206,20 +204,21 @@ module Padrino
206
204
  $:.uniq!; load_paths.uniq!
207
205
  end
208
206
 
209
- private
207
+ private
208
+
210
209
  def module_paths
211
210
  Padrino.modules.map(&:dependency_paths).flatten!
212
211
  end
213
212
 
214
213
  def dependency_paths_was
215
214
  [
216
- "#{root}/config/database.rb",
217
- "#{root}/lib/**/*.rb",
215
+ "#{root}/config/database.rb",
216
+ "#{root}/lib/**/*.rb",
218
217
  "#{root}/shared/lib/**/*.rb",
219
- "#{root}/models/**/*.rb",
220
- "#{root}/shared/models/**/*.rb",
218
+ "#{root}/models/**/*.rb",
219
+ "#{root}/shared/models/**/*.rb",
221
220
  "#{root}/config/apps.rb"
222
221
  ]
223
222
  end
224
- end # self
225
- end # Padrino
223
+ end
224
+ end
@@ -26,7 +26,6 @@ cs:
26
26
  am: "dop"
27
27
  pm: "odp"
28
28
 
29
- # Used in array.to_sentence.
30
29
  support:
31
30
  array:
32
31
  words_connector: ", "
@@ -26,7 +26,6 @@ da:
26
26
  am: ""
27
27
  pm: ""
28
28
 
29
- # Used in array.to_sentence.
30
29
  support:
31
30
  array:
32
31
  words_connector: ", "
@@ -26,7 +26,6 @@ de:
26
26
  am: "am"
27
27
  pm: "pm"
28
28
 
29
- # Benutzt in array.to_sentence.
30
29
  support:
31
30
  array:
32
31
  words_connector: ", "
@@ -26,7 +26,6 @@ en:
26
26
  am: "am"
27
27
  pm: "pm"
28
28
 
29
- # Used in array.to_sentence.
30
29
  support:
31
30
  array:
32
31
  words_connector: ", "
@@ -13,7 +13,7 @@ es:
13
13
  abbr_day_names: [Dom, Lun, Mar, Mie, Jue, Vie, Sab]
14
14
  month_names: [~, Enero, Febrero, Marzo, Abril, Mayo, Junio, Julio, Agosto, Septiembre, Octubre, Noviembre, Diciembre]
15
15
  abbr_month_names: [~, Ene, Feb, Mar, Abr, May, Jun, Jul, Ago, Sep, Oct, Nov, Dic]
16
- order:
16
+ order:
17
17
  - day
18
18
  - month
19
19
  - year
@@ -26,7 +26,6 @@ es:
26
26
  am: "am"
27
27
  pm: "pm"
28
28
 
29
- # Used in array.to_sentence.
30
29
  support:
31
30
  array:
32
31
  words_connector: ", "
@@ -10,10 +10,10 @@ fr:
10
10
  only_day: "%e"
11
11
 
12
12
  day_names: [Dimanche, Lundi, Mardi, Mercredi, Jeudi, Vendredi, Samedi]
13
- abbr_day_names: [Lun, Mar, Mer, Jeu, Ven, Sam, Dim]
13
+ abbr_day_names: [Dim, Lun, Mar, Mer, Jeu, Ven, Sam]
14
14
  month_names: [~, Janvier, Février, Mars, Avril, Mai, Juin, Juillet, Août, Septembre, Octobre, Novembre, Décembre]
15
15
  abbr_month_names: [~, Jan, Fev, Mar, Avr, Mai, Jun, Jul, Aou, Sep, Oct, Nov, Dec]
16
- order:
16
+ order:
17
17
  - day
18
18
  - month
19
19
  - year
@@ -26,7 +26,6 @@ fr:
26
26
  am: "am"
27
27
  pm: "pm"
28
28
 
29
- # Used in array.to_sentence.
30
29
  support:
31
30
  array:
32
31
  words_connector: ", "
@@ -13,7 +13,7 @@ hu:
13
13
  abbr_day_names: [vas, hét, kedd, sze, csüt, pén, szo]
14
14
  month_names: [~, január, február, március, április, május, június, július, augusztus, szeptember, oktober, november, december]
15
15
  abbr_month_names: [~, jan, febr, márc, ápr, máj, jún, júl, aug, szept, okt, nov, dec]
16
- order:
16
+ order:
17
17
  - year
18
18
  - month
19
19
  - day
@@ -26,7 +26,6 @@ hu:
26
26
  am: "de"
27
27
  pm: "du"
28
28
 
29
- # Used in array.to_sentence.
30
29
  support:
31
30
  array:
32
31
  words_connector: ", "