layout_by_action 0.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 20b94e2962763d30e7e52fa8956a233a5a55ee8a
4
+ data.tar.gz: e153f1f34232ee4cbba6f02c130cf522b344f091
5
+ SHA512:
6
+ metadata.gz: 15bfc7f4a79bb03b61f2437ed52ff462f11c0ac389830920d9db654c41d072342ce60c9ce048f8cfe75e27d3bc7a35acb696bb524793489d86b15988fd9fcbdb
7
+ data.tar.gz: db8f49cd3aff4357d41818e3efacb3a4ad5d2d9be41e73e37f33b4e3cc6f2c131564b978e0c9333c0c190a849bcd28c0b1693855363b7642f6f1983bde2457e6
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in layout_by_action.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,24 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('config/routes.rb') { "spec/routing" }
15
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
+
17
+ # Capybara features specs
18
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
19
+
20
+ # Turnip features and steps
21
+ watch(%r{^spec/acceptance/(.+)\.feature$})
22
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23
+ end
24
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 barelyknown
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # layout_by_action for Rails Controllers
2
+
3
+ You might want to specify layouts for individual actions in your controllers.
4
+
5
+ Add `gem "layout_by_action"` to your `Gemfile` to get this syntax:
6
+
7
+ class ExampleController < ApplicationController
8
+ layout_by_action new: "company", show: "example"
9
+ end
10
+
11
+ You can set a default layout.
12
+
13
+ layout_by_action "default", new: "company", show: "example"
14
+
15
+ You can also specify an array of actions for any layout.
16
+
17
+ layout_by_action [:new, :edit] => "company", show: "example"
18
+
19
+ ## About
20
+
21
+ Extracted from a Rails project by [@barelyknown](http://twitter.com/barelyknown) :)
22
+
23
+ This gem is an answer to a [popular question on Stack Overflow](http://stackoverflow.com/questions/3025784/rails-layouts-per-action/18454800).
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'layout_by_action/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "layout_by_action"
8
+ spec.version = LayoutByAction::VERSION
9
+ spec.authors = ["barelyknown"]
10
+ spec.email = ["barelyknown@icloud.com"]
11
+ spec.description = %q{Add layout_by_action method to application controllers}
12
+ spec.summary = %q{Add layout_by_action method to application controllers}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "guard-rspec"
25
+
26
+ spec.add_dependency "activesupport"
27
+ end
@@ -0,0 +1,10 @@
1
+ require "active_support/concern"
2
+ require "active_support/core_ext/hash/indifferent_access"
3
+
4
+ require "layout_by_action/version"
5
+ require "layout_by_action/able"
6
+
7
+ require "layout_by_action/railtie" if defined?(Rails)
8
+
9
+ module LayoutByAction
10
+ end
@@ -0,0 +1,37 @@
1
+ module LayoutByAction
2
+ module Able
3
+ extend ActiveSupport::Concern
4
+
5
+ def layout_by_action(action_name=params[:action])
6
+ self.class.layouts.fetch(action_name) do
7
+ self.class.default_layout
8
+ end
9
+ end
10
+
11
+ module ClassMethods
12
+ def default_layout=(value)
13
+ @default_layout = value
14
+ end
15
+
16
+ def default_layout
17
+ @default_layout
18
+ end
19
+
20
+ def layouts
21
+ @layouts ||= HashWithIndifferentAccess.new
22
+ end
23
+
24
+ def layout_by_action(default=nil, actions_and_layouts)
25
+ include LayoutByAction::Able
26
+ self.default_layout = default
27
+ actions_and_layouts.each do |actions, layout|
28
+ Array(actions).each do |action|
29
+ layouts[action] = layout
30
+ end
31
+ end
32
+ layout :layout_by_action
33
+ end
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,9 @@
1
+ module LayoutByAction
2
+ class Railtie < Rails::Railtie
3
+ initializer "layout_by_action.action_controller" do
4
+ ActiveSupport.on_load(:action_controller) do
5
+ include LayoutByAction::Able
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module LayoutByAction
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,42 @@
1
+ require "spec_helper"
2
+
3
+ # stand ins for Rails application controller
4
+ # it is extended by the railtie
5
+
6
+ class ApplicationController
7
+ include LayoutByAction::Able
8
+ def self.layout(method); end
9
+ end
10
+
11
+ class YourController < ApplicationController; end
12
+
13
+ module LayoutByAction
14
+ describe YourController do
15
+ let!(:layout_by_action) { { new: "alt_one", [:show, :index] => "alt_two" } }
16
+ let!(:default) { nil }
17
+
18
+ before { described_class.layout_by_action default, layout_by_action }
19
+
20
+ it "should add layout_by_action to subclasses of application controller" do
21
+ expect(described_class).to respond_to(:layout_by_action)
22
+ end
23
+
24
+ it "should provide the specified layout when a single action is used" do
25
+ expect(subject.layout_by_action(:new)).to eq "alt_one"
26
+ end
27
+
28
+ it "should provide the right layout when an array of actions are used" do
29
+ [:show, :index].each do |action|
30
+ expect(subject.layout_by_action(action)).to eq "alt_two"
31
+ end
32
+ end
33
+
34
+ context "when a default is provided" do
35
+ let!(:default) { "default" }
36
+
37
+ it "should use the default layout for an action not specified" do
38
+ expect(subject.layout_by_action(:default)).to eq "default"
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,2 @@
1
+ # tested on a rails 4 app
2
+ # feel free to add tests for the railtie :)
@@ -0,0 +1,16 @@
1
+ require "rubygems"
2
+ require "bundler/setup"
3
+
4
+ require "layout_by_action"
5
+
6
+ RSpec.configure do |config|
7
+ config.treat_symbols_as_metadata_keys_with_true_values = true
8
+ config.run_all_when_everything_filtered = true
9
+ config.filter_run :focus
10
+
11
+ # Run specs in random order to surface order dependencies. If you find an
12
+ # order dependency and want to debug it, you can fix the order by providing
13
+ # the seed, which is printed after each run.
14
+ # --seed 1234
15
+ config.order = 'random'
16
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: layout_by_action
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - barelyknown
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activesupport
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Add layout_by_action method to application controllers
84
+ email:
85
+ - barelyknown@icloud.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .rspec
92
+ - Gemfile
93
+ - Guardfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - layout_by_action.gemspec
98
+ - lib/layout_by_action.rb
99
+ - lib/layout_by_action/able.rb
100
+ - lib/layout_by_action/railtie.rb
101
+ - lib/layout_by_action/version.rb
102
+ - spec/lib/layout_by_action/able_spec.rb
103
+ - spec/lib/layout_by_action/railtie_spec.rb
104
+ - spec/spec_helper.rb
105
+ homepage: ''
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.0.2
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Add layout_by_action method to application controllers
129
+ test_files:
130
+ - spec/lib/layout_by_action/able_spec.rb
131
+ - spec/lib/layout_by_action/railtie_spec.rb
132
+ - spec/spec_helper.rb