ezmedium-controller-ext 0.0.1.a
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +21 -0
- data/README.md +21 -0
- data/Rakefile +2 -0
- data/ezmedium-controller-ext.gemspec +28 -0
- data/lib/ezmedium/controller-ext/authorization_helpers_ext.rb +27 -0
- data/lib/ezmedium/controller-ext/sections_ext.rb +74 -0
- data/lib/ezmedium/controller-ext/title_estuary_ext.rb +34 -0
- data/lib/ezmedium/controller-ext/user_roles_ext.rb +22 -0
- data/lib/ezmedium/controller-ext/version.rb +12 -0
- data/lib/ezmedium/controller-ext.rb +67 -0
- data/lib/ezmedium-controller-ext.rb +2 -0
- metadata +93 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright 2011 Steven Hancock and EZMedium
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
data/README.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# ezmedium-controller-ext
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
## Note on Patches/Pull Requests
|
8
|
+
|
9
|
+
* Fork the project.
|
10
|
+
* Make your feature addition or bug fix.
|
11
|
+
* Add tests for it. This is important so I don't break it in a
|
12
|
+
future version unintentionally.
|
13
|
+
* Commit, do not mess with rakefile, version, or history.
|
14
|
+
(if you want to have your own version, that is fine but bump version in a
|
15
|
+
commit by itself I can ignore when I pull)
|
16
|
+
* Send me a pull request. Bonus points for topic branches.
|
17
|
+
|
18
|
+
## Copyright
|
19
|
+
|
20
|
+
Copyright (c) 2011 Steven Hancock and EZMedium. See MIT-LICENSE for details.
|
21
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "ezmedium/controller-ext/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "ezmedium-controller-ext"
|
7
|
+
s.version = Ezmedium::ControllerExt::Version::STRING
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Steven Hancock"]
|
10
|
+
s.email = ["stevenh512@gmail.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{A set of general-purpose Rails 3 controller extensions used by ezmedium.com}
|
13
|
+
s.description = %q{A set of general-purpose Rails 3 controller extensions used by ezmedium.com}
|
14
|
+
s.rubyforge_project = "ezmedium-controller-ext"
|
15
|
+
|
16
|
+
s.required_rubygems_version = "> 1.3.6"
|
17
|
+
|
18
|
+
s.add_dependency("activesupport", "~> 3.0.5")
|
19
|
+
|
20
|
+
s.add_development_dependency("bundler")
|
21
|
+
s.add_development_dependency("rake")
|
22
|
+
|
23
|
+
s.files = `git ls-files`.split("\n")
|
24
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
25
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
26
|
+
s.require_paths = ["lib"]
|
27
|
+
end
|
28
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Ezmedium::ControllerExt.for(:authorization_helpers) do
|
2
|
+
|
3
|
+
def self.included(klass)
|
4
|
+
klass.class_eval do
|
5
|
+
helper_method :can?
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def can?(action, object)
|
12
|
+
logged_in? && current_user.can?(action, object)
|
13
|
+
end
|
14
|
+
|
15
|
+
def unauthorized!(message = nil)
|
16
|
+
respond_to do |format|
|
17
|
+
format.html do
|
18
|
+
message = ["I'm sorry, you don't have the correct permissions to do that", message].compact.join(" - ")
|
19
|
+
redirect_to :root, :alert => message
|
20
|
+
end
|
21
|
+
format.json { head :forbidden }
|
22
|
+
format.xml { head :forbidden }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
@@ -0,0 +1,74 @@
|
|
1
|
+
Ezmedium::ControllerExt.for(:sections) do
|
2
|
+
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
helper_method :show_sidebar_left?, :hide_sidebar_left?, :show_sidebar_right?, :hide_sidebar_right?, :show_header?, :hide_header?
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
|
11
|
+
def show_sidebar!(opts = {})
|
12
|
+
before_filter :show_sidebar!, opts
|
13
|
+
end
|
14
|
+
|
15
|
+
def hide_sidebar!(opts = {})
|
16
|
+
before_filter :hide_sidebar!, opts
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
module InstanceMethods
|
22
|
+
|
23
|
+
def show_sidebar_left!
|
24
|
+
@hide_sidebar_left = false
|
25
|
+
end
|
26
|
+
|
27
|
+
def hide_sidebar_left!
|
28
|
+
@hide_sidebar_left = true
|
29
|
+
end
|
30
|
+
|
31
|
+
def show_sidebar_right!
|
32
|
+
@hide_sidebar_right = false
|
33
|
+
end
|
34
|
+
|
35
|
+
def hide_sidebar_right!
|
36
|
+
@hide_sidebar_right = true
|
37
|
+
end
|
38
|
+
|
39
|
+
def show_header!
|
40
|
+
@hide_header = false
|
41
|
+
end
|
42
|
+
|
43
|
+
def hide_header!
|
44
|
+
@hide_header = true
|
45
|
+
end
|
46
|
+
|
47
|
+
def show_sidebar_left?
|
48
|
+
!hide_sidebar_left?
|
49
|
+
end
|
50
|
+
|
51
|
+
def hide_sidebar_left?
|
52
|
+
defined?(@hide_sidebar_left) && @hide_sidebar_left
|
53
|
+
end
|
54
|
+
|
55
|
+
def show_sidebar_right?
|
56
|
+
!hide_sidebar_right?
|
57
|
+
end
|
58
|
+
|
59
|
+
def hide_sidebar_right?
|
60
|
+
defined?(@hide_sidebar_right) && @hide_sidebar_right
|
61
|
+
end
|
62
|
+
|
63
|
+
def show_header?
|
64
|
+
!hide_header?
|
65
|
+
end
|
66
|
+
|
67
|
+
def hide_header?
|
68
|
+
defined?(@hide_header) && @hide_header
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
Ezmedium::ControllerExt.for(:title_estuary) do
|
2
|
+
|
3
|
+
def self.included(p)
|
4
|
+
p.helper_method(:page_title_is, :hide_title?)
|
5
|
+
end
|
6
|
+
|
7
|
+
protected
|
8
|
+
|
9
|
+
def hide_title?
|
10
|
+
instance_variable_defined?(:@hide_title) && @hide_title
|
11
|
+
end
|
12
|
+
|
13
|
+
def hide_title!
|
14
|
+
@hide_title = true
|
15
|
+
end
|
16
|
+
|
17
|
+
def show_title!
|
18
|
+
@hide_title = false
|
19
|
+
end
|
20
|
+
|
21
|
+
def page_title_is(title)
|
22
|
+
self.page_title = title
|
23
|
+
end
|
24
|
+
|
25
|
+
def interpolation_options
|
26
|
+
@__interpolation_options ||= {}
|
27
|
+
end
|
28
|
+
|
29
|
+
def add_title_variables!(mapping = {})
|
30
|
+
interpolation_options.merge!(mapping)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Ezmedium::ControllerExt.for(:user_roles) do
|
2
|
+
|
3
|
+
def self.included(p)
|
4
|
+
p.helper_method(:page_title_is, :hide_title?)
|
5
|
+
end
|
6
|
+
|
7
|
+
protected
|
8
|
+
|
9
|
+
# Get roles accessible by the current user
|
10
|
+
def accessible_roles
|
11
|
+
# Don't display user role - it gets added automatically and should be
|
12
|
+
# transparent to the system.
|
13
|
+
@accessible_roles ||= Role.accessible_by(current_ability, :read) - [Role.by_name(:user)]
|
14
|
+
end
|
15
|
+
|
16
|
+
# Make the current user object available to views
|
17
|
+
def get_user
|
18
|
+
@current_user = current_user
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module Ezmedium
|
4
|
+
module ControllerExt
|
5
|
+
mattr_accessor :known_extensions
|
6
|
+
self.known_extensions ||= {}
|
7
|
+
|
8
|
+
def self.load_default!
|
9
|
+
dir = File.expand_path("controller-ext", File.dirname(__FILE__))
|
10
|
+
Dir[File.join(dir, "*.rb")].each do |f|
|
11
|
+
require f
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# Lookup controller extensions.
|
16
|
+
def self.[](name)
|
17
|
+
name = name.to_sym
|
18
|
+
if known_extensions.has_key?(name)
|
19
|
+
return known_extensions[name]
|
20
|
+
else
|
21
|
+
constant_name = "#{name.to_s.classify}Ext"
|
22
|
+
[nil, "Ezmedium::ControllerExt", "Ezmedium", "ControllerExt"].each do |namespace|
|
23
|
+
full = [namespace, constant_name].compact.join("::")
|
24
|
+
begin
|
25
|
+
constant = full.constantize
|
26
|
+
known_extensions[name] = constant
|
27
|
+
return constant
|
28
|
+
rescue NameError
|
29
|
+
end
|
30
|
+
end
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.for(name, &blk)
|
36
|
+
constant_name = "#{name.to_s.classify}Ext"
|
37
|
+
const_set(constant_name, Module.new) unless const_defined?(constant_name)
|
38
|
+
const_get(constant_name).tap do |m|
|
39
|
+
m.module_eval(&blk) if blk.present?
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
module ClassMethods
|
44
|
+
|
45
|
+
def use_controller_exts(*args)
|
46
|
+
args.each do |k|
|
47
|
+
mod = Ezmedium::ControllerExt[k]
|
48
|
+
include mod if mod.present?
|
49
|
+
end
|
50
|
+
end
|
51
|
+
alias uses_controller_exts use_controller_exts
|
52
|
+
|
53
|
+
end
|
54
|
+
# Include the mixin in action controller.
|
55
|
+
ActionController::Base.extend(ClassMethods) if defined?(ActionController::Base)
|
56
|
+
|
57
|
+
if defined?(Rails::Railtie)
|
58
|
+
class Railtie < Rails::Railtie
|
59
|
+
initializer "ezmedium.controller-ext" do
|
60
|
+
Ezmedium::ControllerExt.load_default!
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ezmedium-controller-ext
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.a
|
5
|
+
prerelease: 6
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Steven Hancock
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-04-08 00:00:00.000000000 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: activesupport
|
17
|
+
requirement: &73920840 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 3.0.5
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *73920840
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: bundler
|
28
|
+
requirement: &73920650 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *73920650
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rake
|
39
|
+
requirement: &73920420 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *73920420
|
48
|
+
description: A set of general-purpose Rails 3 controller extensions used by ezmedium.com
|
49
|
+
email:
|
50
|
+
- stevenh512@gmail.com
|
51
|
+
executables: []
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- .gitignore
|
56
|
+
- Gemfile
|
57
|
+
- MIT-LICENSE
|
58
|
+
- README.md
|
59
|
+
- Rakefile
|
60
|
+
- ezmedium-controller-ext.gemspec
|
61
|
+
- lib/ezmedium-controller-ext.rb
|
62
|
+
- lib/ezmedium/controller-ext.rb
|
63
|
+
- lib/ezmedium/controller-ext/authorization_helpers_ext.rb
|
64
|
+
- lib/ezmedium/controller-ext/sections_ext.rb
|
65
|
+
- lib/ezmedium/controller-ext/title_estuary_ext.rb
|
66
|
+
- lib/ezmedium/controller-ext/user_roles_ext.rb
|
67
|
+
- lib/ezmedium/controller-ext/version.rb
|
68
|
+
has_rdoc: true
|
69
|
+
homepage: ''
|
70
|
+
licenses: []
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ! '>'
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: 1.3.6
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project: ezmedium-controller-ext
|
89
|
+
rubygems_version: 1.6.2
|
90
|
+
signing_key:
|
91
|
+
specification_version: 3
|
92
|
+
summary: A set of general-purpose Rails 3 controller extensions used by ezmedium.com
|
93
|
+
test_files: []
|