oasis 0.2.0 → 0.2.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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -1,6 +1,22 @@
1
1
  path = File.dirname(__FILE__)
2
2
  require "#{path}/oasis/debug"
3
+ require "#{path}/oasis/app/loader"
4
+ require "#{path}/oasis/dependencies"
3
5
 
4
6
  # extend the routing system, if its loaded.
5
7
  require "#{path}/oasis/routes" if defined? ActionController::Routing
6
- require "#{path}/oasis/layout" if defined? ActionController::Layout
8
+ # extend the layout system, if its loaded.
9
+ require "#{path}/oasis/layout" if defined? ActionController::Layout
10
+
11
+ if defined? Rails
12
+ # this makes rails reload the models, controllers, etc. inside of a Rails Engine.
13
+ Rails.configuration.after_initialize do
14
+ ActiveSupport::Dependencies.load_once_paths = ActiveSupport::Dependencies.load_once_paths.select { |path| (path =~ /app/).nil? }
15
+ end
16
+ end
17
+
18
+ module Oasis
19
+ # The set of all loaded plugins
20
+ mattr_accessor :apps
21
+ self.apps = Oasis::App::List.new
22
+ end
@@ -0,0 +1,22 @@
1
+ module Oasis
2
+ module App
3
+ class List < Array
4
+ # Finds plugins with the set with the given name (accepts Strings or Symbols), or
5
+ # index. So, Engines.plugins[0] returns the first-loaded Plugin, and Engines.plugins[:engines]
6
+ # returns the Plugin instance for the engines plugin itself.
7
+ def [](name_or_index)
8
+ if name_or_index.is_a?(Fixnum)
9
+ super
10
+ else
11
+ self.find { |plugin| plugin.name.to_s == name_or_index.to_s }
12
+ end
13
+ end
14
+
15
+ # Go through each plugin, highest priority first (last loaded first). Effectively,
16
+ # this is like <tt>Engines.plugins.reverse</tt>
17
+ def by_precedence
18
+ reverse
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ module Oasis
2
+ module App
3
+ module Loader
4
+
5
+ def register_plugin_as_loaded_with_oasis(plugin)
6
+ register_plugin_as_loaded_without_oasis(plugin)
7
+ Oasis.apps << plugin if plugin.engine?
8
+ Oasis::Debug.log "**** Loading App: #{plugin.name}"
9
+ end
10
+
11
+ def self.included(base)
12
+ base.class_eval do
13
+ alias_method_chain :register_plugin_as_loaded, :oasis
14
+ end
15
+ end
16
+
17
+ end
18
+ end
19
+ end
20
+
21
+ Rails::Plugin::Loader.send :include, Oasis::App::Loader
@@ -0,0 +1,48 @@
1
+ # a majority of this code has been adapted
2
+ # from the Rails Engines project which has been largely
3
+ # discontinued and integrated into Rails, itself. ...except for this.
4
+ # Thanks to everyone involved in that work, to make this possible.
5
+ module Oasis
6
+ module Dependencies
7
+
8
+ def require_or_load(file_name, const_path=nil)
9
+ file_loaded = false
10
+ # only look for controller and helper files.
11
+ %w(controller helper).each do |file_type|
12
+ if file_name =~ /^(.*app\/#{file_type}s\/)?(.*_#{file_type})(\.rb)?$/
13
+ base_name = $2
14
+
15
+ # jump through the loaded/registered oasis apps, looking for
16
+ # similar files that you may want to try to reference.
17
+ Oasis.apps.each do |app|
18
+ plugin_file_name = File.expand_path(File.join(app.directory, 'app', "#{file_type}s", base_name))
19
+ Oasis::Debug.log "checking engine '#{app.name}' for '#{base_name}'"
20
+ if File.file? "#{plugin_file_name}.rb"
21
+ Oasis::Debug.log "loading from engine '#{app.name}'"
22
+ file_loaded = true if super(plugin_file_name, const_path)
23
+ end
24
+ end
25
+
26
+ # Ensure we are only loading from the /app directory at this point.
27
+ app_file_name = File.join(RAILS_ROOT, 'app', "#{file_type}s", "#{base_name}")
28
+
29
+ if File.file? "#{app_file_name}.rb"
30
+ Oasis::Debug.log "loading from application: #{base_name}"
31
+ file_loaded = true if super(app_file_name, const_path)
32
+ else
33
+ Oasis::Debug.log "file not found in application"
34
+ end
35
+ end
36
+ end
37
+
38
+ # if we managed to load a file, return true. If not, default to the original method.
39
+ # Note that this relies on the RHS of a boolean || not to be evaluated if the LHS is true.
40
+ file_loaded || super(file_name, const_path)
41
+ end
42
+ end
43
+
44
+ end
45
+
46
+ module ::ActiveSupport::Dependencies #:nodoc:
47
+ extend Oasis::Dependencies
48
+ end
@@ -0,0 +1,44 @@
1
+ module Oasis
2
+ # only require this if you need it. This is designed for use as pre-initializer.
3
+ # do not bother setting this within your engine's init.rb file, its too late by then.
4
+ module Loader
5
+ # this method defines a series of methods and method chains
6
+ # that can be used to augment the plugin/engines loader to
7
+ # consider more potential load paths within the app/ directory.
8
+ # this should only be necessary if you have code hiding in a top-level
9
+ # directory, beneath vendor/plugins/<your_engine>/app
10
+ # eg: vendor/plugins/<your_engine>/app/cells
11
+ #
12
+ # this method should be used in the *master* environment.rb
13
+ # of your rails application.
14
+ #
15
+ # example:
16
+ #
17
+ # require 'oasis/loader'
18
+ # Oasis::Loader.add_app_load_path_support_for :cells
19
+ #
20
+ # Rails::Initializer.run do |config|
21
+ # ...
22
+ # end
23
+ def self.add_app_load_path_support_for(*names)
24
+ names.each do |name|
25
+ Rails::Plugin.class_eval <<-EOS
26
+ def has_#{name}_directory? # def has_cells_directory?
27
+ File.directory?(File.join(directory, 'app', '#{name}')) # File.directory?(File.join(directory, 'app', 'cells'))
28
+ end # end
29
+ #
30
+ def #{name}_path # def cells_path
31
+ File.join(directory, 'app', '#{name}') # File.join(directory, 'app', 'cells')
32
+ end # end
33
+ #
34
+ def load_paths_with_#{name} # def load_paths_with_cells
35
+ paths = load_paths_without_#{name} # paths = load_paths_without_cells
36
+ paths << #{name}_path if has_#{name}_directory? # paths << cells_path if has_cells_directory?
37
+ paths # paths
38
+ end # end
39
+ alias_method_chain :load_paths, :#{name} # alias_method_chain :load_paths, :cells
40
+ EOS
41
+ end
42
+ end
43
+ end
44
+ end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{oasis}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Derek Perez", "Chris Eppstein"]
12
- s.date = %q{2009-12-21}
12
+ s.date = %q{2009-12-29}
13
13
  s.description = %q{a collection of enhancements for rails engines. Designed to work with Rails 2.3.}
14
14
  s.email = %q{derek@derekperez.com}
15
15
  s.extra_rdoc_files = [
@@ -24,8 +24,12 @@ Gem::Specification.new do |s|
24
24
  "Rakefile",
25
25
  "VERSION",
26
26
  "lib/oasis.rb",
27
+ "lib/oasis/app/list.rb",
28
+ "lib/oasis/app/loader.rb",
27
29
  "lib/oasis/debug.rb",
30
+ "lib/oasis/dependencies.rb",
28
31
  "lib/oasis/layout.rb",
32
+ "lib/oasis/loader.rb",
29
33
  "lib/oasis/routes.rb",
30
34
  "oasis.gemspec",
31
35
  "test/fixtures/layout_tests/views/layouts/default_layout.html.erb",
@@ -37,6 +41,7 @@ Gem::Specification.new do |s|
37
41
  "test/fixtures/layout_tests/views/products/wish_list.html.erb",
38
42
  "test/helper.rb",
39
43
  "test/test_oasis_layouts.rb",
44
+ "test/test_oasis_loader.rb",
40
45
  "test/test_oasis_routing.rb"
41
46
  ]
42
47
  s.homepage = %q{http://github.com/perezd/oasis}
@@ -47,6 +52,7 @@ Gem::Specification.new do |s|
47
52
  s.test_files = [
48
53
  "test/helper.rb",
49
54
  "test/test_oasis_layouts.rb",
55
+ "test/test_oasis_loader.rb",
50
56
  "test/test_oasis_routing.rb"
51
57
  ]
52
58
 
@@ -0,0 +1,21 @@
1
+ require 'helper'
2
+ require 'oasis/loader'
3
+
4
+ module Rails
5
+ class Plugin
6
+ def load_paths
7
+ []
8
+ end
9
+ end
10
+ end
11
+
12
+ class TestOasisLoader < Test::Unit::TestCase
13
+
14
+ should "add methods to Rails::Plugin to add loader support for cells" do
15
+ Oasis::Loader.add_app_load_path_support_for :cells
16
+ assert Rails::Plugin.new.respond_to?(:has_cells_directory?)
17
+ assert Rails::Plugin.new.respond_to?(:cells_path)
18
+ assert Rails::Plugin.new.respond_to?(:load_paths_with_cells)
19
+ end
20
+
21
+ end
@@ -1,5 +1,33 @@
1
1
  require 'helper'
2
2
 
3
+ class MockController
4
+ attr_accessor :routes
5
+
6
+ def initialize(routes)
7
+ self.routes = routes
8
+ end
9
+
10
+ def url_for(options)
11
+ only_path = options.delete(:only_path)
12
+
13
+ port = options.delete(:port) || 80
14
+ port_string = port == 80 ? '' : ":#{port}"
15
+
16
+ protocol = options.delete(:protocol) || "http"
17
+ host = options.delete(:host) || "test.host"
18
+ anchor = "##{options.delete(:anchor)}" if options.key?(:anchor)
19
+
20
+ path = routes.generate(options)
21
+
22
+ only_path ? "#{path}#{anchor}" : "#{protocol}://#{host}#{port_string}#{path}#{anchor}"
23
+ end
24
+
25
+ def request
26
+ @request ||= ActionController::TestRequest.new
27
+ end
28
+ end
29
+
30
+
3
31
  class TestOasisRouting < Test::Unit::TestCase
4
32
 
5
33
  ROUTING = ActionController::Routing
@@ -8,7 +36,22 @@ class TestOasisRouting < Test::Unit::TestCase
8
36
  Oasis::Routes.routing_for(:customers) do |customers|
9
37
  customers.connect "/customers", :controller => "customers"
10
38
  customers.connect "/cool-stuff", :controller => "customers"
39
+ customers.search "/search", :controller => "customers"
40
+ end
41
+ end
42
+
43
+ def setup_for_named_route
44
+ klass = Class.new(MockController)
45
+ set.install_helpers(klass)
46
+ klass.new(set)
47
+ end
48
+
49
+ should "provide explicit namespacing to routing set based on collection name" do
50
+ set.draw do |map|
51
+ map.routing_for(:customers)
11
52
  end
53
+ controller = setup_for_named_route
54
+ assert_equal "/search", controller.send(:customers_search_path)
12
55
  end
13
56
 
14
57
  should "define a named routing set" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oasis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derek Perez
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-12-21 00:00:00 -08:00
13
+ date: 2009-12-29 00:00:00 -08:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -40,8 +40,12 @@ files:
40
40
  - Rakefile
41
41
  - VERSION
42
42
  - lib/oasis.rb
43
+ - lib/oasis/app/list.rb
44
+ - lib/oasis/app/loader.rb
43
45
  - lib/oasis/debug.rb
46
+ - lib/oasis/dependencies.rb
44
47
  - lib/oasis/layout.rb
48
+ - lib/oasis/loader.rb
45
49
  - lib/oasis/routes.rb
46
50
  - oasis.gemspec
47
51
  - test/fixtures/layout_tests/views/layouts/default_layout.html.erb
@@ -53,6 +57,7 @@ files:
53
57
  - test/fixtures/layout_tests/views/products/wish_list.html.erb
54
58
  - test/helper.rb
55
59
  - test/test_oasis_layouts.rb
60
+ - test/test_oasis_loader.rb
56
61
  - test/test_oasis_routing.rb
57
62
  has_rdoc: true
58
63
  homepage: http://github.com/perezd/oasis
@@ -85,4 +90,5 @@ summary: a collection of enhancements for rails engines.
85
90
  test_files:
86
91
  - test/helper.rb
87
92
  - test/test_oasis_layouts.rb
93
+ - test/test_oasis_loader.rb
88
94
  - test/test_oasis_routing.rb