Module: ApplicationHelper
- Defined in:
- app/helpers/application_helper.rb
Overview
Copyright 2011 innoQ Deutschland GmbH
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Instance Method Summary collapse
- #error_messages_for(object) ⇒ Object
- #iqvoc_default_rdf_namespaces ⇒ Object
-
#item_listing(items, &block) ⇒ Object
Formats a list ob items or returns a remark if no items where given.
-
#nav_items(items) ⇒ Object
expects an array of hashes with the following members: :content - usually a navigation link :active? - an optional function determining whether the respective item is currently active :controller - an optional string, used instead of ‘active?` to check for a specific controller :authorized? - an optional function determining whether the respective item is available to the current user (defaults to true).
- #options_for_language_select(selected = nil) ⇒ Object
- #user_details(user) ⇒ Object
Instance Method Details
#error_messages_for(object) ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'app/helpers/application_helper.rb', line 69 def (object) if object.errors.any? content_tag :ul, :class => "flash_error error_list" do object.errors..each do |msg| concat(content_tag(:li, msg)) end end end end |
#iqvoc_default_rdf_namespaces ⇒ Object
38 39 40 41 42 43 44 |
# File 'app/helpers/application_helper.rb', line 38 def iqvoc_default_rdf_namespaces Iqvoc.rdf_namespaces.merge({ :default => root_url(:format => nil, :lang => nil, :trailing_slash => true).gsub(/\/\/$/, "/"), # gsub because of a Rails bug :-( :coll => collections_url(:trailing_slash => true, :lang => nil, :format => nil), :schema => controller.schema_url(:format => nil, :anchor => "", :lang => nil) }) end |
#item_listing(items, &block) ⇒ Object
Formats a list ob items or returns a remark if no items where given
57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/helpers/application_helper.rb', line 57 def item_listing(items, &block) return content_tag :p, "-", :class => 'term-unavailable' if items.empty? content_tag :ul, :class => "entity_list" do items.map do |item| content_tag :li, :class => (items.last == item ? "last-child" : "") do block.call(item) end end.join("\n").html_safe end end |
#nav_items(items) ⇒ Object
expects an array of hashes with the following members: :content - usually a navigation link :active? - an optional function determining whether the respective item is
currently active
:controller - an optional string, used instead of ‘active?` to check for a
specific controller
:authorized? - an optional function determining whether the respective item
is available to the current user (defaults to true)
27 28 29 30 31 32 33 34 35 36 |
# File 'app/helpers/application_helper.rb', line 27 def nav_items(items) items.map do |item| if (not item[:authorized?]) || instance_eval(&item[:authorized?]) active = item[:controller] ? params[:controller] == item[:controller] : (item[:active?] ? instance_eval(&item[:active?]) : false) content_tag "li", instance_eval(&item[:content]), :class => ("active" if active) end end.join.html_safe end |
#options_for_language_select(selected = nil) ⇒ Object
46 47 48 49 50 |
# File 'app/helpers/application_helper.rb', line 46 def (selected = nil) locales_collection = Iqvoc.available_languages.map { |l| [l, l] } (locales_collection, selected) end |
#user_details(user) ⇒ Object
52 53 54 |
# File 'app/helpers/application_helper.rb', line 52 def user_details(user) "#{user.name} (#{user.telephone_number})" end |