module ApplicationHelper def title(*args) res = content_tag :h1, class: 'page-title' do if args.first.is_a?(Symbol) && (args[1].respond_to?(:model_name) || args[1].class.respond_to?(:model_name)) model = args[1].respond_to?(:model_name) ? args[1] : args[1].class if args.first == :index t('action.index.label', models: model.model_name.human_plural) else t("action.#{args.first}.label", model: model.model_name.human) end else args.first end end content_for :page_title, res res end # overwrite i18n l, to handle nil values def l(*args) return '' unless args.first super(*args) end def are_you_sure?(record) t('helpers.links.are_you_sure') end def active_list active_list_object end def application_title 'Qwaiter' end # Helper for displaying HTML currency values def currency(amount, opts={}) amount ||= 0.0 amount = amount.to_f #prefix = case company.currency # when 'GBP' then '£ ' # when 'USD' then '$ ' # else '€ ' # end prefix = '€ ' return (prefix + ("%.2f" % amount)).html_safe # Rails native is ambiguous since is uses translation hashes options = {:unit => '€'}.merge(opts) number_to_currency(amount, options) end def list_open? active_list_id.present? end def active_list_id current_user.try(:active_list_id) end def no_content_given(model) t('helpers.list.no_records') end def slider_image image_tag('spinner.gif') end def show_boolean(bool) t("general.boolean.boolean_#{bool.present? ? 'yes' : 'no'}") end def facebook_link link_to 'Facebook', 'https://www.facebook.com/Qwaiter', target: :_blank end def twitter_link link_to 'Twitter', 'https://www.twitter.com/Qwaiter', target: :_blank end # Add a script call to be executed when the dom is loaded. # When called without a script it will return the total added script content # - onload_javascript 'var a=1' # - onload_javascript 'var b=3' # = onload_javascript #=> var a=1;var b=3 def onload_javascript(script = nil) if block_given? script = script.to_s value = nil buffer = with_output_buffer { value = yield } script += (buffer.presence || value).to_s end script = script.call if script.respond_to?(:call) script.present? ? (@onload_javascripts ||= []) << script : (@onload_javascripts || []).join(';') end def mustache_template(template) render(template, handlers: [:mustache]) end def top_bar(options = {}, &block) title = options[:title] title = title.present? ? content_tag(:h3, t("user.#{title}"), class: 'title', data: {t: title}) : '' content_tag :div, class: 'top-button-bar' do content_tag :div, class: 'button-bar-inner' do content_tag :div, class: 'button-bar-content' do (title + capture(&block)).html_safe end end end end end