padrino-core 0.5.0 → 0.6.1

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.
@@ -0,0 +1,102 @@
1
+ require 'thor'
2
+ require 'thor/rake_compat'
3
+
4
+ module Padrino
5
+ module Cli
6
+ class Base < Thor
7
+ include Thor::Actions
8
+ include Thor::RakeCompat
9
+
10
+ class_option :chdir, :type => :string, :aliases => "-c"
11
+
12
+ desc "start", "Starts the Padrino application"
13
+ method_option :environment, :type => :string, :aliases => "-e", :required => true, :default => :development
14
+ method_option :adapter, :type => :string, :aliases => "-a", :required => true, :default => :thin
15
+ method_option :host, :type => :string, :aliases => "-h", :required => true, :default => "localhost"
16
+ method_option :port, :type => :numeric, :aliases => "-p", :required => true, :default => 3000
17
+ method_option :boot, :type => :string, :aliases => "-b", :required => true, :default => "config/boot.rb"
18
+ method_option :daemonize, :type => :boolean, :aliases => "-d"
19
+ def start
20
+ require File.dirname(__FILE__) + "/cli/adapter"
21
+ boot = check_boot
22
+ return unless boot
23
+ require boot
24
+ Padrino::Cli::Adapter.start(options)
25
+ end
26
+
27
+ desc "stop", "Stops the Padrino application"
28
+ def stop
29
+ require File.dirname(__FILE__) + "/cli/adapter"
30
+ Padrino::Cli::Adapter.stop
31
+ end
32
+
33
+ desc "test", "Executes all the Padrino test files"
34
+ def test
35
+ require File.dirname(__FILE__) + "/cli/test"
36
+ Padrino::Cli::Test.start
37
+ end
38
+
39
+ desc "rake", "Execute rake tasks in {Padrino.root}/lib/tasks"
40
+ method_option :boot, :type => :string, :aliases => "-b", :required => true, :default => "config/boot.rb"
41
+ method_option :environment, :type => :string, :aliases => "-e", :required => true, :default => :development
42
+ method_option :task_list, :type => :string, :aliases => "-T" # Only for accept rake
43
+ def rake(task="")
44
+ require 'padrino-core/support_lite'
45
+ require 'padrino-core/tasks'
46
+ boot = check_boot
47
+ return unless boot
48
+ require 'rake'
49
+ require boot
50
+ puts "=> Executing Rake..."
51
+ Rake.application.init
52
+ load(File.dirname(__FILE__) + "/cli/rake.rb")
53
+ Rake.application.top_level
54
+ end
55
+
56
+ desc "console", "Boots up the Padrino application irb console"
57
+ method_option :boot, :type => :string, :aliases => "-b", :required => true, :default => "config/boot.rb"
58
+ method_option :environment, :type => :string, :aliases => "-e", :required => true, :default => :development
59
+ def console
60
+ require File.dirname(__FILE__) + "/version"
61
+ boot = check_boot
62
+ return unless boot
63
+ ARGV.clear
64
+ puts "=> Loading #{options.environment} console (Padrino v.#{Padrino.version})"
65
+ require 'irb'
66
+ require "irb/completion"
67
+ require boot
68
+ require File.dirname(__FILE__) + '/cli/console'
69
+ IRB.start
70
+ end
71
+
72
+ private
73
+ def check_boot
74
+ ENV["PADRINO_ENV"] ||= options.environment.to_s
75
+ chdir(options.chdir)
76
+ unless File.exist?(options.boot)
77
+ puts "=> Could not find boot file: #{options.boot.inspect} !!!"
78
+ return
79
+ end
80
+ options.boot
81
+ end
82
+
83
+ protected
84
+ def self.banner(task)
85
+ "padrino-gen #{task.name}"
86
+ end
87
+
88
+ def chdir(dir)
89
+ return unless dir
90
+ begin
91
+ Dir.chdir(dir.to_s)
92
+ rescue Errno::ENOENT
93
+ puts "=> Specified Padrino root '#{dir}' " +
94
+ "does not appear to exist!"
95
+ rescue Errno::EACCES
96
+ puts "=> Specified Padrino root '#{dir}' " +
97
+ "cannot be accessed by the current user!"
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
@@ -1,7 +1,6 @@
1
1
  module Padrino
2
- module Tasks
2
+ module Cli
3
3
  module Adapter
4
-
5
4
  class << self
6
5
  # Start for the given options a rackup handler
7
6
  def start(options)
@@ -7,7 +7,7 @@ end
7
7
  def applications
8
8
  puts "==== List of Mounted Applications ====\n\n"
9
9
  Padrino.mounted_apps.each do |app|
