r_decorator 0.0.6 → 0.0.7

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.
@@ -58,14 +58,12 @@ module RDecorator
58
58
  end
59
59
 
60
60
  def self.decorate_class!(klass)
61
- unless klass.method_defined?(:decorated)
62
- klass.class_eval <<-STR
63
- def decorated(options={})
64
- @_decorator ||= #{self.name}.new(self, options)
65
- end
66
- alias_method :deco, :decorated
67
- STR
68
- end
61
+ klass.class_eval <<-STR
62
+ def decorated(options={})
63
+ @_decorator ||= #{self.name}.new(self, options)
64
+ end
65
+ alias_method :deco, :decorated
66
+ STR
69
67
  end
70
68
 
71
69
  def self.target_to_class(target, ignore_missing = false)
@@ -1,3 +1,3 @@
1
1
  module RDecorator
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -31,6 +31,18 @@ feature "Definition" do
31
31
 
32
32
  class NoClassDecorator < RDecorator::Base
33
33
  end
34
+
35
+ class Parent
36
+ end
37
+
38
+ class Child < Parent
39
+ end
40
+
41
+ class ParentDecorator < RDecorator::Base
42
+ end
43
+
44
+ class ChildDecorator < ParentDecorator
45
+ end
34
46
 
35
47
  scenario "Auto decoration by class-name" do
36
48
  foo = Foo.new
@@ -41,5 +53,12 @@ feature "Definition" do
41
53
  this = This.new
42
54
  this.decorated.say.should eq "Yeah!Yeah!Yeah!"
43
55
  end
56
+
57
+ scenario "inheritance" do
58
+ parent = Parent.new
59
+ child = Child.new
60
+ parent.decorated.should be_instance_of(ParentDecorator)
61
+ child.decorated.should be_instance_of(ChildDecorator)
62
+ end
44
63
 
45
64
  end
@@ -1,23 +1,17 @@
1
- <h1>Listing authors</h1>
2
-
3
- <table>
4
- <tr>
5
- <th>Name</th>
6
- <th></th>
7
- <th></th>
8
- <th></th>
9
- </tr>
10
-
11
1
  <% @authors.each do |author| %>
12
- <tr>
13
- <td><%= author.name %></td>
14
- <td><%= link_to 'Show', author %></td>
15
- <td><%= link_to 'Edit', edit_author_path(author) %></td>
16
- <td><%= link_to 'Destroy', author, method: :delete, data: { confirm: 'Are you sure?' } %></td>
17
- </tr>
18
- <% end %>
19
- </table>
2
+ <%= author.deco.name %>
3
+ <%= author.deco.reverse_name %>
4
+ <%= author.deco.name_link %>
20
5
 
21
- <br />
22
-
23
- <%= link_to 'New Author', new_author_path %>
6
+ <% if params[:partial] == 'collection' %>
7
+ <%= render author.books %>
8
+ <% elsif params[:partial] == 'locals' %>
9
+ <% author.books.each do |book| %>
10
+ <%= render :partial => 'books/book_locals', :locals => {:b => book} %>
11
+ <% end %>
12
+ <% else %>
13
+ <% author.books.each do |book| %>
14
+ <%= render book %>
15
+ <% end %>
16
+ <% end %>
17
+ <% end %>
@@ -1,10 +1,2 @@
1
- <p id="notice"><%= notice %></p>
2
-
3
- <p>
4
- <b>Name:</b>
5
- <%= @author.name %>
6
- </p>
7
-
8
-
9
- <%= link_to 'Edit', edit_author_path(@author) %> |
10
- <%= link_to 'Back', authors_path %>
1
+ <%= @author.deco.name %>
2
+ <%= @author.decorated.capitalized_name %>
@@ -2,8 +2,6 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>Dummy</title>
5
- <%= stylesheet_link_tag "application", :media => "all" %>
6
- <%= javascript_include_tag "application" %>
7
5
  <%= csrf_meta_tags %>
8
6
  </head>
9
7
  <body>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: r_decorator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -42,7 +42,6 @@ files:
42
42
  - lib/r_decorator/view_context.rb
43
43
  - r_decortator.gemspec
