padrino-core 0.9.10 → 0.9.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,9 +13,9 @@ module Padrino
13
13
  #
14
14
  # ==== Options
15
15
  #
16
- # :to:: The class of application that you want mount
17
- # :path:: Map the app to the given path
18
- # :host:: Map the app to the given host
16
+ # :to:: The class of application that you want mount
17
+ # :path:: Map the app to the given path
18
+ # :host:: Map the app to the given host
19
19
  #
20
20
  # ==== Examples
21
21
  #
@@ -66,6 +66,8 @@ module Padrino
66
66
  next unless rPath =~ match && rest = $1
67
67
  next unless rest.empty? || rest[0] == ?/
68
68
 
69
+ rest = "/" if rest.empty?
70
+
69
71
  return app.call(
70
72
  env.merge(
71
73
  'SCRIPT_NAME' => (script_name + path),
@@ -9,9 +9,9 @@ module Padrino
9
9
  # Padrino.run! # with these defaults => host: "localhost", port: "3000", adapter: the first found
10
10
  # Padrino.run!("localhost", "4000", "mongrel") # use => host: "localhost", port: "3000", adapter: "mongrel"
11
11
  #
12
- def self.run!(*args)
13
- Padrino.load! unless Padrino.loaded?
14
- Server.build(*args)
12
+ def self.run!(options={})
13
+ Padrino.load!
14
+ Server.build(options)
15
15
  end
16
16
 
17
17
  ##
@@ -24,7 +24,11 @@ module Padrino
24
24
  Handlers = %w[thin mongrel webrick] unless const_defined?(:Handlers)
25
25
 
26
26
  private
27
- def self.build(host="localhost", port=3000, adapter=nil)
27
+ def self.build(options={})
28
+ host = options[:host] || "localhost"
29
+ port = options[:port] || 3000
30
+ adapter = options[:adapter]
31
+
28
32
  handler_name = adapter ? adapter.to_s.capitalize : detect_handler.name.gsub(/.*::/, '')
29
33
 
30
34
  begin
@@ -34,6 +38,8 @@ module Padrino
34
38
  exit
35
39
  end
36
40
 
41
+ puts "=> Padrino/#{Padrino.version} has taken the stage #{Padrino.env} on #{port}"
42
+
37
43
  handler.run Padrino.application, :Host => host, :Port => port do |server|
38
44
  trap(:INT) do
39
45
  # Use thins' hard #stop! if available, otherwise just #stop
@@ -3,89 +3,105 @@
3
3
  #
4
4
  # Why use ActiveSupport and not our own library or extlib?
5
5
  #
6
- # 1) Writing custom method extensions needed (i.e string inflections) is not a good use of time.
7
- # 2) Loading custom method extensions or separate gem would conflict when AR or MM has been loaded.
8
- # 3) Datamapper is planning to move to ActiveSupport and away from extlib.
6
+ # 1) Rewriting custom method extensions needed (i.e string inflectors) is not a good use of time.
7
+ # 2) Loading custom method extensions or separate gems would conflict with AS when AR or MM has been loaded.
8
+ # 3) Datamapper 1.0 supports ActiveSupport 3.0 and no longer requires extlib.
9
9
  #
10
- # Extensions required for Padrino:
11
- #
12
- # * Class#cattr_accessor
13
- # * Module#alias_method_chain
14
- # * String#inflectors (classify, underscore, camelize, pluralize, etc)
15
- # * Array#extract_options!
16
- # * Object#blank?
17
- # * Object#present?
18
- # * Hash#slice, Hash#slice!
19
- # * Hash#to_params
20
- # * Hash#symbolize_keys, Hash.symbolize_keys!
21
- # * Hash#reverse_merge, Hash#reverse_merge!
22
- # * Symbol#to_proc
23
- # * SupportLite::OrderedHash
24
- #
25
-
26
- require 'i18n'
27
- require 'rbconfig'
28
- require 'active_support/version'
29
- require 'active_support/core_ext/kernel'
30
- require 'active_support/core_ext/module'
31
- require 'active_support/deprecation'
32
- require 'active_support/core_ext/class/attribute_accessors'
33
- require 'active_support/core_ext/hash'
34
- require 'active_support/inflector'
35
- require 'active_support/core_ext/object'
36
- require 'active_support/core_ext/object/blank'
37
- require 'active_support/core_ext/array'
38
- require 'active_support/core_ext/module'
39
- require 'active_support/ordered_hash'
40
10
 
41
- # AS 3.0 has been removed it because is now available in Ruby 1.8.7 and 1.9.
42
- require 'active_support/core_ext/symbol' if ActiveSupport::VERSION::MAJOR < 3
11
+ require 'active_support/core_ext/string/conversions' unless String.method_defined?(:to_date)
12
+ require 'active_support/core_ext/kernel' unless Kernel.method_defined?(:silence_warnings)
13
+ require 'active_support/core_ext/module' unless Module.method_defined?(:alias_method_chain)
14
+ require 'active_support/core_ext/class/attribute_accessors' unless Class.method_defined?(:cattr_reader)
15
+ require 'active_support/core_ext/hash/keys' unless Hash.method_defined?(:symbolize_keys!)
16
+ require 'active_support/core_ext/hash/deep_merge' unless Hash.method_defined?(:deep_merge)
17
+ require 'active_support/core_ext/hash/reverse_merge' unless Hash.method_defined?(:reverse_merge)
18
+ require 'active_support/core_ext/hash/slice' unless Hash.method_defined?(:slice)
19
+ require 'active_support/core_ext/object/blank' unless Object.method_defined?(:present?)
20
+ require 'active_support/core_ext/array' unless Array.method_defined?(:from)
21
+ require 'active_support/ordered_hash' unless defined?(ActiveSupport::OrderedHash)
22
+ require 'active_support/inflector' unless String.method_defined?(:humanize)
23
+ require 'active_support/core_ext/float/rounding' unless Float.method_defined?(:round)
24
+ require 'active_support/option_merger' unless defined?(ActiveSupport::OptionMerger)
43
25
 
44
- ##
45
- # Define our own OrderedHash based on AS::OrderedHash
46
- #
47
- unless defined?(SupportLite::OrderedHash)
48
- module SupportLite
49
- OrderedHash = ::ActiveSupport::OrderedHash
50
- end
26
+ begin
27
+ require 'active_support/core_ext/symbol'
28
+ rescue LoadError
29
+ # AS 3.0 has been removed it because is now available in Ruby > 1.8.7 but we want keep Ruby 1.8.6 support.
30
+ class Symbol
31
+ # Turns the symbol into a simple proc, which is especially useful for enumerations like: people.map(&:name)
32
+ def to_proc
33
+ Proc.new { |*args| args.shift.__send__(self, *args) }
34
+ end
35
+ end unless :to_proc.respond_to?(:to_proc)
51
36
  end
52
37
 
53
- ##
54
- # Alias allowing for use of either method to get query parameters
55
- #
56
- unless Hash.method_defined?(:to_params)
38
+ # On ActiveSupport < 3.0.0 this is called misc
39
+ begin
40
+ require 'active_support/core_ext/object/with_options'
41
+ rescue LoadError
42
+ require 'active_support/core_ext/object/misc'
43
+ end unless Object.method_defined?(:with_options)
44
+
45
+ if defined?(ActiveSupport::CoreExtensions::Hash) && !Hash.method_defined?(:slice)
46
+ # This mean that we are using AS 2.3.x
57
47
  class Hash
58
- alias :to_params :to_query
48
+ include ActiveSupport::CoreExtensions::Hash::Keys
49
+ include ActiveSupport::CoreExtensions::Hash::DeepMerge
50
+ include ActiveSupport::CoreExtensions::Hash::ReverseMerge
51
+ include ActiveSupport::CoreExtensions::Hash::Slice
59
52
  end
60
53
  end
61
54
 
62
55
  ##
63
- # Loads our locales configuration files
56
+ # Used to know if this file was required
64
57
  #
65
- I18n.load_path += Dir["#{File.dirname(__FILE__)}/locale/*.yml"]
58
+ module SupportLite; end unless defined?(SupportLite)
66
59
 
67
- module Padrino
68
- ##
69
- # This method return the correct location of padrino bin or
70
- # exec it using Kernel#system with the given args
71
- #
72
- def self.bin(*args)
73
- @_padrino_bin ||= [self.ruby_command, File.expand_path("../../../bin/padrino", __FILE__)]
74
- args.empty? ? @_padrino_bin : system(args.unshift(@_padrino_bin).join(" "))
60
+ module ObjectSpace
61
+ class << self
62
+ # Returns all the classes in the object space.
63
+ def classes
64
+ klasses = []
65
+ ObjectSpace.each_object(Class) {|o| klasses << o}
66
+ klasses
67
+ end
75
68
  end
69
+ end unless ObjectSpace.respond_to?(:classes)
76
70
 
77
- ##
78
- # Return the path to the ruby interpreter taking into account multiple
79
- # installations and windows extensions.
80
- #
81
- def self.ruby_command
82
- @ruby_command ||= begin
83
- ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
84
- ruby << Config::CONFIG['EXEEXT']
85
-
86
- # escape string in case path to ruby executable contain spaces.
87
- ruby.sub!(/.*\s.*/m, '"\&"')
88
- ruby
71
+ class Object
72
+ def full_const_get(name)
73
+ list = name.split("::")
74
+ list.shift if list.first.blank?
75
+ obj = self
76
+ list.each do |x|
77
+ # This is required because const_get tries to look for constants in the
78
+ # ancestor chain, but we only want constants that are HERE
79
+ obj = obj.const_defined?(x) ? obj.const_get(x) : obj.const_missing(x)
89
80
  end
81
+ obj
82
+ end
83
+ end unless Object.method_defined?(:full_const_get)
84
+
85
+ # FileSet helper method for iterating and interacting with files inside a directory
86
+ class FileSet
87
+ # Iterates over every file in the glob pattern and yields to a block
88
+ # Returns the list of files matching the glob pattern
89
+ # FileSet.glob_require('padrino-core/application/*.rb', __FILE__) { |file| load file }
90
+ def self.glob(glob_pattern, file_path=nil, &block)
91
+ glob_pattern = File.join(File.dirname(file_path), glob_pattern) if file_path
92
+ file_list = Dir.glob(glob_pattern).sort
93
+ file_list.each { |file| block.call(file) }
94
+ file_list
90
95
  end
91
- end
96
+
97
+ # Requires each file matched in the glob pattern into the application
98
+ # FileSet.glob_require('padrino-core/application/*.rb', __FILE__)
99
+ def self.glob_require(glob_pattern, file_path=nil)
100
+ self.glob(glob_pattern, file_path) { |f| require f }
101
+ end
102
+ end unless defined?(FileSet)
103
+
104
+ ##
105
+ # Loads our locales configuration files
106
+ #
107
+ I18n.load_path += Dir["#{File.dirname(__FILE__)}/locale/*.yml"] if defined?(I18n)
@@ -1,10 +1,11 @@
1
1
  ##
2
- # Manages Padrino version from the VERSION file managed by Jeweler
2
+ # Manages current Padrino version for use in gem generation.
3
+ #
3
4
  # We put this in a separate file so you can get padrino version
4
5
  # without include full padrino core.
5
6
  #
6
7
  module Padrino
7
- VERSION = '0.9.10' unless defined?(Padrino::VERSION)
8
+ VERSION = '0.9.11' unless defined?(Padrino::VERSION)
8
9
  ##
9
10
  # Return the current Padrino version
10
11
  #
data/padrino-core.gemspec CHANGED
@@ -1,126 +1,23 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
1
+ require File.expand_path("../lib/padrino-core/version.rb", __FILE__)
2
+ require 'rubygems'
3
+ require 'bundler'
5
4
 
6
5
  Gem::Specification.new do |s|
7
- s.name = %q{padrino-core}
8
- s.version = "0.9.10"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
+ s.name = "padrino-core"
7
+ s.rubyforge_project = "padrino-core"
11
8
  s.authors = ["Padrino Team", "Nathan Esquenazi", "Davide D'Agostino", "Arthur Chiu"]
12
- s.date = %q{2010-04-22}
13
- s.default_executable = %q{padrino}
14
- s.description = %q{The Padrino core gem required for use of this framework}
15
9
  s.email = %q{padrinorb@gmail.com}
10
+ s.summary = %q{The required Padrino core gem}
11
+ s.homepage = "http://github.com/padrino/padrino-framework/tree/master/padrino-core"
12
+ s.description = %q{The Padrino core gem required for use of this framework}
13
+ s.default_executable = %q{padrino}
16
14
  s.executables = ["padrino"]
17
- s.extra_rdoc_files = [
18
- "README.rdoc"
19
- ]
20
- s.files = [
21
- ".document",
22
- ".gitignore",
23
- "LICENSE",
24
- "README.rdoc",
25
- "Rakefile",
26
- "bin/padrino",
27
- "lib/padrino-core.rb",
28
- "lib/padrino-core/application.rb",
29
- "lib/padrino-core/application/mounter.rb",
30
- "lib/padrino-core/application/rendering.rb",
31
- "lib/padrino-core/application/routing.rb",
32
- "lib/padrino-core/application/showexceptions.rb",
33
- "lib/padrino-core/caller.rb",
34
- "lib/padrino-core/cli/adapter.rb",
35
- "lib/padrino-core/cli/base.rb",
36
- "lib/padrino-core/cli/console.rb",
37
- "lib/padrino-core/cli/rake.rb",
38
- "lib/padrino-core/images/404.png",
39
- "lib/padrino-core/images/500.png",
40
- "lib/padrino-core/loader.rb",
41
- "lib/padrino-core/locale/da.yml",
42
- "lib/padrino-core/locale/de.yml",
43
- "lib/padrino-core/locale/en.yml",
44
- "lib/padrino-core/locale/fr.yml",
45
- "lib/padrino-core/locale/it.yml",
46
- "lib/padrino-core/locale/pt_br.yml",
47
- "lib/padrino-core/locale/ru.yml",
48
- "lib/padrino-core/logger.rb",
49
- "lib/padrino-core/reloader.rb",
50
- "lib/padrino-core/router.rb",
51
- "lib/padrino-core/server.rb",
52
- "lib/padrino-core/support_lite.rb",
53
- "lib/padrino-core/tasks.rb",
54
- "lib/padrino-core/version.rb",
55
- "padrino-core.gemspec",
56
- "test/fixtures/apps/.components",
57
- "test/fixtures/apps/.gitignore",
58
- "test/fixtures/apps/complex.rb",
59
- "test/fixtures/apps/simple.rb",
60
- "test/fixtures/dependencies/a.rb",
61
- "test/fixtures/dependencies/b.rb",
62
- "test/fixtures/dependencies/c.rb",
63
- "test/helper.rb",
64
- "test/test_application.rb",
65
- "test/test_core.rb",
66
- "test/test_dependencies.rb",
67
- "test/test_logger.rb",
68
- "test/test_mounter.rb",
69
- "test/test_reloader_complex.rb",
70
- "test/test_reloader_simple.rb",
71
- "test/test_rendering.rb",
72
- "test/test_router.rb",
73
- "test/test_routing.rb",
74
- "test/test_server.rb"
75
- ]
76
- s.homepage = %q{http://github.com/padrino/padrino-framework/tree/master/padrino-core}
15
+ s.required_rubygems_version = ">= 1.3.6"
16
+ s.version = Padrino.version
17
+ s.date = Time.now.strftime("%Y-%m-%d")
18
+ s.extra_rdoc_files = Dir["*.rdoc"]
19
+ s.files = %w(.document .gitignore LICENSE README.rdoc Rakefile padrino-core.gemspec) + Dir.glob("{bin,lib,test}/**/*")
77
20
  s.rdoc_options = ["--charset=UTF-8"]
78
- s.require_paths = ["lib"]
79
- s.rubyforge_project = %q{padrino-core}
80
- s.rubygems_version = %q{1.3.6}
81
- s.summary = %q{The required Padrino core gem}
82
-
83
- if s.respond_to? :specification_version then
84
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
85
- s.specification_version = 3
86
-
87
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
88
- s.add_runtime_dependency(%q<sinatra>, [">= 1.0.0"])
89
- s.add_runtime_dependency(%q<i18n>, [">= 0.3.2"])
90
- s.add_runtime_dependency(%q<usher>, [">= 0.6.2"])
91
- s.add_runtime_dependency(%q<thor>, [">= 0.13.0"])
92
- s.add_runtime_dependency(%q<bundler>, [">= 0.9.7"])
93
- s.add_runtime_dependency(%q<activesupport>, ["= 2.3.5"])
94
- s.add_development_dependency(%q<shoulda>, [">= 2.10.3"])
95
- s.add_development_dependency(%q<mocha>, [">= 0.9.7"])
96
- s.add_development_dependency(%q<rack-test>, [">= 0.5.0"])
97
- s.add_development_dependency(%q<webrat>, [">= 0.5.1"])
98
- s.add_development_dependency(%q<haml>, [">= 2.2.22"])
99
- else
100
- s.add_dependency(%q<sinatra>, [">= 1.0.0"])
101
- s.add_dependency(%q<i18n>, [">= 0.3.2"])
102
- s.add_dependency(%q<usher>, [">= 0.6.2"])
103
- s.add_dependency(%q<thor>, [">= 0.13.0"])
104
- s.add_dependency(%q<bundler>, [">= 0.9.7"])
105
- s.add_dependency(%q<activesupport>, ["= 2.3.5"])
106
- s.add_dependency(%q<shoulda>, [">= 2.10.3"])
107
- s.add_dependency(%q<mocha>, [">= 0.9.7"])
108
- s.add_dependency(%q<rack-test>, [">= 0.5.0"])
109
- s.add_dependency(%q<webrat>, [">= 0.5.1"])
110
- s.add_dependency(%q<haml>, [">= 2.2.22"])
111
- end
112
- else
113
- s.add_dependency(%q<sinatra>, [">= 1.0.0"])
114
- s.add_dependency(%q<i18n>, [">= 0.3.2"])
115
- s.add_dependency(%q<usher>, [">= 0.6.2"])
116
- s.add_dependency(%q<thor>, [">= 0.13.0"])
117
- s.add_dependency(%q<bundler>, [">= 0.9.7"])
118
- s.add_dependency(%q<activesupport>, ["= 2.3.5"])
119
- s.add_dependency(%q<shoulda>, [">= 2.10.3"])
120
- s.add_dependency(%q<mocha>, [">= 0.9.7"])
121
- s.add_dependency(%q<rack-test>, [">= 0.5.0"])
122
- s.add_dependency(%q<webrat>, [">= 0.5.1"])
123
- s.add_dependency(%q<haml>, [">= 2.2.22"])
124
- end
125
- end
126
-
21
+ s.require_path = 'lib'
22
+ s.add_bundler_dependencies :core, :development
23
+ end
@@ -17,11 +17,11 @@ class Complex2Demo < Padrino::Application
17
17
  end
18
18
 
19
19
  Complex1Demo.controllers do
20
- get("(/)"){ "Given random #{LibDemo.give_me_a_random}" }
20
+ get("/"){ "Given random #{LibDemo.give_me_a_random}" }
21
21
  end
22
22
 
23
23
  Complex2Demo.controllers do
24
- get("(/)"){ "The magick number is: 33!" } # Change only the number!!!
24
+ get("/"){ "The magick number is: 62!" } # Change only the number!!!
25
25
  end
26
26
 
27
27
  Padrino.load!
@@ -2,16 +2,23 @@ PADRINO_ROOT = File.dirname(__FILE__) unless defined? PADRINO_ROOT
2
2
  # Remove this comment if you want do some like this: ruby PADRINO_ENV=test app.rb
3
3
  #
4
4
  # require 'rubygems'
5
- # require 'lib/padrino-core'
5
+ # require 'padrino-core'
6
6
  #
7
7
 
8
8
  class SimpleDemo < Padrino::Application
9
9
  set :reload, true
10
+ before { true }
11
+ after { true }
12
+ error(404) { "404" }
10
13
  end
11
14
 
12
15
  SimpleDemo.controllers do
13
16
  get "/" do
14
- 'The magick number is: 77!' # Change only the number!!!
17
+ 'The magick number is: 39!' # Change only the number!!!
18
+ end
19
+
20
+ get "/rand" do
21
+ rand(99).to_s
15
22
  end
16
23
  end
17
24
 
@@ -20,5 +27,7 @@ end
20
27
  # Padrino.mount_core("SimpleDemo")
21
28
  # Padrino.run! unless Padrino.loaded? # If you enable reloader prevent to re-run the app
22
29
  #
30
+ # Then run it from your console: ruby -I"lib" test/fixtures/apps/simple.rb
31
+ #
23
32
 
24
33
  Padrino.load!
data/test/helper.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  ENV['PADRINO_ENV'] = 'test'
2
2
  PADRINO_ROOT = File.dirname(__FILE__) unless defined? PADRINO_ROOT
3
3
 
4
- require 'rubygems'
4
+ require File.expand_path('../../../load_paths', __FILE__)
5
5
  require 'padrino-core'
6
6
  require 'test/unit'
7
7
  require 'rack/test'