Module: Homeland::ApplicationHelper

Defined in:
app/helpers/homeland/application_helper.rb

Constant Summary collapse

DEFAULT_AVATAR =
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPAAAADwCAMAAAAJixmgAAAAFVBMVEWkpKSnp6eqqqq3t7fS0tLV1dXZ2dmshcKEAAAAtklEQVR4Ae3XsRGAAAjAQFRk/5HtqaTz5H+DlInvAQAAAAAAAAAAAAAAAAAAAACymiveO6o7BQsWLFiwYMGCBS8PFixYsGDBggULFixYsGDBggULFixYsGDBggULFixYsGDBc4IFCxYsWLBgwYIFC14ZfOeAPRQ8IliwYMGCBQsWLFiwYMGCBQsWLFiwYMGCBQsWLFiwYMGCBQsWLFiwYMGCBQv+JQAAAAAAAAAAAAAAAAAAAOAB4KJfdHmj+kwAAAAASUVORK5CYII='

Instance Method Summary collapse

Instance Method Details

#node_tag(node) ⇒ Object



16
17
18
19
20
21
22
# File 'app/helpers/homeland/application_helper.rb', line 16

def node_tag(node)
  return '' if node.blank?

  label = [node.badge_html, (:span, node.name, class: 'name')].join(' ')

  link_to raw(label), homeland.node_topics_path(node.id), class: 'node'
end

#notice_messageObject



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/helpers/homeland/application_helper.rb', line 45

def notice_message
  flash_messages = []

  flash.each do |type, message|
    type = :danger
    type = :success if type.to_sym == :notice
    close_button = raw %(<button type="button" class="close" data-dismiss="alert">×</button>)
    text = (:div, close_button + message, class: "alert alert-dismissible alert-#{type}")
    flash_messages << text if message
  end

  flash_messages.join("\n").html_safe
end

#render_errors(target) ⇒ Object



5
6
7
8
9
# File 'app/helpers/homeland/application_helper.rb', line 5

def render_errors(target)
  if target.errors.present?
    render partial: '/homeland/shared/error_messages', locals: { target: target }
  end
end

#timeago(time, options = {}) ⇒ Object



11
12
13
14
# File 'app/helpers/homeland/application_helper.rb', line 11

def timeago(time, options = {})
  options[:class] ||= "timeago"
  (:abbr, time.to_s, options.merge(:title => time.getutc.iso8601)) if time
end

#user_avatar_tag(obj, opts = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/helpers/homeland/application_helper.rb', line 31

def user_avatar_tag(obj, opts = {})
  default = image_tag(DEFAULT_AVATAR, class: 'avatar media-object')
  return default if obj.blank?
  return default if obj.user.blank?

  if obj.user_avatar_url == nil
    img = default
  else
    img = image_tag(obj.user_avatar_url, class: 'avatar media-object')
  end

  link_to img, obj., title: obj.user_name, class: 'user-avatar'
end

#user_name_tag(obj) ⇒ Object



24
25
26
27
28
29
# File 'app/helpers/homeland/application_helper.rb', line 24

def user_name_tag(obj)
  return '' if obj.blank?
  return '' if obj.user_name.blank?

  link_to obj.user_name, obj., class: 'user-name'
end