Module: ApplicationHelper

Defined in:
app/helpers/application_helper.rb

Overview

Copyright 2011-2013 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

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 << (:strong, header) if header
  html << capture(&block)

  (:div, :class => "alert alert-#{type}") do
    html
  end
end

#error_messages_for(object) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/helpers/application_helper.rb', line 53

def error_messages_for(object)
  if object.errors.any?
     :div, :class => 'alert alert-error' do
      (:p, (:strong, t('txt.common.form_errors'))) <<
      (:ul) do
        object.errors.full_messages.each do |msg|
          concat (:li, msg)
        end
      end
    end
  end
end

#glyph(name) ⇒ Object



109
110
111
# File 'app/helpers/application_helper.rb', line 109

def glyph(name)
  raw GLYPHS[name]
end

#html_classes(*args) ⇒ Object



113
114
115
# File 'app/helpers/application_helper.rb', line 113

def html_classes(*args)
  args.compact.join(" ")
end

#icon(name, additional_css = "") ⇒ Object



100
101
102
103
104
105
106
107
# File 'app/helpers/application_helper.rb', line 100

def icon(name, additional_css = "")
  css_classes = %W(fa fa-#{name})
  if additional_css.respond_to?(:split)
    css_classes << additional_css.split(" ")
  end

   :i, "", :class => css_classes.join(" ")
end

#iqvoc_default_rdf_namespacesObject



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 => rdf_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 of items or returns a remark if no items where given



41
42
43
44
45
46
47
48
49
50
51
# File 'app/helpers/application_helper.rb', line 41

def item_listing(items, &block)
  return nil if items.empty?

   :ul, :class => "entity_list" do
    items.map do |item|
       :li, :class => (items.last == item ? "last-child" : "") do
        block.call(item)
      end
    end.join("\n").html_safe
  end
end

#login_logoutObject



80
81
82
83
84
85
86
# File 'app/helpers/application_helper.rb', line 80

def 
  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

#page_header(args = {}) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/helpers/application_helper.rb', line 66

def page_header(args = {})
  if title = args[:title]
    content_for(:title, title)
  end

  content_for :page_header do
     :div, :class => "page-header" do
       :h1 do
        ("#{title} #{(:small, args[:desc])}").html_safe
      end
    end
  end
end

#page_titleObject



117
118
119
120
121
122
123
# File 'app/helpers/application_helper.rb', line 117

def page_title
  if content_for?(:title)
    "#{content_for(:title)}#{Iqvoc.title}"
  else
    Iqvoc.title
  end
end

#user_details(user) ⇒ Object



32
33
34
35
36
37
38
# File 'app/helpers/application_helper.rb', line 32

def user_details(user)
  details = mail_to(user.email, user.name)
  if user.telephone_number?
    details << " " << user.telephone_number
  end
  details
end