table_help 0.1.7 → 0.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a3e5072199d7fc4e375ea7004f0e5273e3bf7506f022d6d914367a31e4d9bb6c
4
- data.tar.gz: bfb79ce50422f7f4d9ff9a2c9c1258cb70e0674d150f1ebf18f0e346a96dd557
3
+ metadata.gz: 83bae016ff083d16a91ed0fad825fc5101d6e3fbf077e5ce3119292ef4892f02
4
+ data.tar.gz: c564ba4d849a4d873deb048e42364cfea7aef495bfea2fdc35fb45bbe6898987
5
5
  SHA512:
6
- metadata.gz: '09195fb6084a198e35c1dcd6dd216009a6a8d2c9ea774e902c56278ff08fbc4dc50b6a9fadb277045c2edb3754ec5d0d08946b6dfde82d0ba81dfbcf2d984fd0'
7
- data.tar.gz: 4652bd99bf54e6991f6e24b445a7e1e3f5665074b3d7384e051acae16da6f3010208224841a17382d5ab625ddec51e157ff25079fe246cb09983a50678e7b260
6
+ metadata.gz: 7a3c5a0ce4c1a1ff8471b33af2a4538a86c74aa45246486b05a9536029714a0e1aea69c1cde704f676e5bfd1ff639fd474acdf63c6d6b084e714f35273595d97
7
+ data.tar.gz: 822e84442656dda89a3d9f1b310185dcef248da15e0c18f4cf97dacc05ffecaa622c6a2f97e342ed95cf56feabfcce979ae378dbef8d30216e6c83423df8c996
@@ -1,18 +1,21 @@
1
1
  module TableHelp
2
2
  class TableFor
3
- attr_reader :collection, :context, :options, :column_names, :strategies
4
- delegate :concat, :capture, :tag, to: :context
3
+ Column = Struct.new(:name, :human_name)
4
+
5
+ attr_reader :collection, :context, :options, :columns, :strategies, :q
6
+ delegate :concat, :capture, :tag, :sort_link, to: :context
5
7
 
6
8
  def initialize(collection, context, options = {})
7
9
  @collection = collection
8
10
  @context = context
9
11
  @options = default_options.merge(options)
10
- @column_names = []
12
+ @columns = []
11
13
  @strategies = []
14
+ @q = @options.delete(:q)
12
15
  end
13
16
 
14
17
  def column(name = nil, method_name = nil, &block)
15
- column_names << Formatter.format_attribute_name(name, collection)
18
+ columns << Column.new(name, Formatter.format_attribute_name(name, collection))
16
19
  strategies << Strategy.new(name, block_given? ? block : method_name)
17
20
  end
18
21
 
@@ -30,13 +33,21 @@ module TableHelp
30
33
  def thead
31
34
  tag.thead do
32
35
  tag.tr do
33
- column_names.each do |column_name|
34
- concat tag.th(column_name)
36
+ columns.each do |column|
37
+ if sortable?
38
+ concat tag.th(sort_link(q, column.name, column.human_name))
39
+ else
40
+ concat tag.th(column.human_name)
41
+ end
35
42
  end
36
43
  end
37
44
  end
38
45
  end
39
46
 
47
+ def sortable?
48
+ !q.nil? && respond_to?(:sort_link)
49
+ end
50
+
40
51
  def tbody
41
52
  tag.tbody do
42
53
  collection.each do |record|
@@ -1,3 +1,3 @@
1
1
  module TableHelp
2
- VERSION = "0.1.7".freeze
2
+ VERSION = "0.2.0".freeze
3
3
  end
@@ -818,3 +818,19 @@ Processing by ArticlesController#show as HTML
818
818
  Completed 200 OK in 18ms (Views: 12.5ms)
819
819
 
820
820
 
821
+ DEPRECATION WARNING: You didn't set `secret_key_base`. Read the upgrade documentation to learn more about this new config option. (called from block (3 levels) in <top (required)> at /Users/yhirano/dev/src/github.com/yhirano55/table_help/spec/table_help_spec.rb:14)
822
+ Started GET "/articles" for 127.0.0.1 at 2018-06-15 18:09:49 +0900
823
+ Processing by ArticlesController#index as HTML
824
+ Rendering articles/index.html.erb
825
+ Rendered articles/index.html.erb (4.5ms)
826
+ Completed 200 OK in 19ms (Views: 17.2ms)
827
+
828
+
829
+ Started GET "/articles/5" for 127.0.0.1 at 2018-06-15 18:09:49 +0900
830
+ Processing by ArticlesController#show as HTML
831
+ Parameters: {"id"=>"5"}
832
+ Rendering articles/show.html.erb
833
+ Rendered articles/show.html.erb (1.7ms)
834
+ Completed 200 OK in 19ms (Views: 12.2ms)
835
+
836
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: table_help
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoshiyuki Hirano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-05 00:00:00.000000000 Z
11
+ date: 2018-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -85,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
85
  version: '0'
86
86
  requirements: []
87
87
  rubyforge_project:
88
- rubygems_version: 2.7.3
88
+ rubygems_version: 2.7.6
89
89
  signing_key:
90
90
  specification_version: 4
91
91
  summary: Provide helper methods to build collection or resource tables for Rails 5