draper 0.10.0 → 0.11.0
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.
- data/.travis.yml +0 -1
- data/Gemfile +3 -3
- data/Rakefile +8 -8
- data/Readme.markdown +41 -22
- data/doc/css/full_list.css +2 -2
- data/doc/css/style.css +30 -30
- data/doc/js/app.js +10 -10
- data/doc/js/full_list.js +8 -8
- data/draper.gemspec +2 -2
- data/lib/draper.rb +1 -1
- data/lib/draper/base.rb +65 -22
- data/lib/draper/decorated_enumerable_proxy.rb +6 -1
- data/lib/draper/model_support.rb +2 -2
- data/lib/draper/railtie.rb +19 -0
- data/lib/draper/system.rb +7 -4
- data/lib/draper/version.rb +1 -1
- data/lib/generators/draper/decorator/decorator_generator.rb +26 -4
- data/lib/generators/draper/decorator/templates/decorator.rb +2 -2
- data/lib/generators/{rspec → draper/decorator}/templates/decorator_spec.rb +1 -1
- data/lib/generators/{test_unit → draper/decorator}/templates/decorator_test.rb +1 -1
- data/lib/generators/draper/install/install_generator.rb +6 -6
- data/lib/generators/rails/decorator_generator.rb +3 -3
- data/performance/bechmark.rb +5 -5
- data/performance/decorators.rb +4 -4
- data/performance/models.rb +2 -2
- data/spec/draper/base_spec.rb +176 -10
- data/spec/draper/helper_support_spec.rb +1 -1
- data/spec/draper/model_support_spec.rb +23 -14
- data/spec/draper/view_context_spec.rb +4 -4
- data/spec/generators/draper/decorator/decorator_generator_spec.rb +81 -1
- data/spec/generators/draper/install/install_generator_spec.rb +5 -5
- data/spec/spec_helper.rb +3 -0
- data/spec/support/samples/application_controller.rb +8 -11
- data/spec/support/samples/decorator_with_allows.rb +1 -1
- data/spec/support/samples/decorator_with_application_helper.rb +5 -5
- data/spec/support/samples/decorator_with_denies.rb +1 -1
- data/spec/support/samples/decorator_with_multiple_allows.rb +4 -0
- data/spec/support/samples/product.rb +28 -7
- data/spec/support/samples/some_thing.rb +2 -0
- data/spec/support/samples/some_thing_decorator.rb +3 -0
- metadata +62 -37
- data/lib/generators/rspec/decorator_generator.rb +0 -11
- data/lib/generators/test_unit/decorator_generator.rb +0 -11
- data/spec/generators/rspec/decorator_generator_spec.rb +0 -22
- data/spec/generators/test_unit/decorator_generator_spec.rb +0 -22
@@ -19,24 +19,24 @@ describe Draper::InstallGenerator do
|
|
19
19
|
it { should contain "class ApplicationDecorator < Draper::Base" }
|
20
20
|
end
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
describe 'spec/decorators/application_decorator_spec.rb' do
|
24
24
|
subject { file('spec/decorators/application_decorator_spec.rb') }
|
25
25
|
it { should exist }
|
26
26
|
it { should contain "describe ApplicationDecorator do" }
|
27
27
|
end
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
context "using test_unit" do
|
31
31
|
before { run_generator ["", "-t=test_unit"] }
|
32
|
-
|
32
|
+
|
33
33
|
it_should_behave_like "ApplicationDecoratorGenerator"
|
34
|
-
|
34
|
+
|
35
35
|
describe 'spec/decorators/application_decorator_spec.rb' do
|
36
36
|
subject { file('spec/decorators/application_decorator_spec.rb') }
|
37
37
|
it { should_not exist }
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
describe 'spec/decorators/application_decorator_test.rb' do
|
41
41
|
subject { file('test/decorators/application_decorator_test.rb') }
|
42
42
|
it { should exist }
|
data/spec/spec_helper.rb
CHANGED
@@ -7,6 +7,7 @@ require './spec/support/samples/application_controller.rb'
|
|
7
7
|
require './spec/support/samples/application_helper.rb'
|
8
8
|
require './spec/support/samples/decorator.rb'
|
9
9
|
require './spec/support/samples/decorator_with_allows.rb'
|
10
|
+
require './spec/support/samples/decorator_with_multiple_allows.rb'
|
10
11
|
require './spec/support/samples/decorator_with_application_helper.rb'
|
11
12
|
require './spec/support/samples/decorator_with_denies.rb'
|
12
13
|
require './spec/support/samples/namespaced_product.rb'
|
@@ -14,5 +15,7 @@ require './spec/support/samples/namespaced_product_decorator.rb'
|
|
14
15
|
require './spec/support/samples/product.rb'
|
15
16
|
require './spec/support/samples/product_decorator.rb'
|
16
17
|
require './spec/support/samples/specific_product_decorator.rb'
|
18
|
+
require './spec/support/samples/some_thing.rb'
|
19
|
+
require './spec/support/samples/some_thing_decorator.rb'
|
17
20
|
require './spec/support/samples/widget.rb'
|
18
21
|
require './spec/support/samples/widget_decorator.rb'
|
@@ -9,38 +9,35 @@ module ActionController
|
|
9
9
|
def self.before_filter(name)
|
10
10
|
@@before_filters << name
|
11
11
|
end
|
12
|
-
def self.helper(mod)
|
13
|
-
extend mod
|
14
|
-
end
|
15
12
|
end
|
16
13
|
end
|
17
14
|
|
15
|
+
Draper::System.setup(:action_controller)
|
16
|
+
|
18
17
|
class ApplicationController < ActionController::Base
|
19
18
|
extend ActionView::Helpers
|
20
19
|
extend ActionView::Helpers::TagHelper
|
21
20
|
extend ActionView::Helpers::UrlHelper
|
22
|
-
extend ApplicationHelper
|
23
|
-
|
21
|
+
extend ApplicationHelper
|
22
|
+
|
24
23
|
def view_context
|
25
24
|
@view_context ||= ApplicationController
|
26
25
|
end
|
27
|
-
|
26
|
+
|
28
27
|
def view_context=(input)
|
29
28
|
@view_context = input
|
30
29
|
end
|
31
|
-
|
30
|
+
|
32
31
|
def self.hello
|
33
32
|
"Hello!"
|
34
33
|
end
|
35
|
-
|
34
|
+
|
36
35
|
def self.capture(&block)
|
37
36
|
@@capture = true
|
38
37
|
block.call
|
39
38
|
end
|
40
|
-
|
39
|
+
|
41
40
|
def self.capture_triggered
|
42
41
|
@@capture ||= false
|
43
42
|
end
|
44
43
|
end
|
45
|
-
|
46
|
-
Draper::System.setup
|
@@ -1,20 +1,20 @@
|
|
1
|
-
class DecoratorWithApplicationHelper < Draper::Base
|
1
|
+
class DecoratorWithApplicationHelper < Draper::Base
|
2
2
|
def uses_hello_world
|
3
3
|
h.hello_world
|
4
4
|
end
|
5
|
-
|
5
|
+
|
6
6
|
def sample_content
|
7
7
|
h.content_tag :span, "Hello, World!"
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
def sample_link
|
11
11
|
h.link_to "Hello", "/World"
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def sample_truncate
|
15
15
|
h.truncate("Once upon a time", :length => 7)
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def length
|
19
19
|
"overridden"
|
20
20
|
end
|
@@ -1,6 +1,10 @@
|
|
1
1
|
class Product < ActiveRecord::Base
|
2
2
|
include Draper::ModelSupport
|
3
3
|
|
4
|
+
def self.find_by_name(name)
|
5
|
+
@@dummy ||= Product.new
|
6
|
+
end
|
7
|
+
|
4
8
|
def self.first
|
5
9
|
@@first ||= Product.new
|
6
10
|
end
|
@@ -8,7 +12,7 @@ class Product < ActiveRecord::Base
|
|
8
12
|
def self.last
|
9
13
|
@@last ||= Product.new
|
10
14
|
end
|
11
|
-
|
15
|
+
|
12
16
|
def self.all
|
13
17
|
[Product.new, Product.new]
|
14
18
|
end
|
@@ -24,29 +28,33 @@ class Product < ActiveRecord::Base
|
|
24
28
|
def self.find(id)
|
25
29
|
return Product.new
|
26
30
|
end
|
27
|
-
|
31
|
+
|
28
32
|
def self.sample_class_method
|
29
33
|
"sample class method"
|
30
34
|
end
|
31
|
-
|
35
|
+
|
32
36
|
def hello_world
|
33
37
|
"Hello, World"
|
34
38
|
end
|
35
|
-
|
39
|
+
|
36
40
|
def goodnight_moon
|
37
41
|
"Goodnight, Moon"
|
38
42
|
end
|
39
|
-
|
43
|
+
|
40
44
|
def title
|
41
45
|
"Sample Title"
|
42
46
|
end
|
43
|
-
|
47
|
+
|
48
|
+
def some_action
|
49
|
+
self.nonexistant_method
|
50
|
+
end
|
51
|
+
|
44
52
|
def block
|
45
53
|
yield
|
46
54
|
end
|
47
55
|
|
48
56
|
def self.reflect_on_association(association_symbol)
|
49
|
-
OpenStruct.new(:klass => self)
|
57
|
+
association_symbol.to_s.starts_with?("poro") ? nil : OpenStruct.new(:klass => self)
|
50
58
|
end
|
51
59
|
|
52
60
|
def similar_products
|
@@ -56,4 +64,17 @@ class Product < ActiveRecord::Base
|
|
56
64
|
def previous_version
|
57
65
|
Product.new
|
58
66
|
end
|
67
|
+
|
68
|
+
def thing
|
69
|
+
SomeThing.new
|
70
|
+
end
|
71
|
+
|
72
|
+
def poro_similar_products
|
73
|
+
[Product.new, Product.new]
|
74
|
+
end
|
75
|
+
|
76
|
+
def poro_previous_version
|
77
|
+
Product.new
|
78
|
+
end
|
79
|
+
|
59
80
|
end
|
metadata
CHANGED
@@ -1,34 +1,50 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: draper
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 51
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 11
|
9
|
+
- 0
|
10
|
+
version: 0.11.0
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Jeff Casimir
|
14
|
+
- Steve Klabnik
|
9
15
|
autorequire:
|
10
16
|
bindir: bin
|
11
17
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
18
|
+
|
19
|
+
date: 2012-03-14 00:00:00 Z
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
15
22
|
name: activesupport
|
16
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
17
25
|
none: false
|
18
|
-
requirements:
|
19
|
-
- -
|
20
|
-
- !ruby/object:Gem::Version
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 23
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 3
|
33
|
+
- 10
|
21
34
|
version: 2.3.10
|
22
35
|
type: :runtime
|
23
|
-
|
24
|
-
version_requirements: *70130732077940
|
36
|
+
version_requirements: *id001
|
25
37
|
description: Draper implements a decorator or presenter pattern for Rails applications.
|
26
|
-
email:
|
38
|
+
email:
|
27
39
|
- jeff@casimircreative.com
|
40
|
+
- steve@steveklabnik.com
|
28
41
|
executables: []
|
42
|
+
|
29
43
|
extensions: []
|
44
|
+
|
30
45
|
extra_rdoc_files: []
|
31
|
-
|
46
|
+
|
47
|
+
files:
|
32
48
|
- .gitignore
|
33
49
|
- .rspec
|
34
50
|
- .travis.yml
|
@@ -65,6 +81,7 @@ files:
|
|
65
81
|
- lib/draper/helper_support.rb
|
66
82
|
- lib/draper/lazy_helpers.rb
|
67
83
|
- lib/draper/model_support.rb
|
84
|
+
- lib/draper/railtie.rb
|
68
85
|
- lib/draper/rspec_integration.rb
|
69
86
|
- lib/draper/system.rb
|
70
87
|
- lib/draper/version.rb
|
@@ -72,15 +89,13 @@ files:
|
|
72
89
|
- lib/generators/draper/decorator/USAGE
|
73
90
|
- lib/generators/draper/decorator/decorator_generator.rb
|
74
91
|
- lib/generators/draper/decorator/templates/decorator.rb
|
92
|
+
- lib/generators/draper/decorator/templates/decorator_spec.rb
|
93
|
+
- lib/generators/draper/decorator/templates/decorator_test.rb
|
75
94
|
- lib/generators/draper/install/install_generator.rb
|
76
95
|
- lib/generators/draper/install/templates/application_decorator.rb
|
77
96
|
- lib/generators/draper/install/templates/application_decorator_spec.rb
|
78
97
|
- lib/generators/draper/install/templates/application_decorator_test.rb
|
79
98
|
- lib/generators/rails/decorator_generator.rb
|
80
|
-
- lib/generators/rspec/decorator_generator.rb
|
81
|
-
- lib/generators/rspec/templates/decorator_spec.rb
|
82
|
-
- lib/generators/test_unit/decorator_generator.rb
|
83
|
-
- lib/generators/test_unit/templates/decorator_test.rb
|
84
99
|
- performance/active_record.rb
|
85
100
|
- performance/bechmark.rb
|
86
101
|
- performance/decorators.rb
|
@@ -91,8 +106,6 @@ files:
|
|
91
106
|
- spec/draper/view_context_spec.rb
|
92
107
|
- spec/generators/draper/decorator/decorator_generator_spec.rb
|
93
108
|
- spec/generators/draper/install/install_generator_spec.rb
|
94
|
-
- spec/generators/rspec/decorator_generator_spec.rb
|
95
|
-
- spec/generators/test_unit/decorator_generator_spec.rb
|
96
109
|
- spec/spec_helper.rb
|
97
110
|
- spec/support/samples/active_record.rb
|
98
111
|
- spec/support/samples/application_controller.rb
|
@@ -101,46 +114,56 @@ files:
|
|
101
114
|
- spec/support/samples/decorator_with_allows.rb
|
102
115
|
- spec/support/samples/decorator_with_application_helper.rb
|
103
116
|
- spec/support/samples/decorator_with_denies.rb
|
117
|
+
- spec/support/samples/decorator_with_multiple_allows.rb
|
104
118
|
- spec/support/samples/namespaced_product.rb
|
105
119
|
- spec/support/samples/namespaced_product_decorator.rb
|
106
120
|
- spec/support/samples/product.rb
|
107
121
|
- spec/support/samples/product_decorator.rb
|
122
|
+
- spec/support/samples/some_thing.rb
|
123
|
+
- spec/support/samples/some_thing_decorator.rb
|
108
124
|
- spec/support/samples/specific_product_decorator.rb
|
109
125
|
- spec/support/samples/widget.rb
|
110
126
|
- spec/support/samples/widget_decorator.rb
|
111
127
|
homepage: http://github.com/jcasimir/draper
|
112
128
|
licenses: []
|
129
|
+
|
113
130
|
post_install_message:
|
114
131
|
rdoc_options: []
|
115
|
-
|
132
|
+
|
133
|
+
require_paths:
|
116
134
|
- lib
|
117
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
135
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
136
|
none: false
|
119
|
-
requirements:
|
120
|
-
- -
|
121
|
-
- !ruby/object:Gem::Version
|
122
|
-
|
123
|
-
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
hash: 3
|
141
|
+
segments:
|
142
|
+
- 0
|
143
|
+
version: "0"
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
145
|
none: false
|
125
|
-
requirements:
|
126
|
-
- -
|
127
|
-
- !ruby/object:Gem::Version
|
128
|
-
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
hash: 3
|
150
|
+
segments:
|
151
|
+
- 0
|
152
|
+
version: "0"
|
129
153
|
requirements: []
|
154
|
+
|
130
155
|
rubyforge_project: draper
|
131
|
-
rubygems_version: 1.8.
|
156
|
+
rubygems_version: 1.8.15
|
132
157
|
signing_key:
|
133
158
|
specification_version: 3
|
134
159
|
summary: Decorator pattern implementation for Rails.
|
135
|
-
test_files:
|
160
|
+
test_files:
|
136
161
|
- spec/draper/base_spec.rb
|
137
162
|
- spec/draper/helper_support_spec.rb
|
138
163
|
- spec/draper/model_support_spec.rb
|
139
164
|
- spec/draper/view_context_spec.rb
|
140
165
|
- spec/generators/draper/decorator/decorator_generator_spec.rb
|
141
166
|
- spec/generators/draper/install/install_generator_spec.rb
|
142
|
-
- spec/generators/rspec/decorator_generator_spec.rb
|
143
|
-
- spec/generators/test_unit/decorator_generator_spec.rb
|
144
167
|
- spec/spec_helper.rb
|
145
168
|
- spec/support/samples/active_record.rb
|
146
169
|
- spec/support/samples/application_controller.rb
|
@@ -149,11 +172,13 @@ test_files:
|
|
149
172
|
- spec/support/samples/decorator_with_allows.rb
|
150
173
|
- spec/support/samples/decorator_with_application_helper.rb
|
151
174
|
- spec/support/samples/decorator_with_denies.rb
|
175
|
+
- spec/support/samples/decorator_with_multiple_allows.rb
|
152
176
|
- spec/support/samples/namespaced_product.rb
|
153
177
|
- spec/support/samples/namespaced_product_decorator.rb
|
154
178
|
- spec/support/samples/product.rb
|
155
179
|
- spec/support/samples/product_decorator.rb
|
180
|
+
- spec/support/samples/some_thing.rb
|
181
|
+
- spec/support/samples/some_thing_decorator.rb
|
156
182
|
- spec/support/samples/specific_product_decorator.rb
|
157
183
|
- spec/support/samples/widget.rb
|
158
184
|
- spec/support/samples/widget_decorator.rb
|
159
|
-
has_rdoc:
|
@@ -1,11 +0,0 @@
|
|
1
|
-
module Rspec
|
2
|
-
class DecoratorGenerator < ::Rails::Generators::NamedBase
|
3
|
-
source_root File.expand_path('../templates', __FILE__)
|
4
|
-
|
5
|
-
SPEC_ROOT = 'spec/decorators/'
|
6
|
-
|
7
|
-
def build_model_and_application_decorator_specs
|
8
|
-
template 'decorator_spec.rb', "#{SPEC_ROOT}#{singular_name}_decorator_spec.rb"
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
module TestUnit
|
2
|
-
class DecoratorGenerator < ::Rails::Generators::NamedBase
|
3
|
-
source_root File.expand_path('../templates', __FILE__)
|
4
|
-
|
5
|
-
TEST_ROOT = 'test/decorators/'
|
6
|
-
|
7
|
-
def build_model_decorator_tests
|
8
|
-
template 'decorator_test.rb', "#{TEST_ROOT}#{singular_name}_decorator_test.rb"
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
# Generators are not automatically loaded by Rails
|
4
|
-
require 'generators/rspec/decorator_generator'
|
5
|
-
|
6
|
-
describe Rspec::DecoratorGenerator do
|
7
|
-
# Tell the generator where to put its output (what it thinks of as Rails.root)
|
8
|
-
destination File.expand_path("../../../../tmp", __FILE__)
|
9
|
-
|
10
|
-
before { prepare_destination }
|
11
|
-
|
12
|
-
describe 'no arguments' do
|
13
|
-
before { run_generator %w(products) }
|
14
|
-
|
15
|
-
describe 'spec/decorators/products_decorator_spec.rb' do
|
16
|
-
subject { file('spec/decorators/products_decorator_spec.rb') }
|
17
|
-
it { should exist }
|
18
|
-
it { should contain "describe ProductsDecorator" }
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
end
|