Module: ConceptsHelper
- Defined in:
- app/helpers/concepts_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.
Instance Method Summary collapse
- #concept_header(concept) ⇒ Object
-
#concept_view_data(concept) ⇒ Object
Renders associated objects of a given concept to a hash structure.
- #letter_selector(letters = ('A'..'Z').to_a, &block) ⇒ Object
-
#nested_list(hash, options = {}) ⇒ Object
turns a hash of concept/relations pairs of arbitrary nesting depth into the corresponding HTML list.
-
#treeview(concepts, broader = false, dragabble = false) ⇒ Object
if ‘broader` is supplied, the tree’s direction is reversed (descendants represent broader relations).
Instance Method Details
#concept_header(concept) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 |
# File 'app/helpers/concepts_helper.rb', line 83 def concept_header(concept) desc = concept.class.model_name.human if concept.expired_at desc += " #{t('txt.views.concepts.expired_at', date: l(concept.expired_at, format: :long))} " end title = concept.pref_label || concept.origin page_header title: title.to_s, desc: desc.html_safe end |
#concept_view_data(concept) ⇒ Object
Renders associated objects of a given concept to a hash structure. This hash is taken by view/layouts/_sections to be rendered.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/helpers/concepts_helper.rb', line 49 def concept_view_data(concept) res = {} render_concept_association(res, concept, Collection::Member::Base) Iqvoc::Concept.labeling_classes.each do |labeling_class, languages| (languages || Iqvoc.available_languages).each do |lang| render_concept_association(res, concept, labeling_class, lang: lang) end end Iqvoc::Concept.relation_classes.each do |relation_class| render_concept_association(res, concept, relation_class) end Iqvoc::Concept.match_classes.each do |match_class| render_concept_association(res, concept, match_class) end Iqvoc::Concept.note_classes.each do |note_class| render_concept_association(res, concept, note_class) end Iqvoc::Concept.notation_classes.each do |notation_class| render_concept_association(res, concept, notation_class) end Iqvoc::Concept.additional_association_classes.keys.each do |assoc_class| render_concept_association(res, concept, assoc_class) end res end |
#letter_selector(letters = ('A'..'Z').to_a, &block) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'app/helpers/concepts_helper.rb', line 38 def letter_selector(letters = ('A'..'Z').to_a, &block) content_tag :ul, class: 'letter-selector list-unstyled' do letters.map do |letter| content_tag :li, link_to(letter, yield(letter)), class: ('active' if params[:prefix] == letter.to_s.downcase) end.join('').html_safe end end |
#nested_list(hash, options = {}) ⇒ Object
turns a hash of concept/relations pairs of arbitrary nesting depth into the corresponding HTML list
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/helpers/concepts_helper.rb', line 25 def nested_list(hash, ={}) ordered = [:ordered] || false .delete(:ordered) content_tag(ordered ? 'ol' : 'ul', ) do hash.map do |concept, rels| rels.empty? ? content_tag('li', concept) : content_tag('li') do h(concept) + nested_list(rels, ordered: ordered) # NB: recursive end end.join("\n").html_safe end end |
#treeview(concepts, broader = false, dragabble = false) ⇒ Object
if ‘broader` is supplied, the tree’s direction is reversed (descendants represent broader relations)
19 20 21 |
# File 'app/helpers/concepts_helper.rb', line 19 def treeview(concepts, broader = false, dragabble = false) render "concepts/hierarchical/treeview", concepts: concepts, broader: broader, dragabble: false end |