frill 0.1.12 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.12
1
+ 0.1.13
data/lib/frill/frill.rb CHANGED
@@ -8,6 +8,7 @@ module Frill
8
8
 
9
9
  def self.decorators
10
10
  @decorators ||= dependency_graph.to_a
11
+ @decorators.dup
11
12
  end
12
13
 
13
14
  def self.reset!
@@ -15,12 +16,18 @@ module Frill
15
16
  @dependency_graph = nil
16
17
  end
17
18
 
18
- def self.decorate object, context
19
- decorators.each do |d|
20
- object.extend d if d.frill? object, context
21
- end
19
+ def self.decorate object, context, options={}
20
+ frills = decorators
22
21
 
23
- object
22
+ if subset = options[:with]
23
+ frills.select! {|d| subset.include? d}
24
+ end
25
+
26
+ frills.each do |f|
27
+ object.extend f if f.frill? object, context
28
+ end
29
+
30
+ object
24
31
  end
25
32
 
26
33
  def self.dependency_graph
data/lib/frill/rails.rb CHANGED
@@ -23,13 +23,42 @@ module ActionController
23
23
  helper_method :frill
24
24
 
25
25
  private
26
- def frill object
27
- if object.respond_to?(:each)
28
- object.each do |o|
29
- Frill.decorate o, self
26
+ def frill object, options={}
27
+ RailsFrillHelper.new(object, self, options).frill
28
+ end
29
+
30
+ class RailsFrillHelper
31
+ def initialize(object, controller, options)
32
+ @object = object
33
+ @controller = controller
34
+ @options = options
35
+ end
36
+
37
+ def frill
38
+ extend_with_view_context
39
+ frill_object
40
+ object
41
+ end
42
+
43
+ private
44
+ attr_reader :options, :object, :controller
45
+
46
+ def frill_object
47
+ objects.each do |o|
48
+ Frill.decorate o, controller, options
49
+ end
50
+ end
51
+
52
+ def extend_with_view_context
53
+ options[:with] << ViewContextFrill if options[:with]
54
+ end
55
+
56
+ def objects
57
+ if object.respond_to? :each
58
+ object
59
+ else
60
+ [object]
30
61
  end
31
- else
32
- Frill.decorate object, self
33
62
  end
34
63
  end
35
64
  end
data/readme.markdown CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  [![Build Status](https://secure.travis-ci.org/moonmaster9000/frill.png)](http://travis-ci.org/moonmaster9000/frill)
4
4
  [![Build Dependency Status](https://gemnasium.com/moonmaster9000/frill.png)](https://gemnasium.com/moonmaster9000/frill.png)
5
+ [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/moonmaster9000/frill)
5
6
 
6
7
  Simple decoration of objects for presentation. Out of the box integration with Rails.
7
8
 
@@ -103,6 +104,14 @@ Or, in a view:
103
104
  <%= render frill(@foo.comments) %>
104
105
  ```
105
106
 
107
+ ### 'frill' with only a subset of frills
108
+
109
+ You can tell `frill` to consider only a subset of frills for decoration with the `with` option:
110
+
111
+ ```erb
112
+ <%= render frill(@posts, with: [TextPostFrill, PicturePostFrill, VideoPostFrill])
113
+ ```
114
+
106
115
  ## A longer story
107
116
 
108
117
  Your product manager writes the following story for you:
@@ -330,6 +339,8 @@ describe HtmlTimestampFrill do
330
339
  end
331
340
  ```
332
341
 
342
+ Note (2012/09/05): because of a subtle bug in RSpec, the above stub chain `stub_chain(:request, :format, :html?)` fails on the latest RSpec release (2.11.0) but is fixed in master. See issue [#587](https://github.com/rspec/rspec-rails/issues/587) and the [commit that fixes it](https://github.com/rspec/rspec-mocks/commit/05741e90083280c1b9e069350d7e3afbf4a45456).
343
+
333
344
  Since frills are just modules, it's possible to test your frills in relative isolation.
334
345
 
335
346
  ```ruby
data/spec/frill_spec.rb CHANGED
@@ -42,11 +42,33 @@ describe Frill do
42
42
  end
43
43
  end
44
44
 
45
- it "should decorate the object with any applicable modules" do
46
- Frill.decorate object, object_context
45
+ context "(object, context)" do
46
+ it "should decorate the object with any applicable modules" do
47
+ Frill.decorate object, object_context
47
48
 
48
- eigenclass.included_modules.should include applicable_module
49
- eigenclass.included_modules.should_not include unapplicable_module
49
+ eigenclass.included_modules.should include applicable_module
50
+ eigenclass.included_modules.should_not include unapplicable_module
51
+ end
52
+ end
53
+
54
+ context "(object, context, with: module_subset)" do
55
+ let!(:another_applicable_module) do
56
+ Module.new do
57
+ include Frill
58
+
59
+ def self.frill?(*)
60
+ true
61
+ end
62
+ end
63
+ end
64
+
65
+ it "should only attempt to frill with the specified module subset" do
66
+ Frill.decorate object, object_context, with: [another_applicable_module]
67
+
68
+ eigenclass.included_modules.should include another_applicable_module
69
+ eigenclass.included_modules.should_not include applicable_module
70
+ eigenclass.included_modules.should_not include unapplicable_module
71
+ end
50
72
  end
51
73
  end
52
74
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: frill
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.1.13
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-05 00:00:00.000000000 Z
12
+ date: 2012-09-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70283482709540 !ruby/object:Gem::Requirement
16
+ requirement: &70273354014740 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.2.2
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70283482709540
24
+ version_requirements: *70273354014740
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70283482708760 !ruby/object:Gem::Requirement
27
+ requirement: &70273354013980 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70283482708760
35
+ version_requirements: *70273354013980
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec-rails
38
- requirement: &70283482708100 !ruby/object:Gem::Requirement
38
+ requirement: &70273354013420 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70283482708100
46
+ version_requirements: *70273354013420
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: capybara
49
- requirement: &70283482707520 !ruby/object:Gem::Requirement
49
+ requirement: &70273354035640 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70283482707520
57
+ version_requirements: *70273354035640
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: pry
60
- requirement: &70283482706760 !ruby/object:Gem::Requirement
60
+ requirement: &70273354035120 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70283482706760
68
+ version_requirements: *70273354035120
69
69
  description:
70
70
  email: moonmaster9000@gmail.com
71
71
  executables: []