Module: TagsHelper

Defined in:
app/helpers/tags_helper.rb

Instance Method Summary collapse

Instance Method Details

tag_object is to be tagged



47
48
49
50
51
52
53
54
55
56
# File 'app/helpers/tags_helper.rb', line 47

def add_tag_link(object: nil, attribute: nil) # tag_object is to be tagged
  if object.has_tags?
    link_to('Add tag',
            new_tag_path(tag_object_id: object.id, tag_object_type: object.class.name, tag_object_attribute: attribute),
            id: "tag_splat_#{object.class}_#{object.id}"
           )
  else
    nil
  end
end


58
59
60
# File 'app/helpers/tags_helper.rb', line 58

def destroy_tag_link(tag)
  destroy_object_link(tag)
end

#inserted_keywordObject

Session related helpers



70
71
72
# File 'app/helpers/tags_helper.rb', line 70

def inserted_keyword
  inserted_pinboard_item_object_for_klass('Keyword')
end

#inserted_keyword_tag_countObject



74
75
76
# File 'app/helpers/tags_helper.rb', line 74

def inserted_keyword_tag_count
  inserted_keyword.try(:tags).try(:count)
end

#is_default_tagged?(object) ⇒ Integer, false

Returns true if the object is tagged, and is tagged with the keyword presently defaulted on the pinboard.

Returns:

  • (Integer, false)

    true if the object is tagged, and is tagged with the keyword presently defaulted on the pinboard



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

def is_default_tagged?(object)
  return false if object.blank?
  keyword = inserted_keyword
  return false if keyword.blank?
  t = Tag.where(tag_object: object, keyword: keyword).first.try(:id)
  t ? t : false
end


43
44
45
# File 'app/helpers/tags_helper.rb', line 43

def link_to_destroy_tag(link_text, tag)
  link_to(link_text, '', class: 'tag-destroy', tag_id: tag.id)
end

#tag_annotation_tag(tag) ⇒ Object



9
10
11
12
# File 'app/helpers/tags_helper.rb', line 9

def tag_annotation_tag(tag)
  return nil if tag.nil?
  (:span, controlled_vocabulary_term_tag(tag.keyword))
end

#tag_default_icon(object) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'app/helpers/tags_helper.rb', line 28

def tag_default_icon(object)
  (:span, 'Tag', 
    data: {
    'tag-default' => 'true',
    'tag-object-global-id' => object.to_global_id.to_s,
    'default-tagged-id' => is_default_tagged?(object),
    'inserted-keyword-count' => inserted_keyword_tag_count
    })
end


38
39
40
41
# File 'app/helpers/tags_helper.rb', line 38

def tag_link(tag)
  return nil if tag.nil?
  link_to(tag_tag(tag), metamorphosize_if(tag.tag_object))
end

#tag_list_tag(object) ⇒ String (html)?

Returns a ul/li of tags for the object.

Returns:

  • (String (html), nil)

    a ul/li of tags for the object



16
17
18
19
# File 'app/helpers/tags_helper.rb', line 16

def tag_list_tag(object)
  return nil unless object.has_tags? && object.tags.load.any?
  (:h3, 'Tags') + tag_pills_tag(object)
end

#tag_pills_tag(object) ⇒ Object



21
22
23
24
25
26
# File 'app/helpers/tags_helper.rb', line 21

def tag_pills_tag(object)
  return nil unless object.has_tags? && object.tags.load.any?
  (:ul, class: 'annotations__tag_list') do
    object.tags.collect { |a| (:li, tag_annotation_tag(a)) }.join.html_safe
  end
end

#tag_tag(tag) ⇒ Object



3
4
5
6
7
# File 'app/helpers/tags_helper.rb', line 3

def tag_tag(tag)
  return nil if tag.nil?
  pieces =  [controlled_vocabulary_term_tag(tag.keyword), tag.tag_object_type, object_tag(tag.tag_object)]
  pieces.compact.join(': ').html_safe
end

#tags_recent_objects_partialTrue

Returns indicates a custom partial should be used, see list_helper.rb.

Returns:

  • (True)

    indicates a custom partial should be used, see list_helper.rb



64
65
66
# File 'app/helpers/tags_helper.rb', line 64

def tags_recent_objects_partial
  true
end