table_sortable 0.3.3 → 0.4.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
  SHA1:
3
- metadata.gz: 1c71932ec8cb88cab6d3c896f1a88465f2de37f6
4
- data.tar.gz: 59b5b8c69fc4be9a9a610dd99d50d5c7969b8ce4
3
+ metadata.gz: 58f56319bff9c3d3ab049d249641cc00e51ec909
4
+ data.tar.gz: f930fc8ef35415aba073a22f324125a19c83258e
5
5
  SHA512:
6
- metadata.gz: 2ac86b08493279aa0636e34ffe490823438523f1befb9a36d04acee52d088841e86fd6ad54cc9cc6355720a6f66e17d77d3ef5a12642c83e1cee2312534d62f5
7
- data.tar.gz: efb115d0bd7582047363bc7d647911378b9ab2cfd0e524356d8f379f966170a40f330546b988647b7bfc2ea9909580c5dcf0a3b1e71495538ad59eb046b0884f
6
+ metadata.gz: 256f910ad188856f5809326ba5d14ff87e9b8778800098cf616d6eafd80ef0d86e1c98a352af5ddb41183934e0e54f0a4ee6896bfa0f75b7b8f52093972b90b9
7
+ data.tar.gz: 501252f87cb2f3c750fc56122989ff24fe19e242e8a66f9cd3a02ced8cb90e10d0968e0e0b9470f47e55728d6f745fd1273ee24f109de041469840a972db6cb7
data/README.md CHANGED
@@ -38,19 +38,19 @@ please see the [jQuery tablesorter plugin for Rails](https://github.com/themilkm
38
38
  ## Usage
39
39
 
40
40
  First, we need to setup our controller. For this example this will be a users controller.
41
- Let's `include TableSortable` so that we can use its methods.
41
+ Let's `include TableSortable::Controller` so that we can use its methods.
42
42
 
43
43
  ```ruby
44
44
  #controllers/users_controller.rb
45
45
  class UsersController < ApplicationController
46
- include TableSortable
46
+ include TableSortable::Controller
47
47
  ```
48
48
 
49
49
  Next, let's define our columns.
50
50
  ```ruby
51
51
  #controllers/users_controller.rb
52
52
  class UsersController < ApplicationController
53
- include TableSortable
53
+ include TableSortable::Controller
54
54
 
55
55
  define_colunns :first_name, :last_name, :email, :created_at
56
56
  ```
@@ -151,7 +151,7 @@ TableSortable lets you define the columns one by one with many custom attributes
151
151
  ```ruby
152
152
  #controllers/users_controller.rb
153
153
  class UsersController < ApplicationController
154
- include TableSortable
154
+ include TableSortable::Controller
155
155
 
156
156
  define_column :full_name,
157
157
  value: -> (user) {"#{user.first_name} #{user.last_name}"}
@@ -1,14 +1,15 @@
1
1
  module TableSortable
2
2
  class Column
3
3
 
4
- attr_reader :name, :label, :filter, :sorter, :template, :placeholder, :content#, :sort_priority
4
+ attr_reader :name, :label, :filter, :sorter, :template, :placeholder, :content, :translation_key
5
5
 
6
6
  def initialize(col_name, *options)
7
7
 
8
8
  options = options.extract_options!
9
9
  value = options[:value] || col_name
10
10
  content = options[:content] || value
11
- label = options[:label] || (options[:label] == false ? '' : col_name.to_s.titleize)
11
+ translation_key = options[:translation_key]
12
+ label = options[:label] || (options[:label] == false ? '' : I18n.translate("table_sortable.#{"#{translation_key}." if translation_key }#{col_name.to_s}", :default => col_name.to_s).titleize)
12
13
  placeholder = options[:placeholder] || (options[:placeholder] == false ? nil : label)
13
14
  # priority = options[:priority]
14
15
  template = options[:template] || col_name
@@ -13,12 +13,14 @@ module TableSortable
13
13
  def define_columns(*args)
14
14
  options = args.extract_options!
15
15
  column_offset = options[:offset] || 0
16
+ translation_key = options[:translation_key]
16
17
  columns = args
17
18
  before_action(options) do
19
+ define_translation_key translation_key
20
+ define_column_offset column_offset
18
21
  columns.each do |column|
19
- define_column column
22
+ define_column column, translation_key: translation_key
20
23
  end
21
- define_column_offset column_offset
22
24
  end
23
25
  end
24
26
 
@@ -39,10 +41,16 @@ module TableSortable
39
41
  define_column_offset offset
40
42
  end
41
43
  end
44
+
45
+ def define_translation_key(key)
46
+ before_action do
47
+ define_translation_key key
48
+ end
49
+ end
42
50
  end
43
51
 
44
52
  def define_column(col_name, *options)
45
- options = options.extract_options!
53
+ options = default_column_options.merge(options.extract_options!)
46
54
  @columns.add(col_name, options)
47
55
  end
48
56
 
@@ -54,12 +62,20 @@ module TableSortable
54
62
  @column_offset = offset
55
63
  end
56
64
 
65
+ def define_translation_key(key)
66
+ @translation_key = key
67
+ end
68
+
57
69
  def columns
58
70
  @columns.sort_by(column_order)
59
71
  end
60
72
 
61
73
  private
62
74
 
75
+ def default_column_options
76
+ {translation_key: @translation_key}
77
+ end
78
+
63
79
  def filter_and_sort(scope, params = nil)
64
80
  populate_params(params)
65
81
 
@@ -92,7 +108,7 @@ module TableSortable
92
108
 
93
109
  public
94
110
 
95
- attr_reader :column_order, :column_offset
111
+ attr_reader :column_order, :column_offset, :translation_key
96
112
 
97
113
  end
98
114
  end
@@ -1,3 +1,3 @@
1
1
  module TableSortable
2
- VERSION = "0.3.3"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: table_sortable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oded Davidov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-03 00:00:00.000000000 Z
11
+ date: 2017-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler