layout_options 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +71 -0
- data/README.textile +39 -0
- data/Rakefile +2 -0
- data/layout_options.gemspec +29 -0
- data/lib/layout_options/layout_options.rb +30 -0
- data/lib/layout_options/storage.rb +15 -0
- data/lib/layout_options/version.rb +7 -0
- data/lib/layout_options.rb +7 -0
- data/spec/layout_options_spec.rb +29 -0
- data/spec/layout_options_storage_spec.rb +16 -0
- data/spec/spec_helper.rb +4 -0
- metadata +154 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
layout_options (0.1)
|
5
|
+
actionpack (~> 3.0.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
abstract (1.0.0)
|
11
|
+
actionpack (3.0.3)
|
12
|
+
activemodel (= 3.0.3)
|
13
|
+
activesupport (= 3.0.3)
|
14
|
+
builder (~> 2.1.2)
|
15
|
+
erubis (~> 2.6.6)
|
16
|
+
i18n (~> 0.4)
|
17
|
+
rack (~> 1.2.1)
|
18
|
+
rack-mount (~> 0.6.13)
|
19
|
+
rack-test (~> 0.5.6)
|
20
|
+
tzinfo (~> 0.3.23)
|
21
|
+
activemodel (3.0.3)
|
22
|
+
activesupport (= 3.0.3)
|
23
|
+
builder (~> 2.1.2)
|
24
|
+
i18n (~> 0.4)
|
25
|
+
activesupport (3.0.3)
|
26
|
+
archive-tar-minitar (0.5.2)
|
27
|
+
builder (2.1.2)
|
28
|
+
columnize (0.3.2)
|
29
|
+
diff-lcs (1.1.2)
|
30
|
+
erubis (2.6.6)
|
31
|
+
abstract (>= 1.0.0)
|
32
|
+
i18n (0.4.2)
|
33
|
+
linecache19 (0.5.11)
|
34
|
+
ruby_core_source (>= 0.1.4)
|
35
|
+
rack (1.2.1)
|
36
|
+
rack-mount (0.6.13)
|
37
|
+
rack (>= 1.0.0)
|
38
|
+
rack-test (0.5.6)
|
39
|
+
rack (>= 1.0)
|
40
|
+
rspec (2.1.0)
|
41
|
+
rspec-core (~> 2.1.0)
|
42
|
+
rspec-expectations (~> 2.1.0)
|
43
|
+
rspec-mocks (~> 2.1.0)
|
44
|
+
rspec-core (2.1.0)
|
45
|
+
rspec-expectations (2.1.0)
|
46
|
+
diff-lcs (~> 1.1.2)
|
47
|
+
rspec-mocks (2.1.0)
|
48
|
+
rspec-rails (2.1.0)
|
49
|
+
rspec (~> 2.1.0)
|
50
|
+
ruby-debug-base19 (0.11.24)
|
51
|
+
columnize (>= 0.3.1)
|
52
|
+
linecache19 (>= 0.5.11)
|
53
|
+
ruby_core_source (>= 0.1.4)
|
54
|
+
ruby-debug19 (0.11.6)
|
55
|
+
columnize (>= 0.3.1)
|
56
|
+
linecache19 (>= 0.5.11)
|
57
|
+
ruby-debug-base19 (>= 0.11.19)
|
58
|
+
ruby_core_source (0.1.4)
|
59
|
+
archive-tar-minitar (>= 0.5.2)
|
60
|
+
tzinfo (0.3.23)
|
61
|
+
|
62
|
+
PLATFORMS
|
63
|
+
ruby
|
64
|
+
|
65
|
+
DEPENDENCIES
|
66
|
+
actionpack (~> 3.0.1)
|
67
|
+
bundler (>= 1.0.0.rc.6)
|
68
|
+
layout_options!
|
69
|
+
rspec (~> 2.1.0)
|
70
|
+
rspec-rails (~> 2.1.0)
|
71
|
+
ruby-debug19 (~> 0.11.6)
|
data/README.textile
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
h1. layout_options
|
2
|
+
|
3
|
+
The layout_options gem provides a single place to set all of your layouts in
|
4
|
+
your controller. This gem really shines when using inherited_resources and
|
5
|
+
you need multiple layouts.
|
6
|
+
|
7
|
+
This gem came from that exact scenario.
|
8
|
+
|
9
|
+
h2. Usage
|
10
|
+
|
11
|
+
To add @layout_options@ to your project just add it to your Gemfile, require it
|
12
|
+
in your ApplicationController and define your layouts within each controller.
|
13
|
+
|
14
|
+
h3. Example
|
15
|
+
|
16
|
+
Adding layout_options to your Gemfile:
|
17
|
+
|
18
|
+
<code>
|
19
|
+
gem 'layout_options', '~> 0.1'
|
20
|
+
</code>
|
21
|
+
|
22
|
+
Require layout_options in your ApplicationController:
|
23
|
+
|
24
|
+
<code>
|
25
|
+
require 'layout_options' # require the gem
|
26
|
+
|
27
|
+
class ApplicationController < ActionController::Base
|
28
|
+
# ...
|
29
|
+
end
|
30
|
+
</code>
|
31
|
+
|
32
|
+
Define your layouts in your controllers:
|
33
|
+
|
34
|
+
<code>
|
35
|
+
class UsersController < ApplicationController
|
36
|
+
# define your layouts
|
37
|
+
layout_options :overlay => [:new, :edit], :none => :destroy
|
38
|
+
end
|
39
|
+
</code>
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path("../lib/layout_options/version", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "layout_options"
|
6
|
+
s.version = LayoutOptions::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ['Dane Harrigan']
|
9
|
+
s.email = ['dane.harrigan@gmail.com']
|
10
|
+
s.homepage = "http://rubygems.org/gems/layout_options"
|
11
|
+
s.summary = 'A single place for setting all of your layouts in a controller'
|
12
|
+
s.description = 'The layout_options gem provides a single place to set all of your ' <<
|
13
|
+
'layouts in your controller. This gem really shines when multiple layouts are needed ' <<
|
14
|
+
'when using inherited_resources.'
|
15
|
+
|
16
|
+
s.required_rubygems_version = ">= 1.3.6"
|
17
|
+
s.rubyforge_project = "layout_options"
|
18
|
+
|
19
|
+
s.add_dependency 'actionpack','~> 3.0.1'
|
20
|
+
|
21
|
+
s.add_development_dependency "bundler", ">= 1.0.0.rc.6"
|
22
|
+
s.add_development_dependency "rspec", "~> 2.1.0"
|
23
|
+
s.add_development_dependency "rspec-rails", "~> 2.1.0"
|
24
|
+
s.add_development_dependency 'ruby-debug19', '~> 0.11.6'
|
25
|
+
|
26
|
+
s.files = `git ls-files`.split("\n")
|
27
|
+
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
28
|
+
s.require_path = 'lib'
|
29
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module LayoutOptions
|
2
|
+
def self.included(controller)
|
3
|
+
controller.send(:include, LayoutOptions::InstanceMethods)
|
4
|
+
controller.send(:extend, LayoutOptions::ClassMethods)
|
5
|
+
controller.send(:layout, :layout_options_selector)
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
def layout_options(args={})
|
10
|
+
LayoutOptions::Storage[controller_name] = args
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module InstanceMethods
|
15
|
+
def layout_options_selector
|
16
|
+
layout_options = LayoutOptions::Storage[controller_name].clone || {}
|
17
|
+
no_layout = layout_options.delete(:none) || []
|
18
|
+
no_layout = [no_layout] unless Array === no_layout
|
19
|
+
action = action_name.to_sym
|
20
|
+
|
21
|
+
layout_options.each do |key, values|
|
22
|
+
values = [values] unless Array === values
|
23
|
+
return key.to_s if values.include?(action)
|
24
|
+
end
|
25
|
+
|
26
|
+
no_layout.map! { |value| value.to_sym }
|
27
|
+
return no_layout.include?(action) ? false : 'application'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class FooController < ActionController::Base
|
4
|
+
layout_options :overlay => :edit, :none => :destroy
|
5
|
+
end
|
6
|
+
|
7
|
+
describe LayoutOptions do
|
8
|
+
let(:controller) { FooController.new }
|
9
|
+
describe '#edit' do
|
10
|
+
it 'uses the overlay layout' do
|
11
|
+
controller.stub(:action_name => 'edit')
|
12
|
+
controller.layout_options_selector.should == 'overlay'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#show' do
|
17
|
+
it 'uses the application layout' do
|
18
|
+
controller.stub(:action_name => 'show')
|
19
|
+
controller.layout_options_selector.should == 'application'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#destroy' do
|
24
|
+
it 'uses no layout' do
|
25
|
+
controller.stub(:action_name => 'destroy')
|
26
|
+
controller.layout_options_selector.should == false
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe LayoutOptions::Storage do
|
4
|
+
describe '[]=' do
|
5
|
+
it 'storages the values' do
|
6
|
+
LayoutOptions::Storage[:key] = :value
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '[]' do
|
11
|
+
before(:each) { LayoutOptions::Storage[:key] = :value }
|
12
|
+
it 'it returns the value stored' do
|
13
|
+
LayoutOptions::Storage[:key].should == :value
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: layout_options
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
version: "0.1"
|
9
|
+
platform: ruby
|
10
|
+
authors:
|
11
|
+
- Dane Harrigan
|
12
|
+
autorequire:
|
13
|
+
bindir: bin
|
14
|
+
cert_chain: []
|
15
|
+
|
16
|
+
date: 2010-11-27 00:00:00 -05:00
|
17
|
+
default_executable:
|
18
|
+
dependencies:
|
19
|
+
- !ruby/object:Gem::Dependency
|
20
|
+
name: actionpack
|
21
|
+
prerelease: false
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 3
|
29
|
+
- 0
|
30
|
+
- 1
|
31
|
+
version: 3.0.1
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: bundler
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 1
|
44
|
+
- 0
|
45
|
+
- 0
|
46
|
+
- rc
|
47
|
+
- 6
|
48
|
+
version: 1.0.0.rc.6
|
49
|
+
type: :development
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: rspec
|
53
|
+
prerelease: false
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ~>
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
segments:
|
60
|
+
- 2
|
61
|
+
- 1
|
62
|
+
- 0
|
63
|
+
version: 2.1.0
|
64
|
+
type: :development
|
65
|
+
version_requirements: *id003
|
66
|
+
- !ruby/object:Gem::Dependency
|
67
|
+
name: rspec-rails
|
68
|
+
prerelease: false
|
69
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ~>
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
segments:
|
75
|
+
- 2
|
76
|
+
- 1
|
77
|
+
- 0
|
78
|
+
version: 2.1.0
|
79
|
+
type: :development
|
80
|
+
version_requirements: *id004
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: ruby-debug19
|
83
|
+
prerelease: false
|
84
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
segments:
|
90
|
+
- 0
|
91
|
+
- 11
|
92
|
+
- 6
|
93
|
+
version: 0.11.6
|
94
|
+
type: :development
|
95
|
+
version_requirements: *id005
|
96
|
+
description: The layout_options gem provides a single place to set all of your layouts in your controller. This gem really shines when multiple layouts are needed when using inherited_resources.
|
97
|
+
email:
|
98
|
+
- dane.harrigan@gmail.com
|
99
|
+
executables: []
|
100
|
+
|
101
|
+
extensions: []
|
102
|
+
|
103
|
+
extra_rdoc_files: []
|
104
|
+
|
105
|
+
files:
|
106
|
+
- .gitignore
|
107
|
+
- Gemfile
|
108
|
+
- Gemfile.lock
|
109
|
+
- README.textile
|
110
|
+
- Rakefile
|
111
|
+
- layout_options.gemspec
|
112
|
+
- lib/layout_options.rb
|
113
|
+
- lib/layout_options/layout_options.rb
|
114
|
+
- lib/layout_options/storage.rb
|
115
|
+
- lib/layout_options/version.rb
|
116
|
+
- spec/layout_options_spec.rb
|
117
|
+
- spec/layout_options_storage_spec.rb
|
118
|
+
- spec/spec_helper.rb
|
119
|
+
has_rdoc: true
|
120
|
+
homepage: http://rubygems.org/gems/layout_options
|
121
|
+
licenses: []
|
122
|
+
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
segments:
|
134
|
+
- 0
|
135
|
+
version: "0"
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
segments:
|
142
|
+
- 1
|
143
|
+
- 3
|
144
|
+
- 6
|
145
|
+
version: 1.3.6
|
146
|
+
requirements: []
|
147
|
+
|
148
|
+
rubyforge_project: layout_options
|
149
|
+
rubygems_version: 1.3.7
|
150
|
+
signing_key:
|
151
|
+
specification_version: 3
|
152
|
+
summary: A single place for setting all of your layouts in a controller
|
153
|
+
test_files: []
|
154
|
+
|