Module: Undercase::ApplicationHelper
- Defined in:
- app/helpers/undercase/application_helper.rb
Defined Under Namespace
Classes: Dropdown
Instance Method Summary collapse
- #content_with_toolbar(toolbar_links) ⇒ Object
- #dropdown(link_text, options = {}, &block) ⇒ Object
- #inline_message(type, content_or_options_with_block = nil, options = nil, &block) ⇒ Object
- #length_of_time(from_date, current_date = Date.today) ⇒ Object
Instance Method Details
#content_with_toolbar(toolbar_links) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'app/helpers/undercase/application_helper.rb', line 14 def () content = content_tag(:div) do yield end = content_tag(:div, .join.html_safe, class: 'toolbar') = content + content_tag(:div, .html_safe, class: 'content-with-toolbar') end |
#dropdown(link_text, options = {}, &block) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'app/helpers/undercase/application_helper.rb', line 5 def dropdown(link_text, = {}, &block) contents = capture(&block) placement = .fetch(:placement) { "left" } dropdown = Dropdown.new(link_text, placement, contents) render "undercase/popups/dropdown", dropdown: dropdown end |
#inline_message(type, content_or_options_with_block = nil, options = nil, &block) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/helpers/undercase/application_helper.rb', line 23 def (type, = nil, = nil, &block) raise ArgumentError unless [:notice, :pending, :warning, :severe, :success].include?(type) if block_given? = else content = end ||= {} [:class] = ["inline-#{type}", [:class]].compact.join(" ") if block_given? content_tag(:div, , &block) else content_tag(:div, content, ) end end |
#length_of_time(from_date, current_date = Date.today) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/helpers/undercase/application_helper.rb', line 42 def length_of_time(from_date, current_date = Date.today) time_hash = distance_of_time_in_words_hash(from_date, current_date) time_hash = convert_one_year_to_months(time_hash) time_hash = convert_years_to_half_years(time_hash) ["years", "months", "days"].each do |unit| distance = time_hash[unit] if distance && distance > 0 result = '%{distance} %{unit}' if unit == "months" unit = "mos" result += '.' end unit = unit.singularize if distance <= 1 return (result % { unit: unit, distance: distance }).gsub('.5',' ½') end end "1 #{I18n.t(:days, default: "days").singularize}" end |