padrino-core 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,6 +1,17 @@
1
1
  = padrino-core
2
2
 
3
- Description goes here.
3
+ == Installation
4
+
5
+ To install the 'full-stack' padrino framework, simply grab the latest version from gemcutter:
6
+
7
+ $ sudo gem install padrino --source http://gemcutter.org
8
+
9
+ This will install the necessary padrino gems to get you started.
10
+ Now you are ready to use this gem to enhance your sinatra projects or to create new Padrino applications.
11
+
12
+ == Usage
13
+
14
+ Include padrino-core overview here
4
15
 
5
16
  == Copyright
6
17
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
data/lib/padrino-core.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  require 'sinatra/base'
2
- Dir[File.dirname(__FILE__) + '/padrino-core/**/*.rb'].each {|file| require file }
2
+ Dir[File.dirname(__FILE__) + '/padrino-core/*.rb'].each {|file| require file }
3
3
 
4
4
  # Defines our PADRINO_ENV
5
5
  PADRINO_ENV = ENV["PADRINO_ENV"] ||= ENV["RACK_ENV"] ||= "development" unless defined?(PADRINO_ENV)
6
6
 
7
7
  module Padrino
8
+ class ApplicationLoadError < RuntimeError; end
8
9
 
9
10
  # Helper method for file references.
10
11
  #
@@ -14,20 +15,12 @@ module Padrino
14
15
  def self.root(*args)
15
16
  File.join(PADRINO_ROOT, *args)
16
17
  end
17
-
18
- # Returns the prepared rack application mapping each 'mounted' application
18
+
19
+ # Returns the resulting rack builder mapping each 'mounted' application
19
20
  def self.application
20
- Rack::Builder.new do
21
- Padrino.mounted_apps.each do |app|
22
- require(app.app_file)
23
- app_klass = app.klass.constantize
24
- map app.uri_root do
25
- app_klass.set :uri_root, app.uri_root
26
- app_klass.set :app_file, app.app_file
27
- run app_klass
28
- end
29
- end
30
- end
21
+ raise ApplicationLoadError.new("At least one application must be mounted onto Padrino!") if self.mounted_apps.none?
22
+ builder = Rack::Builder.new
23
+ self.mounted_apps.each { |app| app.map_onto(builder) }
24
+ builder
31
25
  end
32
-
33
26
  end
@@ -1,4 +1,5 @@
1
1
  module Padrino
2
+ class ApplicationSetupError < RuntimeError; end
2
3
  # Subclasses of this become independent Padrino applications (stemming from Sinatra::Application)
3
4
  # These subclassed applications can be easily mounted into other Padrino applications as well.
4
5
  class Application < Sinatra::Application
@@ -26,7 +27,7 @@ module Padrino
26
27
  # Makes the routes defined in the block and in the Modules given
27
28
  # in `extensions` available to the application
28
29
  def controllers(*extensions, &block)
29
- @routes = {} if reload? # This perform a basic reload controller
30
+ @routes = Padrino::Application.dupe_routes if reload? # This performs a basic controller reload
30
31
  instance_eval(&block) if block_given?
31
32
  include(*extensions) if extensions.any?
32
33
  end
@@ -41,9 +42,10 @@ module Padrino
41
42
  protected
42
43
 
43
44
  # Setup the application by registering initializers, load paths and logger
44
- # Invoked automatically when an application instance is created
45
+ # Invoked automatically when an application is first instantiated
45
46
  def setup_application!
46
47
  return if @configured
48
+ self.calculate_paths
47
49
  self.register_initializers
48
50
  self.register_framework_extensions
49
51
  self.require_load_paths
@@ -61,20 +63,27 @@ module Padrino
61
63
  set :reload, development?
62
64
  # Padrino specific
63
65
  set :app_name, self.to_s.underscore.to_sym
64
- set :app_file, Padrino.mounted_root(self.app_name.to_s, "/app.rb")
65
66
  set :environment, PADRINO_ENV.to_sym
66
- set :images_path, self.public + "/images"
67
67
  set :default_builder, 'StandardFormBuilder'
68
68
  enable :flash
69
69
  # Plugin specific
70
70
  enable :padrino_helpers
71
71
  end
72
72
 
73
+ # Calculates any required paths after app_file and root have been properly configured
74
+ # Executes as part of the setup_application! method
75
+ def calculate_paths
76
+ raise ApplicationSetupError.new("Please specify 'app_file' configuration option!") unless self.app_file
77
+ set :views, find_view_path if find_view_path
78
+ set :images_path, File.join(self.public, "/images") unless self.respond_to?(:images_path)
79
+ end
80
+
73
81
  # Requires the middleware and initializer modules to configure components
74
82
  def register_initializers
75
83
  use Rack::Session::Cookie
76
84
  use Rack::Flash if flash?
77
85
  use Padrino::Reloader if reload?
86
+ register DatabaseSetup if defined?(DatabaseSetup)
78
87
  Dir[Padrino.root + '/config/initializers/*.rb'].each do |file|
79
88
  Padrino.load_dependencies(file)
80
89
  file_class = File.basename(file, '.rb').classify
@@ -91,7 +100,7 @@ module Padrino
91
100
 
92
101
  # Require all files within the application's load paths
93
102
  def require_load_paths
