module Birds::App::Helpers::View

Public Instance Methods

cl(text) click to toggle source
   # File lib/birds/app/helpers/view.rb
44 def cl(text)
45   text
46     .gsub(settings.highlighting_prefix,  '')
47     .gsub(settings.highlighting_postfix, '')
48 end
facet_query(field, value, gap = nil) click to toggle source
   # File lib/birds/app/helpers/view.rb
82 def facet_query(field, value, gap = nil)
83   gap ? range_query(field, value, gap) : field_query(field, value)
84 end
field_query(field, value) click to toggle source
   # File lib/birds/app/helpers/view.rb
86 def field_query(field, value)
87   %Q{#{field}:"#{value}"}
88 end
glyphicon(name, options = {}) click to toggle source
    # File lib/birds/app/helpers/view.rb
128 def glyphicon(name, options = {})
129   name, options = name.to_s.tr('_', '-'), options.dup
130 
131   options[:class] = %W[glyphicon glyphicon-#{name}]
132     .push(*options.delete(:class)).compact.join(' ')
133 
134   tag_(:span, options)
135 end
hl(text) click to toggle source
   # File lib/birds/app/helpers/view.rb
38 def hl(text)
39   h(text)
40     .gsub(h(settings.highlighting_prefix),  settings.highlighting_prefix)
41     .gsub(h(settings.highlighting_postfix), settings.highlighting_postfix)
42 end
nav_item(path, name, title = nil) click to toggle source
pagination_for(*args) click to toggle source
    # File lib/birds/app/helpers/view.rb
104 def pagination_for(*args)
105   params = args.last.is_a?(Hash) ?
106     args.pop.reject { |_, v| v.nil? } : {}
107 
108   ul_([
109     [@prev_page, :first, 1],
110     [@prev_page, :prev,  @prev_page],
111     [@next_page, :next,  @next_page],
112     [@next_page, :last,  @total_pages]
113   ], class: 'pagination') { |condition, type, page|
114     [link_to_if(condition, pagination_icon(type), *args, rel: type,
115       params: params.merge(page: page)), class: disabled?(condition)]
116   }
117 end
pagination_icon(type) click to toggle source
    # File lib/birds/app/helpers/view.rb
119 def pagination_icon(type)
120   tag_(:span, glyphicon(*{
121     first: [:fast_backward, title: 'First page'],
122     prev:  [:backward,      title: 'Previous page'],
123     next:  [:forward,       title: 'Next page'],
124     last:  [:fast_forward,  title: 'Last page']
125   }[type]))
126 end
query_params(q = @query, fq = @filter) click to toggle source
    # File lib/birds/app/helpers/view.rb
100 def query_params(q = @query, fq = @filter)
101   { q: q, 'fq[]' => fq }
102 end
range_label(value, gap) click to toggle source
   # File lib/birds/app/helpers/view.rb
96 def range_label(value, gap)
97   value < 0 ? "before #{-value}" : "#{value}–#{value + gap - 1}"
98 end
range_query(field, value, gap) click to toggle source
   # File lib/birds/app/helpers/view.rb
90 def range_query(field, value, gap)
91   value < 0 ?
92     %Q|#{field}:[* TO #{-value}}| :
93     %Q|#{field}:[#{value} TO #{value + gap}}|
94 end
values_for(key, document = @document) click to toggle source
    # File lib/birds/app/helpers/view.rb
137 def values_for(key, document = @document)
138   Array(document[key = key.to_s]).dup.tap { |values|
139     return if values.empty?
140 
141     if settings.browse_fields.include?(key)
142       values.map! { |v| link_to(v = hl(v), :browse, key, v) }
143     elsif field = settings.linkable_fields[key]
144       values.map! { |v| link_to_field(field, v) }
145     else
146       values.map!(&method(:hl))
147     end
148   }
149 end