Sha256: 662333abeb3492c114a791df961212cf556b5303561c1d51cdb8365e56e4ecac

Contents?: true

Size: 916 Bytes

Versions: 7

Compression:

Stored size: 916 Bytes

Contents

module Odania
	module Controllers
		# TODO: Better name?
		module UrlHelpers
			# The current site depending on the host, e.g. www.odania.de
			def current_site
				@current_site ||= Odania::Site.active.where(host: request.host_with_port).first
			end

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

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

			# Thanks to https://github.com/mbleigh/acts-as-taggable-on
			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
		end
	end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
odania_core-0.0.7 lib/odania/controllers/url_helpers.rb
odania_core-0.0.6 lib/odania/controllers/url_helpers.rb
odania_core-0.0.5 lib/odania/controllers/url_helpers.rb
odania_core-0.0.4 lib/odania/controllers/url_helpers.rb
odania_core-0.0.3 lib/odania/controllers/url_helpers.rb
odania_core-0.0.2 lib/odania/controllers/url_helpers.rb
odania_core-0.0.1 lib/odania/controllers/url_helpers.rb