Class: Gonzui::SnippetMaker
- Inherits:
-
Object
- Object
- Gonzui::SnippetMaker
- Includes:
- URIMaker
- Defined in:
- lib/gonzui/webapp/snippet.rb
Constant Summary
Constants included from URIMaker
Instance Method Summary collapse
-
#initialize(content, result_item, link_uri = nil) ⇒ SnippetMaker
constructor
A new instance of SnippetMaker.
- #make_context_grep ⇒ Object
- #make_line_oriented_kwic ⇒ Object
Methods included from URIMaker
#decompose_search_query, #escape_path, #get_default_query_value, #get_query_value, #get_short_name, #make_advanced_search_uri, #make_doc_uri, #make_google_uri, #make_lineno_uri, #make_markup_uri, #make_search_uri, #make_search_uri_partial, #make_source_uri, #make_stat_uri, #make_top_uri, #make_uri_general, #make_uri_with_options
Constructor Details
#initialize(content, result_item, link_uri = nil) ⇒ SnippetMaker
Returns a new instance of SnippetMaker.
16 17 18 19 20 21 22 23 |
# File 'lib/gonzui/webapp/snippet.rb', line 16 def initialize(content, result_item, link_uri = nil) @content = content @result_item = result_item @link_uri = link_uri # FIXME: should be customizable? @ncontexts = 1 end |
Instance Method Details
#make_context_grep ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/gonzui/webapp/snippet.rb', line 141 def make_context_grep context_lines = collect_context_lines pre = [:pre, {:class => "lines"}] prev_lineno = nil context_lines.keys.sort.each {|lineno| lineno_uri = make_lineno_uri(@link_uri, lineno) lineno_mark = [:a, {:href => lineno_uri }, lineno.to_s + ": "] pre.push(make_separator)if prev_lineno and lineno > prev_lineno + 1 pre.push(lineno_mark, context_lines[lineno], "\n") prev_lineno = lineno } return pre end |
#make_line_oriented_kwic ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/gonzui/webapp/snippet.rb', line 127 def make_line_oriented_kwic lines_with_lineno = make_kwic pre = [:pre, {:class => "lines"}] lines_with_lineno.sort_by {|line, lineno| lineno }.each {|line, lineno| lineno_uri = make_lineno_uri(@link_uri, lineno) lineno_mark = [:a, {:href => lineno_uri}, lineno.to_s + ": "] pre.push(lineno_mark, line) pre.push("\n") } return pre end |