Module: DocumentsHelper

Defined in:
lib/picolena/templates/app/helpers/documents_helper.rb

Instance Method Summary collapse

Instance Method Details

#describe_results(page, total_hits, dt, query) ⇒ Object

Returns a localized sentence like “Results 1-10 of 12 for Zimbabwe (0.472s)” or “Résultats 1-2 parmi 2 pour whatever (0.012s)”



17
18
19
20
21
22
23
24
25
26
# File 'lib/picolena/templates/app/helpers/documents_helper.rb', line 17

def describe_results(page, total_hits, dt, query)
  [:results.l,
  (:strong,"#{page.first_item_number}-#{page.last_item_number}"),
  :of.l,
  (:strong,total_hits),
  :for.l,
  (:strong,query),
  show_time_needed(dt)
  ].join(' ')
end

#highlight_matching_content(document) ⇒ Object

When possible, highlights content of the document that matches the query.



34
35
36
37
38
# File 'lib/picolena/templates/app/helpers/documents_helper.rb', line 34

def highlight_matching_content(document)
  (:ul,document.matching_content.collect{|sentence|
    (:li,h(sentence).gsub(/&lt;&lt;(.*?)&gt;&gt;/,'<strong>\1</strong>').gsub(/\v|\f/,''))
  }) if document.matching_content
end

#highlighted_cache(document, query) ⇒ Object



79
80
81
# File 'lib/picolena/templates/app/helpers/documents_helper.rb', line 79

def highlighted_cache(document, query)
  h(document.highlighted_cache(query)).gsub(/\n/,'<br/>').gsub(/&lt;&lt;(.*?)&gt;&gt;/,(:span, '\1', :class=>"matching_content"))
end

#icon_and_filename_for(document) ⇒ Object

Returns icon and filename for any given document.



46
47
48
# File 'lib/picolena/templates/app/helpers/documents_helper.rb', line 46

def icon_and_filename_for(document)
  [icon_for(document.ext_as_sym),document.filename].join("&nbsp;")
end

#icon_for(ext) ⇒ Object

Returns the location (if avaible) of the filetype icon.



51
52
53
54
# File 'lib/picolena/templates/app/helpers/documents_helper.rb', line 51

def icon_for(ext)
  icon_symbol=Picolena::FiletypeToIconSymbol[ext]
  image_tag("icons/#{icon_symbol}.png") if icon_symbol
end

#language_icon_for(document) ⇒ Object



40
41
42
43
# File 'lib/picolena/templates/app/helpers/documents_helper.rb', line 40

def language_icon_for(document)
  lang=document.language
  link_to(image_tag("flags/#{lang}.png"), document_url('lang:'<<lang)) unless lang.blank?
end

Returns a link to a backup search engine that could maybe find more results for the same query.



57
58
59
# File 'lib/picolena/templates/app/helpers/documents_helper.rb', line 57

def link_to_backup_search_engine(query)
  link_to :backup_search_engine_name.l, :backup_search_engine_url.l<<query
end

For any indexed document, returns a link to show its cached content.



74
75
76
77
# File 'lib/picolena/templates/app/helpers/documents_helper.rb', line 74

def link_to_cached_content(document, query)
  link_name="("<<(:small,:cached.l)<<")"
  link_to link_name, cached_document_path(:id => document.probably_unique_id, :query => query)
end

For any indexed document, returns a link to its containing directory.



62
63
64
65
# File 'lib/picolena/templates/app/helpers/documents_helper.rb', line 62

def link_to_containing_directory(document)
  link_name=image_tag('icons/remote_folder.png')<<'&nbsp;'<<(:small,document.alias_path)
  link_to link_name, document.alias_path, :target=>'_blank'
end

For any indexed document, returns a link to show its content.



68
69
70
71
# File 'lib/picolena/templates/app/helpers/documents_helper.rb', line 68

def link_to_plain_text_content(document)
  link_name=image_tag('icons/plain_text_small.png')<<'&nbsp;'<<(:small,:text_content.l)
  link_to link_name, content_document_path(document.probably_unique_id)
end

#nothing_found?Boolean

Returns true if no document as been found for a given query.

Returns:

  • (Boolean)


3
4
5
# File 'lib/picolena/templates/app/helpers/documents_helper.rb', line 3

def nothing_found?
  @matching_documents.nil? or @matching_documents.entries.empty?
end

#should_paginate(page, query, sort) ⇒ Object

Very basic pagination. Provides liks to Next, Prev and FirstPage when needed.



9
10
11
12
13
# File 'lib/picolena/templates/app/helpers/documents_helper.rb', line 9

def should_paginate(page,query, sort)
  [(link_to("&larr;&larr;", :action => :show, :id => query, :sort=>sort) if page.number>2),
   (link_to("&larr;", :action => :show, :id => query, :page => page.prev.number, :sort=>sort) if page.prev?),
   (link_to("&rarr;", :action => :show, :id => query, :page => page.next.number, :sort=>sort) if page.next?)].compact.join(" | ")
end

#show_time_needed(dt) ⇒ Object

Returns the time needed to treat the query and launch the search, with a ms precision : (0.472s)



29
30
31
# File 'lib/picolena/templates/app/helpers/documents_helper.rb', line 29

def show_time_needed(dt)
  (:small,'('<<number_with_precision(dt,3)<<'s)')
end

#sort_by_date_or_relevance(query) ⇒ Object



83
84
85
86
# File 'lib/picolena/templates/app/helpers/documents_helper.rb', line 83

def sort_by_date_or_relevance(query)
  [link_to_unless_current('By date', document_path(query, :sort=>'by_date')),
   link_to_unless_current('By relevance', document_path(query))].join("&nbsp;")
end