Module: DataAttributesHelper

Defined in:
app/helpers/data_attributes_helper.rb

Instance Method Summary collapse

Instance Method Details



41
42
43
44
45
46
# File 'app/helpers/data_attributes_helper.rb', line 41

def add_data_attribute_link(object: nil, attribute: nil)
  link_to('Add data attribute', new_data_attribute_path(
    data_attribute: {
      attribute_subject_type: object.class.base_class.name,
      attribute_subject_id: object.id})) if object.has_data_attributes?
end

#data_attribute_annotation_tag(data_attribute) ⇒ Object



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

def data_attribute_annotation_tag(data_attribute)
  return nil if data_attribute.nil?
  s = (data_attribute_predicate_tag(data_attribute) + ': ' + (:span, data_attribute.value, class: [:annotation__data_attribute_value]) ).html_safe
  (:span, s.html_safe, class: [:annotation__data_attribute])
end

#data_attribute_autocomplete_tag(data_attribute) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'app/helpers/data_attributes_helper.rb', line 14

def data_attribute_autocomplete_tag(data_attribute)
  return nil if data_attribute.nil?
  [
    [ (:span, data_attribute.predicate_name, class: [:feedback, 'feedback-thin', 'feedback-primary']),
      (:span, data_attribute.value, class: [:feedback, 'feedback-thin', 'feedback-primary']),
      (:span, data_attribute.type, class: [:feedback, 'feedback-thin', 'feedback-secondary']),
      (:span, data_attribute.attribute_subject_type, class: [:feedback, 'feedback-thin', 'feedback-light'])].join(' ').html_safe,
  (:div, object_tag(data_attribute.annotated_object.metamorphosize))
  ].join.html_safe
end


57
58
59
60
61
62
63
# File 'app/helpers/data_attributes_helper.rb', line 57

def data_attribute_edit_link(data_attribute)
  if data_attribute.metamorphosize.editable?
    link_to 'Edit', edit_data_attribute_path(data_attribute)
  else
    (:em, 'Edit')
  end
end


48
49
50
51
# File 'app/helpers/data_attributes_helper.rb', line 48

def data_attribute_link(data_attribute)
  return nil if data_attribute.nil?
  link_to(object_tag(data_attribute).html_safe, data_attribute.annotated_object.metamorphosize)
end

#data_attribute_list_tag(object) ⇒ Object



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

def data_attribute_list_tag(object)
  return nil unless object.has_data_attributes? && object.data_attributes.any?
  (:h3, 'Data attributes') +
    (:ul, class: 'annotations__data_attribute_list') do
    object.data_attributes.collect{|a| 
      (:li, data_attribute_annotation_tag(a)) 
    }.join.html_safe 
  end
end

#data_attribute_predicate_tag(data_attribute) ⇒ Object

TODO deprecate



26
27
28
29
# File 'app/helpers/data_attributes_helper.rb', line 26

def data_attribute_predicate_tag(data_attribute)
    return nil if data_attribute.nil?
    data_attribute.predicate_name
end

#data_attribute_tag(data_attribute) ⇒ Object



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

def data_attribute_tag(data_attribute)
  return nil if data_attribute.nil?
  (data_attribute.predicate_name + ' ' + data_attribute.value + ' on ' + object_tag(data_attribute.annotated_object) ).html_safe
end

#data_attributes_search_formObject



53
54
55
# File 'app/helpers/data_attributes_helper.rb', line 53

def data_attributes_search_form
  render('/data_attributes/quick_search_form')
end