draper 0.11.1 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.txt +23 -0
- data/Gemfile +4 -0
- data/Readme.markdown +32 -8
- data/draper.gemspec +1 -0
- data/lib/draper.rb +1 -0
- data/lib/draper/active_model_support.rb +24 -0
- data/lib/draper/base.rb +30 -22
- data/lib/draper/decorated_enumerable_proxy.rb +12 -9
- data/lib/draper/helper_support.rb +1 -1
- data/lib/draper/lazy_helpers.rb +1 -1
- data/lib/draper/model_support.rb +2 -4
- data/lib/draper/railtie.rb +31 -0
- data/lib/draper/rspec_integration.rb +22 -11
- data/lib/draper/system.rb +9 -0
- data/lib/draper/version.rb +1 -1
- data/lib/generators/decorator/decorator_generator.rb +28 -0
- data/lib/generators/{draper/decorator → decorator}/templates/decorator.rb +5 -3
- data/lib/generators/resource_override.rb +12 -0
- data/lib/generators/rspec/decorator_generator.rb +9 -0
- data/lib/generators/rspec/templates/decorator_spec.rb +4 -0
- data/lib/generators/test_unit/decorator_generator.rb +9 -0
- data/lib/generators/test_unit/templates/decorator_test.rb +7 -0
- data/performance/active_record.rb +1 -1
- data/performance/models.rb +1 -1
- data/spec/draper/base_spec.rb +74 -15
- data/spec/draper/helper_support_spec.rb +4 -4
- data/spec/draper/model_support_spec.rb +1 -1
- data/spec/draper/view_context_spec.rb +2 -7
- data/spec/generators/decorator/decorator_generator_spec.rb +52 -0
- data/spec/spec_helper.rb +21 -17
- data/spec/support/samples/active_model.rb +9 -0
- data/spec/support/samples/active_record.rb +8 -0
- data/spec/support/samples/application_helper.rb +1 -1
- data/spec/support/samples/decorator.rb +1 -1
- data/spec/support/samples/decorator_with_allows.rb +1 -1
- data/spec/support/samples/non_active_model_product.rb +2 -0
- data/spec/support/samples/specific_product_decorator.rb +1 -1
- metadata +30 -18
- data/lib/generators/draper/decorator/USAGE +0 -7
- data/lib/generators/draper/decorator/decorator_generator.rb +0 -43
- data/lib/generators/draper/decorator/templates/decorator_spec.rb +0 -5
- data/lib/generators/draper/decorator/templates/decorator_test.rb +0 -12
- data/lib/generators/draper/install/install_generator.rb +0 -39
- data/lib/generators/draper/install/templates/application_decorator.rb +0 -28
- data/lib/generators/draper/install/templates/application_decorator_spec.rb +0 -4
- data/lib/generators/draper/install/templates/application_decorator_test.rb +0 -11
- data/lib/generators/rails/decorator_generator.rb +0 -15
- data/spec/generators/draper/decorator/decorator_generator_spec.rb +0 -102
- data/spec/generators/draper/install/install_generator_spec.rb +0 -46
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: draper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-05-09 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
17
|
-
requirement: &
|
17
|
+
requirement: &70309298925200 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,7 +22,18 @@ dependencies:
|
|
22
22
|
version: 2.3.10
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70309298925200
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: redcarpet
|
28
|
+
requirement: &70309298924340 !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: *70309298924340
|
26
37
|
description: Draper implements a decorator or presenter pattern for Rails applications.
|
27
38
|
email:
|
28
39
|
- jeff@casimircreative.com
|
@@ -35,6 +46,7 @@ files:
|
|
35
46
|
- .rspec
|
36
47
|
- .travis.yml
|
37
48
|
- .yardopts
|
49
|
+
- CHANGELOG.txt
|
38
50
|
- Gemfile
|
39
51
|
- Guardfile
|
40
52
|
- Rakefile
|
@@ -62,6 +74,7 @@ files:
|
|
62
74
|
- doc/top-level-namespace.html
|
63
75
|
- draper.gemspec
|
64
76
|
- lib/draper.rb
|
77
|
+
- lib/draper/active_model_support.rb
|
65
78
|
- lib/draper/base.rb
|
66
79
|
- lib/draper/decorated_enumerable_proxy.rb
|
67
80
|
- lib/draper/helper_support.rb
|
@@ -72,16 +85,13 @@ files:
|
|
72
85
|
- lib/draper/system.rb
|
73
86
|
- lib/draper/version.rb
|
74
87
|
- lib/draper/view_context.rb
|
75
|
-
- lib/generators/
|
76
|
-
- lib/generators/
|
77
|
-
- lib/generators/
|
78
|
-
- lib/generators/
|
79
|
-
- lib/generators/
|
80
|
-
- lib/generators/
|
81
|
-
- lib/generators/
|
82
|
-
- lib/generators/draper/install/templates/application_decorator_spec.rb
|
83
|
-
- lib/generators/draper/install/templates/application_decorator_test.rb
|
84
|
-
- lib/generators/rails/decorator_generator.rb
|
88
|
+
- lib/generators/decorator/decorator_generator.rb
|
89
|
+
- lib/generators/decorator/templates/decorator.rb
|
90
|
+
- lib/generators/resource_override.rb
|
91
|
+
- lib/generators/rspec/decorator_generator.rb
|
92
|
+
- lib/generators/rspec/templates/decorator_spec.rb
|
93
|
+
- lib/generators/test_unit/decorator_generator.rb
|
94
|
+
- lib/generators/test_unit/templates/decorator_test.rb
|
85
95
|
- performance/active_record.rb
|
86
96
|
- performance/bechmark.rb
|
87
97
|
- performance/decorators.rb
|
@@ -90,9 +100,9 @@ files:
|
|
90
100
|
- spec/draper/helper_support_spec.rb
|
91
101
|
- spec/draper/model_support_spec.rb
|
92
102
|
- spec/draper/view_context_spec.rb
|
93
|
-
- spec/generators/
|
94
|
-
- spec/generators/draper/install/install_generator_spec.rb
|
103
|
+
- spec/generators/decorator/decorator_generator_spec.rb
|
95
104
|
- spec/spec_helper.rb
|
105
|
+
- spec/support/samples/active_model.rb
|
96
106
|
- spec/support/samples/active_record.rb
|
97
107
|
- spec/support/samples/application_controller.rb
|
98
108
|
- spec/support/samples/application_helper.rb
|
@@ -103,6 +113,7 @@ files:
|
|
103
113
|
- spec/support/samples/decorator_with_multiple_allows.rb
|
104
114
|
- spec/support/samples/namespaced_product.rb
|
105
115
|
- spec/support/samples/namespaced_product_decorator.rb
|
116
|
+
- spec/support/samples/non_active_model_product.rb
|
106
117
|
- spec/support/samples/product.rb
|
107
118
|
- spec/support/samples/product_decorator.rb
|
108
119
|
- spec/support/samples/some_thing.rb
|
@@ -139,9 +150,9 @@ test_files:
|
|
139
150
|
- spec/draper/helper_support_spec.rb
|
140
151
|
- spec/draper/model_support_spec.rb
|
141
152
|
- spec/draper/view_context_spec.rb
|
142
|
-
- spec/generators/
|
143
|
-
- spec/generators/draper/install/install_generator_spec.rb
|
153
|
+
- spec/generators/decorator/decorator_generator_spec.rb
|
144
154
|
- spec/spec_helper.rb
|
155
|
+
- spec/support/samples/active_model.rb
|
145
156
|
- spec/support/samples/active_record.rb
|
146
157
|
- spec/support/samples/application_controller.rb
|
147
158
|
- spec/support/samples/application_helper.rb
|
@@ -152,6 +163,7 @@ test_files:
|
|
152
163
|
- spec/support/samples/decorator_with_multiple_allows.rb
|
153
164
|
- spec/support/samples/namespaced_product.rb
|
154
165
|
- spec/support/samples/namespaced_product_decorator.rb
|
166
|
+
- spec/support/samples/non_active_model_product.rb
|
155
167
|
- spec/support/samples/product.rb
|
156
168
|
- spec/support/samples/product_decorator.rb
|
157
169
|
- spec/support/samples/some_thing.rb
|
@@ -1,43 +0,0 @@
|
|
1
|
-
module Draper
|
2
|
-
class DecoratorGenerator < Rails::Generators::Base
|
3
|
-
desc <<-DESC
|
4
|
-
Description:
|
5
|
-
Generate a decorator for the given model.
|
6
|
-
Example: rails g draper:decorator Article
|
7
|
-
generates: "app/decorators/article_decorator"
|
8
|
-
"spec/decorators/article_decorator_spec"
|
9
|
-
DESC
|
10
|
-
|
11
|
-
argument :resource_name, :type => :string
|
12
|
-
class_option "test-framework", :type => :string, :default => "rspec", :aliases => "-t", :desc => "Test framework to be invoked"
|
13
|
-
|
14
|
-
source_root File.expand_path('../templates', __FILE__)
|
15
|
-
|
16
|
-
DECORATORS_ROOT = 'app/decorators/'
|
17
|
-
|
18
|
-
def build_model_decorator
|
19
|
-
template 'decorator.rb', "#{DECORATORS_ROOT}#{resource_name.singularize}_decorator.rb"
|
20
|
-
end
|
21
|
-
|
22
|
-
def build_decorator_tests
|
23
|
-
case options["test-framework"]
|
24
|
-
when "rspec"
|
25
|
-
build_decorator_spec
|
26
|
-
when "test_unit"
|
27
|
-
build_decorator_test
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
def build_decorator_spec
|
33
|
-
empty_directory 'spec/decorators'
|
34
|
-
template 'decorator_spec.rb', File.join('spec/decorators', "#{resource_name.singularize}_decorator_spec.rb")
|
35
|
-
end
|
36
|
-
|
37
|
-
def build_decorator_test
|
38
|
-
empty_directory 'test/decorators/'
|
39
|
-
template 'decorator_test.rb', File.join('test/decorators', "#{resource_name.singularize}_decorator_test.rb")
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
module Draper
|
2
|
-
class InstallGenerator < Rails::Generators::Base
|
3
|
-
|
4
|
-
desc <<-DESC
|
5
|
-
Description:
|
6
|
-
Generate application and spec decorators in your application.
|
7
|
-
DESC
|
8
|
-
|
9
|
-
class_option "test-framework", :type => :string, :default => "rspec", :aliases => "-t", :desc => "Test framework to be invoked"
|
10
|
-
|
11
|
-
source_root File.expand_path('../templates', __FILE__)
|
12
|
-
|
13
|
-
def build_application_decorator
|
14
|
-
empty_directory 'app/decorators'
|
15
|
-
template 'application_decorator.rb', File.join('app/decorators', 'application_decorator.rb')
|
16
|
-
end
|
17
|
-
|
18
|
-
def build_decorator_tests
|
19
|
-
case options["test-framework"]
|
20
|
-
when "rspec"
|
21
|
-
build_application_decorator_spec
|
22
|
-
when "test_unit"
|
23
|
-
build_application_decorator_test
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
def build_application_decorator_spec
|
29
|
-
empty_directory 'spec/decorators'
|
30
|
-
template 'application_decorator_spec.rb', File.join('spec/decorators', 'application_decorator_spec.rb')
|
31
|
-
end
|
32
|
-
|
33
|
-
def build_application_decorator_test
|
34
|
-
empty_directory 'test/decorators/'
|
35
|
-
template 'application_decorator_test.rb', File.join('test/decorators', 'application_decorator_test.rb')
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
class ApplicationDecorator < Draper::Base
|
2
|
-
# Lazy Helpers
|
3
|
-
# PRO: Call Rails helpers without the h. proxy
|
4
|
-
# ex: number_to_currency(model.price)
|
5
|
-
# CON: Add a bazillion methods into your decorator's namespace
|
6
|
-
# and probably sacrifice performance/memory
|
7
|
-
#
|
8
|
-
# Enable them by uncommenting this line:
|
9
|
-
# lazy_helpers
|
10
|
-
|
11
|
-
# Shared Decorations
|
12
|
-
# Consider defining shared methods common to all your models.
|
13
|
-
#
|
14
|
-
# Example: standardize the formatting of timestamps
|
15
|
-
#
|
16
|
-
# def formatted_timestamp(time)
|
17
|
-
# h.content_tag :span, time.strftime("%a %m/%d/%y"),
|
18
|
-
# :class => 'timestamp'
|
19
|
-
# end
|
20
|
-
#
|
21
|
-
# def created_at
|
22
|
-
# formatted_timestamp(model.created_at)
|
23
|
-
# end
|
24
|
-
#
|
25
|
-
# def updated_at
|
26
|
-
# formatted_timestamp(model.updated_at)
|
27
|
-
# end
|
28
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require File.expand_path('../../draper/decorator/decorator_generator.rb', __FILE__)
|
2
|
-
class Rails::DecoratorGenerator < Draper::DecoratorGenerator
|
3
|
-
|
4
|
-
source_root File.expand_path('../../draper/decorator/templates', __FILE__)
|
5
|
-
|
6
|
-
class_option :invoke_after_finished, :type => :string, :description => "Generator to invoke when finished"
|
7
|
-
|
8
|
-
def build_model_and_application_decorators
|
9
|
-
super
|
10
|
-
if self.options[:invoke_after_finished]
|
11
|
-
Rails::Generators.invoke(self.options[:invoke_after_finished], [@name, @_initializer.first[1..-1]])
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
@@ -1,102 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
# Generators are not automatically loaded by Rails
|
4
|
-
require 'generators/draper/decorator/decorator_generator'
|
5
|
-
|
6
|
-
describe Draper::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
|
-
context 'decorator context' do
|
13
|
-
before { run_generator ["product"] }
|
14
|
-
|
15
|
-
describe 'app/decorators/product_decorator.rb' do
|
16
|
-
subject { file('app/decorators/product_decorator.rb') }
|
17
|
-
it { should exist }
|
18
|
-
it { should contain "class ProductDecorator < ApplicationDecorator" }
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'default test framework' do
|
23
|
-
before { run_generator ["product"] }
|
24
|
-
|
25
|
-
describe 'spec/decorators/product_decorator_spec.rb' do
|
26
|
-
subject { file('spec/decorators/product_decorator_spec.rb') }
|
27
|
-
it { should exist }
|
28
|
-
it { should contain "describe ProductDecorator" }
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'using rspec' do
|
33
|
-
before { run_generator ["product", "-t=rspec"] }
|
34
|
-
|
35
|
-
describe 'spec/decorators/product_decorator_spec.rb' do
|
36
|
-
subject { file('spec/decorators/product_decorator_spec.rb') }
|
37
|
-
it { should exist }
|
38
|
-
it { should contain "describe ProductDecorator" }
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context 'using rspec' do
|
43
|
-
before { run_generator ["product", "-t=test_unit"] }
|
44
|
-
|
45
|
-
describe 'test/decorators/product_decorator_test.rb' do
|
46
|
-
subject { file('test/decorators/product_decorator_test.rb') }
|
47
|
-
it { should exist }
|
48
|
-
it { should contain "class ProductDecoratorTest < ActiveSupport::TestCase" }
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
|
54
|
-
=begin
|
55
|
-
describe 'no arguments' do
|
56
|
-
before { run_generator %w(products) }
|
57
|
-
|
58
|
-
describe 'app/decorators/products_decorator.rb' do
|
59
|
-
subject { file('app/decorators/products_decorator.rb') }
|
60
|
-
it { should exist }
|
61
|
-
it { should contain "class ProductsDecorator < ApplicationDecorator" }
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
|
66
|
-
context 'simple' do
|
67
|
-
before { run_generator %w(products) }
|
68
|
-
|
69
|
-
describe 'app/decorators/products_decorator.rb' do
|
70
|
-
subject { file('app/decorators/products_decorator.rb') }
|
71
|
-
it { should exist }
|
72
|
-
it { should contain "class ProductsDecorator < ApplicationDecorator" }
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
context 'using rspec' do
|
81
|
-
|
82
|
-
describe 'app/decorators/products_decorator.rb' do
|
83
|
-
subject { file('app/decorators/products_decorator.rb') }
|
84
|
-
it { should exist }
|
85
|
-
it { should contain "class ProductsDecorator < ApplicationDecorator" }
|
86
|
-
end
|
87
|
-
|
88
|
-
shared_examples_for "ApplicationDecoratorGenerator" do
|
89
|
-
describe 'app/decorators/application_decorator.rb' do
|
90
|
-
subject { file('app/decorators/application_decorator.rb') }
|
91
|
-
it { should exist }
|
92
|
-
it { should contain "class ApplicationDecorator < Draper::Base" }
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
describe 'spec/decorators/application_decorator_spec.rb' do
|
97
|
-
subject { file('spec/decorators/application_decorator_spec.rb') }
|
98
|
-
it { should exist }
|
99
|
-
it { should contain "describe ApplicationDecorator do" }
|
100
|
-
end
|
101
|
-
end
|
102
|
-
=end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
# Generators are not automatically loaded by Rails
|
4
|
-
require 'generators/draper/install/install_generator'
|
5
|
-
|
6
|
-
describe Draper::InstallGenerator 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
|
-
context 'using rspec' do
|
13
|
-
before { run_generator }
|
14
|
-
|
15
|
-
shared_examples_for "ApplicationDecoratorGenerator" do
|
16
|
-
describe 'app/decorators/application_decorator.rb' do
|
17
|
-
subject { file('app/decorators/application_decorator.rb') }
|
18
|
-
it { should exist }
|
19
|
-
it { should contain "class ApplicationDecorator < Draper::Base" }
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe 'spec/decorators/application_decorator_spec.rb' do
|
24
|
-
subject { file('spec/decorators/application_decorator_spec.rb') }
|
25
|
-
it { should exist }
|
26
|
-
it { should contain "describe ApplicationDecorator do" }
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
context "using test_unit" do
|
31
|
-
before { run_generator ["", "-t=test_unit"] }
|
32
|
-
|
33
|
-
it_should_behave_like "ApplicationDecoratorGenerator"
|
34
|
-
|
35
|
-
describe 'spec/decorators/application_decorator_spec.rb' do
|
36
|
-
subject { file('spec/decorators/application_decorator_spec.rb') }
|
37
|
-
it { should_not exist }
|
38
|
-
end
|
39
|
-
|
40
|
-
describe 'spec/decorators/application_decorator_test.rb' do
|
41
|
-
subject { file('test/decorators/application_decorator_test.rb') }
|
42
|
-
it { should exist }
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|