active-list 4.2.4 → 5.0.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 +7 -0
- data/VERSION +1 -1
- data/{lib → app}/assets/images/active-list.png +0 -0
- data/app/assets/images/active-list.svg +415 -0
- data/{lib/assets/javascripts/active-list.jquery.js → app/assets/javascripts/active_list.jquery.js} +2 -2
- data/app/assets/stylesheets/active_list.css.scss +7 -0
- data/{lib/active-list/compass/stylesheets/active-list/_background.scss → app/assets/stylesheets/active_list/background.scss} +10 -8
- data/{lib/active-list/compass/stylesheets/active-list/_minimal.scss → app/assets/stylesheets/active_list/minimal.scss} +16 -16
- data/{lib/active-list/compass/stylesheets/active-list/_theme.scss → app/assets/stylesheets/active_list/theme.scss} +37 -37
- data/lib/active-list.rb +1 -37
- data/lib/active_list.rb +43 -0
- data/lib/active_list/action_pack.rb +46 -0
- data/lib/active_list/definition.rb +17 -0
- data/lib/active_list/definition/abstract_column.rb +54 -0
- data/lib/active_list/definition/action_column.rb +76 -0
- data/lib/active_list/definition/association_column.rb +80 -0
- data/lib/active_list/definition/attribute_column.rb +58 -0
- data/lib/active_list/definition/check_box_column.rb +17 -0
- data/lib/active_list/definition/data_column.rb +88 -0
- data/lib/active_list/definition/empty_column.rb +10 -0
- data/lib/active_list/definition/field_column.rb +20 -0
- data/lib/active_list/definition/status_column.rb +10 -0
- data/lib/active_list/definition/table.rb +159 -0
- data/lib/active_list/definition/text_field_column.rb +10 -0
- data/lib/active_list/exporters.rb +28 -0
- data/lib/active_list/exporters/abstract_exporter.rb +55 -0
- data/lib/active_list/exporters/csv_exporter.rb +32 -0
- data/lib/active_list/exporters/excel_csv_exporter.rb +38 -0
- data/lib/active_list/exporters/open_document_spreadsheet_exporter.rb +82 -0
- data/lib/active_list/generator.rb +122 -0
- data/lib/active_list/generator/finder.rb +150 -0
- data/lib/active_list/helpers.rb +33 -0
- data/lib/{active-list → active_list}/rails/engine.rb +3 -2
- data/lib/active_list/renderers.rb +25 -0
- data/lib/active_list/renderers/abstract_renderer.rb +29 -0
- data/lib/active_list/renderers/simple_renderer.rb +356 -0
- metadata +74 -55
- data/lib/active-list/action_pack.rb +0 -48
- data/lib/active-list/columns/action_column.rb +0 -83
- data/lib/active-list/columns/data_column.rb +0 -151
- data/lib/active-list/columns/field_column.rb +0 -29
- data/lib/active-list/compass/stylesheets/_active-list.scss +0 -7
- data/lib/active-list/definition.rb +0 -103
- data/lib/active-list/exporters.rb +0 -71
- data/lib/active-list/exporters/csv_exporter.rb +0 -30
- data/lib/active-list/exporters/excel_csv_exporter.rb +0 -36
- data/lib/active-list/exporters/open_document_spreadsheet_exporter.rb +0 -81
- data/lib/active-list/finder.rb +0 -134
- data/lib/active-list/generator.rb +0 -88
- data/lib/active-list/renderers.rb +0 -28
- data/lib/active-list/renderers/simple_renderer.rb +0 -335
- data/lib/assets/stylesheets/active-list.css.scss +0 -7
metadata
CHANGED
@@ -1,95 +1,103 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active-list
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
NC4yLjQ=
|
6
|
-
prerelease:
|
4
|
+
version: 5.0.0
|
7
5
|
platform: ruby
|
8
6
|
authors:
|
9
7
|
- Brice Texier
|
10
8
|
autorequire:
|
11
9
|
bindir: bin
|
12
10
|
cert_chain: []
|
13
|
-
date:
|
11
|
+
date: 2014-03-25 00:00:00.000000000 Z
|
14
12
|
dependencies:
|
15
13
|
- !ruby/object:Gem::Dependency
|
16
14
|
name: rails
|
17
15
|
requirement: !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
16
|
requirements:
|
20
|
-
- -
|
17
|
+
- - '>='
|
21
18
|
- !ruby/object:Gem::Version
|
22
|
-
version: '3.
|
19
|
+
version: '3.2'
|
20
|
+
- - <
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '4.1'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
26
|
requirements:
|
28
|
-
- -
|
27
|
+
- - '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.2'
|
30
|
+
- - <
|
29
31
|
- !ruby/object:Gem::Version
|
30
|
-
version: '
|
32
|
+
version: '4.1'
|
31
33
|
- !ruby/object:Gem::Dependency
|
32
34
|
name: compass-rails
|
33
35
|
requirement: !ruby/object:Gem::Requirement
|
34
|
-
none: false
|
35
36
|
requirements:
|
36
|
-
- -
|
37
|
+
- - ~>
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 1.1.7
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 1.1.7
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rubyzip
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - '>='
|
37
52
|
- !ruby/object:Gem::Version
|
38
|
-
version: '1'
|
53
|
+
version: '1.0'
|
39
54
|
type: :runtime
|
40
55
|
prerelease: false
|
41
56
|
version_requirements: !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
57
|
requirements:
|
44
|
-
- -
|
58
|
+
- - '>='
|
45
59
|
- !ruby/object:Gem::Version
|
46
|
-
version: '1'
|
60
|
+
version: '1.0'
|
47
61
|
- !ruby/object:Gem::Dependency
|
48
62
|
name: fastercsv
|
49
63
|
requirement: !ruby/object:Gem::Requirement
|
50
|
-
none: false
|
51
64
|
requirements:
|
52
|
-
- -
|
65
|
+
- - '>='
|
53
66
|
- !ruby/object:Gem::Version
|
54
67
|
version: '1.5'
|
55
68
|
type: :runtime
|
56
69
|
prerelease: false
|
57
70
|
version_requirements: !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
71
|
requirements:
|
60
|
-
- -
|
72
|
+
- - '>='
|
61
73
|
- !ruby/object:Gem::Version
|
62
74
|
version: '1.5'
|
63
75
|
- !ruby/object:Gem::Dependency
|
64
76
|
name: i18n-complements
|
65
77
|
requirement: !ruby/object:Gem::Requirement
|
66
|
-
none: false
|
67
78
|
requirements:
|
68
|
-
- -
|
79
|
+
- - '>='
|
69
80
|
- !ruby/object:Gem::Version
|
70
81
|
version: '0'
|
71
82
|
type: :runtime
|
72
83
|
prerelease: false
|
73
84
|
version_requirements: !ruby/object:Gem::Requirement
|
74
|
-
none: false
|
75
85
|
requirements:
|
76
|
-
- -
|
86
|
+
- - '>='
|
77
87
|
- !ruby/object:Gem::Version
|
78
88
|
version: '0'
|
79
89
|
- !ruby/object:Gem::Dependency
|
80
90
|
name: sqlite3
|
81
91
|
requirement: !ruby/object:Gem::Requirement
|
82
|
-
none: false
|
83
92
|
requirements:
|
84
|
-
- -
|
93
|
+
- - '>='
|
85
94
|
- !ruby/object:Gem::Version
|
86
95
|
version: '0'
|
87
96
|
type: :development
|
88
97
|
prerelease: false
|
89
98
|
version_requirements: !ruby/object:Gem::Requirement
|
90
|
-
none: false
|
91
99
|
requirements:
|
92
|
-
- -
|
100
|
+
- - '>='
|
93
101
|
- !ruby/object:Gem::Version
|
94
102
|
version: '0'
|
95
103
|
description: Generates action methods to provide clean tables.
|
@@ -103,51 +111,62 @@ files:
|
|
103
111
|
- LICENSE
|
104
112
|
- README.rdoc
|
105
113
|
- VERSION
|
114
|
+
- app/assets/images/active-list.png
|
115
|
+
- app/assets/images/active-list.svg
|
116
|
+
- app/assets/javascripts/active_list.jquery.js
|
117
|
+
- app/assets/stylesheets/active_list.css.scss
|
118
|
+
- app/assets/stylesheets/active_list/background.scss
|
119
|
+
- app/assets/stylesheets/active_list/minimal.scss
|
120
|
+
- app/assets/stylesheets/active_list/theme.scss
|
106
121
|
- lib/active-list.rb
|
107
|
-
- lib/
|
108
|
-
- lib/
|
109
|
-
- lib/
|
110
|
-
- lib/
|
111
|
-
- lib/
|
112
|
-
- lib/
|
113
|
-
- lib/
|
114
|
-
- lib/
|
115
|
-
- lib/
|
116
|
-
- lib/
|
117
|
-
- lib/
|
118
|
-
- lib/
|
119
|
-
- lib/
|
120
|
-
- lib/
|
121
|
-
- lib/
|
122
|
-
- lib/
|
123
|
-
- lib/
|
124
|
-
- lib/
|
125
|
-
- lib/
|
126
|
-
- lib/
|
127
|
-
- lib/
|
122
|
+
- lib/active_list.rb
|
123
|
+
- lib/active_list/action_pack.rb
|
124
|
+
- lib/active_list/definition.rb
|
125
|
+
- lib/active_list/definition/abstract_column.rb
|
126
|
+
- lib/active_list/definition/action_column.rb
|
127
|
+
- lib/active_list/definition/association_column.rb
|
128
|
+
- lib/active_list/definition/attribute_column.rb
|
129
|
+
- lib/active_list/definition/check_box_column.rb
|
130
|
+
- lib/active_list/definition/data_column.rb
|
131
|
+
- lib/active_list/definition/empty_column.rb
|
132
|
+
- lib/active_list/definition/field_column.rb
|
133
|
+
- lib/active_list/definition/status_column.rb
|
134
|
+
- lib/active_list/definition/table.rb
|
135
|
+
- lib/active_list/definition/text_field_column.rb
|
136
|
+
- lib/active_list/exporters.rb
|
137
|
+
- lib/active_list/exporters/abstract_exporter.rb
|
138
|
+
- lib/active_list/exporters/csv_exporter.rb
|
139
|
+
- lib/active_list/exporters/excel_csv_exporter.rb
|
140
|
+
- lib/active_list/exporters/open_document_spreadsheet_exporter.rb
|
141
|
+
- lib/active_list/generator.rb
|
142
|
+
- lib/active_list/generator/finder.rb
|
143
|
+
- lib/active_list/helpers.rb
|
144
|
+
- lib/active_list/rails/engine.rb
|
145
|
+
- lib/active_list/renderers.rb
|
146
|
+
- lib/active_list/renderers/abstract_renderer.rb
|
147
|
+
- lib/active_list/renderers/simple_renderer.rb
|
128
148
|
homepage: http://github.com/burisu/active-list
|
129
149
|
licenses:
|
130
150
|
- MIT
|
151
|
+
metadata: {}
|
131
152
|
post_install_message:
|
132
153
|
rdoc_options: []
|
133
154
|
require_paths:
|
134
155
|
- lib
|
135
156
|
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
-
none: false
|
137
157
|
requirements:
|
138
|
-
- -
|
158
|
+
- - '>='
|
139
159
|
- !ruby/object:Gem::Version
|
140
160
|
version: '0'
|
141
161
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
|
-
none: false
|
143
162
|
requirements:
|
144
|
-
- -
|
163
|
+
- - '>='
|
145
164
|
- !ruby/object:Gem::Version
|
146
165
|
version: '0'
|
147
166
|
requirements: []
|
148
167
|
rubyforge_project:
|
149
|
-
rubygems_version:
|
168
|
+
rubygems_version: 2.0.14
|
150
169
|
signing_key:
|
151
|
-
specification_version:
|
170
|
+
specification_version: 4
|
152
171
|
summary: Easy tables in Rails app
|
153
172
|
test_files: []
|
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'action_controller'
|
2
|
-
require 'action_view'
|
3
|
-
|
4
|
-
module ActiveList
|
5
|
-
|
6
|
-
module ActionController
|
7
|
-
|
8
|
-
def self.included(base) #:nodoc:
|
9
|
-
base.extend(ClassMethods)
|
10
|
-
end
|
11
|
-
|
12
|
-
module ClassMethods
|
13
|
-
# Permits to define and generate methods to manage dynamic
|
14
|
-
# table ActiveList
|
15
|
-
def list(*args, &block)
|
16
|
-
name, options = nil, {}
|
17
|
-
name = args[0] if args[0].is_a? Symbol
|
18
|
-
options = args[-1] if args[-1].is_a? Hash
|
19
|
-
name ||= self.controller_name.to_sym
|
20
|
-
model = (options[:model]||name).to_s.classify.constantize
|
21
|
-
options[:controller_method_name] = "list#{'_'+name.to_s if name != self.controller_name.to_sym}"
|
22
|
-
options[:view_method_name] = "_#{self.controller_name}_list_#{name}_tag"
|
23
|
-
options[:records_variable_name] = "@#{name}"
|
24
|
-
table = ActiveList::Table.new(name, model, options)
|
25
|
-
if block_given?
|
26
|
-
yield table
|
27
|
-
else
|
28
|
-
table.load_default_columns
|
29
|
-
end
|
30
|
-
|
31
|
-
class_eval(table.send(:generate_controller_method_code), __FILE__, __LINE__)
|
32
|
-
ActionView::Base.send(:class_eval, table.send(:generate_view_method_code), __FILE__, __LINE__)
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
module ViewsHelper
|
40
|
-
def list(*args, &block)
|
41
|
-
name, options = nil, {}
|
42
|
-
name = args[0] if args[0].is_a? Symbol
|
43
|
-
options = args[-1] if args[-1].is_a? Hash
|
44
|
-
self.send("_#{options[:controller]||self.controller_name}_#{__method__}_#{name||self.controller_name}_tag", &block)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
@@ -1,83 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
module ActiveList
|
3
|
-
|
4
|
-
class Table
|
5
|
-
|
6
|
-
# Add a new method in Table which permit to define data columns
|
7
|
-
def action(name, options = {})
|
8
|
-
@columns << ActionColumn.new(self, name, options)
|
9
|
-
end
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
class ActionColumn < Column
|
14
|
-
|
15
|
-
def header_code
|
16
|
-
"''"
|
17
|
-
end
|
18
|
-
|
19
|
-
|
20
|
-
def operation(record = 'record')
|
21
|
-
@options[:method] = :delete if @name.to_s == "destroy" and !@options.has_key?(:method)
|
22
|
-
@options[:confirm] = :are_you_sure_you_want_to_delete if @name.to_s == "destroy" and !@options.has_key?(:confirm)
|
23
|
-
link_options = ""
|
24
|
-
if @options['data-confirm'] or @options[:confirm]
|
25
|
-
link_options << ", 'data-confirm' => ::I18n.translate('labels.#{@options['data-confirm']||@options[:confirm]}')"
|
26
|
-
end
|
27
|
-
if @options['data-method'] or @options[:method]
|
28
|
-
link_options << ", :method => h('#{(@options['data-method']||@options[:method])}')"
|
29
|
-
end
|
30
|
-
action = @name
|
31
|
-
format = @options[:format] ? ", :format=>'#{@options[:format]}'" : ""
|
32
|
-
if @options[:remote]
|
33
|
-
raise Exception.new("Sure to use :remote ?")
|
34
|
-
remote_options = @options.dup
|
35
|
-
remote_options['data-confirm'] = ::I18n.translate('labels.'+@options[:confirm].to_s) unless @options[:confirm].nil?
|
36
|
-
remote_options.delete :remote
|
37
|
-
remote_options.delete :image
|
38
|
-
remote_options = remote_options.inspect.to_s
|
39
|
-
remote_options = remote_options[1..-2]
|
40
|
-
code = "link_to_remote(#{image}"
|
41
|
-
code += ", {:url=>{:action=>:"+@name.to_s+", :id=>"+record+".id"+format+"}"
|
42
|
-
code += ", "+remote_options+"}"
|
43
|
-
code += ", {:title=>::I18n.translate('labels.#{action}')}"
|
44
|
-
code += ")"
|
45
|
-
elsif @options[:actions]
|
46
|
-
raise Exception.new("options[:actions] have to be a Hash.") unless @options[:actions].is_a? Hash
|
47
|
-
cases = []
|
48
|
-
for a in @options[:actions]
|
49
|
-
v = a[1][:action].to_s.split('_')[-1]
|
50
|
-
cases << record+"."+@name.to_s+".to_s=="+a[0].inspect+"\nlink_to(content_tag(:i) + h(::I18n.translate('labels.#{v}'))"+
|
51
|
-
", {"+(a[1][:controller] ? ':controller=>:'+a[1][:controller].to_s+', ' : '')+":action=>'"+a[1][:action].to_s+"', :id=>"+record+".id"+format+"}"+
|
52
|
-
# ", {:id=>'"+@name.to_s+"_'+"+record+".id.to_s"+link_options+"}"+
|
53
|
-
", {:class=>'#{@name}'"+link_options+"}"+
|
54
|
-
")\n"
|
55
|
-
end
|
56
|
-
|
57
|
-
code = "if "+cases.join("elsif ")+"end"
|
58
|
-
else
|
59
|
-
url = @options[:url] ||= {}
|
60
|
-
url[:controller] ||= @options[:controller]||self.table.model.name.underscore.pluralize.to_sym
|
61
|
-
url[:action] ||= @name
|
62
|
-
url[:id] ||= "RECORD.id"
|
63
|
-
url.delete_if{|k, v| v.nil?}
|
64
|
-
url = "{"+url.collect{|k, v| ":#{k}=>"+(v.is_a?(String) ? v.gsub(/RECORD/, record) : v.inspect)}.join(", ")+format+"}"
|
65
|
-
# code = "{:id=>'"+@name.to_s+"_'+"+record+".id.to_s"+link_options+"}"
|
66
|
-
code = "{:class=>'#{@name}'"+link_options+"}"
|
67
|
-
code = "link_to(content_tag(:i) + h(::I18n.translate('labels.#{action}')), "+url+", "+code+")"
|
68
|
-
end
|
69
|
-
if @options[:if]
|
70
|
-
code = "if (" + (@options[:if].is_a?(Symbol) ? "#{record}.#{@options[:if]}" : @options[:if].to_s.gsub('RECORD', record)) + ")\n" + code + "\n end"
|
71
|
-
end
|
72
|
-
if @options[:unless]
|
73
|
-
code = "unless (" + (@options[:unless].is_a?(Symbol) ? "#{record}.#{@options[:unless]}" : @options[:unless].to_s.gsub('RECORD', record)) + ")\n" + code + "\n end"
|
74
|
-
end
|
75
|
-
code
|
76
|
-
end
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
end
|
82
|
-
|
83
|
-
end
|
@@ -1,151 +0,0 @@
|
|
1
|
-
module ActiveList
|
2
|
-
|
3
|
-
class Table
|
4
|
-
|
5
|
-
# Retrieves all columns in database
|
6
|
-
def table_columns
|
7
|
-
cols = self.model_columns.collect{|c| c.name}
|
8
|
-
@columns.select{|c| c.is_a? DataColumn and cols.include? c.name.to_s}
|
9
|
-
end
|
10
|
-
|
11
|
-
def data_columns
|
12
|
-
@columns.select{|c| c.is_a? DataColumn}
|
13
|
-
end
|
14
|
-
|
15
|
-
# Add a new method in Table which permit to define data columns
|
16
|
-
def column(name, options={})
|
17
|
-
@columns << DataColumn.new(self, name, options)
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
class DataColumn < Column
|
23
|
-
|
24
|
-
def header_code
|
25
|
-
if @options[:label].is_a? String
|
26
|
-
"::I18n.translate('labels.#{@options[:label].strip}')"
|
27
|
-
elsif through = @options[:through]
|
28
|
-
through = [through] unless through.is_a? Array
|
29
|
-
model, reflection = @table.model, nil
|
30
|
-
for ref in through
|
31
|
-
unless reflection.nil?
|
32
|
-
model = reflection.class_name.constantize rescue nil
|
33
|
-
end
|
34
|
-
raise Exception.new("Unknown model #{reflection.class_name}") if model.nil?
|
35
|
-
reflection = model.reflections[ref]
|
36
|
-
raise Exception.new("Unknown reflection :#{ref} (#{through.inspect}) for the ActiveRecord: "+model.name) if reflection.nil?
|
37
|
-
end
|
38
|
-
"#{model.name}.human_attribute_name('#{reflection.name}')"
|
39
|
-
else
|
40
|
-
"#{@table.model.name}.human_attribute_name('#{@name}')"
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
|
45
|
-
# Code for rows
|
46
|
-
def datum_code(record='rekord', child = false)
|
47
|
-
code = if child and @options[:children].is_a? Symbol
|
48
|
-
"#{record}.#{@options[:children]}"
|
49
|
-
elsif child and @options[:children].is_a? FalseClass
|
50
|
-
"nil"
|
51
|
-
elsif through = @options[:through] and !child
|
52
|
-
through = [through] unless through.is_a?(Array)
|
53
|
-
foreign_record = record
|
54
|
-
through.each { |x| foreign_record += '.'+x.to_s }
|
55
|
-
"(#{foreign_record}.#{@name} rescue nil)"
|
56
|
-
else
|
57
|
-
"#{record}.#{@name}"
|
58
|
-
end
|
59
|
-
return code
|
60
|
-
end
|
61
|
-
|
62
|
-
# Code for exportation
|
63
|
-
def exporting_datum_code(record='rekord', noview=false)
|
64
|
-
datum = self.datum_code(record)
|
65
|
-
if self.datatype == :boolean
|
66
|
-
datum = "(#{datum} ? ::I18n.translate('list.export.true_value') : ::I18n.translate('list.export.false_value'))"
|
67
|
-
elsif self.datatype == :date
|
68
|
-
datum = "(#{datum}.nil? ? '' : ::I18n.localize(#{datum}))"
|
69
|
-
elsif self.datatype == :decimal and not noview
|
70
|
-
currency = nil
|
71
|
-
if currency = self.options[:currency]
|
72
|
-
currency = currency[:body] if currency.is_a?(Hash)
|
73
|
-
currency = :currency if currency.is_a?(TrueClass)
|
74
|
-
currency = "RECORD.#{currency}" if currency.is_a?(Symbol)
|
75
|
-
raise Exception.new("Option :currency is not valid. Hash, Symbol or true/false") unless currency.is_a?(String)
|
76
|
-
end
|
77
|
-
datum = "(#{datum}.nil? ? '' : ::I18n.localize(#{datum}#{', :currency=>'+currency.gsub(/RECORD/, record) if currency}))"
|
78
|
-
elsif @name.to_s.match(/(^|\_)currency$/) and self.datatype == :string and self.limit == 3
|
79
|
-
datum = "(#{datum}.nil? ? '' : ::I18n.currency_label(#{datum}))"
|
80
|
-
elsif @name==:country and self.datatype == :string and self.limit == 2
|
81
|
-
datum = "(#{datum}.nil? ? '' : ::I18n.translate('countries.'+#{datum}))"
|
82
|
-
elsif @name==:language and self.datatype == :string and self.limit <= 8
|
83
|
-
datum = "(#{datum}.nil? ? '' : ::I18n.translate('languages.'+#{datum}))"
|
84
|
-
elsif self.enumerize?
|
85
|
-
datum = "(#{datum}.nil? ? '' : #{datum}.text)"
|
86
|
-
end
|
87
|
-
return datum
|
88
|
-
end
|
89
|
-
|
90
|
-
# Returns the data type of the column if the column is in the database
|
91
|
-
def datatype
|
92
|
-
@options[:datatype] || (@column ? @column.type : nil)
|
93
|
-
end
|
94
|
-
|
95
|
-
|
96
|
-
def enumerize?
|
97
|
-
if self.table.model.respond_to?(@name) and !@options[:through]
|
98
|
-
if self.table.model.method(@name).arity.zero?
|
99
|
-
if self.table.model.send(@name).respond_to?(:values)
|
100
|
-
return true
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
return false
|
105
|
-
end
|
106
|
-
|
107
|
-
def numeric?
|
108
|
-
[:decimal, :integer, :float, :numeric].include? self.datatype
|
109
|
-
end
|
110
|
-
|
111
|
-
# Returns the size/length of the column if the column is in the database
|
112
|
-
def limit
|
113
|
-
@column.limit if @column
|
114
|
-
end
|
115
|
-
|
116
|
-
|
117
|
-
# Returns the class name of the used model
|
118
|
-
def class_name
|
119
|
-
klass = self.table.model
|
120
|
-
if through = @options[:through]
|
121
|
-
through = [through] unless through.is_a? Array
|
122
|
-
for ref in through
|
123
|
-
klass = klass.reflections[ref].class_name.constantize
|
124
|
-
end
|
125
|
-
end
|
126
|
-
return klass.name
|
127
|
-
end
|
128
|
-
|
129
|
-
# Defines if column is exportable
|
130
|
-
def exportable?
|
131
|
-
true
|
132
|
-
end
|
133
|
-
|
134
|
-
# Check if a column is sortable
|
135
|
-
def sortable?
|
136
|
-
#not self.action? and
|
137
|
-
not self.options[:through] and not @column.nil?
|
138
|
-
end
|
139
|
-
|
140
|
-
# Generate code in order to get the (foreign) record of the column
|
141
|
-
def record_expr(record='record')
|
142
|
-
if @options[:through]
|
143
|
-
return ([record]+[@options[:through]]).flatten.join(".")
|
144
|
-
else
|
145
|
-
return record
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
end
|
150
|
-
|
151
|
-
end
|