king_views 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +20 -0
- data/VERSION +1 -1
- data/king_format/lib/helpers/formatting_helper.rb +54 -17
- data/king_list/lib/king_list/list_helper.rb +5 -5
- data/king_views.gemspec +4 -3
- metadata +5 -4
data/.gitignore
ADDED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.2
|
@@ -45,7 +45,7 @@ module KingFormat
|
|
45
45
|
# 4. I18n actually resided in rails
|
46
46
|
# Whatever you use be aware to always pass all formatting options since rails
|
47
47
|
# merges unavailable keys with i18n defaults
|
48
|
-
def strfval
|
48
|
+
def strfval( object, fld, val=nil, opts={} )
|
49
49
|
# If no value given, call fld on object to get the current value
|
50
50
|
#return the content(a pointer) or an empty string OR nil of field is not available
|
51
51
|
val ||= object.respond_to?(fld) ? ( object.send(fld) || '') : nil
|
@@ -54,7 +54,7 @@ module KingFormat
|
|
54
54
|
nil
|
55
55
|
elsif val.is_a?(Symbol) # enum value from acts_as_enum
|
56
56
|
translated_enum_value(object, fld, val)
|
57
|
-
elsif val.is_a?(DateTime) || val.is_a?(Time)
|
57
|
+
elsif val.is_a?(DateTime) || val.is_a?(Time)
|
58
58
|
I18n.localize(val)
|
59
59
|
elsif val.is_a?(TrueClass) || val.is_a?(FalseClass)
|
60
60
|
val ? t(:'sk.yes') : t(:'sk.no')
|
@@ -62,13 +62,13 @@ module KingFormat
|
|
62
62
|
(val && !val.blank?) ? number_to_percentage_auto_precision(val) : ''
|
63
63
|
elsif (object.class.is_money_field?(fld) rescue nil) || opts[:currency]
|
64
64
|
# field is defined as money field OR currency options are passed in
|
65
|
-
|
65
|
+
format_method = "#{fld}_format_opts".to_sym
|
66
66
|
# check if the object has a custom money format method => price_total_format_opts
|
67
|
-
fopts = object
|
68
|
-
strfmoney(val, fopts
|
67
|
+
fopts = object && object.respond_to?(format_method) ? object.send(format_method) : opts[:currency]
|
68
|
+
strfmoney(val, fopts)
|
69
69
|
elsif ( val.is_a?(Date) || (object.class.is_date_field?(fld) rescue nil) || opts[:date] )
|
70
70
|
# field is defined as date field OR date options are passed in
|
71
|
-
return val if val.blank? # blank value can occur when a is_date_field is empty
|
71
|
+
return val if val.blank? # blank value can occur when a is_date_field is empty
|
72
72
|
# get date from opts or default or fallback into i18n
|
73
73
|
format = opts[:date] || default_date_format
|
74
74
|
format.blank? ? ::I18n.localize(val) : val.strftime(format)
|
@@ -89,9 +89,10 @@ module KingFormat
|
|
89
89
|
# from options hash or @default_currency_format or i18n as fallback
|
90
90
|
# === Params
|
91
91
|
# val<Number>:: the number to format
|
92
|
-
# opts<Hash{Symbol=>String}>:: Rails compatible currency formatting options
|
93
|
-
|
94
|
-
|
92
|
+
# opts<Hash{Symbol=>String}>:: Rails compatible currency formatting options,
|
93
|
+
# when nil searches default format, last exit is rails i18n
|
94
|
+
def strfmoney(val, opts=nil)
|
95
|
+
settings = opts || default_currency_format || {}
|
95
96
|
number_to_currency(val, settings.merge({:locale => I18n.locale}))
|
96
97
|
end
|
97
98
|
|
@@ -100,23 +101,60 @@ module KingFormat
|
|
100
101
|
::ActiveSupport::Deprecation.warn('"formatted_value" has been deprecated, use the "strfval" instead. Func will be removed within next releases', caller)
|
101
102
|
strfval(object, fld, val, opts)
|
102
103
|
end
|
104
|
+
# Formatting as Percentage, but use precision only if needed.
|
105
|
+
# Examples:
|
106
|
+
# number_to_percentage_auto_precision(19)
|
107
|
+
# => 19%
|
108
|
+
# number_to_percentage_auto_precision(7.5)
|
109
|
+
# => 7,5%
|
110
|
+
def number_to_percentage_auto_precision(number)
|
111
|
+
return nil unless number
|
112
|
+
# for now use seperator
|
113
|
+
pres = (number.to_i == number.to_f) ? 0 : 1
|
114
|
+
sep = I18n.t(:'number.format.precision.separator')
|
115
|
+
number_to_percentage(number,{:precision => pres, :separator=>sep } )
|
116
|
+
end
|
103
117
|
|
104
|
-
#
|
118
|
+
# Translate the value of an enum field, as defined by act_as_enum
|
119
|
+
# Example:
|
120
|
+
# client.sending_method = :fax
|
121
|
+
# translated_enum_value(client, :sending_method)
|
122
|
+
# => "activerecord.attributes.client.enum.sending_method.fax"
|
123
|
+
def translated_enum_value(object_or_class, fieldname, value = nil)
|
124
|
+
if object_or_class.is_a?(Class)
|
125
|
+
klass = object_or_class
|
126
|
+
else
|
127
|
+
klass = object_or_class.class
|
128
|
+
# If no value given, get the current value
|
129
|
+
value ||= object_or_class.send(fieldname)
|
130
|
+
end
|
131
|
+
# Don't translate blank value
|
132
|
+
return nil if value.blank?
|
133
|
+
#return the translation
|
134
|
+
klass.human_attribute_name("enum.#{fieldname.to_s}.#{value.to_s}")
|
135
|
+
end
|
136
|
+
|
137
|
+
# Returns the default date formatting, as string '%d.%m.%Y'
|
105
138
|
# The returned string is passed to strftime(format)
|
106
|
-
# Override this function
|
139
|
+
# Override this function or set the thread var somehere in your including
|
140
|
+
# class
|
141
|
+
# => scope when used in view is ActionView::Base
|
107
142
|
# === Returns
|
108
143
|
# <String>:: strftime compatible string
|
109
144
|
def default_date_format
|
110
|
-
|
145
|
+
Thread.current[:default_date_format]
|
111
146
|
end
|
112
147
|
|
113
|
-
# Returns the default currency formatting
|
148
|
+
# Returns the default currency formatting, in I18n style
|
114
149
|
# The returned hash is used in rails number_to_currency helper.
|
115
|
-
# Override this function
|
150
|
+
# Override this function or set the thread var somehere in your including
|
151
|
+
# class
|
152
|
+
# => scope when used in view is ActionView::Base
|
153
|
+
#
|
116
154
|
# === Returns
|
117
155
|
# <Hash>:: number_to_currency compatible options hash
|
118
156
|
def default_currency_format
|
119
|
-
|
157
|
+
Thread.current[:default_currency_format]
|
120
158
|
end
|
121
159
|
|
122
160
|
# Formats a number to the visible decimal places. If there are more decimal
|
@@ -146,6 +184,5 @@ module KingFormat
|
|
146
184
|
"%01.#{precision}f" % rounded_number
|
147
185
|
end
|
148
186
|
|
149
|
-
end # FormattingHelper
|
150
|
-
|
187
|
+
end # FormattingHelper
|
151
188
|
end # KingFormat
|
@@ -83,22 +83,22 @@ module KingList
|
|
83
83
|
# Header linking for all, default
|
84
84
|
# - table_for(@users) do |t, user|
|
85
85
|
# - t.column :name # with sorting
|
86
|
-
# - t.column :email
|
86
|
+
# - t.column :email
|
87
87
|
#
|
88
88
|
# Header linking for all, but exclude individual columns from sorting:
|
89
89
|
# - table_for(@users)do |t, user|
|
90
90
|
# - t.column :name, :sorting => false # without sorting
|
91
|
-
# - t.column :last_name
|
91
|
+
# - t.column :last_name
|
92
92
|
#
|
93
93
|
# NO header linking for all columns:
|
94
94
|
# - table_for(@users, :sorting => false) do |t, user|
|
95
|
-
# - t.column :name
|
96
|
-
# - t.column :email
|
95
|
+
# - t.column :name
|
96
|
+
# - t.column :email
|
97
97
|
#
|
98
98
|
# No header linking for all, but allow sorting for individual columns:
|
99
99
|
# - table_for(@users, :sorting => false) do |t, user|
|
100
100
|
# - t.column :name, :sorting => true # with sorting
|
101
|
-
# - t.column :last_name
|
101
|
+
# - t.column :last_name
|
102
102
|
#
|
103
103
|
def table_for(collection, options={}, html_options={}, &block)
|
104
104
|
return if collection.nil? || collection.empty?
|
data/king_views.gemspec
CHANGED
@@ -5,18 +5,19 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{king_views}
|
8
|
-
s.version = "1.1.
|
8
|
+
s.version = "1.1.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Georg Leciejewski"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-11-01}
|
13
13
|
s.description = %q{Clean up your Forms using king_form for dl or labeled forms. Use king_list for an easy markup of tables in your lists and dl-enabled listings in your detail views. }
|
14
14
|
s.email = %q{gl@salesking.eu}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"README.rdoc"
|
17
17
|
]
|
18
18
|
s.files = [
|
19
|
-
"
|
19
|
+
".gitignore",
|
20
|
+
"CHANGELOG.rdoc",
|
20
21
|
"MIT-LICENSE",
|
21
22
|
"README.rdoc",
|
22
23
|
"Rakefile",
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: king_views
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 1.1.
|
9
|
+
- 2
|
10
|
+
version: 1.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Georg Leciejewski
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-11-01 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -28,6 +28,7 @@ extensions: []
|
|
28
28
|
extra_rdoc_files:
|
29
29
|
- README.rdoc
|
30
30
|
files:
|
31
|
+
- .gitignore
|
31
32
|
- CHANGELOG.rdoc
|
32
33
|
- MIT-LICENSE
|
33
34
|
- README.rdoc
|