94
- load_paths.each { |path| Padrino.load_dependencies(File.join(self.root, path)) }
103
+ load_paths.each { |path| Padrino.load_dependencies(File.join(self.root, path)) }
95
104
  end
96
105
 
97
106
  # Creates the log directory and redirects output to file if needed
@@ -103,9 +112,16 @@ module Padrino
103
112
  $stderr.reopen(log)
104
113
  end
105
114
 
106
- # Returns the load_paths for the application relative to the application root
115
+ # Returns the load_paths for the application (relative to the application root)
107
116
  def load_paths
108
- @load_paths ||= ["models/*.rb", "urls.rb", "controllers/*.rb", "helpers/*.rb"]
117
+ @load_paths ||= ["urls.rb", "config/urls.rb", "models/*.rb", "app/models/*.rb",
118
+ "controllers/*.rb", "app/controllers/*.rb","helpers/*.rb", "app/helpers/*.rb"]
119
+ end
120
+
121
+ # Returns the path to the views directory from root by returning the first that is found
122
+ def find_view_path
123
+ @view_paths = ["views", "app/views"].collect { |path| File.join(self.root, path) }
124
+ @view_paths.find { |path| Dir[File.join(path, '/**/*')].any? }
109
125
  end
110
126
  end
111
127
  end
@@ -3,7 +3,8 @@ module Padrino
3
3
  # Requires necessary dependencies as well as application files from root lib and models
4
4
  def load!
5
5
  load_required_gems # load bundler gems
6
- load_dependencies("#{root}/config/apps.rb", "#{root}/lib/**/*.rb", "#{root}/models/*.rb") # load root app dependencies
6
+ load_dependencies("#{root}/config/apps.rb", "#{root}/config/database.rb")
7
+ load_dependencies("#{root}/lib/**/*.rb", "#{root}/models/*.rb") # load root app dependencies
7
8
  reload! # We need to fill our Stat::CACHE but we do that only for development
8
9
  end
9
10
 
@@ -5,18 +5,32 @@ module Padrino
5
5
  # @example Mounter.new("blog_app", :app_file => "/path/to/root/app.rb").to("/blog")
6
6
  # @example Mounter.new("blog_app", :app_class => "Blog").to("/blog")
7
7
  class Mounter
8
- attr_accessor :name, :uri_root, :app_file, :klass
8
+ attr_accessor :name, :uri_root, :app_file, :app_klass
9
9
  def initialize(name, options={})
10
- @name = name
11
- @klass = options[:app_class] || name.classify
12
- @app_file = options[:app_file] || Padrino.mounted_root(name, 'app.rb')
10
+ @name = name
11
+ @app_klass = options[:app_class] || name.classify
12
+ @app_file = options[:app_file] || Padrino.mounted_root(name, 'app.rb')
13
13
  end
14
14
 
15
- # registers the mounted application to Padrino
15
+ # Registers the mounted application onto Padrino
16
+ # @example Mounter.new("blog_app").to("/blog")
16
17
  def to(mount_url)
17
18
  @uri_root = mount_url
18
19
  Padrino.mounted_apps << self
19
20
  end
21
+
22
+ # Maps Padrino application onto a Rack::Builder
23
+ # For use in constructing a Rack application
24
+ # @example @app.map_onto(@builder)
25
+ def map_onto(builder)
26
+ require(self.app_file)
27
+ app_data, app_klass = self, self.app_klass.constantize
28
+ builder.map self.uri_root do
29
+ app_klass.set :uri_root, app_data.uri_root
30
+ app_klass.set :app_file, app_data.app_file
31
+ run app_klass
32
+ end
33
+ end
20
34
  end
21
35
 
22
36
  class << self
@@ -30,11 +44,17 @@ module Padrino
30
44
  @mounted_apps ||= []
31
45
  end
32
46
 
33
- # Mounts a new sub-application onto Padrino
47
+ # Mounts a new sub-application onto Padrino project
34
48
  # @example Padrino.mount("blog_app").to("/blog")
35
- # @example Padrino.mount("blog_app", :app_file => "/path/to/root/app.rb").to("/blog")
36
49
  def mount(name, options={})
37
50
  Mounter.new(name, options)
38
51
  end
52
+
53
+ # Mounts the core application onto Padrino project
54
+ # @example Padrino.mount_core(:app_file => "/path/to/file", :app_class => "Blog")
55
+ def mount_core(options={})
56
+ options.reverse_merge!(:app_file => Padrino.root('app.rb'))
57
+ Mounter.new("core", options).to("/")
58
+ end
39
59
  end
40
- end
60
+ end
@@ -5,4 +5,5 @@ unless String.method_defined?(:titleize) && Hash.method_defined?(:slice)
5
5
  require 'active_support/core_ext/class/attribute_accessors'
6
6
  require 'active_support/core_ext/hash'
7
7
  require 'active_support/core_ext/array'
8
+ require 'active_support/core_ext/module'
8
9
  end
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.1.1"
8
+ s.version = "0.1.2"
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-17}
12
+ s.date = %q{2009-11-18}
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}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Padrino Team
@@ -12,7 +12,7 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2009-11-17 00:00:00 -08:00
15
+ date: 2009-11-18 00:00:00 -08:00
16
16
  default_executable: padrino
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency