Module: Fir::Helpers
Defined Under Namespace
Classes: MenuNotDefined
Instance Method Summary collapse
- #absolutize(path) ⇒ Object
- #content_tag(name, content_or_options = {}, options = {}) ⇒ Object
- #link_to(text, url) ⇒ Object
- #menu(name, options = {}) ⇒ Object
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 content_tag(name, = {}, = {}) if .is_a?(Hash) = content = nil else content = end Builder::XmlMarkup.new.tag!(name, content, ) end |
#link_to(text, url) ⇒ Object
19 20 21 |
# File 'lib/fir/helpers.rb', line 19 def link_to(text, url) content_tag('a', text, 'href' => url) end |
#menu(name, options = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/fir/helpers.rb', line 24 def (name, = {}) raise(ArgumentError, 'menu requires a block') unless block_given? = {:link_to_current => false}.merge() 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 = pair[text] path = absolutize((.is_a?(Hash) ? ['link'] : ) || '') if [:link_to_current] or path != @request.path_info yield link_to(text, path), true else yield content_tag('span', text, 'class' => 'selected'), false end end end |