king_views 1.1.0 → 1.1.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/README.rdoc CHANGED
@@ -1,14 +1,11 @@
1
1
  = KingViews
2
2
 
3
- This is the new offical home of KingViews(forked from schorsch)
4
-
5
3
  KingViews where extracted from SalesKing(https://www.SalesKing.eu) and consist
6
- of three different view helpers, KingForm( dl || labeled forms, enhanced inputs ),
4
+ of three different view helpers, KingForm( dl or labeled forms, enhanced inputs ),
7
5
  KingList( dl, tables ) and KingFormat( date, money, percent )
8
6
 
9
- This stuff is not optimized(yet) to run seamlessly within any rails project.
10
- Fixes for rails 2.3.5 and of course 3.0 are needed. Some refacturing and of
11
- course testing(still stuck in SalesKing) should be done, leaving space for forks.
7
+ This stuff is not tested with rails 3.0 and testing is still stuck in SalesKing
8
+ .. leaving space for forks.
12
9
 
13
10
  == Install
14
11
 
@@ -89,4 +86,4 @@ Also see README http://github.com/salesking/king_views/tree/master/king_format/
89
86
  # see above for usage in views
90
87
 
91
88
  == License
92
- Copyright (c) 2009 Georg Leciejewski, released under the MIT-LICENSE
89
+ Copyright (c) 2009,2010 Georg Leciejewski, released under the MIT-LICENSE
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.1.1
@@ -270,7 +270,7 @@ module KingForm
270
270
  title = options.delete(:title) || build_title(fieldname)
271
271
  value = options.delete(:value) || @template.strfval(current_object, fieldname)
272
272
 
273
- if info_text = options.delete(:info) #add info tag if info test given
273
+ if info_text = options.delete(:info) #add info tag if info given
274
274
  value << info_tag(info_text)
275
275
  end
276
276
  #keep existing class and add class right to wrapping element if its a money field
@@ -3,8 +3,11 @@ module KingFormat
3
3
  module FormattingHelper
4
4
 
5
5
  include ActionView::Helpers::NumberHelper
6
+
6
7
  # Get a nice formatted string for an object attribute value.
7
8
  #
9
+ # ====
10
+ #
8
11
  # ==== Parameters
9
12
  # object<Object>:: The object on which the given fld name will be called
10
13
  # => object.send(fld), to get the value
@@ -15,20 +18,33 @@ module KingFormat
15
18
  # opts<Hash{Symbol=>String}>:: Options
16
19
  #
17
20
  # ==== Options opts
18
- # currency<Hash{Symbol=>String}>:: Currency settings to format string as a money like found in rails I18n.
19
- # or see rails number_helper.
20
- # When set, object AND fld must be set and the field must be in money_fields (via: has_money_fields)
21
- # Alternatively you can call the method with currency options set which will also lead to money rendering
22
- # format -> defaults to :html returned html string has escaped html entities
21
+ # :currency<Hash{Symbol=>String}>:: Currency settings to format string as
22
+ # money like found in rails I18n(see rails number_helper)
23
+ # Leads to money rendering when set.
24
+ # :format<Symbol>:: when set to :html returns string with escaped html entities
23
25
  #
24
26
  # ==== AutoDetect Types
25
27
  # A value is formatted according to its type which we try to detect.
26
28
  # <Symbol>:: assume a value from acts_as_enum
27
29
  # <DateTime|Time|Date>::I18n.localize -> l(value)
28
- # <TrueClass|FalseClass>:: translate to yes / no
29
- # <MoneyField String>:: coming from a has_percent_fields, formats the number with number_to_percentage_auto_precision
30
- # <PercentField String>:: comming from has_money_fields I18n formats as money string
31
- #
30
+ # Used if value is a Date class, field is declared in has_date_fields, or
31
+ # opts[:date] is set
32
+ # <TrueClass|FalseClass>:: translates to yes/no in sk namespace t(:'sk.yes')
33
+ # <PercentField|String>:: coming from a has_percent_fields, formats the
34
+ # number with number_to_percentage_auto_precision
35
+ # <MoneyField|String>:: Used if opts[:currency] is set OR field is defined
36
+ # via has_money_fields.
37
+ # Formats the value as money string using different formatting fallbacks:
38
+ # 1. options passed in via :currency=>{..}
39
+ # 2. if object and val are present AND the object has a method called:
40
+ # "fieldname"_format_opts => price_format_opts
41
+ # It's return value(Hash{Rails currency format opts} is used.
42
+ # This should be used if you have a default format for all money vals, but
43
+ # one differs eg. in precision
44
+ # 3. @default_currency_format
45
+ # 4. I18n actually resided in rails
46
+ # Whatever you use be aware to always pass all formatting options since rails
47
+ # merges unavailable keys with i18n defaults
32
48
  def strfval (object, fld, val=nil, opts={})
33
49
  # If no value given, call fld on object to get the current value
34
50
  #return the content(a pointer) or an empty string OR nil of field is not available
@@ -45,10 +61,13 @@ module KingFormat
45
61
  elsif (object.class.is_percent_field?(fld) rescue nil)
46
62
  (val && !val.blank?) ? number_to_percentage_auto_precision(val) : ''
47
63
  elsif (object.class.is_money_field?(fld) rescue nil) || opts[:currency]
48
- # field is defined as money field OR currency options are passed in
49
- strfmoney(val, opts[:currency])
64
+ # field is defined as money field OR currency options are passed in
65
+ method_name = "#{fld}_format_opts".to_sym
66
+ # check if the object has a custom money format method => price_total_format_opts
67
+ fopts = object.send(method_name) if object && object.respond_to?(method_name)
68
+ strfmoney(val, fopts || opts[:currency])
50
69
  elsif ( val.is_a?(Date) || (object.class.is_date_field?(fld) rescue nil) || opts[:date] )
51
- # field is defined as date field OR date options are passed in
70
+ # field is defined as date field OR date options are passed in
52
71
  return val if val.blank? # blank value can occur when a is_date_field is empty
53
72
  # get date from opts or default or fallback into i18n
54
73
  format = opts[:date] || default_date_format
@@ -66,8 +85,11 @@ module KingFormat
66
85
  end
67
86
  end #strfval
68
87
 
69
- # Formats the given value using rails number_to_currency. Get currency
88
+ # Formats the given value using rails number_to_currency. Get's currency
70
89
  # from options hash or @default_currency_format or i18n as fallback
90
+ # === Params
91
+ # val<Number>:: the number to format
92
+ # opts<Hash{Symbol=>String}>:: Rails compatible currency formatting options
71
93
  def strfmoney(val, opts={})
72
94
  settings = opts || default_currency_format
73
95
  number_to_currency(val, settings.merge({:locale => I18n.locale}))
@@ -81,6 +103,7 @@ module KingFormat
81
103
 
82
104
  # Returns the default date formatting.
83
105
  # The returned string is passed to strftime(format)
106
+ # Override this function somehere in you controllers or set the instance var
84
107
  # === Returns
85
108
  # <String>:: strftime compatible string
86
109
  def default_date_format
@@ -88,7 +111,8 @@ module KingFormat
88
111
  end
89
112
 
90
113
  # Returns the default currency formatting
91
- # The returned hash is used in rails number_to_currency helper
114
+ # The returned hash is used in rails number_to_currency helper.
115
+ # Override this function somehere in you controllers or set the instance var
92
116
  # === Returns
93
117
  # <Hash>:: number_to_currency compatible options hash
94
118
  def default_currency_format
@@ -34,7 +34,7 @@ module KingFormat
34
34
  # ==== Parameter
35
35
  # fieldname<String>:: The fieldname to check. Is casted into a symbol.
36
36
  def is_money_field?(fieldname)
37
- self.class.money_fields.include?(fieldname.to_sym)
37
+ self.class.is_money_field?(fieldname)
38
38
  end
39
39
  end
40
40
 
data/king_views.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{king_views}
8
- s.version = "1.1.0"
8
+ s.version = "1.1.1"
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-09-25}
12
+ s.date = %q{2010-10-07}
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 = [
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: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
- - 0
10
- version: 1.1.0
9
+ - 1
10
+ version: 1.1.1
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-09-25 00:00:00 +02:00
18
+ date: 2010-10-07 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies: []
21
21