sorting_table_for 0.2.0 → 0.2.1
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.
- data/CHANGELOG.mdown +4 -0
- data/init.rb +0 -4
- data/lib/sorting_table_for.rb +3 -0
- data/lib/sorting_table_for/format_cell.rb +189 -0
- data/lib/sorting_table_for/format_line.rb +110 -0
- data/lib/sorting_table_for/i18n.rb +16 -9
- data/lib/sorting_table_for/model_scope.rb +76 -0
- data/lib/sorting_table_for/table_builder.rb +15 -306
- data/spec/db/schema.rb +1 -1
- data/spec/fixtures/{user.rb → sorting_table_for_user.rb} +2 -2
- data/spec/helpers/builder_spec.rb +8 -5
- data/spec/helpers/caption_spec.rb +7 -4
- data/spec/helpers/cell_value_spec.rb +7 -4
- data/spec/helpers/column_spec.rb +14 -11
- data/spec/helpers/footer_spec.rb +7 -4
- data/spec/helpers/header_spec.rb +33 -8
- data/spec/helpers/i18n_spec.rb +12 -7
- data/spec/locales/test.yml +11 -2
- data/spec/locales/test_rails3.yml +6 -4
- data/spec/model/sorting_table_model_scope_spec.rb +24 -18
- data/spec/spec_helper.rb +18 -0
- metadata +7 -15
- data/lib/model/sorting_table_model_scope.rb +0 -72
data/spec/spec_helper.rb
CHANGED
@@ -56,6 +56,24 @@ module SortingTableForSpecHelper
|
|
56
56
|
include ActiveSupport
|
57
57
|
include SortingTableFor
|
58
58
|
|
59
|
+
def routes_rails2
|
60
|
+
ActionController::Routing::Routes.clear!
|
61
|
+
ActionController::Routing::Routes.draw do |map|
|
62
|
+
map.resources :sorting_table_for_users, :member => { :edit_password => :get }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def routes_rails3
|
67
|
+
Rails.application.routes.clear!
|
68
|
+
Rails.application.routes.draw do
|
69
|
+
resources :sorting_table_for_users do
|
70
|
+
member do
|
71
|
+
get :edit_password
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
59
77
|
def have_comp_tag(selector, options = {})
|
60
78
|
if ::SortingTableFor::Tools::rails3?
|
61
79
|
if options.has_key? :text
|
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sorting_table_for
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 2
|
8
|
-
- 0
|
9
|
-
version: 0.2.0
|
4
|
+
prerelease:
|
5
|
+
version: 0.2.1
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Thomas Floch
|
@@ -27,14 +23,16 @@ extensions: []
|
|
27
23
|
extra_rdoc_files:
|
28
24
|
- README.mdown
|
29
25
|
files:
|
30
|
-
- lib/
|
26
|
+
- lib/sorting_table_for/format_cell.rb
|
27
|
+
- lib/sorting_table_for/format_line.rb
|
31
28
|
- lib/sorting_table_for/i18n.rb
|
29
|
+
- lib/sorting_table_for/model_scope.rb
|
32
30
|
- lib/sorting_table_for/table_builder.rb
|
33
31
|
- lib/sorting_table_for/tools.rb
|
34
32
|
- lib/sorting_table_for.rb
|
35
33
|
- spec/db/database.yml
|
36
34
|
- spec/db/schema.rb
|
37
|
-
- spec/fixtures/
|
35
|
+
- spec/fixtures/sorting_table_for_user.rb
|
38
36
|
- spec/helpers/builder_spec.rb
|
39
37
|
- spec/helpers/caption_spec.rb
|
40
38
|
- spec/helpers/cell_value_spec.rb
|
@@ -71,23 +69,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
71
69
|
requirements:
|
72
70
|
- - ">="
|
73
71
|
- !ruby/object:Gem::Version
|
74
|
-
segments:
|
75
|
-
- 0
|
76
72
|
version: "0"
|
77
73
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
74
|
none: false
|
79
75
|
requirements:
|
80
76
|
- - ">="
|
81
77
|
- !ruby/object:Gem::Version
|
82
|
-
segments:
|
83
|
-
- 1
|
84
|
-
- 3
|
85
|
-
- 4
|
86
78
|
version: 1.3.4
|
87
79
|
requirements: []
|
88
80
|
|
89
81
|
rubyforge_project: sorting_table_for
|
90
|
-
rubygems_version: 1.
|
82
|
+
rubygems_version: 1.5.2
|
91
83
|
signing_key:
|
92
84
|
specification_version: 3
|
93
85
|
summary: A Rails table builder made to easily create and sort a table
|
@@ -1,72 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module SortingTableModelScope
|
4
|
-
|
5
|
-
# Include the methods in models
|
6
|
-
def self.included(base)
|
7
|
-
base.extend(SingletonMethods)
|
8
|
-
end
|
9
|
-
|
10
|
-
module SingletonMethods
|
11
|
-
|
12
|
-
# Return a scope of the object with an order
|
13
|
-
#
|
14
|
-
# === Usage
|
15
|
-
#
|
16
|
-
# sorting_table(the params) - Sorting by the given parameters
|
17
|
-
# sorting_table(the params, column name) - Sort by the column name with direction ascending, if no parameters
|
18
|
-
# sorting_table(the params, column name, direction) - Sort by the column name with the given direction, if no parameters
|
19
|
-
#
|
20
|
-
# === Exemples
|
21
|
-
#
|
22
|
-
# User.sorting_table(params)
|
23
|
-
# User.sorting_table(params, :username)
|
24
|
-
# User.sorting_table(params, :username, :desc)
|
25
|
-
#
|
26
|
-
def sorting_table(*args)
|
27
|
-
raise ArgumentError, 'sorting_table: Too many arguments (max : 3)' if args.size > 3
|
28
|
-
sort_table_param = get_sorting_table_params(args)
|
29
|
-
return scoped({}) if !sort_table_param and args.size == 1
|
30
|
-
sort, direction = get_sort_and_direction(sort_table_param, args)
|
31
|
-
return scoped({}) if !sort or !valid_column?(sort) or !valid_direction?(direction)
|
32
|
-
scoped({ :order => "#{sort} #{direction}" })
|
33
|
-
end
|
34
|
-
|
35
|
-
private
|
36
|
-
|
37
|
-
# Return the params for sorting table
|
38
|
-
def get_sorting_table_params(args)
|
39
|
-
return nil unless args.first.is_a? Hash
|
40
|
-
return nil unless args.first.has_key? SortingTableFor::TableBuilder.params_sort_table.to_s
|
41
|
-
args.first[SortingTableFor::TableBuilder.params_sort_table.to_s]
|
42
|
-
end
|
43
|
-
|
44
|
-
# Parse the params and return the column name and the direction
|
45
|
-
def get_sort_and_direction(sort_table_param, args)
|
46
|
-
if sort_table_param
|
47
|
-
key = sort_table_param.keys.first rescue nil
|
48
|
-
value = sort_table_param.values.first rescue nil
|
49
|
-
return nil if !key.is_a?(String) or !value.is_a?(String)
|
50
|
-
return key, value
|
51
|
-
end
|
52
|
-
return nil if args.size < 2
|
53
|
-
return args[1], 'asc' if args.size == 2
|
54
|
-
return args[1], args[2]
|
55
|
-
end
|
56
|
-
|
57
|
-
# Return true if the column name exist
|
58
|
-
def valid_column?(column)
|
59
|
-
column_names.include? column.to_s.downcase
|
60
|
-
end
|
61
|
-
|
62
|
-
# Return true if the direction exist
|
63
|
-
def valid_direction?(direction)
|
64
|
-
%[asc desc].include? direction.to_s.downcase
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
if defined? ActiveRecord
|
71
|
-
ActiveRecord::Base.send :include, SortingTableModelScope
|
72
|
-
end
|