spectabular 2.0.1 → 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/lib/spectabular/helper.rb +34 -20
- data/lib/spectabular/table.rb +9 -13
- data/lib/spectabular/version.rb +1 -1
- metadata +9 -9
data/lib/spectabular/helper.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
module Spectabular
|
2
2
|
module Helper
|
3
|
-
|
3
|
+
|
4
4
|
def table_for(collection,*columns)
|
5
5
|
columns = columns.first if columns.size <= 1
|
6
6
|
columns ||= default_columns_for(collection)
|
7
|
-
@table = Spectabular::Table.new( :collection => instance_variable_get("@#{collection}"),
|
8
|
-
:collection_name => collection.to_s.humanize,
|
9
|
-
:columns => columns,
|
7
|
+
@table = Spectabular::Table.new( :collection => instance_variable_get("@#{collection}"),
|
8
|
+
:collection_name => collection.to_s.humanize,
|
9
|
+
:columns => columns,
|
10
10
|
:context => self
|
11
11
|
)
|
12
12
|
output = []
|
@@ -19,8 +19,8 @@ module Spectabular
|
|
19
19
|
join_formatted output
|
20
20
|
end
|
21
21
|
|
22
|
-
|
23
|
-
|
22
|
+
private
|
23
|
+
|
24
24
|
def join_formatted(array,join_string="\n")
|
25
25
|
join_string.html_safe + safe_join(array, join_string.html_safe ) + join_string.html_safe
|
26
26
|
end
|
@@ -28,34 +28,34 @@ module Spectabular
|
|
28
28
|
def spectabular_header
|
29
29
|
content_tag(:thead, header_row).html_safe
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
def header_row
|
33
33
|
content_tag(:tr, join_formatted(mapped_headers)).html_safe
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
def mapped_headers
|
37
|
-
@table.headers.map do |header|
|
38
|
-
|
37
|
+
@table.headers.map do |header|
|
38
|
+
content_tag(:th, header)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
def spectabular_body
|
43
43
|
content_tag(:tbody, join_formatted(mapped_body)).html_safe
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
def mapped_body
|
47
|
-
@table.rows.map do |record,row|
|
47
|
+
@table.rows.map do |record,row|
|
48
48
|
@column_number = 0
|
49
49
|
content_tag(:tr, join_formatted(mapped_row(row)), :id => dom_id(record), :class => row_class_for(record) )
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
53
|
def mapped_row(row)
|
54
|
-
row.map do |name,cell|
|
54
|
+
row.map do |name,cell|
|
55
55
|
content_tag :td, cell.to_s.html_safe, :class => cell_class_for(name,@column_number+=1)
|
56
56
|
end
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
def row_class_for(record)
|
60
60
|
token = [cycle('odd','even')]
|
61
61
|
is_active = [:active?, :is_active?, :published?].find {|m| record.respond_to? m }
|
@@ -64,16 +64,30 @@ module Spectabular
|
|
64
64
|
end
|
65
65
|
token.join(" ")
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
def cell_class_for(name,column_number)
|
69
69
|
column_number == 1 ? "tbl-#{name} lead" : name
|
70
70
|
end
|
71
71
|
|
72
72
|
def spectabular_pagination
|
73
|
-
return ""
|
74
|
-
content_tag(:p,
|
73
|
+
return "" if pagination_method.nil?
|
74
|
+
content_tag(:p, self.send(pagination_method, @table.collection), :class => 'pagination').html_safe
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
|
+
# Currently supports:
|
78
|
+
# - will_paginate
|
79
|
+
# - kaminari
|
80
|
+
def pagination_method
|
81
|
+
case
|
82
|
+
when self.respond_to?(:will_paginate)
|
83
|
+
:will_paginate
|
84
|
+
when self.respond_to?(:paginate)
|
85
|
+
:paginate
|
86
|
+
else
|
87
|
+
nil
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
77
91
|
def default_columns_for(collection)
|
78
92
|
{}.tap do |columns_hash|
|
79
93
|
collection.to_s.classify.constantize.content_columns.map do |c|
|
@@ -81,7 +95,7 @@ module Spectabular
|
|
81
95
|
end
|
82
96
|
end
|
83
97
|
end
|
84
|
-
|
98
|
+
|
85
99
|
def default_formatting_for(record,name,column_type)
|
86
100
|
attribute = record.send(name)
|
87
101
|
case column_type
|
@@ -95,4 +109,4 @@ module Spectabular
|
|
95
109
|
end
|
96
110
|
|
97
111
|
end
|
98
|
-
end
|
112
|
+
end
|
data/lib/spectabular/table.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Spectabular
|
2
2
|
|
3
3
|
class Table
|
4
|
-
attr_accessor :columns, :skip_sorting_row, :collection, :collection_name, :context
|
4
|
+
attr_accessor :columns, :skip_sorting_row, :collection, :collection_name, :context
|
5
5
|
attr_writer :default_empty
|
6
6
|
|
7
7
|
def initialize(options={})
|
@@ -15,7 +15,7 @@ module Spectabular
|
|
15
15
|
when Array
|
16
16
|
@columns.flatten
|
17
17
|
when Hash
|
18
|
-
sorted_hash_for(@columns).map {|g| {:header => g[0]
|
18
|
+
sorted_hash_for(@columns).map {|g| {:header => header_for(g[0]), :helper => g[1]}}
|
19
19
|
else
|
20
20
|
[@columns]
|
21
21
|
end
|
@@ -59,14 +59,6 @@ module Spectabular
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
-
def will_paginate?
|
63
|
-
if will_paginate.nil?
|
64
|
-
collection_supports_pagination?
|
65
|
-
else
|
66
|
-
will_paginate
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
62
|
def headers
|
71
63
|
@headers ||= columns.map do |column|
|
72
64
|
if column.respond_to? :to_sym
|
@@ -98,9 +90,13 @@ module Spectabular
|
|
98
90
|
items
|
99
91
|
end
|
100
92
|
end
|
101
|
-
|
102
|
-
def
|
103
|
-
|
93
|
+
|
94
|
+
def header_for(name)
|
95
|
+
if name.respond_to?(:sub)
|
96
|
+
name.sub(/^\d+\s?-\s?/,'')
|
97
|
+
else
|
98
|
+
name.to_s.titlecase
|
99
|
+
end
|
104
100
|
end
|
105
101
|
|
106
102
|
end
|
data/lib/spectabular/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spectabular
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: '2.1'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,22 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-04-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &70205170674100 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 3.
|
21
|
+
version: '3.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70205170674100
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: sqlite3
|
27
|
-
requirement: &
|
27
|
+
requirement: &70205170669800 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70205170669800
|
36
36
|
description: Spectabular provides a helper method which turns ActiveModel resources
|
37
37
|
into tabular displays. It provides some minimal customization options.
|
38
38
|
email:
|
@@ -94,7 +94,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
94
94
|
version: '0'
|
95
95
|
segments:
|
96
96
|
- 0
|
97
|
-
hash:
|
97
|
+
hash: -1739884906625239554
|
98
98
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
99
|
none: false
|
100
100
|
requirements:
|
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
103
|
version: '0'
|
104
104
|
segments:
|
105
105
|
- 0
|
106
|
-
hash:
|
106
|
+
hash: -1739884906625239554
|
107
107
|
requirements: []
|
108
108
|
rubyforge_project:
|
109
109
|
rubygems_version: 1.8.11
|