sortabl 0.5.0 → 0.5.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
2
  SHA1:
3
- metadata.gz: a6c4af3f0e56418608ff656d0f7b6ab202a36ef5
4
- data.tar.gz: a33bedac5421960f53ee0f27b8dc75bac744592d
3
+ metadata.gz: bc5b7d426b26777c5cbe848607372226a88e9373
4
+ data.tar.gz: 09680458a7901a7b4a1bfc6210fa67a23e7ac927
5
5
  SHA512:
6
- metadata.gz: 67ce18ed70f06f3b3469245e7e080439005d667dbc5fbeea7358e46fb8341ae0570252203761646734622662d7ecd39d3a10cbf5522dd0a40f7cd3c56bd72d12
7
- data.tar.gz: 4d8334f0ce2a0ac8bd694a6c5bfaf9dcef4d60e3f241eef3087f53cf64f82254f68ae1bad46b7993417bd57c9795a73eca5ef4e119b7166607a43a495027888e
6
+ metadata.gz: 38d58995baff555155b23b02b5020037fe92d15cd322b04731e2202b4f0801616bcd7da4872226b945b2fab012ef1fbc713913b3c60fb0157a1799c57d9fb8f8
7
+ data.tar.gz: c4373fd8cffee63ee7029ad0f18031f93cfd510a5b1af26962a0dd8de578dda095033c71a41f559b21f5245a91f6ca097126cd73f1d7aed8b3ec910115c57cf1
metadata CHANGED
@@ -1,57 +1,75 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sortabl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frederic Walch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-02 00:00:00.000000000 Z
11
+ date: 2016-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '4.0'
20
+ - - "~>"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '4.0'
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: activesupport
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
- - - "~>"
37
+ - - ">="
32
38
  - !ruby/object:Gem::Version
33
39
  version: '4.0'
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '5.0'
34
43
  type: :runtime
35
44
  prerelease: false
36
45
  version_requirements: !ruby/object:Gem::Requirement
37
46
  requirements:
38
- - - "~>"
47
+ - - ">="
39
48
  - !ruby/object:Gem::Version
40
49
  version: '4.0'
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '5.0'
41
53
  - !ruby/object:Gem::Dependency
42
54
  name: actionview
43
55
  requirement: !ruby/object:Gem::Requirement
44
56
  requirements:
45
- - - "~>"
57
+ - - ">="
46
58
  - !ruby/object:Gem::Version
47
59
  version: '4.0'
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '5.0'
48
63
  type: :runtime
49
64
  prerelease: false
50
65
  version_requirements: !ruby/object:Gem::Requirement
51
66
  requirements:
52
- - - "~>"
67
+ - - ">="
53
68
  - !ruby/object:Gem::Version
54
69
  version: '4.0'
70
+ - - "~>"
71
+ - !ruby/object:Gem::Version
72
+ version: '5.0'
55
73
  - !ruby/object:Gem::Dependency
56
74
  name: bundler
57
75
  requirement: !ruby/object:Gem::Requirement
@@ -100,12 +118,7 @@ email:
100
118
  executables: []
101
119
  extensions: []
102
120
  extra_rdoc_files: []
103
- files:
104
- - README.md
105
- - lib/sortabl.rb
106
- - lib/sortabl/sortabl_core.rb
107
- - lib/sortabl/sortabl_helper.rb
108
- - lib/sortabl/version.rb
121
+ files: []
109
122
  homepage: https://github.com/freder1c/sortabl
110
123
  licenses:
111
124
  - MIT