10
- puts " * '#{app.name}' mapped to '#{app.uri_root}'"
10
+ puts " * %-10s mapped to %s" % [app.name, app.uri_root]
11
11
  end
12
12
  puts
13
13
  Padrino.mounted_apps.collect { |app| "#{app.name} => #{app.uri_root}" }
@@ -0,0 +1,25 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+ require File.dirname(__FILE__) + '/../tasks'
5
+
6
+ Dir["lib/tasks/**/*.rake"].each { |ext| load(ext) }
7
+ Padrino::Tasks.files.flatten.uniq.each { |ext| load(ext) }
8
+
9
+ def shell
10
+ @_shell ||= Thor::Shell::Basic.new
11
+ end
12
+
13
+ task :environment do
14
+ Padrino.logger_env = :test
15
+ Padrino.mounted_apps.each do |app|
16
+ Padrino.require_dependency(app.app_file)
17
+ app.app_object.setup_application!
18
+ end
19
+ end
20
+
21
+ desc 'Load the seed data from db/seeds.rb'
22
+ task :seed => :environment do
23
+ seed_file = Padrino.root('db', 'seeds.rb')
24
+ load(seed_file) if File.exist?(seed_file)
25
+ end
@@ -1,7 +1,6 @@
1
1
  module Padrino
2
- module Tasks
2
+ module Cli
3
3
  module Test
4
-
5
4
  class << self
6
5
 
7
6
  # This method executes tests found for the given app.
@@ -14,8 +13,8 @@ module Padrino
14
13
  cmd = "ruby -rubygems -I.:lib -e'%w( #{tests.join(' ')} ).each { |file| require file }'"
15
14
  system cmd
16
15
  end
17
-
18
16
  end
17
+
19
18
  end
20
19
  end
21
20
  end
Binary file
Binary file
@@ -5,9 +5,8 @@ module Padrino
5
5
  return false if loaded?
6
6
  @_called_from = first_caller
7
7
  load_required_gems # load bundler gems
8
- require_dependencies("#{root}/config/apps.rb", "#{root}/config/database.rb") # load configuration
9
- load_apps_models # load all models of our apps
10
8
  require_dependencies("#{root}/lib/**/*.rb", "#{root}/models/**/*.rb") # load root app models
9
+ require_dependencies("#{root}/config/database.rb", "#{root}/config/apps.rb") # load configuration
11
10
  Stat.reload! # We need to fill our Stat::CACHE but we do that only for development
12
11
  Thread.current[:padrino_loaded] = true
13
12
  end
@@ -73,11 +72,6 @@ module Padrino
73
72
  end
74
73
  end
75
74
 
76
- # Loads for each mounted applications their models
77
- def load_apps_models
78
- Padrino.mounted_apps.each { |mounted_app| load_dependencies("#{mounted_app.app_root}/models/**/*.rb") }
79
- end
80
-
81
75
  # Prints out a message to the stdout if not in test environment
82
76
  def say(text)
83
77
  print text if Padrino.env != :test
@@ -3,7 +3,11 @@ module Padrino
3
3
  def self.logger
4
4
  Thread.current[:padrino_logger] ||= Padrino::Logger.setup!
5
5
  end
6
-
6
+
7
+ def self.logger_env=(env)
8
+ Thread.current[:padrino_logger] ||= Padrino::Logger.setup!(env)
9
+ end
10
+
7
11
  class Logger
8
12
 
9
13
  attr_accessor :level
@@ -65,8 +69,8 @@ module Padrino
65
69
 
66
70
 
67
71
  # Setup a new logger
68
- def self.setup!
69
- config = Config[Padrino.env] || Config[:test]
72
+ def self.setup!(env=nil)
73
+ config = Config[env || Padrino.env] || Config[:test]
70
74
  stream = case config[:stream]
71
75
  when :to_file
72
76
  FileUtils.mkdir_p(Padrino.root("log")) unless File.exists?(Padrino.root("log"))
@@ -32,6 +32,8 @@ module Padrino
32
32
  app_obj.set :app_name, app_data.name
33
33
  app_obj.set :app_file, app_data.app_file unless File.exist?(app_obj.app_file)
34
34
  app_obj.set :root, app_data.app_root unless app_data.app_root.blank?
35
+ # We need to initialize here the app.
36
+ app_obj.setup_application!
35
37
  run app_obj
36
38
  end
37
39
  end
File without changes
@@ -20,7 +20,7 @@ Required for Padrino to run:
20
20
  =end
21
21
  require 'i18n'
22
22
  # Load our locales
23
- I18n.load_path += Dir["#{File.dirname(__FILE__)}/padrino-core/locale/*.yml"]
23
+ I18n.load_path += Dir["#{File.dirname(__FILE__)}/locale/*.yml"]
24
24
 
25
25
  module Padrino
26
26
  # Return the current support used.
@@ -1,88 +1,17 @@
1
- require 'thor'
2
- require 'thor/rake_compat'
3
- require File.dirname(__FILE__) + "/tasks/helpers"
4
-
5
1
  module Padrino
6
- module Tasks
7
- class Base < Thor
8
- include Thor::Actions
9
- include Thor::RakeCompat
10
- include Padrino::Tasks::Helpers
11
-
12
- class_option :chdir, :type => :string, :aliases => "-c"
13
-
14
- desc "start", "Starts the Padrino application"
15
- method_option :environment, :type => :string, :aliases => "-e", :required => true, :default => :development
16
- method_option :adapter, :type => :string, :aliases => "-a", :required => true, :default => :thin
17
- method_option :host, :type => :string, :aliases => "-h", :required => true, :default => "localhost"
18
- method_option :port, :type => :numeric, :aliases => "-p", :required => true, :default => 3000
19
- method_option :boot, :type => :string, :aliases => "-b", :required => true, :default => "config/boot.rb"
20
- method_option :daemonize, :type => :boolean, :aliases => "-d"
21
- def start
22
- require File.dirname(__FILE__) + "/tasks/adapter"
23
- boot = check_boot
24
- return unless boot
25
- require boot
26
- Padrino::Tasks::Adapter.start(options)
27
- end
28
-
29
- desc "stop", "Stops the Padrino application"
30
- def stop
31
- require File.dirname(__FILE__) + "/tasks/adapter"
32
- Padrino::Tasks::Adapter.stop
33
- end
34
2
 
35
- desc "test", "Executes all the Padrino test files"
36
- def test
37
- require File.dirname(__FILE__) + "/tasks/test"
38
- Padrino::Tasks::Test.start
39
- end
40
-
41
- desc "rake", "Execute rake tasks in {Padrino.root}/lib/tasks"
42
- method_option :boot, :type => :string, :aliases => "-b", :required => true, :default => "config/boot.rb"
43
- method_option :environment, :type => :string, :aliases => "-e", :required => true, :default => :development
44
- def rake
45
- boot = check_boot
46
- return unless boot
47
- require 'rake'
48
- puts "=> Executing Rake..."
49
- Rake.application.init
50
- load(File.dirname(__FILE__) + "/tasks/rake_tasks.rb")
51
- Padrino::Tasks::RakeFile.boot_file = boot
52
- Rake.application.top_level
53
- end
54
-
55
- desc "console", "Boots up the Padrino application irb console"
56
- method_option :boot, :type => :string, :aliases => "-b", :required => true, :default => "config/boot.rb"
57
- method_option :environment, :type => :string, :aliases => "-e", :required => true, :default => :development
58
- def console
59
- require File.dirname(__FILE__) + "/version"
60
- boot = check_boot
61
- return unless boot
62
- ARGV.clear
63
- puts "=> Loading #{options.environment} console (Padrino v.#{Padrino.version})"
64
- require 'irb'
65
- require "irb/completion"
66
- require boot
67
- require File.dirname(__FILE__) + '/tasks/console'
68
- IRB.start
69
- end
70
-
71
- private
72
- def check_boot
73
- ENV["PADRINO_ENV"] ||= options.environment.to_s
74
- chdir(options.chdir)
75
- unless File.exist?(options.boot)
76
- puts "=> Could not find boot file: #{options.boot.inspect} !!!"
77
- return
78
- end
79
- options.boot
80
- end
3
+ # Ti module it's used for bootstrap with padrino rake
4
+ # thirdy party tasks, in your gem/plugin/extension you
5
+ # need only do this:
6
+ #
7
+ # Padrino::Tasks.files << yourtask.rb
8
+ #
9
+ module Tasks
81
10
 
82
- protected
83
- def self.banner(task)
84
- "padrino-gen #{task.name}"
85
- end
11
+ # Returns a list of files to handle with padrino rake
12
+ def self.files
13
+ @files ||= []
86
14
  end
15
+
87
16
  end
88
17
  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.5.0"
8
+ s.version = "0.6.1"
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-01-06}
12
+ s.date = %q{2010-01-14}
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}
@@ -28,22 +28,25 @@ Gem::Specification.new do |s|
28
28
  "lib/padrino-core.rb",
29
29
  "lib/padrino-core/application.rb",
30
30
  "lib/padrino-core/caller.rb",