44
44
  - spec/decorators/definition_spec.rb
45
- - spec/decorators/view_helpers_spec.rb
46
45
  - spec/dummy/.gitignore
47
46
  - spec/dummy/.rspec
48
47
  - spec/dummy/Gemfile
@@ -50,11 +49,7 @@ files:
50
49
  - spec/dummy/Rakefile
51
50
  - spec/dummy/app/assets/images/rails.png
52
51
  - spec/dummy/app/assets/javascripts/application.js
53
- - spec/dummy/app/assets/javascripts/authors.js.coffee
54
- - spec/dummy/app/assets/javascripts/books.js.coffee
55
52
  - spec/dummy/app/assets/stylesheets/application.css
56
- - spec/dummy/app/assets/stylesheets/authors.css.scss
57
- - spec/dummy/app/assets/stylesheets/books.css.scss
58
53
  - spec/dummy/app/assets/stylesheets/scaffolds.css.scss
59
54
  - spec/dummy/app/controllers/application_controller.rb
60
55
  - spec/dummy/app/controllers/authors_controller.rb
@@ -62,16 +57,10 @@ files:
62
57
  - spec/dummy/app/decorators/author_decorator.rb
63
58
  - spec/dummy/app/decorators/book_decorator.rb
64
59
  - spec/dummy/app/helpers/application_helper.rb
65
- - spec/dummy/app/helpers/authors_helper.rb
66
- - spec/dummy/app/helpers/books_helper.rb
67
- - spec/dummy/app/mailers/.gitkeep
68
60
  - spec/dummy/app/models/.gitkeep
69
61
  - spec/dummy/app/models/author.rb
70
62
  - spec/dummy/app/models/book.rb
71
- - spec/dummy/app/views/authors/_form.html.erb
72
- - spec/dummy/app/views/authors/edit.html.erb
73
63
  - spec/dummy/app/views/authors/index.html.erb
74
- - spec/dummy/app/views/authors/new.html.erb
75
64
  - spec/dummy/app/views/authors/show.html.erb
76
65
  - spec/dummy/app/views/books/_book.html.erb
77
66
  - spec/dummy/app/views/books/_book_locals.html.erb
@@ -107,11 +96,10 @@ files:
107
96
  - spec/dummy/public/index.html
108
97
  - spec/dummy/public/robots.txt
109
98
  - spec/dummy/script/rails
110
- - spec/dummy/spec/decorators/author_decorator_spec.rb
111
- - spec/dummy/spec/decorators/book_decorator_spec.rb
112
- - spec/dummy/spec/requests/action_view_helpers_spec.rb
113
- - spec/dummy/spec/requests/controller_ivar_spec.rb
114
- - spec/dummy/spec/requests/partial_spec.rb
99
+ - spec/dummy/spec/decorators/view_helpers_spec.rb
100
+ - spec/dummy/spec/features/action_view_helpers_spec.rb
101
+ - spec/dummy/spec/features/controller_ivar_spec.rb
102
+ - spec/dummy/spec/features/partial_spec.rb
115
103
  - spec/dummy/spec/spec_helper.rb
116
104
  - spec/dummy/vendor/assets/javascripts/.gitkeep
117
105
  - spec/dummy/vendor/assets/stylesheets/.gitkeep
@@ -122,9 +110,6 @@ files:
122
110
  - spec/fake_app/books/_book_locals.html.erb
123
111
  - spec/fake_app/books/show.html.erb
124
112
  - spec/fake_app/fake_app.rb
125
- - spec/features/action_view_helpers_spec.rb
126
- - spec/features/controller_ivar_spec.rb
127
- - spec/features/partial_spec.rb
128
113
  - spec/spec_helper.rb
129
114
  homepage: https://github.com/takuya327/r_decorator
130
115
  licenses: []
@@ -152,7 +137,6 @@ specification_version: 3
152
137
  summary: A readable and simple view helper for Rails 3
153
138
  test_files:
154
139
  - spec/decorators/definition_spec.rb
155
- - spec/decorators/view_helpers_spec.rb
156
140
  - spec/dummy/.gitignore
157
141
  - spec/dummy/.rspec
