Module: Stay::ApplicationHelper
- Includes:
- CurrencyHelper
- Defined in:
- app/helpers/stay/application_helper.rb
Constant Summary
collapse
- ICON_SIZE =
14
Instance Method Summary
collapse
-
#active_badge(condition, options = {}) ⇒ Object
-
#badge_class(state) ⇒ Object
-
#button_to_with_icon(icon_name, text, url, options = {}) ⇒ Object
-
#icon_class(state) ⇒ Object
-
#link_to_with_icon(icon_name, text, url, options = {}) ⇒ Object
-
#svg_icon(name:, classes: "", width:, height:) ⇒ Object
#currency_options, #currency_presentation, #currency_symbol, #should_render_currency_dropdown?, #supported_currency_options
Instance Method Details
#active_badge(condition, options = {}) ⇒ Object
45
46
47
48
49
50
51
52
53
|
# File 'app/helpers/stay/application_helper.rb', line 45
def active_badge(condition, options = {})
label = options[:label]
label ||= condition ? I18n.t("admin.say_yes") : I18n.t("admin.say_no")
css_class = condition ? "badge-active" : "badge-inactive"
content_tag(:small, class: "badge badge-pill #{css_class}") do
label
end
end
|
#badge_class(state) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'app/helpers/stay/application_helper.rb', line 6
def badge_class(state)
case state
when "approved"
"green"
when "rejected"
"red"
when "accepted"
"orange"
when "confirmed"
"green"
when "booking_request"
"orange"
when "invoice_sent"
"orange"
when "canceled"
"red"
end
end
|
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'app/helpers/stay/application_helper.rb', line 73
def button_to_with_icon(icon_name, text, url, options = {})
options[:class] = (options[:class].to_s + " icon-link with-tip action-#{icon_name}").strip
options[:title] = text if options[:no_text]
text = options[:no_text] ? "" : content_tag(:span, text)
options.delete(:no_text)
options[:width] ||= ICON_SIZE
options[:height] ||= ICON_SIZE
if icon_name
icon = if icon_name.ends_with?(".svg")
svg_icon(name: icon_name, classes: "#{'mr-2' unless text.empty?} icon icon-#{icon_name}", width: options[:width], height: options[:height])
else
content_tag(:span, "", class: "#{'mr-2' unless text.empty?} icon icon-#{icon_name}")
end
text = "#{icon} #{text}".html_safe
end
button_to(text, url, options)
end
|
#icon_class(state) ⇒ Object
25
26
27
28
29
30
31
32
33
34
|
# File 'app/helpers/stay/application_helper.rb', line 25
def icon_class(state)
case state
when "approved"
"icon-check-circle"
when "rejected"
"icon-times-circle"
else
"icon-exclamation-circle"
end
end
|
#link_to_with_icon(icon_name, text, url, options = {}) ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'app/helpers/stay/application_helper.rb', line 55
def link_to_with_icon(icon_name, text, url, options = {})
options[:class] = (options[:class].to_s + " icon-link with-tip action-#{icon_name}").strip
options[:title] = text if options[:no_text]
text = options[:no_text] ? "" : content_tag(:span, text)
options.delete(:no_text)
options[:width] ||= ICON_SIZE
options[:height] ||= ICON_SIZE
if icon_name
icon = if icon_name.ends_with?(".svg")
svg_icon(name: icon_name, classes: "#{'mr-2' unless text.empty?} icon icon-#{icon_name}", width: options[:width], height: options[:height])
else
content_tag(:span, "", class: "#{'mr-2' unless text.empty?} icon icon-#{icon_name}")
end
text = "#{icon} #{text}"
end
link_to(text.html_safe, url, options)
end
|
#svg_icon(name:, classes: "", width:, height:) ⇒ Object
36
37
38
39
40
41
42
43
|
# File 'app/helpers/stay/application_helper.rb', line 36
def svg_icon(name:, classes: "", width:, height:)
if name.ends_with?(".svg")
icon_name = File.basename(name, File.extname(name))
inline_svg_tag "#{icon_name}.svg", class: "icon-#{icon_name} #{classes}", size: "#{width}px*#{height}px"
else
inline_svg_tag "#{name}.svg", class: "icon-#{name} #{classes}", size: "#{width}px*#{height}px"
end
end
|