Module: JapMagWidgetsHelper
- Defined in:
- app/helpers/jap_mag_widgets_helper.rb
Instance Method Summary collapse
- #bootstrap_button_group(checkbox, id = nil, status = nil, default = nil) ⇒ Object
- #bootstrap_menu(links) ⇒ Object
- #bootstrap_scope_button(scopes, options = {}) ⇒ Object
- #bootstrap_stacked_progress_bar(percent, options = {}) ⇒ Object
-
#cta(text, url, options = {}) ⇒ Object
call to action.
- #cta_params(options = {}) ⇒ Object
- #get_body_class ⇒ Object
- #get_body_id ⇒ Object
- #get_wrapper_class ⇒ Object
- #input_for_selection(text) ⇒ Object
- #is_mobile_device? ⇒ Boolean
- #last_deployed_at ⇒ Object
- #link_to_external(text, link, options = {}) ⇒ Object
- #long_date(date) ⇒ Object
- #paginator(collections, options = {}) ⇒ Object
- #retina_image_tag(name_at_1x, options = {}) ⇒ Object
- #short_date(date) ⇒ Object
- #title(*titles) ⇒ Object
Instance Method Details
#bootstrap_button_group(checkbox, id = nil, status = nil, default = nil) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/helpers/jap_mag_widgets_helper.rb', line 82 def checkbox, id = nil, status = nil, default = nil status ||= %w(turned_on turned_off) default ||= "turned_off" content_tag :div, "id" => id, "class" => "bootstrap-toggle" do = content_tag :div, "class" => "btn-group", "data-toggle" => "buttons-radio" do status.collect do |s| content_tag :button, "type" => "button", "class" => "btn btn-default #{s}#{" active" if s == default}", "data-status" => s do _("/page.my.pac.status.#{s}") end end.join.html_safe end + checkbox end end |
#bootstrap_menu(links) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/helpers/jap_mag_widgets_helper.rb', line 49 def links links.collect do |link| klass = [] klass << link[:klass] if link[:klass] klass << "last-child" if link == links.last if (link[:controller_action].is_a?(Array) and current_controller_action_in?(*link[:controller_action])) \ or (current_controller_action_in?(link[:controller_action])) klass << "active" end klass = klass.empty? ? nil : klass.join(" ") content_tag :li, class: klass do link_to link[:text], link[:path], link[:html_options] end end.join.html_safe end |
#bootstrap_scope_button(scopes, options = {}) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/helpers/jap_mag_widgets_helper.rb', line 68 def scopes, = {} content_tag :ul, class: "nav nav-tabs simple-tabs" do scopes.collect do |scope| url = eval("#{[:path].to_s}(scope: :#{scope[:key]})") current = ((params[:scope] == scope[:key].to_s) or (scope[:default] and scope[:default] == true and params[:scope].blank?)) klass = %w(nav-link) klass << :active if current link = link_to("#{content_tag(:span, scope[:text])} (#{scope[:count]})".html_safe, url, class: klass.join(' ')) concat content_tag(:li, link, class: 'nav-item') end end end |
#bootstrap_stacked_progress_bar(percent, options = {}) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'app/helpers/jap_mag_widgets_helper.rb', line 99 def percent, = {} klass = if percent < 50 :success elsif percent >= 50 and percent < 80 :warning else :danger end #percent = "#{percent * 100}%" [:precision] ||= 2 percent = number_to_percentage percent, opts_for_container = {class: :progress} if [:tooltip] placement = [:tooltip][:placement] || "top" opts_for_container.merge!("data-toggle" => "tooltip", "data-placement" => placement, title: [:tooltip][:title]) end content_tag :div, opts_for_container do content_tag :div, class: "progress-bar progress-bar-#{klass}", role: :progressbar, style: "width: #{percent}" do percent end end end |
#cta(text, url, options = {}) ⇒ Object
call to action
143 144 145 146 147 148 149 |
# File 'app/helpers/jap_mag_widgets_helper.rb', line 143 def cta text, url, = {} klass = %w(button button-rounded button-caution) klass << [:class] if [:class].present? [:class] = klass.join(" ") link_to text, url, end |
#cta_params(options = {}) ⇒ Object
151 152 153 |
# File 'app/helpers/jap_mag_widgets_helper.rb', line 151 def cta_params = {} {data: {disable_with: _("/actions.wait")}, class: "button button-rounded button-caution"}.merge end |
#get_body_class ⇒ Object
7 8 9 10 11 12 13 |
# File 'app/helpers/jap_mag_widgets_helper.rb', line 7 def get_body_class c = [] c << controller.controller_name c << "mobile" if is_mobile_device? c.collect{|e| e.titleize.gsub(/\s/, "")}.join " " end |
#get_body_id ⇒ Object
15 16 17 |
# File 'app/helpers/jap_mag_widgets_helper.rb', line 15 def get_body_id content_for(:id).to_s.titleize.gsub(/\s/, "") unless content_for(:id).blank? end |
#get_wrapper_class ⇒ Object
19 20 21 22 23 24 |
# File 'app/helpers/jap_mag_widgets_helper.rb', line 19 def get_wrapper_class c = [] c << controller.action_name c.collect{|e| e.titleize.gsub(/\s/, "")}.join " " end |
#input_for_selection(text) ⇒ Object
136 137 138 |
# File 'app/helpers/jap_mag_widgets_helper.rb', line 136 def input_for_selection text (content_tag :input, nil, value: text, size: text.length, class: "form-input for-selection").html_safe end |
#is_mobile_device? ⇒ Boolean
2 3 4 5 |
# File 'app/helpers/jap_mag_widgets_helper.rb', line 2 def is_mobile_device? mobile_user_agents = 'palm|blackberry|nokia|phone|midp|mobi|symbian|chtml|ericsson|minimo|audiovox|motorola|samsung|telit|upg1|windows ce|ucweb|astel|plucker|x320|x240|j2me|sgh|portable|sprint|docomo|kddi|softbank|android|mmp|pdxgw|netfront|xiino|vodafone|portalmmm|sagem|mot-|sie-|ipod|up\\.b|webos|amoi|novarra|cdm|alcatel|pocket|iphone|mobileexplorer|mobile' request.user_agent.to_s.downcase =~ Regexp.new(mobile_user_agents) end |
#last_deployed_at ⇒ Object
44 45 46 47 |
# File 'app/helpers/jap_mag_widgets_helper.rb', line 44 def last_deployed_at file = File.join("tmp", "restart.txt") File.exists?(file) ? File.atime(file) : nil end |
#link_to_external(text, link, options = {}) ⇒ Object
125 126 127 128 129 130 131 132 133 134 |
# File 'app/helpers/jap_mag_widgets_helper.rb', line 125 def link_to_external text, link, = {} .merge!(target: :_blank) if [:anonymous] link = "http://anonym.to/?#{link}" .delete(:anonymous) end link_to "#{text}#{fa_icon "external-link-alt", type: :fas}".html_safe, link, end |
#long_date(date) ⇒ Object
155 156 157 |
# File 'app/helpers/jap_mag_widgets_helper.rb', line 155 def long_date date I18n.l date, format: :long end |
#paginator(collections, options = {}) ⇒ Object
40 41 42 |
# File 'app/helpers/jap_mag_widgets_helper.rb', line 40 def paginator collections, = {} will_paginate collections, end |
#retina_image_tag(name_at_1x, options = {}) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'app/helpers/jap_mag_widgets_helper.rb', line 164 def retina_image_tag name_at_1x, = {} # webp for Chrome if [:webp] name_at_1x = name_at_1x.gsub /\.[a-zA-Z]+$/, '.webp' .delete :webp end # retina name_at_2x = name_at_1x.gsub /\.\w+$/, "@2x\\0" # i18n if [:i18n] name_at_1x = name_at_1x.gsub /\.[a-zA-Z]+$/, ".#{I18n.locale}\\0" name_at_2x = name_at_2x.gsub /\.[a-zA-Z]+$/, ".#{I18n.locale}\\0" .delete :i18n end # HTML 5 specific tag attributes srcset = "#{asset_path(name_at_1x)} 1x, #{asset_path(name_at_2x)} 2x" = .merge(srcset: srcset) image_tag name_at_1x, end |
#short_date(date) ⇒ Object
160 161 162 |
# File 'app/helpers/jap_mag_widgets_helper.rb', line 160 def short_date date I18n.l date, format: :short end |
#title(*titles) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/helpers/jap_mag_widgets_helper.rb', line 26 def title *titles seperator = " - " = {sitename: _("/logo")} = titles.last.is_a?(Hash) ? titles.pop : {} = .merge() page_title = page_title_for_return = titles.join(seperator) page_title = [:sitename] + seperator + page_title_for_return if not [:sitename].blank? content_for :title, page_title page_title_for_return end |