table_for_helper 0.21 → 0.25
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/table_for_helper/builder.rb +19 -4
- data/lib/table_for_helper/version.rb +1 -1
- metadata +2 -2
@@ -6,7 +6,12 @@ module TableForHelper
|
|
6
6
|
def initialize collection, options = nil
|
7
7
|
@collection = collection
|
8
8
|
@options = options.symbolize_keys
|
9
|
-
|
9
|
+
if options.has_key?(:model)
|
10
|
+
@model = options[:model]
|
11
|
+
options.delete :model
|
12
|
+
else
|
13
|
+
@model = collection.first.class
|
14
|
+
end
|
10
15
|
|
11
16
|
@head = {}
|
12
17
|
@body = {}
|
@@ -16,6 +21,11 @@ module TableForHelper
|
|
16
21
|
yield self if block_given?
|
17
22
|
end
|
18
23
|
|
24
|
+
# Get a localized attribute name
|
25
|
+
def attribute_name attribute
|
26
|
+
@model.methods.include?(:human_attribute_name) ? @model.human_attribute_name(attribute) : attribute.to_s
|
27
|
+
end
|
28
|
+
|
19
29
|
# Add a new column to the table
|
20
30
|
def column name, title = nil, options = nil, &block
|
21
31
|
# Move a value from the title to options variable for 2 params usage
|
@@ -27,11 +37,11 @@ module TableForHelper
|
|
27
37
|
# Take a title for this column from the dictionary
|
28
38
|
if !title
|
29
39
|
# A title for a reference
|
30
|
-
if name.is_a?
|
40
|
+
if name.is_a?(Class) && name.methods.include?(:model_name)
|
31
41
|
title = name.model_name.human
|
32
|
-
# A title for
|
42
|
+
# A title for a model attribute
|
33
43
|
else
|
34
|
-
title =
|
44
|
+
title = attribute_name name
|
35
45
|
end
|
36
46
|
end
|
37
47
|
|
@@ -51,6 +61,11 @@ module TableForHelper
|
|
51
61
|
@footer_options[name] = options if options
|
52
62
|
end
|
53
63
|
|
64
|
+
# Get a localized model name
|
65
|
+
def model_name options = {}
|
66
|
+
@model.methods.include?(:human_attribute_name) ? @model.model_name.human(options) : @model.to_s
|
67
|
+
end
|
68
|
+
|
54
69
|
# Generate a html
|
55
70
|
def to_html
|
56
71
|
# Add all model attributes if no block given
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: table_for_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.25'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-24 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A Rails helper for generating tables from resources collections.
|
15
15
|
email:
|