Module: Undercase::ApplicationHelper

Defined in:
app/helpers/undercase/application_helper.rb

Defined Under Namespace

Classes: Dropdown

Instance Method Summary collapse

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_with_toolbar(toolbar_links)
  content = (:div) do
    yield
  end
  toolbar = (:div, toolbar_links.join.html_safe, class: 'toolbar')
  content_and_toolbar = content + toolbar
  (:div, content_and_toolbar.html_safe, class: 'content-with-toolbar')
end


5
6
7
8
9
10
11
12
# File 'app/helpers/undercase/application_helper.rb', line 5

def dropdown(link_text, options = {}, &block)
  contents = capture(&block)
  placement = options.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

Raises:

  • (ArgumentError)


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 inline_message(type, content_or_options_with_block = nil, options = nil, &block)
  raise ArgumentError unless [:notice, :pending, :warning, :severe, :success].include?(type)

  if block_given?
    options = content_or_options_with_block
  else
    content = content_or_options_with_block
  end

  options ||= {}
  options[:class] = ["inline-#{type}", options[:class]].compact.join(" ")

  if block_given?
    (:div, options, &block)
  else
    (:div, content, options)
  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