Module: ApplicationHelper

Defined in:
app/helpers/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#browser_iconObject


26
27
28
# File 'app/helpers/application_helper.rb', line 26

def browser_icon
  icon 'shortcut icon'
end

#canonical_urlObject


17
18
19
20
21
22
23
24
# File 'app/helpers/application_helper.rb', line 17

def canonical_url
  subdomain = Whitelabel.label ? Whitelabel[:label_id] : 'www'
  options = {
    subdomain: subdomain,
    only_path: false
  }
  tag :link, rel: :canonical, href: url_for(options)
end

#hint(close = true) ⇒ Object


56
57
58
59
60
61
# File 'app/helpers/application_helper.rb', line 56

def hint(close=true)
  (:section, class: :hint) do
    concat (:div, link_to(t("hint.close"), '#'), class: :close) if close
    yield
  end
end

#icon(type) ⇒ Object


38
39
40
41
# File 'app/helpers/application_helper.rb', line 38

def icon(type)
  path = image_path Whitelabel.label ? "labels/#{Whitelabel[:label_id]}.ico" : "favicon.ico"
  tag :link, rel: type, href: path
end

#label_url(label) ⇒ Object


12
13
14
15
# File 'app/helpers/application_helper.rb', line 12

def label_url(label)
  host = Rails.env.development? ? 'onruby.dev' : "onruby.#{label.tld}"
  root_url(subdomain: label.label_id, domain: host)
end

#markdown(content) ⇒ Object


43
44
45
46
47
# File 'app/helpers/application_helper.rb', line 43

def markdown(content)
  return nil unless content
  content = markdown_parser.render(content).html_safe
   :div, content, class: :markdown
end

#render_cached(*keys) ⇒ Object


63
64
65
66
67
68
69
# File 'app/helpers/application_helper.rb', line 63

def render_cached(*keys)
  defaults  = [Whitelabel[:label_id], I18n.locale]
  key       = defaults.concat(keys.present? ? keys : [controller_name, action_name]).join("/")

  Rails.logger.info "cache fragment '#{key}'"
  cache(key, expires_in: 4.hours, skip_digest: true) { yield }
end

#rss_feedObject


34
35
36
# File 'app/helpers/application_helper.rb', line 34

def rss_feed
  auto_discovery_link_tag :rss, events_path(format: :xml), title: "Event-Feed"
end

#section_box(name) ⇒ Object


49
50
51
52
53
54
# File 'app/helpers/application_helper.rb', line 49

def section_box(name)
   :section, class: name, id: name do
    concat (:h2, (:i, '', class: "icon icon-#{name}") + t("main.#{name}"))
    yield
  end
end

#touch_iconObject


30
31
32
# File 'app/helpers/application_helper.rb', line 30

def touch_icon
  icon 'apple-touch-icon-precomposed'
end

#whitelabel_javascript_include_tagObject


7
8
9
10
# File 'app/helpers/application_helper.rb', line 7

def whitelabel_javascript_include_tag
  link = "labels/#{Whitelabel[:label_id]}"
  javascript_include_tag link if Rails.root.join("app/assets/javascripts/labels").entries.map(&:to_s).any? { |path| path.to_s =~ /#{Whitelabel[:label_id]}/ }
end

2
3
4
5
# File 'app/helpers/application_helper.rb', line 2

def whitelabel_stylesheet_link_tag
  link = "labels/#{Whitelabel[:label_id]}"
  stylesheet_link_tag link if File.exists? Rails.root.join("app/assets/stylesheets/#{link}.sass")
end