Module: Fir::Helpers

Includes:
ERB::Util
Included in:
ErbAdapter
Defined in:
lib/fir/helpers.rb

Defined Under Namespace

Classes: MenuNotDefined

Instance Method Summary collapse

Instance Method Details

#absolutize(path) ⇒ Object



5
6
7
# File 'lib/fir/helpers.rb', line 5

def absolutize(path)
	File.join(Fir.config.relative_url_root, path)
end

#content_tag(name, content_or_options = {}, options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/fir/helpers.rb', line 9

def (name, content_or_options = {}, options = {})
	if content_or_options.is_a?(Hash)
		options = content_or_options
		content = nil
	else
		content = content_or_options
	end
	Builder::XmlMarkup.new.tag!(name, content, options)
end


19
20
21
# File 'lib/fir/helpers.rb', line 19

def link_to(text, url)
	('a', text, 'href' => url)
end

Raises:

  • (ArgumentError)


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/fir/helpers.rb', line 24

def menu(name, options = {})
	raise(ArgumentError, 'menu requires a block') unless block_given?
	options = {:link_to_current => false}.merge(options)
	items = @menus[name] || raise(MenuNotDefined, "Menu '#{name}' is not defined. Define it in menus.yml.")
	items.each do |pair|
		# pair looks like: {'Menu Text' => 'path' } or {'Menu Text' => {'link' => 'path', 'other_option' => 'value'}}
		text = pair.keys.first
		item_options = pair[text]
		path = absolutize((item_options.is_a?(Hash) ? item_options['link'] : item_options) || '')
		if options[:link_to_current] or path != @request.path_info
			yield link_to(text, path), true
		else
			yield ('span', text, 'class' => 'selected'), false
		end
	end
end