substance_presenter 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e5bfbc14fc7e46251ef3ea5dd82820005c0b6991
4
- data.tar.gz: 35c4117f5eabaf0edd20b2d701d31f0c83e48d16
2
+ SHA256:
3
+ metadata.gz: 456c1f6ecfd590d9ca0101ff663ce1425b4f7db8afc6dc939b4fa58e5671bd8d
4
+ data.tar.gz: db571a9ca0557a7c76cd9edb7db01e695b6bd8a3bfdca4cbc86ae92355f9e824
5
5
  SHA512:
6
- metadata.gz: 4915b321abf75516ced039e1e84cfd3c1ee06645baedbba2ac02851dd8fd1aa70034ec8db7b44ffd8948e856af6695b98e8632448319450ee3c7b8cc46561d29
7
- data.tar.gz: 31fb1a023d3625856eebf1725ce1d697b024f5034cf72a7444311cc267f4449b89900046fb3261517060cc3d46811342c4e0642b857d481fb4a496f9a0832f6d
6
+ metadata.gz: ca48f678dc369a0392c607105694cfbc283b2230662504f03bae8df83735ca45ba3685a86d2bf4ff5ca00f4c49bdb71b624a674eb9c930cca3e2eb49a205b1ab
7
+ data.tar.gz: 1fa14ff4c559e798b45f24338f5feeb26e5681f9e0ec03191e28555041bb1b0cd4a49f5397a02919334972f9bf60cba7cfb30d4d76de032a3be5f58beb30d680
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  begin
2
4
  require 'rspec/core/rake_task'
3
5
 
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'delegate'
4
+
5
+ module Substance
6
+ class Presenter < ::SimpleDelegator
7
+ attr_reader :view
8
+
9
+ class << self
10
+ # Returns true if object has been wrapped in a Presenter
11
+ def decorated?(object)
12
+ object.is_a?(Presenter)
13
+ end
14
+
15
+ # Wrap object in presenter with access to a view context
16
+ def present(object, view)
17
+ return object if decorated?(object)
18
+ new(object, view)
19
+ end
20
+
21
+ # Wrap each object in presenter with access to a view context
22
+ def present_collection(collection, view)
23
+ collection.map do |item|
24
+ present(item, view)
25
+ end
26
+ end
27
+ end
28
+
29
+ def initialize(object, view)
30
+ super(object)
31
+ @view = view
32
+ end
33
+
34
+ def object
35
+ undecorated(__getobj__)
36
+ end
37
+
38
+ private
39
+
40
+ def decorated?(object)
41
+ self.class.decorated?(object)
42
+ end
43
+
44
+ def present_collection(collection, presenter)
45
+ presenter.present_collection(collection, view)
46
+ end
47
+
48
+ def undecorated(potentially_decorated_object)
49
+ if decorated?(potentially_decorated_object)
50
+ potentially_decorated_object.object
51
+ else
52
+ potentially_decorated_object
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "substance/presenter"
4
+
5
+ module Substance
6
+ class Presenter
7
+ module Rails
8
+ module ViewHelper
9
+ # Returns object wrapped in presenter.
10
+ # If object is a collection each member
11
+ # of the collection is wrapped and the collection is returned.
12
+ #
13
+ # Example
14
+ #
15
+ # <%- @foo = present(@foo, FooPresenter) -%>
16
+ #
17
+ def present(object, presenter)
18
+ if object.is_a?(Enumerable)
19
+ presenter.present_collection(object, self)
20
+ else
21
+ presenter.present(object, self)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,56 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'delegate'
4
-
5
- module Substance
6
- class Presenter < ::SimpleDelegator
7
- attr_reader :view
8
-
9
- class << self
10
- # Returns true if object has been wrapped in a Presenter
11
- def decorated?(object)
12
- object.is_a?(Presenter)
13
- end
14
-
15
- # Wrap object in presenter with access to a view context
16
- def present(object, view)
17
- return object if decorated?(object)
18
- new(object, view)
19
- end
20
-
21
- # Wrap each object in presenter with access to a view context
22
- def present_collection(collection, view)
23
- collection.map do |item|
24
- present(item, view)
25
- end
26
- end
27
- end
28
-
29
- def initialize(object, view)
30
- super(object)
31
- @view = view
32
- end
33
-
34
- def object
35
- undecorated(__getobj__)
36
- end
37
-
38
- private
39
-
40
- def decorated?(object)
41
- self.class.decorated?(object)
42
- end
43
-
44
- def present_collection(collection, presenter)
45
- presenter.present_collection(collection, view)
46
- end
47
-
48
- def undecorated(potentially_decorated_object)
49
- if decorated?(potentially_decorated_object)
50
- potentially_decorated_object.object
51
- else
52
- potentially_decorated_object
53
- end
54
- end
55
- end
56
- end
3
+ $:.push File.expand_path("..", __FILE__)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: substance_presenter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ole Palm
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-05-10 00:00:00.000000000 Z
13
+ date: 2018-12-10 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: An easy to use presenter implementation
16
16
  email: ole.palm@substancelab.com
@@ -19,8 +19,10 @@ extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
21
  - Rakefile
22
+ - lib/substance/presenter.rb
23
+ - lib/substance/rails/view_helper.rb
22
24
  - lib/substance_presenter.rb
23
- homepage: http://rubygems.org/gems/substance_presenter
25
+ homepage: https://github.com/substancelab/substance_presenter
24
26
  licenses:
25
27
  - MIT
26
28
  metadata: {}
@@ -40,7 +42,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
40
42
  version: '0'
41
43
  requirements: []
42
44
  rubyforge_project:
43
- rubygems_version: 2.6.14
45
+ rubygems_version: 2.7.6
44
46
  signing_key:
45
47
  specification_version: 4
46
48
  summary: An easy to use presenter implementation