rendition 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +35 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/lib/rendition.rb +8 -0
- data/lib/rendition/action_support.rb +54 -0
- data/lib/rendition/presenter.rb +118 -0
- data/lib/rendition/railtie.rb +57 -0
- data/lib/rendition/rspec_integration.rb +24 -0
- data/lib/rendition/system.rb +23 -0
- data/lib/rendition/version.rb +3 -0
- data/lib/rendition/view_context.rb +21 -0
- data/rendition.gemspec +26 -0
- data/spec/rendition/action_support_spec.rb +31 -0
- data/spec/rendition/presenter_spec.rb +48 -0
- data/spec/rendition/view_context_spec.rb +19 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/support/application_controller.rb +46 -0
- data/spec/support/application_helper.rb +5 -0
- data/spec/support/models.rb +33 -0
- metadata +169 -0
data/.gitignore
ADDED
@@ -0,0 +1,35 @@
|
|
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
|
18
|
+
|
19
|
+
.idea/workspace.xml
|
20
|
+
|
21
|
+
.idea/scopes/scope_settings.xml
|
22
|
+
|
23
|
+
.idea/.name
|
24
|
+
|
25
|
+
.idea/.rakeTasks
|
26
|
+
|
27
|
+
.idea/encodings.xml
|
28
|
+
|
29
|
+
.idea/misc.xml
|
30
|
+
|
31
|
+
.idea/modules.xml
|
32
|
+
|
33
|
+
.idea/rendition.iml
|
34
|
+
|
35
|
+
.idea/vcs.xml
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 jake hoffner
|
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,29 @@
|
|
1
|
+
# Rendition
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'rendition'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install rendition
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/rendition.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
|
2
|
+
require 'rendition/version'
|
3
|
+
require 'rendition/system'
|
4
|
+
require 'rendition/presenter'
|
5
|
+
require 'rendition/action_support'
|
6
|
+
require 'rendition/view_context'
|
7
|
+
require 'rendition/rspec_integration' if defined?(RSpec) and RSpec.respond_to?(:configure)
|
8
|
+
require 'rendition/railtie' if defined?(Rails)
|
@@ -0,0 +1,54 @@
|
|
1
|
+
|
2
|
+
module Rendition
|
3
|
+
module ActionSupport
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
module ClassMethods
|
7
|
+
# @param [Symbol] name
|
8
|
+
# @param [Block] block
|
9
|
+
def expose_presenter(name, default_type = :default, &block)
|
10
|
+
_expose_presenter_or_presenters(:presenter, name, default_type, &block)
|
11
|
+
end
|
12
|
+
|
13
|
+
# @param [Symbol] name
|
14
|
+
# @param [Block] block
|
15
|
+
def expose_presenters(name, default_type = :default, &block)
|
16
|
+
_expose_presenter_or_presenters(:presenters, name, default_type, &block)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def _expose_presenter_or_presenters(method_name, name, default_type, &block)
|
22
|
+
default_exposure = begin self.default_exposure rescue nil end
|
23
|
+
define_method name do |type = default_type, attributes = {}|
|
24
|
+
@_resources ||= {}
|
25
|
+
@_resources.fetch(name) do
|
26
|
+
model = if block_given?
|
27
|
+
instance_eval(&block)
|
28
|
+
else
|
29
|
+
instance_exec(name, &default_exposure)
|
30
|
+
end
|
31
|
+
|
32
|
+
@_resources[name] = send method_name, type, model, attributes
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
define_method "#{name}=".to_sym do |value|
|
37
|
+
@_resources ||= {}
|
38
|
+
@_resources[name] = value
|
39
|
+
end
|
40
|
+
|
41
|
+
helper_method name
|
42
|
+
hide_action name
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def presenter(type = :default, model = nil, attributes = {}, &block)
|
47
|
+
Rendition::Presenter.presenter(self.view_context, type, model, attributes, &block)
|
48
|
+
end
|
49
|
+
|
50
|
+
def presenters(type = :default, models = nil, attributes = {}, &block)
|
51
|
+
Rendition::Presenter.presenters(self.view_context, type, models, attributes, &block)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
module Rendition
|
2
|
+
class Presenter
|
3
|
+
|
4
|
+
attr_reader :view_context
|
5
|
+
attr_reader :model
|
6
|
+
attr_reader :parent_presenter
|
7
|
+
|
8
|
+
def initialize (view_context, model, attributes = {})
|
9
|
+
@view_context = view_context
|
10
|
+
@model = model
|
11
|
+
|
12
|
+
@parent_presenter = attributes[:parent_presenter] if attributes.has_key? :parent_presenter
|
13
|
+
set_attrs(attributes)
|
14
|
+
|
15
|
+
setup
|
16
|
+
end
|
17
|
+
|
18
|
+
def set_attrs(attributes)
|
19
|
+
attributes.each do |name, value|
|
20
|
+
self.send "#{name}=", value if self.respond_to? :"#{name}="
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def setup
|
25
|
+
end
|
26
|
+
|
27
|
+
def method_missing(method, *args, &block)
|
28
|
+
if model and model.respond_to? method
|
29
|
+
val = model.send method, *args, &block
|
30
|
+
|
31
|
+
# if the value is an array then we want to extend that instance of the array to have a presenters method
|
32
|
+
if val.is_a? Array and !val.respond_to? :presenters
|
33
|
+
parent = self
|
34
|
+
val.define_singleton_method :presenters do |type = nil, attributes = {}|
|
35
|
+
type ||= :default
|
36
|
+
@__presenters ||= {}
|
37
|
+
@__presenters.fetch(type) do
|
38
|
+
parent.presenters(type, self, attributes)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
val
|
43
|
+
#elsif view_context.respond_to? method
|
44
|
+
# view_context.send method, *args, &block
|
45
|
+
else
|
46
|
+
super
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def presenter(type = :default, model = nil, attributes = {}, &block)
|
51
|
+
attributes[:parent_presenter] = self
|
52
|
+
self.class.presenter(view_context, type, model, attributes, &block)
|
53
|
+
end
|
54
|
+
|
55
|
+
def presenters(type = :default, models = nil, attributes = {}, &block)
|
56
|
+
attributes[:parent_presenter] = self
|
57
|
+
self.class.presenters(view_context, type, models, attributes, &block)
|
58
|
+
end
|
59
|
+
|
60
|
+
class << self
|
61
|
+
|
62
|
+
def presenter(view_context, types = nil, model = nil, attributes = {}, &block)
|
63
|
+
|
64
|
+
types, model, attributes = _process_args(types, model, attributes, &block)
|
65
|
+
|
66
|
+
if model
|
67
|
+
_find_presenter_class(types, model, attributes).new(view_context, model, attributes)
|
68
|
+
else
|
69
|
+
nil
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def presenters(view_context, type = nil, models = nil, attributes = {}, &block)
|
74
|
+
type, models, attributes = _process_args(type, models, attributes, &block)
|
75
|
+
|
76
|
+
return [] if models.empty?
|
77
|
+
|
78
|
+
klass = _find_presenter_class(type, models.first, attributes)
|
79
|
+
models.collect do |model|
|
80
|
+
klass.new(view_context, model, attributes.clone) if model
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def _process_args(type, model_or_models, attributes = {}, &block)
|
87
|
+
type ||= :default
|
88
|
+
|
89
|
+
# if the model was passed in as the first argument
|
90
|
+
unless type.is_a? Symbol
|
91
|
+
model_or_models = type
|
92
|
+
type = :default
|
93
|
+
end
|
94
|
+
|
95
|
+
if block_given?
|
96
|
+
model_or_models.merge!(attributes) if model_or_models
|
97
|
+
attributes = model_or_models || {}
|
98
|
+
model_or_models = block.call
|
99
|
+
end
|
100
|
+
|
101
|
+
[type, model_or_models, attributes]
|
102
|
+
end
|
103
|
+
|
104
|
+
def _find_presenter_class(type, model, attributes)
|
105
|
+
model = model.model if model.is_a? Rendition::Presenter # allow other presenters to be passed in
|
106
|
+
|
107
|
+
presenter_name = "#{type == :default ? "" : type.to_s.classify}Presenter"
|
108
|
+
begin
|
109
|
+
klass = model.class.const_get(presenter_name)
|
110
|
+
return klass
|
111
|
+
rescue
|
112
|
+
nil
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'rails/railtie'
|
2
|
+
|
3
|
+
#module ActiveModel
|
4
|
+
# class Railtie < Rails::Railtie
|
5
|
+
# generators do |app|
|
6
|
+
# Rails::Generators.configure!(app.config.generators)
|
7
|
+
# require "generators/resource_override"
|
8
|
+
# end
|
9
|
+
# end
|
10
|
+
#end
|
11
|
+
|
12
|
+
module Rendition
|
13
|
+
class Railtie < Rails::Railtie
|
14
|
+
|
15
|
+
##
|
16
|
+
# Decorators are loaded in
|
17
|
+
# => at app boot in non-development environments
|
18
|
+
# => after each request in the development environment
|
19
|
+
#
|
20
|
+
# This is necessary because we might never explicitly reference
|
21
|
+
# Decorator constants.
|
22
|
+
#
|
23
|
+
config.to_prepare do
|
24
|
+
::Rendition::System.load_app_local_presenters
|
25
|
+
end
|
26
|
+
|
27
|
+
##
|
28
|
+
# The `app/decorators` path is eager loaded
|
29
|
+
#
|
30
|
+
# This is the standard "Rails Way" to add paths from which constants
|
31
|
+
# can be loaded.
|
32
|
+
#
|
33
|
+
config.after_initialize do |app|
|
34
|
+
app.config.paths.add 'app/presenters', :eager_load => true
|
35
|
+
end
|
36
|
+
|
37
|
+
initializer "rendition.extend_action_controller_base" do |app|
|
38
|
+
ActiveSupport.on_load(:action_controller) do
|
39
|
+
Rendition::System.setup(:action_controller)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
initializer "rendition.extend_action_mailer_base" do |app|
|
44
|
+
ActiveSupport.on_load(:action_mailer) do
|
45
|
+
Rendition::System.setup(:action_mailer)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
console do
|
50
|
+
require 'action_controller/test_case'
|
51
|
+
#ApplicationController.new.set_current_view_context
|
52
|
+
#Rendition::ViewContext.current.controller.request ||= ActionController::TestRequest.new
|
53
|
+
#Rendition::ViewContext.current.request ||= Rendition::ViewContext.current.controller.request
|
54
|
+
#Rendition::ViewContext.current.params ||= {}
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Rendition
|
2
|
+
module PresenterExampleGroup
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
included { metadata[:type] = :presenter }
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
# Automatically tag specs in specs/Presenters as type: :presenter
|
10
|
+
config.include Rendition::PresenterExampleGroup, :type => :presenter, :example_group => {
|
11
|
+
:file_path => /spec[\\\/]Presenters/
|
12
|
+
}
|
13
|
+
|
14
|
+
# Specs tagged type: :presenter set the Rendition view context
|
15
|
+
config.around do |example|
|
16
|
+
if :presenter == example.metadata[:type]
|
17
|
+
ApplicationController.new.set_current_view_context
|
18
|
+
Rendition::ViewContext.current.controller.request ||= ActionController::TestRequest.new
|
19
|
+
Rendition::ViewContext.current.request ||= Rendition::ViewContext.current.controller.request
|
20
|
+
Rendition::ViewContext.current.params ||= {}
|
21
|
+
end
|
22
|
+
example.call
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Rendition
|
2
|
+
class System
|
3
|
+
def self.app_local_presenter_glob
|
4
|
+
'app/presenters/**/*_presenter.rb'
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.load_app_local_presenters
|
8
|
+
presenter_files = Dir[ "#{ Rails.root }/#{ app_local_presenter_glob }" ]
|
9
|
+
presenter_files.each { |d| require_dependency d }
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.setup(component)
|
13
|
+
if component == :action_controller
|
14
|
+
#ActionController::Base.send(:include, Rendition::ViewContextFilter)
|
15
|
+
ActionController::Base.send(:include, Rendition::ActionSupport)
|
16
|
+
#ActionController::Base.extend(Rendition::HelperSupport)
|
17
|
+
elsif component == :action_mailer
|
18
|
+
#ActionMailer::Base.send(:include, Rendition::ViewContextFilter)
|
19
|
+
ActionMailer::Base.send(:include, Rendition::ActionSupport)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Rendition
|
2
|
+
module ViewContext
|
3
|
+
def self.current
|
4
|
+
Thread.current[:current_view_context]
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.current=(input)
|
8
|
+
Thread.current[:current_view_context] = input
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module ViewContextFilter
|
13
|
+
def set_current_view_context
|
14
|
+
Rendition::ViewContext.current = self.view_context
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.included(source)
|
18
|
+
source.send(:before_filter, :set_current_view_context) if source.respond_to?(:before_filter)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/rendition.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/rendition/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Jake Hoffner"]
|
6
|
+
gem.email = ["jake.hoffner@hoffnercorporation.com"]
|
7
|
+
gem.description = %q{Rails 3 MVC Presenter pattern library}
|
8
|
+
gem.summary = %q{}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "rendition"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Rendition::VERSION
|
17
|
+
gem.rubyforge_project = "rendition"
|
18
|
+
|
19
|
+
gem.add_dependency 'activesupport', '~> 3.2'
|
20
|
+
gem.add_dependency 'actionpack', '~> 3.2'
|
21
|
+
|
22
|
+
gem.add_development_dependency 'ammeter', '~> 0.2.2'
|
23
|
+
gem.add_development_dependency 'rake', '~> 0.9.2'
|
24
|
+
gem.add_development_dependency 'rspec', '~> 2.10'
|
25
|
+
gem.add_development_dependency 'rails', '~> 3.2.3'
|
26
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rendition::ActionSupport do
|
4
|
+
let(:app_controller) { ApplicationController }
|
5
|
+
let(:app_controller_instance) { app_controller.new }
|
6
|
+
|
7
|
+
it "implements #presenter" do
|
8
|
+
app_controller_instance.should respond_to(:presenter)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "implements #presenters" do
|
12
|
+
app_controller_instance.should respond_to(:presenters)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "implements #expose_presenter" do
|
16
|
+
app_controller.should respond_to(:expose_presenter)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "implements #expose_presenters" do
|
20
|
+
app_controller.should respond_to(:expose_presenters)
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "expose_presenter" do
|
24
|
+
let(:product) { app_controller_instance.product }
|
25
|
+
|
26
|
+
it "should always return a presenter instance when the underlying model is available" do
|
27
|
+
product.is_a?(Rendition::Presenter).should be_true
|
28
|
+
product.is_a?(Product::Presenter).should be_true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rendition::Presenter do
|
4
|
+
let(:app_controller_instance) {ApplicationController.new}
|
5
|
+
let(:presenter) { app_controller_instance.product }
|
6
|
+
|
7
|
+
it "should have its model attribute set to the underlying model" do
|
8
|
+
presenter.model.is_a?(Product).should be_true
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should pass-through to the decorated model" do
|
12
|
+
presenter.name.empty?.should be_false
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should implement #context" do
|
16
|
+
presenter.view_context.should_not be_nil
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should implement #model" do
|
20
|
+
presenter.model.should_not be_nil
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should provide access to presenter specific methods" do
|
24
|
+
presenter.name_and_id.should == "#{presenter.name}_#{presenter.id}"
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "nested presenters" do
|
28
|
+
let(:nested_presenters) { presenter.related_products.presenters }
|
29
|
+
|
30
|
+
it "should provide the ability to load child presenters on arrays within the model" do
|
31
|
+
nested_presenters.first.is_a?(Product::Presenter).should be_true
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should have their #parent_presenter attr set" do
|
35
|
+
nested_presenters.first.parent_presenter.should == presenter
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
describe "specifying a non-default presenter type" do
|
41
|
+
let(:alt_presenter) {alt_presenter = app_controller_instance.presenter(:alt, presenter)}
|
42
|
+
|
43
|
+
it "should return itself as a different type of presenter if manually specified" do
|
44
|
+
alt_presenter.is_a?(Product::AltPresenter).should be_true
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#require 'spec_helper'
|
2
|
+
#
|
3
|
+
#describe Rendition::ViewContext do
|
4
|
+
# let(:app_controller) { ApplicationController }
|
5
|
+
# let(:app_controller_instance) { app_controller.new }
|
6
|
+
#
|
7
|
+
# it "implements #set_current_view_context" do
|
8
|
+
# app_controller_instance.should respond_to(:set_current_view_context)
|
9
|
+
# end
|
10
|
+
#
|
11
|
+
# it "calls #before_filter with #set_current_view_context" do
|
12
|
+
# app_controller.before_filters.should include(:set_current_view_context)
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# it "raises an exception if the view_context is fetched without being set" do
|
16
|
+
# Rendition::ViewContext.current = nil
|
17
|
+
# expect {app_controller.current_view_context}.should raise_exception(Exception)
|
18
|
+
# end
|
19
|
+
#end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
|
2
|
+
module ActionController
|
3
|
+
class Base
|
4
|
+
@@before_filters = []
|
5
|
+
def self.before_filters
|
6
|
+
@@before_filters
|
7
|
+
end
|
8
|
+
def self.before_filter(name)
|
9
|
+
@@before_filters << name
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
Rendition::System.setup(:action_controller)
|
15
|
+
|
16
|
+
class ApplicationController < ActionController::Base
|
17
|
+
#extend ActionView::Helpers
|
18
|
+
#extend ActionView::Helpers::TagHelper
|
19
|
+
#extend ActionView::Helpers::UrlHelper
|
20
|
+
extend ApplicationHelper
|
21
|
+
|
22
|
+
expose_presenter :product do
|
23
|
+
Product.test_instance
|
24
|
+
end
|
25
|
+
|
26
|
+
def view_context
|
27
|
+
@view_context ||= ApplicationController
|
28
|
+
end
|
29
|
+
|
30
|
+
def view_context=(input)
|
31
|
+
@view_context = input
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.hello
|
35
|
+
"Hello!"
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.capture(&block)
|
39
|
+
@@capture = true
|
40
|
+
block.call
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.capture_triggered
|
44
|
+
@@capture ||= false
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
|
2
|
+
class Product
|
3
|
+
attr_accessor :name, :id, :related_products
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
self.related_products = []
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.test_instance
|
10
|
+
p = Product.new
|
11
|
+
p.name = "test_name"
|
12
|
+
p.id = "test_id"
|
13
|
+
|
14
|
+
p2 = Product.new
|
15
|
+
p2.name = "related_product_name"
|
16
|
+
p2.id = "related_product_id"
|
17
|
+
|
18
|
+
p.related_products << p2
|
19
|
+
p
|
20
|
+
end
|
21
|
+
|
22
|
+
class Presenter < Rendition::Presenter
|
23
|
+
def name_and_id
|
24
|
+
"#{name}_#{id}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class AltPresenter < Product::Presenter
|
29
|
+
def is_alt?
|
30
|
+
true
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,169 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rendition
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jake Hoffner
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.2'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.2'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: actionpack
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '3.2'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '3.2'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: ammeter
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.2.2
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.2.2
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.9.2
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 0.9.2
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rspec
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '2.10'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '2.10'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: rails
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 3.2.3
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 3.2.3
|
110
|
+
description: Rails 3 MVC Presenter pattern library
|
111
|
+
email:
|
112
|
+
- jake.hoffner@hoffnercorporation.com
|
113
|
+
executables: []
|
114
|
+
extensions: []
|
115
|
+
extra_rdoc_files: []
|
116
|
+
files:
|
117
|
+
- .gitignore
|
118
|
+
- Gemfile
|
119
|
+
- LICENSE
|
120
|
+
- README.md
|
121
|
+
- Rakefile
|
122
|
+
- lib/rendition.rb
|
123
|
+
- lib/rendition/action_support.rb
|
124
|
+
- lib/rendition/presenter.rb
|
125
|
+
- lib/rendition/railtie.rb
|
126
|
+
- lib/rendition/rspec_integration.rb
|
127
|
+
- lib/rendition/system.rb
|
128
|
+
- lib/rendition/version.rb
|
129
|
+
- lib/rendition/view_context.rb
|
130
|
+
- rendition.gemspec
|
131
|
+
- spec/rendition/action_support_spec.rb
|
132
|
+
- spec/rendition/presenter_spec.rb
|
133
|
+
- spec/rendition/view_context_spec.rb
|
134
|
+
- spec/spec_helper.rb
|
135
|
+
- spec/support/application_controller.rb
|
136
|
+
- spec/support/application_helper.rb
|
137
|
+
- spec/support/models.rb
|
138
|
+
homepage: ''
|
139
|
+
licenses: []
|
140
|
+
post_install_message:
|
141
|
+
rdoc_options: []
|
142
|
+
require_paths:
|
143
|
+
- lib
|
144
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ! '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
|
+
none: false
|
152
|
+
requirements:
|
153
|
+
- - ! '>='
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '0'
|
156
|
+
requirements: []
|
157
|
+
rubyforge_project: rendition
|
158
|
+
rubygems_version: 1.8.21
|
159
|
+
signing_key:
|
160
|
+
specification_version: 3
|
161
|
+
summary: ''
|
162
|
+
test_files:
|
163
|
+
- spec/rendition/action_support_spec.rb
|
164
|
+
- spec/rendition/presenter_spec.rb
|
165
|
+
- spec/rendition/view_context_spec.rb
|
166
|
+
- spec/spec_helper.rb
|
167
|
+
- spec/support/application_controller.rb
|
168
|
+
- spec/support/application_helper.rb
|
169
|
+
- spec/support/models.rb
|