oasis 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  = oasis
2
2
 
3
- Description goes here.
3
+ Oasis is a collection of enhancements that were written by Derek Perez and Chris Eppstein to make the Rails Engines platform work better for micro application design.
4
4
 
5
5
  == Note on Patches/Pull Requests
6
6
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
@@ -1,3 +1,6 @@
1
1
  path = File.dirname(__FILE__)
2
2
  require "#{path}/oasis/debug"
3
- require "#{path}/oasis/routes"
3
+
4
+ # extend the routing system, if its loaded.
5
+ require "#{path}/oasis/routes" if defined? ActionController::Routing
6
+ require "#{path}/oasis/layout" if defined? ActionController::Layout
@@ -0,0 +1,61 @@
1
+ module Oasis
2
+ # This module makes it easier for developers to centralize
3
+ # the process they use for defining engine, and engine action
4
+ # specific layouts. Primarily, this strategy works really nicely
5
+ # with class/controller re-opening in the master Rails application.
6
+ module Layout
7
+
8
+ def self.extended(base)
9
+ base.send :include, InstanceMethods
10
+ end
11
+
12
+ module InstanceMethods
13
+
14
+ def layouts
15
+ self.class.read_inheritable_attribute(:layouts)
16
+ end
17
+
18
+ # this method runs for every action, once #layout_for has been
19
+ # defined in a controller, once. There are a series of item
20
+ # types we support, defined below.
21
+ def compute_oasis_layouts
22
+ context = layouts[@action_name.to_sym]
23
+ case
24
+ when context.is_a?(String); return context
25
+ when context.is_a?(Symbol); return send(context)
26
+ when context.is_a?(FalseClass); return false
27
+ when context.is_a?(Proc); return context.call(request)
28
+ else; return layouts[:default]
29
+ end
30
+ end
31
+ end
32
+
33
+ ## CLASS METHODS FOR AC::Base
34
+
35
+ # this is the public api endpoint for controller definitions.
36
+ # layout_path should be either a String, Symbol, or false.
37
+ # optionally, you can pass a proc to this method and it will evaluate
38
+ # as if it were sent a symbol.
39
+ def layout_for(name, layout_path = nil, &blk)
40
+ name = name.to_sym
41
+ write_inheritable_hash(:layouts, :default => predefined_layout) unless predefined_layout == :compute_oasis_layouts
42
+ context = block_given? ? blk : layout_path
43
+ write_inheritable_hash(:layouts, name => context)
44
+ layout(:compute_oasis_layouts)
45
+ end
46
+
47
+ # simple accessor to the layouts defined by Oasis/#layout_for
48
+ def layouts
49
+ self.read_inheritable_attribute(:layouts)
50
+ end
51
+
52
+ private
53
+
54
+ # checks whether or not a layout has been assigned via the #layout method.
55
+ def predefined_layout
56
+ self.read_inheritable_attribute(:layout)
57
+ end
58
+ end
59
+ end
60
+
61
+ ActionController::Base.extend Oasis::Layout
@@ -20,14 +20,16 @@ module Oasis
20
20
  def routing_for(name,*args)
21
21
  raise ActionController::RoutingError, "#{name} routing collection has already been used once." if Oasis::Routes.apps[name] == false
22
22
  raise ActionController::RoutingError, "app: #{name} not registered" unless Oasis::Routes.apps[name]
23
- with_options(args.extract_options!, &Oasis::Routes.apps[name])
23
+
24
+ args = args.extract_options!
25
+ args[:name_prefix] = "#{name}_"
26
+
27
+ with_options(args, &Oasis::Routes.apps[name])
24
28
  Oasis::Routes.apps[name] = false
25
29
  end
26
30
  end
27
31
  end
28
32
 
29
33
  # mixin, and empty the container.
30
- Oasis::Routes.apps = {} if Oasis::Routes.apps.nil?
31
- class ActionController::Routing::RouteSet::Mapper
32
- include Oasis::RouteSet
33
- end
34
+ Oasis::Routes.reset! if Oasis::Routes.apps.nil?
35
+ ActionController::Routing::RouteSet::Mapper.send :include, Oasis::RouteSet
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{oasis}
8
- s.version = "0.1.1"
8
+ s.version = "0.2.0"
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-19}
12
+ s.date = %q{2009-12-21}
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 = [
@@ -25,9 +25,18 @@ Gem::Specification.new do |s|
25
25
  "VERSION",
26
26
  "lib/oasis.rb",
27
27
  "lib/oasis/debug.rb",
28
+ "lib/oasis/layout.rb",
28
29
  "lib/oasis/routes.rb",
29
30
  "oasis.gemspec",
31
+ "test/fixtures/layout_tests/views/layouts/default_layout.html.erb",
32
+ "test/fixtures/layout_tests/views/layouts/fancy_products.html.erb",
33
+ "test/fixtures/layout_tests/views/products/cart.html.erb",
34
+ "test/fixtures/layout_tests/views/products/on_hold.html.erb",
35
+ "test/fixtures/layout_tests/views/products/registry.html.erb",
36
+ "test/fixtures/layout_tests/views/products/supported.html.erb",
37
+ "test/fixtures/layout_tests/views/products/wish_list.html.erb",
30
38
  "test/helper.rb",
39
+ "test/test_oasis_layouts.rb",
31
40
  "test/test_oasis_routing.rb"
32
41
  ]
