record_view_helper 1.0.1 → 1.1.0

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: d613563d57f181d96b21daee693f428ac5424077
4
- data.tar.gz: 1a48fb71c90cd36516e92c14c9465d6b4523f98c
2
+ SHA256:
3
+ metadata.gz: 484e0e2bc1f93978d015d58e826dec01598b1297d1dec6e4dbf30b9b4bf04d77
4
+ data.tar.gz: b56a7796e056fd245510ded3c773fd625b4d4c2000d9a88f9a5016d24761ab9f
5
5
  SHA512:
6
- metadata.gz: 1061d0457c6b9d242e295bc72129db54ab6ce5ed279fa44420457a19996e218b9500c581f2cb781474fe28f6e9e5c727bca7df514496353bc7f544426efb2f8b
7
- data.tar.gz: 7c00b6cd33a07215ade4090543c1e60b04b99b9e33010a6b3f10ad1a3426294ae07892372746aed8e7d7ac661be946e10caaa703bbf64b3a3a6ced3d18d35dca
6
+ metadata.gz: 5473baa96d7ac03c39cb5ea4b9db5f728961980a093775b0e9803f5485ef2f0629bdcbdfafaa5ca28b55885a3583599f10aec5d8651c9708035e71cdaa853a45
7
+ data.tar.gz: 8d19a02261b49c17d17d4bcab66368e0527d653f5f8fde03aa41b6f63b27adb2e692adb8ea9042d47fd564ec48e979e1f8e06e10a8775738b74ac56811ec9361
data/README.md CHANGED
@@ -45,5 +45,9 @@ Or install it yourself as:
45
45
  $ gem install record_view_helper
