Module: WeatherIcons::Rails::IconHelpers
- Defined in:
- lib/weather-icons/rails/helpers.rb
Defined Under Namespace
Modules: Private
Instance Method Summary collapse
-
#wi_icon(names = "flag", options = {}) ⇒ Object
Creates an icon tag given an icon name and possible icon modifiers.
-
#wi_list(icon_name, strings, options = {}) ⇒ Object
Creates an unordered list with the specified icon as the markers.
-
#wi_list_item(icon_name, string, options = {}) ⇒ Object
Creates a list item with the specified icon as the marker.
-
#wi_stacked_icon(names = "flag", options = {}) ⇒ Object
Creates an stack set of icon tags given a base icon name, a main icon name, and possible icon modifiers.
Instance Method Details
#wi_icon(names = "flag", options = {}) ⇒ Object
Creates an icon tag given an icon name and possible icon modifiers.
Examples
wi_icon "day-hail"
# => <i class="wi wi-day-hail"></i>
wi_icon "day-hail", text: "Hailing Outside!"
# => <i class="wi wi-day-hail"></i> Hailing Outside
wi_icon "day-hail 2x"
# => <i class="wi wi-day-hail wi-2x"></i>
wi_icon ["day-hail", "4x"]
# => <i class="wi wi-day-hail wi-4x"></i>
wi_icon "wi-day-hail spin lg"
# => <i class="wi wi-day-hail wi-spin wi-lg">
wi_icon "day-hail 4x", class: "pull-left"
# => <i class="wi wi-day-hail wi-4x pull-left"></i>
wi_icon "day-hail", data: { id: 123 }
# => <i class="wi wi-day-hail" data-id="123"></i>
content_tag(:li, wi_icon("day-hail li", text: "Bulleted list item"))
# => <li><i class="wi wi-day-hail wi-li"></i> Bulleted list item</li>
30 31 32 33 34 35 36 37 |
# File 'lib/weather-icons/rails/helpers.rb', line 30 def wi_icon(names = "flag", = {}) classes = ['wi'] classes.concat Private.icon_names(names) classes.concat Array(.delete(:class)) text = .delete(:text) icon = content_tag(:i, nil, .merge(:class => classes)) Private.icon_join(icon, text) end |
#wi_list(icon_name, strings, options = {}) ⇒ Object
Creates an unordered list with the specified icon as the markers.
Examples
wi_list('day-hail', ['Bad Weather', 'Good Weather'])
# => <ul class: 'wi-ul'>
# => <li>
# => <i class="wi wi-day-hail wi-li"></i> Bad Weather
# => </li>
# => <li>
# => <i class="wi wi-day-hail wi-li"></i> Good Weather
# => </li>
# => </ul>
wi_list('day-hail lg', ['Bad Weather', 'Good Weather'], icon_options: {class: 'pull-right'}, class: 'something' )
# => <ul class: 'wi-ul'>
# => <li class="something">
# => <i class="wi wi-day-hail wi-lg wi-li pull-right"></i> Bad Weather
# => </li>
# => <li class="something">
# => <i class="wi wi-day-hail wi-lg wi-li pull-right"></i> Good Weather
# => </li>
# => </ul>
112 113 114 115 |
# File 'lib/weather-icons/rails/helpers.rb', line 112 def wi_list(icon_name, strings, ={}) list_items = strings.map { |str| wi_list_item(icon_name, str, ) } content_tag(:ul, safe_join(list_items), class: Private.icon_names('ul')) end |
#wi_list_item(icon_name, string, options = {}) ⇒ Object
Creates a list item with the specified icon as the marker. To be used with an ul tag having a class of wi-ul
Examples
wi_list_item('day-hail', 'Bad Weather Today')
# => <li><i class="wi wi-day-hail wi-li"></i> Bad Weather Today</li>
wi_list_item('day-hail md', 'Bad Weather Today', icon_options: {class: 'inverse'}, class: 'something' )
# => <li class="something"><i class="wi wi-day-hail wi-md wi-li inverse"></i> Bad Weather Today</li>
84 85 86 87 |
# File 'lib/weather-icons/rails/helpers.rb', line 84 def wi_list_item(icon_name, string, ={}) = {text: string}.merge(Hash([:icon_options])) content_tag(:li, wi_icon("#{icon_name} li", ), .reject{|key,value| key == :icon_options}) end |
#wi_stacked_icon(names = "flag", options = {}) ⇒ Object
Creates an stack set of icon tags given a base icon name, a main icon name, and possible icon modifiers.
Examples
wi_stacked_icon "day-hail", base: "day-cloudy-gusts"
# => <span class="wi-stack">
# => <i class="wi wi-day-cloudy-gusts wi-stack-2x"></i>
# => <i class="wi wi-day-hail wi-stack-1x"></i>
# => </span>
wi_stacked_icon "day-hail inverse", base: "lightning", class: "pull-right", text: "Hi!"
# => <span class="wi-stack pull-right">
# => <i class="wi wi-lightning wi-stack-2x"></i>
# => <i class="wi wi-day-hail wi-inverse wi-stack-1x"></i>
# => </span> Hi!
wi_stacked_icon "lightning", base: "day-cloudy-gusts", reverse: true
# => <span class="wi-stack">
# => <i class="wi wi-lightning wi-stack-1x"></i>
# => <i class="wi wi-day-cloudt-gusts wi-stack-2x"></i>
# => </span>
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/weather-icons/rails/helpers.rb', line 61 def wi_stacked_icon(names = "flag", = {}) classes = Private.icon_names("stack").concat(Array(.delete(:class))) base_names = Private.array_value(.delete(:base) || "wi-lightning").push("stack-2x") names = Private.array_value(names).push("stack-1x") base = wi_icon(base_names, .delete(:base_options) || {}) icon = wi_icon(names, .delete(:icon_options) || {}) icons = [base, icon] icons.reverse! if .delete(:reverse) text = .delete(:text) stacked_icon = content_tag(:span, safe_join(icons), .merge(:class => classes)) Private.icon_join(stacked_icon, text) end |