padrino-core 0.1.3 → 0.1.4
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.
- data/README.rdoc +191 -2
- data/Rakefile +3 -1
- data/VERSION +1 -1
- data/bin/padrino +2 -1
- data/lib/padrino-core.rb +2 -3
- data/lib/padrino-core/application.rb +42 -19
- data/lib/padrino-core/caller.rb +35 -0
- data/lib/padrino-core/loader.rb +44 -20
- data/lib/padrino-core/mounter.rb +34 -28
- data/lib/padrino-core/support_lite.rb +24 -9
- data/lib/padrino-core/support_lite/as_support.rb +21 -0
- data/lib/padrino-core/support_lite/extlib_support.rb +96 -0
- data/lib/padrino-core/tasks.rb +3 -6
- data/lib/padrino-core/tasks/test.rb +5 -4
- data/lib/padrino-core/version.rb +1 -1
- data/padrino-core.gemspec +14 -13
- data/test/fixtures/{simple_app → apps}/.components +0 -0
- data/test/fixtures/{simple_app → apps}/.gitignore +0 -0
- data/test/fixtures/apps/app.rb +15 -0
- data/test/fixtures/apps/multi.rb +27 -0
- data/test/helper.rb +29 -11
- data/test/test_padrino_core.rb +3 -13
- data/test/test_padrino_mounter.rb +50 -19
- metadata +20 -10
- data/test/active_support_helpers.rb +0 -7
- data/test/fixtures/simple_app/Gemfile +0 -9
- data/test/fixtures/simple_app/app.rb +0 -41
- data/test/test_padrino_application.rb +0 -45
data/lib/padrino-core/mounter.rb
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
module Padrino
|
2
2
|
# Represents a particular mounted padrino application
|
3
3
|
# Stores the name of the application (app folder name) and url mount path
|
4
|
-
# @example Mounter.new("blog_app").to("/blog")
|
5
|
-
# @example Mounter.new("blog_app", :app_file => "/path/to/root/app.rb").to("/blog")
|
6
4
|
# @example Mounter.new("blog_app", :app_class => "Blog").to("/blog")
|
5
|
+
# @example Mounter.new("blog_app", :app_file => "/path/to/blog/app.rb").to("/blog")
|
7
6
|
class Mounter
|
8
|
-
attr_accessor :name, :uri_root, :app_file, :
|
7
|
+
attr_accessor :name, :uri_root, :app_file, :app_class, :app_root
|
9
8
|
def initialize(name, options={})
|
10
|
-
@name = name
|
11
|
-
@
|
12
|
-
@app_file = options[:app_file] ||
|
13
|
-
@app_root = options[:app_root]
|
9
|
+
@name = name.downcase
|
10
|
+
@app_class = options[:app_class] || name.classify
|
11
|
+
@app_file = options[:app_file] || locate_app_file
|
12
|
+
@app_root = options[:app_root]
|
14
13
|
end
|
15
14
|
|
16
15
|
# Registers the mounted application onto Padrino
|
@@ -18,33 +17,37 @@ module Padrino
|
|
18
17
|
def to(mount_url)
|
19
18
|
@uri_root = mount_url
|
20
19
|
Padrino.mounted_apps << self
|
20
|
+
self
|
21
21
|
end
|
22
22
|
|
23
23
|
# Maps Padrino application onto a Rack::Builder
|
24
24
|
# For use in constructing a Rack application
|
25
25
|
# @example @app.map_onto(@builder)
|
26
26
|
def map_onto(builder)
|
27
|
-
require(self.app_file)
|
28
|
-
app_data,
|
27
|
+
self.app_class.constantize rescue require(self.app_file)
|
28
|
+
app_data, app_class = self, self.app_class.constantize
|
29
29
|
builder.map self.uri_root do
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
app_class.set :uri_root, app_data.uri_root
|
31
|
+
app_class.set :app_file, app_data.app_file
|
32
|
+
app_class.set :app_name, app_data.name
|
33
|
+
app_class.set :root, app_data.app_root if app_data.app_root
|
34
|
+
run app_class
|
34
35
|
end
|
35
36
|
end
|
37
|
+
|
38
|
+
# Returns the determined location of the mounted application main file
|
39
|
+
def locate_app_file
|
40
|
+
callers_are_identical = File.identical?(Padrino.first_caller.to_s, Padrino.called_from.to_s)
|
41
|
+
callers_are_identical ? Padrino.first_caller : Padrino.mounted_root(name, "app.rb")
|
42
|
+
end
|
36
43
|
end
|
37
44
|
|
38
45
|
class << self
|
46
|
+
attr_writer :mounted_root # Set root directory where padrino searches mounted apps
|
47
|
+
|
39
48
|
# Returns the root to the mounted apps base directory
|
40
49
|
def mounted_root(*args)
|
41
|
-
@mounted_root ||= "apps"
|
42
|
-
File.join(Padrino.root, @mounted_root, *args)
|
43
|
-
end
|
44
|
-
|
45
|
-
# Set the root directory where padrino search mounted apps
|
46
|
-
def mounted_root=(value)
|
47
|
-
@mounted_root = value
|
50
|
+
File.join(Padrino.root, @mounted_root ||= "apps", *args)
|
48
51
|
end
|
49
52
|
|
50
53
|
# Returns the mounted padrino applications (MountedApp objects)
|
@@ -52,17 +55,20 @@ module Padrino
|
|
52
55
|
@mounted_apps ||= []
|
53
56
|
end
|
54
57
|
|
58
|
+
# Mounts the core application onto Padrino project with given app settings (file, class, root)
|
59
|
+
# @example Padrino.mount_core("Blog")
|
60
|
+
# @example Padrino.mount_core(:app_file => "/path/to/file", :app_class => "Blog")
|
61
|
+
def mount_core(*args)
|
62
|
+
options = args.extract_options!
|
63
|
+
app_class = args.size > 0 ? args.first.to_s.camelize : nil
|
64
|
+
options.reverse_merge!(:app_class => app_class, :app_file => Padrino.root('app/app.rb'), :app_root => Padrino.root)
|
65
|
+
mount("core", options).to("/")
|
66
|
+
end
|
67
|
+
|
55
68
|
# Mounts a new sub-application onto Padrino project
|
56
69
|
# @example Padrino.mount("blog_app").to("/blog")
|
57
70
|
def mount(name, options={})
|
58
71
|
Mounter.new(name, options)
|
59
72
|
end
|
60
|
-
|
61
|
-
# Mounts the core application onto Padrino project
|
62
|
-
# @example Padrino.mount_core(:app_file => "/path/to/file", :app_class => "Blog")
|
63
|
-
def mount_core(options={})
|
64
|
-
options.reverse_merge!(:app_file => Padrino.root('app/app.rb'), :app_root => Padrino.root)
|
65
|
-
Mounter.new("core", options).to("/")
|
66
|
-
end
|
67
73
|
end
|
68
|
-
end
|
74
|
+
end
|
@@ -1,9 +1,24 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
=begin
|
2
|
+
|
3
|
+
This file determines if extlib or activesupport are already loaded, and then ensures
|
4
|
+
the required objects and methods exist for Padrino to use.
|
5
|
+
|
6
|
+
Required for Padrino to run:
|
7
|
+
|
8
|
+
* Class#cattr_accessor
|
9
|
+
* Module#alias_method_chain
|
10
|
+
* String#inflectors (classify, underscore, camelize, etc)
|
11
|
+
* Array#extract_options!
|
12
|
+
* Object#blank?
|
13
|
+
* Object#present?
|
14
|
+
* Hash#symbolize_keys
|
15
|
+
* Hash#reverse_merge, Hash#reverse_merge!
|
16
|
+
* SupportLite::OrderedHash
|
17
|
+
|
18
|
+
=end
|
19
|
+
|
20
|
+
if defined?(Extlib) # load if already using extlib
|
21
|
+
require File.dirname(__FILE__) + '/support_lite/extlib_support'
|
22
|
+
else # load active support by default
|
23
|
+
require File.dirname(__FILE__) + '/support_lite/as_support'
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# This requires necessary pieces of ActiveSupport for the dependencies required by Padrino
|
2
|
+
|
3
|
+
## Class#cattr_accessor
|
4
|
+
require 'active_support/core_ext/class/attribute_accessors' unless Class.method_defined?(:cattr_accessor)
|
5
|
+
## Hash#symbolize_keys, Hash#reverse_merge, Hash#reverse_merge!, Hash#extract_options!
|
6
|
+
require 'active_support/core_ext/hash' unless Hash.method_defined?(:reverse_merge)
|
7
|
+
## String#inflectors
|
8
|
+
require 'active_support/inflector' unless String.method_defined?(:constantize)
|
9
|
+
## Object#blank?, Object#present?
|
10
|
+
require 'active_support/core_ext/blank' unless Object.method_defined?(:blank?)
|
11
|
+
## Array#extract_options!
|
12
|
+
require 'active_support/core_ext/array' unless Array.method_defined?(:extract_options!)
|
13
|
+
## Module#alias_method_chain
|
14
|
+
require 'active_support/core_ext/module' unless Module.method_defined?(:alias_method_chain)
|
15
|
+
## SupportLite::OrderedHash
|
16
|
+
require 'active_support/ordered_hash' unless defined?(ActiveSupport::OrderedHash)
|
17
|
+
unless defined?(SupportLite::OrderedHash)
|
18
|
+
module SupportLite
|
19
|
+
OrderedHash = ::ActiveSupport::OrderedHash
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# This helps extlib to act like ActiveSupport for use with Padrino
|
2
|
+
|
3
|
+
## Class#cattr_accessor
|
4
|
+
unless Class.method_defined?(:cattr_accessor)
|
5
|
+
require 'extlib/class'
|
6
|
+
end
|
7
|
+
|
8
|
+
## SupportLite::OrderedHash
|
9
|
+
unless defined?(SupportLite::OrderedHash)
|
10
|
+
require 'extlib/dictionary'
|
11
|
+
module SupportLite
|
12
|
+
OrderedHash = ::Dictionary
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
## Hash#symbolize_keys
|
17
|
+
unless Hash.method_defined?(:symbolize_keys)
|
18
|
+
require 'extlib/hash'
|
19
|
+
require 'extlib/mash'
|
20
|
+
class Hash
|
21
|
+
def symbolize_keys
|
22
|
+
Mash.new(self).symbolize_keys
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
## Hash#reverse_merge, Hash#reverse_merge!
|
29
|
+
unless Hash.method_defined?(:present?)
|
30
|
+
class Hash
|
31
|
+
def reverse_merge(other_hash)
|
32
|
+
other_hash.merge(self)
|
33
|
+
end
|
34
|
+
|
35
|
+
def reverse_merge!(other_hash)
|
36
|
+
replace(reverse_merge(other_hash))
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
## Array#extract_options!
|
42
|
+
unless Array.method_defined?(:extract_options!)
|
43
|
+
class Array
|
44
|
+
def extract_options!
|
45
|
+
last.is_a?(::Hash) ? pop : {}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
## String#inflectors
|
51
|
+
unless String.method_defined?(:constantize)
|
52
|
+
require 'extlib/inflection'
|
53
|
+
class String
|
54
|
+
def classify; Extlib::Inflection.classify(self); end
|
55
|
+
def underscore; Extlib::Inflection.underscore(self); end
|
56
|
+
def constantize; Extlib::Inflection.constantize(self); end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
## Object#blank?
|
61
|
+
unless Array.method_defined?(:blank?)
|
62
|
+
require 'extlib/blank'
|
63
|
+
end
|
64
|
+
|
65
|
+
## Object#present?
|
66
|
+
unless Array.method_defined?(:present?)
|
67
|
+
class Object
|
68
|
+
def present?
|
69
|
+
!blank?
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
## Module#alias_method_chain
|
75
|
+
unless Module.method_defined?(:alias_method_chain)
|
76
|
+
def alias_method_chain(target, feature)
|
77
|
+
# Strip out punctuation on predicates or bang methods since
|
78
|
+
# e.g. target?_without_feature is not a valid method name.
|
79
|
+
aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1
|
80
|
+
yield(aliased_target, punctuation) if block_given?
|
81
|
+
|
82
|
+
with_method, without_method = "#{aliased_target}_with_#{feature}#{punctuation}", "#{aliased_target}_without_#{feature}#{punctuation}"
|
83
|
+
|
84
|
+
alias_method without_method, target
|
85
|
+
alias_method target, with_method
|
86
|
+
|
87
|
+
case
|
88
|
+
when public_method_defined?(without_method)
|
89
|
+
public target
|
90
|
+
when protected_method_defined?(without_method)
|
91
|
+
protected target
|
92
|
+
when private_method_defined?(without_method)
|
93
|
+
private target
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
data/lib/padrino-core/tasks.rb
CHANGED
@@ -2,23 +2,20 @@ require 'thor'
|
|
2
2
|
require File.dirname(__FILE__) + "/tasks/helpers"
|
3
3
|
|
4
4
|
module Padrino
|
5
|
-
module Tasks
|
5
|
+
module Tasks
|
6
6
|
class Base < Thor
|
7
7
|
include Thor::Actions
|
8
8
|
include Padrino::Tasks::Helpers
|
9
9
|
|
10
10
|
class_option :chdir, :type => :string, :aliases => "-c"
|
11
11
|
|
12
|
-
desc "start
|
13
|
-
|
12
|
+
desc "start", "Starts the Padrino application"
|
14
13
|
method_option :environment, :type => :string, :aliases => "-e", :required => true, :default => :development
|
15
14
|
method_option :adapter, :type => :string, :aliases => "-a", :required => true, :default => :thin
|
16
15
|
method_option :host, :type => :string, :aliases => "-h", :required => true, :default => "localhost"
|
17
16
|
method_option :port, :type => :numeric, :aliases => "-p", :required => true, :default => 3000
|
18
17
|
method_option :boot, :type => :string, :aliases => "-b", :required => true, :default => "config/boot.rb"
|
19
18
|
method_option :daemonize, :type => :boolean, :aliases => "-d"
|
20
|
-
|
21
|
-
desc "start", "Start the Padrino application"
|
22
19
|
def start
|
23
20
|
require File.dirname(__FILE__) + "/tasks/adapter"
|
24
21
|
chdir(options.chdir)
|
@@ -45,7 +42,7 @@ module Padrino
|
|
45
42
|
require File.dirname(__FILE__) + "/version"
|
46
43
|
boot = options.chdir ? File.join(options.chdir, options.boot) : options.boot
|
47
44
|
unless File.exist?(boot)
|
48
|
-
puts "=>
|
45
|
+
puts "=> Could not find boot file: #{boot.inspect} !!!"
|
49
46
|
exit
|
50
47
|
end
|
51
48
|
ENV["PADRINO_ENV"] ||= environment
|
@@ -4,11 +4,12 @@ module Padrino
|
|
4
4
|
|
5
5
|
class << self
|
6
6
|
|
7
|
-
# This
|
8
|
-
# It look for any test/test_*.rb
|
7
|
+
# This method executes tests found for the given app.
|
8
|
+
# It look for any spec/*_spec.rb and test/test_*.rb files in your app root.
|
9
9
|
def start
|
10
|
-
puts "=>
|
11
|
-
tests =
|
10
|
+
puts "=> Executing Tests..."
|
11
|
+
tests = Dir['test/**/test_*.rb'] - ['test/test_helper.rb']
|
12
|
+
tests << Dir['spec/**/*_spec.rb'] - Dir['spec/**/spec_helper.rb']
|
12
13
|
cmd = "ruby -rubygems -I.:lib -e'%w( #{tests.join(' ')} ).each { |file| require file }'"
|
13
14
|
system cmd
|
14
15
|
end
|
data/lib/padrino-core/version.rb
CHANGED
data/padrino-core.gemspec
CHANGED
@@ -5,36 +5,36 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{padrino-core}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.4"
|
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{2009-11-
|
12
|
+
s.date = %q{2009-11-23}
|
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{nesquena@gmail.com}
|
16
16
|
s.executables = ["padrino"]
|
17
17
|
s.extra_rdoc_files = [
|
18
|
-
"
|
19
|
-
"README.rdoc"
|
18
|
+
"README.rdoc"
|
20
19
|
]
|
21
20
|
s.files = [
|
22
21
|
".document",
|
23
22
|
".gitignore",
|
24
23
|
"LICENSE",
|
25
24
|
"README.rdoc",
|
26
|
-
"README.rdoc",
|
27
|
-
"Rakefile",
|
28
25
|
"Rakefile",
|
29
26
|
"VERSION",
|
30
27
|
"bin/padrino",
|
31
28
|
"lib/padrino-core.rb",
|
32
29
|
"lib/padrino-core/application.rb",
|
30
|
+
"lib/padrino-core/caller.rb",
|
33
31
|
"lib/padrino-core/loader.rb",
|
34
32
|
"lib/padrino-core/mounter.rb",
|
35
33
|
"lib/padrino-core/reloader.rb",
|
36
34
|
"lib/padrino-core/stat.rb",
|
37
35
|
"lib/padrino-core/support_lite.rb",
|
36
|
+
"lib/padrino-core/support_lite/as_support.rb",
|
37
|
+
"lib/padrino-core/support_lite/extlib_support.rb",
|
38
38
|
"lib/padrino-core/tasks.rb",
|
39
39
|
"lib/padrino-core/tasks/adapter.rb",
|
40
40
|
"lib/padrino-core/tasks/console.rb",
|
@@ -42,17 +42,15 @@ Gem::Specification.new do |s|
|
|
42
42
|
"lib/padrino-core/tasks/test.rb",
|
43
43
|
"lib/padrino-core/version.rb",
|
44
44
|
"padrino-core.gemspec",
|
45
|
-
"test/
|
46
|
-
"test/fixtures/
|
47
|
-
"test/fixtures/
|
48
|
-
"test/fixtures/
|
49
|
-
"test/fixtures/simple_app/app.rb",
|
45
|
+
"test/fixtures/apps/.components",
|
46
|
+
"test/fixtures/apps/.gitignore",
|
47
|
+
"test/fixtures/apps/app.rb",
|
48
|
+
"test/fixtures/apps/multi.rb",
|
50
49
|
"test/helper.rb",
|
51
|
-
"test/test_padrino_application.rb",
|
52
50
|
"test/test_padrino_core.rb",
|
53
51
|
"test/test_padrino_mounter.rb"
|
54
52
|
]
|
55
|
-
s.homepage = %q{http://github.com/padrino/padrino-core}
|
53
|
+
s.homepage = %q{http://github.com/padrino/padrino-framework/tree/master/padrino-core}
|
56
54
|
s.rdoc_options = ["--charset=UTF-8"]
|
57
55
|
s.require_paths = ["lib"]
|
58
56
|
s.rubygems_version = %q{1.3.5}
|
@@ -66,6 +64,7 @@ Gem::Specification.new do |s|
|
|
66
64
|
s.add_runtime_dependency(%q<sinatra>, [">= 0.9.2"])
|
67
65
|
s.add_runtime_dependency(%q<thor>, [">= 0.11.8"])
|
68
66
|
s.add_development_dependency(%q<haml>, [">= 2.2.1"])
|
67
|
+
s.add_runtime_dependency(%q<bundler>, [">= 0.5.0"])
|
69
68
|
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
70
69
|
s.add_development_dependency(%q<mocha>, [">= 0.9.7"])
|
71
70
|
s.add_development_dependency(%q<rack-test>, [">= 0.5.0"])
|
@@ -74,6 +73,7 @@ Gem::Specification.new do |s|
|
|
74
73
|
s.add_dependency(%q<sinatra>, [">= 0.9.2"])
|
75
74
|
s.add_dependency(%q<thor>, [">= 0.11.8"])
|
76
75
|
s.add_dependency(%q<haml>, [">= 2.2.1"])
|
76
|
+
s.add_dependency(%q<bundler>, [">= 0.5.0"])
|
77
77
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
78
78
|
s.add_dependency(%q<mocha>, [">= 0.9.7"])
|
79
79
|
s.add_dependency(%q<rack-test>, [">= 0.5.0"])
|
@@ -83,6 +83,7 @@ Gem::Specification.new do |s|
|
|
83
83
|
s.add_dependency(%q<sinatra>, [">= 0.9.2"])
|
84
84
|
s.add_dependency(%q<thor>, [">= 0.11.8"])
|
85
85
|
s.add_dependency(%q<haml>, [">= 2.2.1"])
|
86
|
+
s.add_dependency(%q<bundler>, [">= 0.5.0"])
|
86
87
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
87
88
|
s.add_dependency(%q<mocha>, [">= 0.9.7"])
|
88
89
|
s.add_dependency(%q<rack-test>, [">= 0.5.0"])
|
File without changes
|
File without changes
|
@@ -0,0 +1,15 @@
|
|
1
|
+
PADRINO_ROOT = File.dirname(__FILE__) unless defined? PADRINO_ROOT
|
2
|
+
require 'rubygems'
|
3
|
+
require 'sinatra/base'
|
4
|
+
require 'lib/padrino-core'
|
5
|
+
|
6
|
+
class SingleDemo < Padrino::Application; end
|
7
|
+
|
8
|
+
SingleDemo.controllers do
|
9
|
+
get "/test" do
|
10
|
+
'This should work'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
Padrino.mount_core("single_demo")
|
15
|
+
Padrino.load!
|
@@ -0,0 +1,27 @@
|
|
1
|
+
PADRINO_ROOT = File.dirname(__FILE__) unless defined? PADRINO_ROOT
|
2
|
+
require 'sinatra/base'
|
3
|
+
require 'padrino-core'
|
4
|
+
|
5
|
+
class Multi1Demo < Padrino::Application
|
6
|
+
disable :padrino_routing
|
7
|
+
disable :padrino_mailer
|
8
|
+
disable :padrino_helpers
|
9
|
+
|
10
|
+
get "" do
|
11
|
+
"Im Core1Demo"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class Mutli2Demo < Padrino::Application
|
16
|
+
disable :padrino_routing
|
17
|
+
disable :padrino_mailer
|
18
|
+
disable :padrino_helpers
|
19
|
+
|
20
|
+
get "" do
|
21
|
+
"Im Core2Demo"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
Padrino.mount("multi_1_demo").to("/multi_1_demo")
|
26
|
+
Padrino.mount("multi_2_demo").to("/multi_2_demo")
|
27
|
+
Padrino.load!
|