Module: Showbuilder::Corekit
- Included in:
- Showbuilder
- Defined in:
- lib/showbuilder/corekit.rb
Instance Method Summary collapse
- #call_object_methods(object, methods) ⇒ Object
- #contents_tag(tag_name, options = {}, &block) ⇒ Object
- #currency_string(number) ⇒ Object
- #date_string(date) ⇒ Object
- #divc(option_class, &block) ⇒ Object
- #html_contents ⇒ Object
- #merge_class_option(original, another) ⇒ Object
- #percent_string(number) ⇒ Object
- #safe_html_string(text) ⇒ Object
- #time_string(time) ⇒ Object
Instance Method Details
#call_object_methods(object, methods) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/showbuilder/corekit.rb', line 4 def call_object_methods(object, methods) unless object return end methods = Array.wrap(methods) if methods.count == 0 return end first_method = methods.first unless first_method return end unless object.respond_to?(first_method) return end method_result = object.send(first_method) if methods.count <= 1 return method_result else remaining_methods = methods.clone remaining_methods.shift return call_object_methods(method_result, remaining_methods) end end |
#contents_tag(tag_name, options = {}, &block) ⇒ Object
50 51 52 53 54 |
# File 'lib/showbuilder/corekit.rb', line 50 def contents_tag(tag_name, = {}, &block) self.content_tag tag_name, do self.html_contents(&block) end end |
#currency_string(number) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/showbuilder/corekit.rb', line 60 def currency_string(number) if number number_to_currency(number) else '' end end |
#date_string(date) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/showbuilder/corekit.rb', line 68 def date_string(date) case date when Date I18n.l(date) when Time time = date date = time.to_date I18n.l(date) else date.to_s end end |
#divc(option_class, &block) ⇒ Object
56 57 58 |
# File 'lib/showbuilder/corekit.rb', line 56 def divc(option_class, &block) contents_tag :div, :class => option_class , &block end |
#html_contents ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/showbuilder/corekit.rb', line 37 def html_contents contents = [] result = yield contents if contents.count > 0 return contents.join(' ').html_safe end if result.respond_to?(:html_safe) return result.html_safe end end |
#merge_class_option(original, another) ⇒ Object
33 34 35 |
# File 'lib/showbuilder/corekit.rb', line 33 def merge_class_option(original, another) "#{original} #{another}".strip end |
#percent_string(number) ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/showbuilder/corekit.rb', line 81 def percent_string(number) if number number_to_percentage(number, :precision => 2) else '' end end |
#safe_html_string(text) ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/showbuilder/corekit.rb', line 97 def safe_html_string(text) if text.is_a?(String) text.gsub(/\n/, "<br/>").html_safe else text.to_s end end |
#time_string(time) ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/showbuilder/corekit.rb', line 89 def time_string(time) if time I18n.l(time) else '' end end |