Module: TagsHelper

Defined in:
app/helpers/tags_helper.rb

Instance Method Summary (collapse)

Instance Method Details

tag_object is to be tagged



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

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


52
53
54
# File 'app/helpers/tags_helper.rb', line 52

def destroy_tag_link(tag)
  destroy_object_link(tag)
end

- (Object) inserted_keyword

Session related helpers



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

def inserted_keyword
  inserted_pinboard_item_object_for_klass('Keyword')
end

- (Object) inserted_keyword_tag_count



68
69
70
# File 'app/helpers/tags_helper.rb', line 68

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

- (Integer, false) is_default_tagged?(object)

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



74
75
76
77
78
79
80
# File 'app/helpers/tags_helper.rb', line 74

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


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

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

- (Object) tag_annotation_tag(tag)



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), class: [:annotation__tag])
end

- (Object) tag_default_icon(object)



28
29
30
# File 'app/helpers/tags_helper.rb', line 28

def tag_default_icon(object)
  (:span, 'Tag', data: {'tag-object-global-id' => object.to_global_id.to_s, 'default-tagged-id' => is_default_tagged?(object), 'inserted-keyword-count' => inserted_keyword_tag_count  }, class: [:default_tag_widget, 'circle-button', 'btn-disabled'])
end


32
33
34
35
# File 'app/helpers/tags_helper.rb', line 32

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

- (String (html)?) tag_list_tag(object)

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
20
21
22
# File 'app/helpers/tags_helper.rb', line 16

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

- (Object) tag_tag(tag)



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

- (True) tags_recent_objects_partial

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



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

def tags_recent_objects_partial
  true
end

- (Object) tags_search_form



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

def tags_search_form
  render '/tags/quick_search_form'
end