data/README.md DELETED
@@ -1,106 +0,0 @@
1
- # Sortabl
2
-
3
- A Rails Plugin to simplify sorting tables.
4
-
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- ```ruby
10
- gem 'sortabl'
11
- ```
12
-
13
- ## Basic Usage
14
-
15
- ### Controller
16
-
17
- #### Default
18
-
19
- ```ruby
20
- @posts = Post.sortabl(params[:sortabl])
21
- ```
22
-
23
- And that's it! Records will be sorted by permitted parameter `:sortabl`. If parameter `:sortabl` isn't permitted, records will be sorted by primary key. If you don't want to sort by primary key as default, you can set another one by:
24
-
25
- ```ruby
26
- @posts = Post.sortabl(params[:sortabl], default: [author: :asc])
27
- ```
28
-
29
- Even default multiple columns sort is possible:
30
-
31
- ```ruby
32
- @posts = Post.sortabl(params[:sortabl], default: [author: :asc, created_at: :desc])
33
- ```
34
-
35
- #### Limeted Attributes
36
-
37
- Permitted values can be an attribute of model class, followed by `_asc` or `_desc`. For example: `sort: :author_asc`
38
- If there's an attribute permitted which doesn't exist in model, it falls back to sort by `default` key. Attributes can be limited with `only` and `except`. For example:
39
-
40
- ```ruby
41
- @posts = Post.sortabl(params[:sortabl], only: [:title, :author])
42
- # or
43
- @posts = Post.sortabl(params[:sortabl], except: [:text])
44
- ```
45
-
46
-
47
- ### View
48
-
49
- #### Link Helper
50
-
51
- There's also a link helper, which generates needed urls. It works just like you would expect from rails default link_to helper. But instead of hand over a path, just place the desired column name. The helper will do the rest for you:
52
-
53
- ```erb
54
- <table>
55
- <thead>
56
- <th><%= sortabl_link 'Author', :author, id: 'author-column', class: 'author-column' %></th>
57
- </thead>
58
- <tbody>
59
- ...
60
- </tbody>
61
- </table>
62
-
63
- # Will be rendered to:
64
- <table>
65
- <thead>
66
- <th><a id="author-column" class="sortabl author-column" href="/posts?sortabl=author_asc">Author</a></th>
67
- # or
68
- <th><a id="author-column" class="sortabl asc author-column" href="/posts?sortabl=author_desc">Author</a></th>
69
- # or
70
- <th><a id="author-column" class="sortabl desc author-column" href="/posts">Author</a></th>
71
- </thead>
72
- <tbody>
73
- ...
74
- </tbody>
75
- </table>
76
- ```
77
-
78
- This link helper can be placed anywhere in the view. There is no need, that it has to be placed in table head. Furthermore you can use `sortabl_link` as block too.
79
-
80
- ```erb
81
- <%= sortabl_link :author, id: 'author-column', class: 'author-column' do %>
82
- <p>Author</p>
83
- <% end %>
84
- ```
85
-
86
- #### Parameter
87
-
88
- By default, `sortabl_link` will generate `:sortabl` as parameter into the url. If you need to change name of the parameter, you can do so by simply:
89
-
90
- ```ruby
91
- # In view
92
- <%= sortabl_link 'Author', :author, sort_param: :my_custom_sort_param %>
93
-
94
- # In controller
95
- @posts = Post.sortabl(params[:my_custom_sort_param], only: [:title, :author])
96
- ```
97
-
98
- Which hyperlink will be rendered, depends on permitted values.
99
- Gem works also fine with pagination like [will_paginate](https://github.com/mislav/will_paginate).
100
-
101
- Happy sorting ;)
102
-
103
- ## License
104
-
105
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
106
-
@@ -1,45 +0,0 @@
1
- module Sortabl
2
- module ActiveRecordExtensions
3
- module Sortabl
4
-
5
- extend ActiveSupport::Concern
6
-
7
- module ClassMethods
8
-
9
- def sortabl parameter, *args
10
-
11
- # Init
12
- unless args.empty?
13
- default = args[0][:default]
14
- only = args[0][:only]
15
- except = args[0][:except]
16
- end
17
-
18
- raise ArgumentError.new("Invalid Parameters: Do not use 'only' and 'except' together!") if only.present? and except.present?
19
-
20
- # Set default order attribute
21
- # default:
22
- order_by_default = default.present? ? default : self.primary_key
23
-
24
- # Extract column name and direction from parameter
25
- if parameter.present?
26
- column_name = parameter.to_s.gsub(/(_asc$|_desc$)/, '')
27
- direction = parameter.to_s.gsub(/^((?!desc$|asc$).)*/, '')
28
-
29
- # Sort by default if column_name is not included in only or column_name is included in except
30
- return order((order_by_default)) if only.present? and !only.include? column_name.to_sym
31
- return order((order_by_default)) if except.present? and except.include? column_name.to_sym
32
- end
33
-
34
- # Convert param_value to symbol
35
- sort_column = { column_name.to_sym => direction.to_sym } if column_name.present? and direction.present?
36
-
37
- # Order class object
38
- order((sort_column or order_by_default))
39
- end
40
-
41
- end
42
-
43
- end
44
- end
45
- end
@@ -1,45 +0,0 @@
1
- module Sortabl
2
- module ActionViewExtensions
3
- module SortablHelper
4
-
5
- # Renders sortabl link
6
- #
7
- def sortabl_link(name = nil, attribute = nil, html_options = nil, &block)
8
- html_options, attribute, name = attribute, name, block if block_given?
9
- html_options = html_options || {}
10
-
11
- # Support custom sort_param
12
- # If sort_param isn't given, fall back to :sortabl as param
13
- sort_param = html_options[:sort_param] || :sortabl
14
- html_options.except!(:sort_param)
15
-
16
- # Remove current sortabl param from url and add default sortabl param
17
- sortabl_params = params.except(sort_param)
18
- sortabl_params[sort_param] = "#{attribute}_asc"
19
-
20
- # If there was already a sortabl param, invert direction or remove sortabl param
21
- if params[sort_param].present?
22
- if attribute.to_s == params[sort_param].gsub(/(_asc$|_desc$)/, '')
23
- sort_direction = params[sort_param].gsub(/^((?!desc$|asc$).)*/, '')
24
-
25
- sortabl_params[sort_param] = "#{attribute}_desc" if sort_direction == 'asc'
26
- sortabl_params[sort_param] = nil if sort_direction == 'desc'
27
- end
28
- end
29
-
30
- # Add sortabl html class to html_options
31
- html_options[:class] = 'sortabl' + (sort_direction.present? ? " #{sort_direction}" : "") + (html_options[:class].present? ? " #{html_options[:class]}" : "")
32
-
33
- # Support remote true
34
- html_options.except!(:remote).merge!({'data-remote': 'true'}) if html_options[:remote]
35
-
36
- # Generate url from params
37
- url = url_for(sortabl_params)
38
- html_options["href".freeze] ||= url
39
-
40
- content_tag("a".freeze, name || url, html_options, &block)
41
- end
42
-
43
- end
44
- end
45
- end
@@ -1,3 +0,0 @@
1
- module Sortabl
2
- VERSION = "0.5.0"
3
- end
data/lib/sortabl.rb DELETED
@@ -1,9 +0,0 @@
1
- require "sortabl/version"
2
- require "sortabl/sortabl_core"
3
- require "sortabl/sortabl_helper"
4
-
5
- # Extend ActiveRecord's functionality
6
- ActiveRecord::Base.send :include, Sortabl::ActiveRecordExtensions::Sortabl
7
-
8
- # You can do this here or in a Railtie
9
- ActionView::Base.send :include, Sortabl::ActionViewExtensions::SortablHelper