158
142
  - spec/dummy/Gemfile
@@ -160,11 +144,7 @@ test_files:
160
144
  - spec/dummy/Rakefile
161
145
  - spec/dummy/app/assets/images/rails.png
162
146
  - spec/dummy/app/assets/javascripts/application.js
163
- - spec/dummy/app/assets/javascripts/authors.js.coffee
164
- - spec/dummy/app/assets/javascripts/books.js.coffee
165
147
  - spec/dummy/app/assets/stylesheets/application.css
166
- - spec/dummy/app/assets/stylesheets/authors.css.scss
167
- - spec/dummy/app/assets/stylesheets/books.css.scss
168
148
  - spec/dummy/app/assets/stylesheets/scaffolds.css.scss
169
149
  - spec/dummy/app/controllers/application_controller.rb
170
150
  - spec/dummy/app/controllers/authors_controller.rb
@@ -172,16 +152,10 @@ test_files:
172
152
  - spec/dummy/app/decorators/author_decorator.rb
173
153
  - spec/dummy/app/decorators/book_decorator.rb
174
154
  - spec/dummy/app/helpers/application_helper.rb
175
- - spec/dummy/app/helpers/authors_helper.rb
176
- - spec/dummy/app/helpers/books_helper.rb
177
- - spec/dummy/app/mailers/.gitkeep
178
155
  - spec/dummy/app/models/.gitkeep
179
156
  - spec/dummy/app/models/author.rb
180
157
  - spec/dummy/app/models/book.rb
181
- - spec/dummy/app/views/authors/_form.html.erb
182
- - spec/dummy/app/views/authors/edit.html.erb
183
158
  - spec/dummy/app/views/authors/index.html.erb
184
- - spec/dummy/app/views/authors/new.html.erb
185
159
  - spec/dummy/app/views/authors/show.html.erb
186
160
  - spec/dummy/app/views/books/_book.html.erb
187
161
  - spec/dummy/app/views/books/_book_locals.html.erb
@@ -217,11 +191,10 @@ test_files:
217
191
  - spec/dummy/public/index.html
218
192
  - spec/dummy/public/robots.txt
219
193
  - spec/dummy/script/rails
220
- - spec/dummy/spec/decorators/author_decorator_spec.rb
221
- - spec/dummy/spec/decorators/book_decorator_spec.rb
222
- - spec/dummy/spec/requests/action_view_helpers_spec.rb
223
- - spec/dummy/spec/requests/controller_ivar_spec.rb
224
- - spec/dummy/spec/requests/partial_spec.rb
194
+ - spec/dummy/spec/decorators/view_helpers_spec.rb
195
+ - spec/dummy/spec/features/action_view_helpers_spec.rb
196
+ - spec/dummy/spec/features/controller_ivar_spec.rb
197
+ - spec/dummy/spec/features/partial_spec.rb
225
198
  - spec/dummy/spec/spec_helper.rb
226
199
  - spec/dummy/vendor/assets/javascripts/.gitkeep
227
200
  - spec/dummy/vendor/assets/stylesheets/.gitkeep
@@ -232,7 +205,4 @@ test_files:
232
205
  - spec/fake_app/books/_book_locals.html.erb
233
206
  - spec/fake_app/books/show.html.erb
234
207
  - spec/fake_app/fake_app.rb
235
- - spec/features/action_view_helpers_spec.rb
236
- - spec/features/controller_ivar_spec.rb
237
- - spec/features/partial_spec.rb
238
208
  - spec/spec_helper.rb
@@ -1,3 +0,0 @@
1
- # Place all the behaviors and hooks related to the matching controller here.
2
- # All this logic will automatically be available in application.js.
3
- # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
@@ -1,3 +0,0 @@
1
- # Place all the behaviors and hooks related to the matching controller here.
2
- # All this logic will automatically be available in application.js.
3
- # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
@@ -1,3 +0,0 @@
1
- // Place all the styles related to the authors controller here.
2
- // They will automatically be included in application.css.
3
- // You can use Sass (SCSS) here: http://sass-lang.com/
@@ -1,3 +0,0 @@
1
- // Place all the styles related to the books controller here.
2
- // They will automatically be included in application.css.
3
- // You can use Sass (SCSS) here: http://sass-lang.com/
@@ -1,2 +0,0 @@
1
- module AuthorsHelper
2
- end
@@ -1,2 +0,0 @@
1
- module BooksHelper
2
- end
File without changes
@@ -1,21 +0,0 @@
1
- <%= form_for(@author) do |f| %>
2
- <% if @author.errors.any? %>
3
- <div id="error_explanation">
4
- <h2><%= pluralize(@author.errors.count, "error") %> prohibited this author from being saved:</h2>
5
-
6
- <ul>
7
- <% @author.errors.full_messages.each do |msg| %>
8
- <li><%= msg %></li>
9
- <% end %>
10
- </ul>
11
- </div>
12
- <% end %>
13
-
14
- <div class="field">
15
- <%= f.label :name %><br />
16
- <%= f.text_field :name %>
17
- </div>
18
- <div class="actions">
19
- <%= f.submit %>
20
- </div>
21
- <% end %>
@@ -1,6 +0,0 @@
1
- <h1>Editing author</h1>
2
-
3
- <%= render 'form' %>
4
-
5
- <%= link_to 'Show', @author %> |
6
- <%= link_to 'Back', authors_path %>
@@ -1,5 +0,0 @@
1
- <h1>New author</h1>
2
-
3
- <%= render 'form' %>
4
-
5
- <%= link_to 'Back', authors_path %>
@@ -1,4 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe AuthorDecorator do
4
- end
@@ -1,4 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe BookDecorator do
4
- end
@@ -1,16 +0,0 @@
1
- require 'spec_helper'
2
-
3
- feature 'fallback to helpers' do
4
- background do
5
- aamine = Author.create! :name => 'aamine'
6
- @rhg = aamine.books.create! :title => 'RHG'
7
- end
8
-
9
- scenario 'invoking action_view helper methods' do
10
- visit "/authors/#{@rhg.author.id}/books/#{@rhg.id}"
11
- within 'a' do
12
- page.should have_content 'RHG'
13
- end
14
- page.should have_css('img')
15
- end
16
- end
@@ -1,29 +0,0 @@
1
- require 'spec_helper'
2
-
3
- feature 'decorating controller ivar' do
4
- background do
5
- @matz = Author.create! :name => 'matz'
6
- Author.create! :name => 'takahashim'
7
- end
8
- after do
9
- Author.delete_all
10
- end
11
-
12
- scenario 'decorating a model object in ivar' do
13
- visit "/authors/#{@matz.id}"
14
- page.should have_content 'matz'
15
- page.should have_content 'matz'.capitalize
16
- end
17
-
18
- scenario 'decorating model scope in ivar' do
19
- visit '/authors'
20
- page.should have_content 'takahashim'
21
- page.should have_content 'takahashim'.reverse
22
- end
23
-
24
- scenario "decorating models' array in ivar" do
25
- visit '/authors?variable_type=array'
26
- page.should have_content 'takahashim'
27
- page.should have_content 'takahashim'.reverse
28
- end
29
- end
@@ -1,31 +0,0 @@
1
- require 'spec_helper'
2
-
3
- feature 'decorating partial object' do
4
- background do
5
- Author.create! :name => 'aamine'
6
- nari = Author.create! :name => 'nari'
7
- nari.books.create! :title => 'the gc book'
8
- end
9
- after do
10
- Book.delete_all
11
- Author.delete_all
12
- end
13
-
14
- scenario 'decorating implicit @object' do
15
- visit '/authors'
16
- page.should have_content 'the gc book'
17
- page.should have_content 'the gc book'.reverse
18
- end
19
-
20
- scenario 'decorating implicit @collection' do
21
- visit '/authors?partial=collection'
22
- page.should have_content 'the gc book'
23
- page.should have_content 'the gc book'.reverse
24
- end
25
-
26
- scenario 'decorating objects in @locals' do
27
- visit '/authors?partial=locals'
28
- page.should have_content 'the gc book'
29
- page.should have_content 'the gc book'.upcase
30
- end
31
- end