Module: Odania::Controllers::UrlHelpers

Defined in:
lib/odania/controllers/url_helpers.rb

Overview

TODO: Better name?

Instance Method Summary collapse

Instance Method Details

#current_menuObject



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/odania/controllers/url_helpers.rb', line 10

def current_menu
  cur_locale = params[:locale]
  cur_locale = current_site.default_language.iso_639_1 if cur_locale.nil?

  @current_menu ||= current_site.get_current_menu(cur_locale)
  unless @current_menu.nil?
    I18n.locale = @current_menu.language.iso_639_1
    return @current_menu
  end

  Odania::Menu.new(language_id: current_site.default_language.id)
end

#current_siteObject

The current site depending on the host, e.g. www.odania.de



6
7
8
# File 'lib/odania/controllers/url_helpers.rb', line 6

def current_site
  @current_site ||= Odania::Site.active.where(host: request.host_with_port).first
end

#tag_cloud(tags, classes) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/odania/controllers/url_helpers.rb', line 24

def tag_cloud(tags, classes)
  return [] if tags.empty?

  max_count = tags.sort_by(&:count).last.count.to_f

  tags.each do |tag|
    index = ((tag.count / max_count) * (classes.size - 1))
    yield tag, classes[index.nan? ? 0 : index.round]
  end
end