module Birds::App::Helpers::View

Public Instance Methods

cl(text) click to toggle source
# File lib/birds/app/helpers/view.rb, line 43
def cl(text)
  text
    .gsub(settings.highlighting_prefix,  '')
    .gsub(settings.highlighting_postfix, '')
end
facet_query(field, value, gap = nil) click to toggle source
# File lib/birds/app/helpers/view.rb, line 81
def facet_query(field, value, gap = nil)
  gap ? range_query(field, value, gap) : field_query(field, value)
end
field_query(field, value) click to toggle source
# File lib/birds/app/helpers/view.rb, line 85
def field_query(field, value)
  %Q{#{field}:"#{value}"}
end
glyphicon(name, options = {}) click to toggle source
# File lib/birds/app/helpers/view.rb, line 127
def glyphicon(name, options = {})
  name, options = name.to_s.tr('_', '-'), options.dup

  options[:class] = %W[glyphicon glyphicon-#{name}]
    .push(*options.delete(:class)).compact.join(' ')

  tag_(:span, options)
end
hl(text) click to toggle source
# File lib/birds/app/helpers/view.rb, line 37
def hl(text)
  h(text)
    .gsub(h(settings.highlighting_prefix),  settings.highlighting_prefix)
    .gsub(h(settings.highlighting_postfix), settings.highlighting_postfix)
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, line 103
def pagination_for(*args)
  params = args.last.is_a?(Hash) ?
    args.pop.reject { |_, v| v.nil? } : {}

  ul_([
    [@prev_page, :first, 1],
    [@prev_page, :prev,  @prev_page],
    [@next_page, :next,  @next_page],
    [@next_page, :last,  @total_pages]
  ], class: 'pagination') { |condition, type, page|
    [link_to_if(condition, pagination_icon(type), *args, rel: type,
      params: params.merge(page: page)), class: disabled?(condition)]
  }
end
pagination_icon(type) click to toggle source
# File lib/birds/app/helpers/view.rb, line 118
def pagination_icon(type)
  tag_(:span, glyphicon(*{
    first: [:fast_backward, title: 'First page'],
    prev:  [:backward,      title: 'Previous page'],
    next:  [:forward,       title: 'Next page'],
    last:  [:fast_forward,  title: 'Last page']
  }[type]))
end
query_params(q = @query, fq = @filter) click to toggle source
# File lib/birds/app/helpers/view.rb, line 99
def query_params(q = @query, fq = @filter)
  { q: q, 'fq[]' => fq }
end
range_label(value, gap) click to toggle source
# File lib/birds/app/helpers/view.rb, line 95
def range_label(value, gap)
  value < 0 ? "before #{-value}" : "#{value}–#{value + gap - 1}"
end
range_query(field, value, gap) click to toggle source
# File lib/birds/app/helpers/view.rb, line 89
def range_query(field, value, gap)
  value < 0 ?
    %Q|#{field}:[* TO #{-value}}| :
    %Q|#{field}:[#{value} TO #{value + gap}}|
end
values_for(key, document = @document) click to toggle source
# File lib/birds/app/helpers/view.rb, line 136
def values_for(key, document = @document)
  Array(document[key = key.to_s]).dup.tap { |values|
    return if values.empty?

    if settings.browse_fields.include?(key)
      values.map! { |v| link_to(v = hl(v), :browse, key, v) }
    elsif field = settings.linkable_fields[key]
      values.map! { |v| link_to_field(field, v) }
    else
      values.map!(&method(:hl))
    end
  }
end