46
46
  ```
47
47
 
48
+ ## See also
49
+
50
+ - [table-for](https://github.com/hunterae/table-for)
51
+
48
52
  ## License
49
53
  The gem is available as open source under the terms of the [MIT License](https://narazaka.net/license/MIT?2017).
@@ -42,5 +42,22 @@ module RecordViewHelper
42
42
  #
43
43
  # @return [String] (default = "record_view_helper")
44
44
  attr_accessor :locale_namespace
45
+
46
+ # Proc which returns name for column
47
+ #
48
+ # @example in Rails
49
+ # Rails.application.config.record_view_helper.column_name =
50
+ # ->(table_class, column) { "[#{column}]<br>#{table_class.columns_hash[column.to_s].comment}".html_safe }
51
+ #
52
+ # @example basic
53
+ # class MyView < ActionView::Base
54
+ # include RecordViewHelper
55
+ # end
56
+ #
57
+ # MyView.record_view_helper_config.locale_name =
58
+ # ->(table_class, column) { "[#{column}]<br>#{table_class.columns_hash[column.to_s].comment}".html_safe }
59
+ #
60
+ # @return [Proc]
61
+ attr_accessor :column_name
45
62
  end
46
63
  end
@@ -8,12 +8,11 @@ module RecordViewHelper
8
8
  # @yieldparam [RecordValueSetting] setting setting object
9
9
  # @yieldreturn [void]
10
10
  # @return [ActiveSupport::SafeBuffer] rendered result
11
- def dl_for(record, options = {})
12
- return if record.nil?
11
+ def dl_for(record, options = {}) # rubocop:disable Metrics/AbcSize
13
12
  setting = RecordValueSetting.build_from_hash!(
14
13
  record.attributes.keys,
15
14
  record.class.name.tableize,
16
- options
15
+ options,
17
16
  )
18
17
  yield setting if block_given?
19
18
  content_tag(
@@ -21,12 +20,12 @@ module RecordViewHelper
21
20
  safe_join(
22
21
  setting.columns.map do |column|
23
22
  safe_join [
24
- content_tag("dt", record_view_helper_t(setting.table_name, column), setting.header_attrs[column]),
23
+ content_tag("dt", record_view_helper_t(record.class, column), setting.header_attrs[column]),
25
24
  content_tag("dd", format_record_value(record, column, setting.formats[column], setting.links[column]), setting.attrs[column]),
26
25
  ]
27
- end
26
+ end,
28
27
  ),
29
- options
28
+ options,
30
29
  )
31
30
  end
32
31
  end
@@ -29,7 +29,7 @@ module RecordViewHelper
29
29
  formats: options.delete(:formats),
30
30
  links: options.delete(:links),
31
31
  attrs: options.delete(:attrs),
32
- header_attrs: options.delete(:header_attrs)
32
+ header_attrs: options.delete(:header_attrs),
33
33
  )
34
34
  end
35
35
 
@@ -41,7 +41,16 @@ module RecordViewHelper
41
41
  # @param [Hash<Symbol, Symbol|Hash<Symbol, Symbol|Array<Symbol>>>] links links settings
42
42
  # @param [Hash<Symbol, Hash<Symbol, String>>] attrs column value dom tag attrs
43
43
  # @param [Hash<Symbol, Hash<Symbol, String>>] header_attrs column header dom tag attrs
44
- def initialize(columns, table_name, only: nil, except: nil, formats: nil, links: nil, attrs: nil, header_attrs: nil)
44
+ def initialize( # rubocop:disable Metrics/ParameterLists
45
+ columns,
46
+ table_name,
47
+ only: nil,
48
+ except: nil,
49
+ formats: nil,
50
+ links: nil,
51
+ attrs: nil,
52
+ header_attrs: nil
53
+ )
45
54
  @columns = columns
46
55
  @table_name = table_name
47
56
  @only = only || []
@@ -53,12 +53,11 @@ module RecordViewHelper
53
53
  # - s.only :id, :name
54
54
  # / recommended for complex settings
55
55
  # / see RecordValueSetting for details
56
- def table_for(records, options = {})
57
- return if records.empty?
56
+ def table_for(records, options = {}) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
58
57
  setting = RecordValueSetting.build_from_hash!(
59
58
  records.first.attributes.keys,
60
59
  records.first.class.name.tableize,
61
- options
60
+ options,
62
61
  )
63
62
  yield setting if block_given?
64
63
  content_tag(
@@ -70,10 +69,10 @@ module RecordViewHelper
70
69
  "tr",
71
70
  safe_join(
72
71
  setting.columns.map do |column|
73
- content_tag("th", record_view_helper_t(setting.table_name, column), setting.header_attrs[column])
74
- end
75
- )
76
- )
72
+ content_tag("th", record_view_helper_t(records.first.class, column), setting.header_attrs[column])
73
+ end,
74
+ ),
75
+ ),
77
76
  ),
78
77
  content_tag(
79
78
  "tbody",
@@ -84,14 +83,14 @@ module RecordViewHelper
84
83
  safe_join(
85
84
  setting.columns.map do |column|
86
85
  content_tag("td", format_record_value(record, column, setting.formats[column], setting.links[column]), setting.attrs[column])
87
- end
88
- )
86
+ end,
87
+ ),
89
88
  )
90
- end
91
- )
89
+ end,
90
+ ),
92
91
  ),
93
92
  ]),
94
- options
93
+ options,
95
94
  )
96
95
  end
97
96
  end
@@ -28,7 +28,7 @@ module RecordViewHelper
28
28
  else
29
29
  deep_record_values(record, format || [column])
30
30
  end
31
- formatted_value = safe_join values.map { |value| [format_view_value(value), " "] }.flatten[0..-2]
31
+ formatted_value = safe_join values.map {|value| [format_view_value(value), " "] }.flatten[0..-2]
32
32
  case link
33
33
  when String, Symbol
34
34
  link_record_value(record, formatted_value, link, [column])
@@ -49,7 +49,7 @@ module RecordViewHelper
49
49
  # deep_record_values(record, [:a, [:a, :b]]) == [record.a, record.a.b]
50
50
  #
51
51
  def deep_record_values(record, columns)
52
- columns.map { |column| deep_record_value(record, column) }
52
+ columns.map {|column| deep_record_value(record, column) }
53
53
  end
54
54
 
55
55
  # deep call
@@ -61,7 +61,7 @@ module RecordViewHelper
61
61
  # deep_record_value(record, [:a, :b]) == record.a.b
62
62
  #
63
63
  def deep_record_value(record, column)
64
- Array(column).reduce(record) { |receiver, method| receiver.try(:public_send, method) }
64
+ Array(column).reduce(record) {|receiver, method| receiver.try(:public_send, method) }
65
65
  end
66
66
 
67
67
  # format value
@@ -97,13 +97,18 @@ module RecordViewHelper
97
97
 
98
98
  private
99
99
 
100
- def record_view_helper_t(table_name, column)
101
- t(
102
- if record_view_helper_config.locale_name
103
- record_view_helper_config.locale_name.call(table_name, column)
104
- else
105
- "#{record_view_helper_config.locale_namespace}.#{table_name}.columns.#{column}"
106
- end
107
- )
100
+ def record_view_helper_t(table_class, column)
101
+ if record_view_helper_config.column_name
102
+ record_view_helper_config.column_name.call(table_class, column)
103
+ else
104
+ table_name = table_class.name.tableize
105
+ t(
106
+ if record_view_helper_config.locale_name
107
+ record_view_helper_config.locale_name.call(table_name, column)
108
+ else
109
+ "#{record_view_helper_config.locale_namespace}.#{table_name}.columns.#{column}"
110
+ end,
111
+ )
112
+ end
108
113
  end
109
114
  end
@@ -1,4 +1,4 @@
1
1
  module RecordViewHelper
2
2
  # version
3
- VERSION = "1.0.1".freeze
3
+ VERSION = "1.1.0".freeze
4
4
  end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: record_view_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Narazaka
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-07 00:00:00.000000000 Z
11
+ date: 2018-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: activesupport
14
+ name: actionview
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: actionview
28
+ name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,47 +39,47 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rails
42
+ name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '4'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '4'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rspec-rails
56
+ name: onkcop
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '3'
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '3'
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: bundler
70
+ name: rails
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: '4'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: '4'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -109,19 +109,19 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: yard
112
+ name: rspec-rails
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ">="
115
+ - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '0'
117
+ version: '3'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ">="
122
+ - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '0'
124
+ version: '3'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: simplecov
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -137,7 +137,7 @@ dependencies:
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
- name: onkcop
140
+ name: yard
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - ">="
@@ -189,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
189
  version: '0'
190
190
  requirements: []
191
191
  rubyforge_project:
192
- rubygems_version: 2.5.1
192
+ rubygems_version: 2.7.3
193
193
  signing_key:
194
194
  specification_version: 4
195
195
  summary: table builder and description list (dl) helper for Rails / ActiveModels