require 'redcarpet' module ApplicationHelper include ScheduleHelper @@keyQueue = nil @@translationsOnThisPage = nil @@lastTranslation = nil @@allTranslations = nil @@no_banner = true @@banner_attribution_details = nil @@banner_image = nil @@has_content = true @@front_page = false @@body_class = nil @@test_location = nil def init_vars @@keyQueue = nil @@no_banner = true @@banner_attribution_details = nil @@banner_image = nil @@has_content = true @@front_page = false @@body_class = nil end def this_is_the_front_page @@front_page = true end def header_is_fixed @fixed_header = true end def is_header_fixed? @fixed_header ||= false end def is_this_the_front_page? return @@front_page end def header_classes classes = Array.new classes << 'fixed' if is_header_fixed? return classes end def ThereAreTranslationsOnThisPage? @@translationsOnThisPage end def get_all_translations @@allTranslations end def title(page_title) content_for(:title) { page_title.to_s } end def description(page_description) content_for(:description) { page_description.to_s } end def banner_image(banner_image, name: nil, id: nil, user_id: nil, src: nil) @@no_banner = false @@banner_image = banner_image if (name || id || user_id || src) @@banner_attribution_details = {:name => name, :id => id, :user_id => user_id, :src => src} end content_for(:banner_image) { banner_image.to_s } end def banner_attrs(banner_image) @@no_banner = false if banner_image.length > 0 @@banner_image = banner_image return {style: 'background-image: url(' + banner_image + ');', class: 'has-image' } end {class: 'no-image'} end def has_banner? !@@no_banner end def has_content? @@has_content end def has_no_content @@has_content = false end def banner_title(banner_title) @@no_banner = false content_for(:banner) { ('

' + banner_title.to_s + '

').html_safe } end def add_stylesheet(sheet) @stylesheets ||= [] @stylesheets << sheet unless @stylesheets.include?(sheet) end def stylesheets html = '' Rack::MiniProfiler.step('inject_css') do html += inject_css! end (@stylesheets || []).each do |css| Rack::MiniProfiler.step("inject_css #{css}") do html += inject_css! css.to_s end end html += stylesheet_link_tag 'i18n-debug' if request.params['i18nDebug'] return html.html_safe end def add_inline_script(script) @_inline_scripts ||= [] script = Rails.application.assets.find_asset("#{script.to_s}.js").to_s @_inline_scripts << script unless @_inline_scripts.include?(script) end def inline_scripts return '' unless @_inline_scripts.present? "".html_safe end def banner_attribution if @@banner_image && @@banner_attribution_details src = @@banner_attribution_details[:src] attribution = '
' if src == 'panoramio' attribution += '© ' + _('Banner_image_provided_by_panoramio_user') + ' ' + @@banner_attribution_details[:name] + '' + '' + _('Photos_provided_by_Panoramio_are_under_the_copyright_of_their_owners') + '' end attribution += '
' attribution.html_safe end end def dom_ready(&block) content_for(:dom_ready, &block) end def body_class(c) @@body_class ||= Array.new @@body_class << (c.is_a?(Array) ? c.join(' ') : c) end def page_style classes = Array.new classes << 'has-translations' if ThereAreTranslationsOnThisPage? classes << 'no-content' unless @@has_content classes << 'has-banner-image' if @@banner_image classes << @@body_class.join(' ') if @@body_class classes << 'fixed-banner' if is_header_fixed? if params[:controller] classes << params[:action] unless params[:controller] == 'application' classes << params[:controller] if params[:action] classes << "#{params[:controller]}-#{params[:action]}" end end end return classes end def yield_or_default(section, default = '') content_for?(section) ? content_for(section) : default end def _translate_me(translation) @@translationsOnThisPage = true datakeys = '' translation['vars'].each { |key, value| datakeys += ' data-var-' + key.to_s + '="' + value.to_s.gsub('"', '"') + '"' } ('' + (translation['html'] || translation['untranslated']) + '').to_s.html_safe end def _do_translate(key, vars, behavior, behavior_size, locale) translation = {'key' => key, 'lang' => '0', 'vars' => vars} v = vars.dup begin v[:raise] = true options = {:raise => true} if locale options[:locale] = locale.to_sym end translation['untranslated'] = I18n.translate(key, v, options) translation['lang'] = locale.to_s translation['is_translated'] = true hash = Hash.new translations = Translation.where(["locale = ? AND key LIKE ?", locale.to_s, key + '%']).take(6).each { |o| hash[o.key] = o.value } translation['translated'] = hash.to_json.gsub('"', '"') rescue I18n::MissingTranslationData default_translation = I18n::MissingTranslationExceptionHandler.note(key, behavior, behavior_size) translation['untranslated'] = default_translation end return translation end def _can_translate?() false end def off_screen(text, id = nil) content_tag(:span, text.html_safe, id: id, class: 'screen-reader-text') end def url_for_locale(locale, url = nil) return url unless locale.present? unless url.present? new_params = params.merge({action: (params[:_original_action] || params[:action])}) new_params.delete(:_original_action) if Rails.env.development? || Rails.env.test? return url_for(new_params.merge({lang: locale.to_s})) end subdomain = Rails.env.preview? ? "preview-#{locale.to_s}" : locale.to_s return url_for(new_params.merge(host: "#{subdomain}.bikebike.org")) end return url if Rails.env.development? || Rails.env.test? return "https://preview-#{locale.to_s}.bikebike.org#{url}" if Rails.env.preview? "https://#{locale.to_s}.bikebike.org#{url}" end def registration_steps(conference = @conference) { pre: [:policy, :basic_info, :workshops], open: [:policy, :basic_info, :questions, :payment, :workshops] }[@this_conference.registration_status] end def sortable(objects, id = 'id', url: nil, &block) result = '