Module: Prepro::Presenter::DecoratorMixin
- Defined in:
- lib/prepro/presenter.rb
Instance Method Summary collapse
-
#decorated_time_ago_in_words(a_datetime, options = {}) ⇒ Object
Renders time ago, showing absolute time on hover @param a_datetime the time to render @param[Hash, optional] options: * :suffix => printed after the time, default: ‘ ago’ * :suppress_1 => if the number is a one, suppress it.
-
#decorated_time_from_now_in_words(a_datetime, options = {}) ⇒ Object
Renders time from now, showing absolute time on hover @param a_datetime the time to render @param[Hash, optional] options: * :prefix => printed before the time, default: ‘in ’ * :suppress_1 => if the number is a one, suppress it.
- #formatted_boolean(a_boolean) ⇒ Object
-
#formatted_datetime(a_datetime, output_format, options = {}) ⇒ Object
Formats a_datetime @param[DateTime, Nil] a_datetime the datetime to format @param output_format the format to be applied: :distance_in_words, or any datetime format specified in initializers.
- #indicate_blank ⇒ Object
- #presenter_attrs ⇒ Object
- #presenter_attrs=(the_presenter_attrs) ⇒ Object
Instance Method Details
#decorated_time_ago_in_words(a_datetime, options = {}) ⇒ Object
Renders time ago, showing absolute time on hover @param a_datetime the time to render @param[Hash, optional] options:
* :suffix => printed after the time, default: ' ago'
* :suppress_1 => if the number is a one, suppress it. Used for '... in the last month', which
reads better than '... in the last 1 month'
* :text_only => skip html tags
134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/prepro/presenter.rb', line 134 def decorated_time_ago_in_words(a_datetime, = {}) = { :suffix => ' ago', :suppress_1 => false, :text_only => false }.merge() ts = ((presenter_attrs.view_context.time_ago_in_words(a_datetime).gsub('about ', '') + [:suffix]) rescue 'N/A') ts = ts.gsub(/^1\s+/, '') if [:suppress_1] if [:text_only] ts else presenter_attrs.view_context.content_tag(:span, ts, :title => a_datetime.to_s(:full_date_and_time)) end end |
#decorated_time_from_now_in_words(a_datetime, options = {}) ⇒ Object
Renders time from now, showing absolute time on hover @param a_datetime the time to render @param[Hash, optional] options:
* :prefix => printed before the time, default: 'in '
* :suppress_1 => if the number is a one, suppress it. Used for '... in the last month', which
reads better than '... in the last 1 month'
* :text_only => skip html tags
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/prepro/presenter.rb', line 156 def decorated_time_from_now_in_words(a_datetime, = {}) = { :prefix => 'in ', :suppress_1 => false, :text_only => false }.merge() ts = ( ( [:prefix] + presenter_attrs.view_context.time_ago_in_words(a_datetime).gsub('about ', '') ) rescue 'N/A' ) ts = ts.gsub(/^1\s+/, '') if [:suppress_1] if [:text_only] ts else presenter_attrs.view_context.content_tag(:span, ts, :title => a_datetime.to_s(:full_date_and_time)) end end |
#formatted_boolean(a_boolean) ⇒ Object
175 176 177 |
# File 'lib/prepro/presenter.rb', line 175 def formatted_boolean(a_boolean) a_boolean ? 'Yes' : 'No' end |
#formatted_datetime(a_datetime, output_format, options = {}) ⇒ Object
Formats a_datetime @param[DateTime, Nil] a_datetime the datetime to format @param output_format the format to be applied: :distance_in_words,
or any datetime format specified in initializers
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/prepro/presenter.rb', line 111 def formatted_datetime(a_datetime, output_format, = {}) return 'N/A' if a_datetime.blank? case output_format when :distance_in_words if a_datetime < Time.now # in the past decorated_time_ago_in_words(a_datetime, ) else # in the future decorated_time_from_now_in_words(a_datetime, ) end else a_datetime.to_s(output_format) end end |
#indicate_blank ⇒ Object
179 180 181 |
# File 'lib/prepro/presenter.rb', line 179 def indicate_blank presenter_attrs.view_context.content_tag :span, "None Given", :class => 'label' end |
#presenter_attrs ⇒ Object
103 104 105 |
# File 'lib/prepro/presenter.rb', line 103 def presenter_attrs @presenter_attrs end |
#presenter_attrs=(the_presenter_attrs) ⇒ Object
99 100 101 |
# File 'lib/prepro/presenter.rb', line 99 def presenter_attrs=(the_presenter_attrs) @presenter_attrs = the_presenter_attrs end |