33
42
  s.homepage = %q{http://github.com/perezd/oasis}
@@ -37,6 +46,7 @@ Gem::Specification.new do |s|
37
46
  s.summary = %q{a collection of enhancements for rails engines.}
38
47
  s.test_files = [
39
48
  "test/helper.rb",
49
+ "test/test_oasis_layouts.rb",
40
50
  "test/test_oasis_routing.rb"
41
51
  ]
42
52
 
@@ -0,0 +1 @@
1
+ Fancy Products: <%= yield %>
@@ -0,0 +1 @@
1
+ my supported products.
@@ -0,0 +1,80 @@
1
+ require 'helper'
2
+
3
+ ## SETUP
4
+
5
+ # The view_paths array must be set on Base and not LayoutTest so that LayoutTest's inherited
6
+ # method has access to the view_paths array when looking for a layout to automatically assign.
7
+ old_load_paths = ActionController::Base.view_paths
8
+
9
+ ActionView::Template::register_template_handler :mab,
10
+ lambda { |template| template.source.inspect }
11
+
12
+ ActionController::Base.view_paths = [ File.dirname(__FILE__) + '/fixtures/layout_tests/views/' ]
13
+ ActionController::Routing::Routes.draw do |map|
14
+ map.connect ':controller/:action/:id'
15
+ end
16
+
17
+ class LayoutTest < ActionController::Base
18
+ self.view_paths = ActionController::Base.view_paths.dup
19
+ end
20
+
21
+ # Restore view_paths to previous value
22
+ ActionController::Base.view_paths = old_load_paths
23
+
24
+ class ProductsController < LayoutTest
25
+
26
+ layout "default_layout"
27
+ layout_for :cart, "fancy_products"
28
+ layout_for :supported, :calculate_my_layout
29
+ layout_for :wish_list, false
30
+ layout_for :on_hold do |request|
31
+ "fancy_products"
32
+ end
33
+
34
+ protected
35
+
36
+ def calculate_my_layout
37
+ "fancy_products"
38
+ end
39
+
40
+ end
41
+
42
+ ## TEST CASES
43
+
44
+ class TestOasisLayouts < ActionController::TestCase
45
+
46
+ def setup
47
+ @request.host = "www.caring.com"
48
+ end
49
+
50
+ should "define a string based path to a layout file" do
51
+ @controller = ProductsController.new
52
+ get :cart
53
+ assert_equal "layouts/fancy_products", @response.layout
54
+ end
55
+
56
+ should "remove the layout explicitly" do
57
+ @controller = ProductsController.new
58
+ get :wish_list
59
+ assert_nil @response.layout
60
+ end
61
+
62
+ should "define layout from method in controller" do
63
+ @controller = ProductsController.new
64
+ get :supported
65
+ assert_equal "layouts/fancy_products", @response.layout
66
+ end
67
+
68
+ should "define layout from proc" do
69
+ @controller = ProductsController.new
70
+ get :on_hold
71
+ assert_equal "layouts/fancy_products", @response.layout
72
+ end
73
+
74
+ should "fallback to default layout" do
75
+ @controller = ProductsController.new
76
+ get :registry
77
+ assert_equal "layouts/default_layout", @response.layout
78
+ end
79
+
80
+ end
@@ -38,6 +38,7 @@ class TestOasisRouting < Test::Unit::TestCase
38
38
 
39
39
  assert set.recognize_path "/foobar/customers"
40
40
  assert set.recognize_path "/foobar/cool-stuff"
41
+ assert Oasis::Routes.apps[:customers] == false
41
42
  end
42
43
 
43
44
  should "fail if named routing set does not exist" 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.1.1
4
+ version: 0.2.0
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-19 00:00:00 -08:00
13
+ date: 2009-12-21 00:00:00 -08:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -41,9 +41,18 @@ files:
41
41
  - VERSION
42
42
  - lib/oasis.rb
43
43
  - lib/oasis/debug.rb
44
+ - lib/oasis/layout.rb
44
45
  - lib/oasis/routes.rb
45
46
  - oasis.gemspec
47
+ - test/fixtures/layout_tests/views/layouts/default_layout.html.erb
48
+ - test/fixtures/layout_tests/views/layouts/fancy_products.html.erb
49
+ - test/fixtures/layout_tests/views/products/cart.html.erb
50
+ - test/fixtures/layout_tests/views/products/on_hold.html.erb
51
+ - test/fixtures/layout_tests/views/products/registry.html.erb
52
+ - test/fixtures/layout_tests/views/products/supported.html.erb
53
+ - test/fixtures/layout_tests/views/products/wish_list.html.erb
46
54
  - test/helper.rb
55
+ - test/test_oasis_layouts.rb
47
56
  - test/test_oasis_routing.rb
48
57
  has_rdoc: true
49
58
  homepage: http://github.com/perezd/oasis
@@ -75,4 +84,5 @@ specification_version: 3
75
84
  summary: a collection of enhancements for rails engines.
76
85
  test_files:
77
86
  - test/helper.rb
87
+ - test/test_oasis_layouts.rb
78
88
  - test/test_oasis_routing.rb