31
+ "lib/padrino-core/cli.rb",
32
+ "lib/padrino-core/cli/adapter.rb",
33
+ "lib/padrino-core/cli/console.rb",
34
+ "lib/padrino-core/cli/rake.rb",
35
+ "lib/padrino-core/cli/test.rb",
36
+ "lib/padrino-core/images/404.png",
37
+ "lib/padrino-core/images/500.png",
31
38
  "lib/padrino-core/loader.rb",
32
39
  "lib/padrino-core/locale/en.yml",
33
40
  "lib/padrino-core/logger.rb",
34
41
  "lib/padrino-core/mounter.rb",
35
42
  "lib/padrino-core/reloader.rb",
43
+ "lib/padrino-core/routing.rb",
36
44
  "lib/padrino-core/server.rb",
37
45
  "lib/padrino-core/stat.rb",
38
46
  "lib/padrino-core/support_lite.rb",
39
47
  "lib/padrino-core/support_lite/as_support.rb",
40
48
  "lib/padrino-core/support_lite/extlib_support.rb",
41
49
  "lib/padrino-core/tasks.rb",
42
- "lib/padrino-core/tasks/adapter.rb",
43
- "lib/padrino-core/tasks/console.rb",
44
- "lib/padrino-core/tasks/helpers.rb",
45
- "lib/padrino-core/tasks/rake_tasks.rb",
46
- "lib/padrino-core/tasks/test.rb",
47
50
  "lib/padrino-core/version.rb",
48
51
  "padrino-core.gemspec",
49
52
  "test/fixtures/apps/.components",
@@ -57,6 +60,7 @@ Gem::Specification.new do |s|
57
60
  "test/test_mounter.rb",
58
61
  "test/test_reloader_complex.rb",
59
62
  "test/test_reloader_simple.rb",
63
+ "test/test_routing.rb",
60
64
  "test/test_server.rb"
61
65
  ]
62
66
  s.homepage = %q{http://github.com/padrino/padrino-framework/tree/master/padrino-core}
@@ -72,6 +76,7 @@ Gem::Specification.new do |s|
72
76
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
73
77
  s.add_runtime_dependency(%q<sinatra>, [">= 0.9.2"])
74
78
  s.add_runtime_dependency(%q<i18n>, [">= 0.3.2"])
79
+ s.add_runtime_dependency(%q<usher>, [">= 0.6.2"])
75
80
  s.add_runtime_dependency(%q<thor>, [">= 0.11.8"])
76
81
  s.add_development_dependency(%q<haml>, [">= 2.2.1"])
77
82
  s.add_runtime_dependency(%q<bundler>, [">= 0.5.0"])
@@ -82,6 +87,7 @@ Gem::Specification.new do |s|
82
87
  else
83
88
  s.add_dependency(%q<sinatra>, [">= 0.9.2"])
84
89
  s.add_dependency(%q<i18n>, [">= 0.3.2"])
90
+ s.add_dependency(%q<usher>, [">= 0.6.2"])
85
91
  s.add_dependency(%q<thor>, [">= 0.11.8"])
86
92
  s.add_dependency(%q<haml>, [">= 2.2.1"])
87
93
  s.add_dependency(%q<bundler>, [">= 0.5.0"])
@@ -93,6 +99,7 @@ Gem::Specification.new do |s|
93
99
  else
94
100
  s.add_dependency(%q<sinatra>, [">= 0.9.2"])
95
101
  s.add_dependency(%q<i18n>, [">= 0.3.2"])
102
+ s.add_dependency(%q<usher>, [">= 0.6.2"])
96
103
  s.add_dependency(%q<thor>, [">= 0.11.8"])
97
104
  s.add_dependency(%q<haml>, [">= 2.2.1"])
98
105
  s.add_dependency(%q<bundler>, [">= 0.5.0"])
@@ -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: 65!" } # Change only the number!!!
24
+ get("(/)"){ "The magick number is: 53!" } # Change only the number!!!
25
25
  end
26
26
 
27
27
  Padrino.load!
@@ -11,7 +11,7 @@ end
11
11
 
12
12
  SimpleDemo.controllers do
13
13
  get "/" do
14
- 'The magick number is: 60!' # Change only the number!!!
14
+ 'The magick number is: 43!' # Change only the number!!!
15
15
  end
16
16
  end
17
17
 
data/test/helper.rb CHANGED
@@ -1,9 +1,6 @@
1
1
  ENV['PADRINO_ENV'] = 'test'
2
2
  PADRINO_ROOT = File.dirname(__FILE__) unless defined? PADRINO_ROOT
3
3
 
4
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
- $LOAD_PATH.unshift(File.dirname(__FILE__))
6
-
7
4
  require 'rubygems'
8
5
  require 'padrino-core'
9
6
  require 'test/unit'