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.
Constant Summary collapse
- GLYPHS =
{ :yes => "✓", :no => "✗" }
Instance Method Summary collapse
- #alert(type, opts = {}, &block) ⇒ Object
- #error_messages_for(object) ⇒ Object
- #glyph(name) ⇒ Object
- #html_classes(*args) ⇒ Object
- #icon(name, white = nil) ⇒ 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.
- #login_logout ⇒ Object
- #options_for_language_select(selected = nil) ⇒ Object
- #page_header(args = {}) ⇒ Object
- #user_details(user) ⇒ Object
Instance Method Details
#alert(type, opts = {}, &block) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/helpers/application_helper.rb', line 88 def alert(type, opts = {}, &block) header = opts.delete(:header) html = ActiveSupport::SafeBuffer.new html << content_tag(:strong, header) if header html << capture(&block) content_tag(:div, :class => "alert alert-#{type}") do html end end |
#error_messages_for(object) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/helpers/application_helper.rb', line 57 def (object) if object.errors.any? content_tag :div, :class => 'alert alert-error' do content_tag(:p, content_tag(:strong, t('txt.common.form_errors'))) << content_tag(:ul) do object.errors..each do |msg| concat content_tag(:li, msg) end end end end end |
#glyph(name) ⇒ Object
107 108 109 |
# File 'app/helpers/application_helper.rb', line 107 def glyph(name) raw GLYPHS[name] end |
#html_classes(*args) ⇒ Object
111 112 113 |
# File 'app/helpers/application_helper.rb', line 111 def html_classes(*args) args.compact.join(" ") end |
#icon(name, white = nil) ⇒ Object
100 101 102 103 104 105 |
# File 'app/helpers/application_helper.rb', line 100 def icon(name, white = nil) css_class = "icon-#{name}" css_class << " icon-white" if white content_tag :i, "", :class => css_class end |
#iqvoc_default_rdf_namespaces ⇒ Object
24 25 26 27 28 29 30 |
# File 'app/helpers/application_helper.rb', line 24 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
45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/helpers/application_helper.rb', line 45 def item_listing(items, &block) return nil 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 |
#login_logout ⇒ Object
80 81 82 83 84 85 86 |
# File 'app/helpers/application_helper.rb', line 80 def login_logout if current_user link_to t("txt.views.navigation.logout"), user_session_path, :method => :delete else link_to t("txt.views.navigation.login"), new_user_session_path end end |
#options_for_language_select(selected = nil) ⇒ Object
32 33 34 |
# File 'app/helpers/application_helper.rb', line 32 def (selected = nil) locales_collection = Iqvoc.available_languages.map { |l| [l, l] } end |
#page_header(args = {}) ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'app/helpers/application_helper.rb', line 70 def page_header(args = {}) content_for :page_header do content_tag :div, :class => "page-header" do content_tag :h1 do ("#{args.delete(:title)} #{content_tag(:small, args.delete(:desc))}").html_safe end end end end |
#user_details(user) ⇒ Object
36 37 38 39 40 41 42 |
# File 'app/helpers/application_helper.rb', line 36 def user_details(user) details = mail_to(user.email, user.name) if user.telephone_number? details << " " << user.telephone_number end details end |