standard_view 0.1.5 → 0.1.6

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
2
  SHA256:
3
- metadata.gz: 7aa2ea213099a10dc4cbc6ee2569b5ae9ee6f5f1241a2400fab425f36e045e07
4
- data.tar.gz: a7bbfbdee602ab554a91fda869ff2f08f2fe3077260ca473eb967d134a72a683
3
+ metadata.gz: c008e64756322089fed61a72c05266374a16f8ace7c8acf66cd68e404b75ae2e
4
+ data.tar.gz: f470acc9bc29aa29b85627da44467edb1bf623b356a490b538fbe1710ca1d7fa
5
5
  SHA512:
6
- metadata.gz: 99e998104b6fb9a16934278c777be8cb0d04e971271336b99cd5d7d68d698cc9791100c557c1337aa54cf9ce6f5e21045e121adb77369a54f0ff5152a36f569a
7
- data.tar.gz: 01f5ac80bcd913f0e404362996f208046aea18284593df75f8200342d54c11cb349a8b576e4ff8b8b3c1e1504a1d39beb470a5fa1c2fdcc7375d0cd6a61d9a36
6
+ metadata.gz: 249ca7dd708c7d88e113e7cff2d9615bc52d962b7f280a85459ce3c42c7a1c93f3bf1954fd5ba6b3a31dfba1022e5e385ad47a055f96b783c0467e607c30dd51
7
+ data.tar.gz: 7d190a02123ee342c39e9192f338b775c4c0f854968f90fbdffe29195d11a6af504fa6d7e4cec401d1c248331fb37a3de2c995557ed9b558f6b068c116abd04b
@@ -52,5 +52,27 @@ module StandardView
52
52
  method: :delete,
53
53
  data: { confirm: t("common.confirm_destroy") }
54
54
  end
55
+
56
+ def attribute_value_for(material, attribute_name)
57
+ formatted_method_name = "#{attribute_name}_formatted"
58
+ return material.public_send(formatted_method_name) if material.respond_to?(formatted_method_name)
59
+
60
+ return material.public_send(attribute_name) if material.class.try(:primary_key) == attribute_name
61
+ return link_to_related(material, attribute_name) if material.relationship_attributes.include?(attribute_name)
62
+
63
+ i18n_method_name = "#{attribute_name}_i18n"
64
+ return material.public_send(i18n_method_name) if material.respond_to?(i18n_method_name)
65
+
66
+ material.human_attribute_value(attribute_name)
67
+ end
68
+
69
+ def link_to_related(material, attribute_name)
70
+ related_object_method_name = attribute_name.chomp("_id")
71
+ related_object = material.public_send(related_object_method_name)
72
+ raise ArgumentError, "no related object for #{material.inspect}" unless related_object.present?
73
+
74
+ related_material = Material::Base.for(related_object)
75
+ link_to related_material.reference_title, related_material
76
+ end
55
77
  end
56
78
  end
@@ -25,7 +25,7 @@
25
25
  <% material.sorted_attribute_names.each do |attribute_name| %>
26
26
  <tr>
27
27
  <th><%= material.human_attribute_name(attribute_name) %></th>
28
- <td><%= material.human_attribute_value(attribute_name) %></td>
28
+ <td><%= attribute_value_for material, attribute_name %></td>
29
29
  </tr>
30
30
  <% end %>
31
31
  </tbody>
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StandardView
4
- VERSION = "0.1.5"
4
+ VERSION = "0.1.6"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: standard_view
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Garside
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-12 00:00:00.000000000 Z
11
+ date: 2020-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -30,7 +30,7 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.3.4
33
+ version: 0.3.5
34
34
  - - "<"
35
35
  - !ruby/object:Gem::Version
36
36
  version: '1.0'
@@ -40,7 +40,7 @@ dependencies:
40
40
  requirements:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
- version: 0.3.4
43
+ version: 0.3.5
44
44
  - - "<"
45
45
  - !ruby/object:Gem::Version
46
46
  version: '1.0'
@@ -70,7 +70,7 @@ dependencies:
70
70
  requirements:
71
71
  - - ">="
72
72
  - !ruby/object:Gem::Version
73
- version: 0.1.1
73
+ version: 0.1.5
74
74
  - - "<"
75
75
  - !ruby/object:Gem::Version
76
76
  version: '1.0'
@@ -80,7 +80,7 @@ dependencies:
80
80
  requirements:
81
81
  - - ">="
82
82
  - !ruby/object:Gem::Version
83
- version: 0.1.1
83
+ version: 0.1.5
84
84
  - - "<"
85
85
  - !ruby/object:Gem::Version
86
86
  version: '1.0'
@@ -138,14 +138,14 @@ dependencies:
138
138
  requirements:
139
139
  - - "~>"
140
140
  - !ruby/object:Gem::Version
141
- version: '10.0'
141
+ version: '13.0'
142
142
  type: :development
143
143
  prerelease: false
144
144
  version_requirements: !ruby/object:Gem::Requirement
145
145
  requirements:
146
146
  - - "~>"
147
147
  - !ruby/object:Gem::Version
148
- version: '10.0'
148
+ version: '13.0'
149
149
  - !ruby/object:Gem::Dependency
150
150
  name: rspec-rails
151
151
  requirement: !ruby/object:Gem::Requirement