aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/v3/cgi_sql_common.rb
diff options
context:
space:
mode:
authorRalph Amissah <ralph@amissah.com>2011-05-04 23:52:51 -0400
committerRalph Amissah <ralph@amissah.com>2011-05-04 23:53:51 -0400
commitc7c3ab1b867f615344cd36925d5bcd886535bb0e (patch)
tree101530bc3796aab793bd672cc8e8e54f9c44b536 /lib/sisu/v3/cgi_sql_common.rb
parentv3: db, review, directory structure changed, database prefix renamed (diff)
v3: sample search form, revert to generating ruby 1.8.7 sample
* sisu3 using ruby >=1.9.2p180 generates search form for ruby 1.8.7, so: generate sample form using sisu3 -F (options), then; start webrick using ruby 1.8.7 & sisu -W (not sisu3) * take account of alternative output directory structures [work on, test]
Diffstat (limited to 'lib/sisu/v3/cgi_sql_common.rb')
-rw-r--r--lib/sisu/v3/cgi_sql_common.rb93
1 files changed, 67 insertions, 26 deletions
diff --git a/lib/sisu/v3/cgi_sql_common.rb b/lib/sisu/v3/cgi_sql_common.rb
index 924b1533..1174be6e 100644
--- a/lib/sisu/v3/cgi_sql_common.rb
+++ b/lib/sisu/v3/cgi_sql_common.rb
@@ -299,9 +299,9 @@ module SiSU_CGI_sql
end
def text_to_match(identifier='')
m={
- string: /#{identifier}\s*(.+?)/,
- string: /#{identifier}\s*(.+?)(?:;|\n|\r|$)/,
- word: /#{identifier}[\s(]*(\S+)/
+ :string => /#{identifier}\s*(.+?)/,
+ :string => /#{identifier}\s*(.+?)(?:;|\n|\r|$)/,
+ :word => /#{identifier}[\s(]*(\S+)/
}
search_string=if @search_field =~m[:word]
search_string=if @search_field =~m[:braces]; m[:braces].match(@search_field)[1]
@@ -328,10 +328,10 @@ module SiSU_CGI_sql
def initialize(conn,search_for,q,c)
@conn=conn
@text_search_flag=false
- @sql_statement={ body: '', endnotes: '',range: '' }
+ @sql_statement={ :body => '', :endnotes => '', :range => '' }
#@offset||=@@offset
#@offset+=@@limit
- search={ text: [], endnotes: [] }
+ search={ :text => [], :endnotes => [] }
cse=(c =~/\S/) ? true : false
st=Dbi_search_string.new('doc_objects.clean',search_for.text1,q['s1'],cse).string
se=Dbi_search_string.new('endnotes.clean',search_for.text1,q['s1'],cse).string
@@ -645,7 +645,7 @@ module SiSU_CGI_sql
@counters_txt,@counters_endn,@sql_select_body,@sql_select_endnotes='','','',''
FCGI.each_cgi do |cgi|
begin # all code goes in begin section
- @search={ text: [], endnotes: [] }
+ @search={ :text => [], :endnotes => [] }
q=CGI.new
@db=if cgi['db'] =~/\S+/;
@stub=/#{@db_name_prefix}(\S+)/.match(cgi['db'])[1]
@@ -656,13 +656,13 @@ module SiSU_CGI_sql
end
checked_url,checked_stats,checked_searched,checked_tip,checked_case,checked_echo,checked_sql,checked_all,checked_none,checked_selected,checked_default,selected_db='','','','','','','','',''
result_type=(cgi['view']=~/text/) \
- ? result_type={ index: '', text: 'checked'} \
- : result_type={ index: 'checked', text: ''}
+ ? result_type={ :index => '', :text => 'checked'} \
+ : result_type={ :index => 'checked', :text => ''}
@@limit=if cgi['sql_match_limit'].to_s=~/2500/
- checked_sql_limit={ l1000: '', l2500: 'checked'}
+ checked_sql_limit={ :l1000 => '', :l2500 => 'checked'}
'2500'
else
- checked_sql_limit={ l1000: 'checked', l2500: ''}
+ checked_sql_limit={ :l1000 => 'checked', :l2500 => ''}
'1000'
end
checked_echo='checked' if cgi['echo'] =~/\S/
@@ -792,7 +792,7 @@ module SiSU_CGI_sql
</font>
WOK
#eg = %{canned search e.g.:<br /> <a href="#{url}">#{url}</a><br />find: #{analyze}<br />database: #{database}}
- #dbi_canning
+ #% dbi_canning
@header=Form.new(@base,search_field,selected_db,result_type,checked_sql_limit,checked_tip,checked_stats,checked_searched,checked_url,checked_case,checked_echo,checked_sql,checked_all,checked_none,checked_selected,checked_default,search_note,the_can).submission_form #% form
unless q['s1'] =~/\S/ or q['au'] =~/\S/ or @search[:text][1] =~/\S/
print "Content-type: text/html\n\n"
@@ -808,13 +808,13 @@ module SiSU_CGI_sql
@search[:text]<<%{doc_objects.clean~*'#{CGI.unescape(s1)}'}
@search[:endnotes]<<%{endnotes.clean~*'#{CGI.unescape(s1)}'}
end
- #dbi_request
+ #% dbi_request
dbi_statement=Dbi_search_statement.new(@conn,@search_for,q,checked_case)
@text_search_flag=false
@text_search_flag=dbi_statement.text_search_flag
s_contents=dbi_statement.contents
s_endnotes=dbi_statement.endnotes
- @body_main,@endnotes=[],[]
+ @body_main,@endnotes='',''
@search_regx=nil
oldtid=0
if @text_search_flag
@@ -827,7 +827,48 @@ module SiSU_CGI_sql
@endnotes << '<p><hr><br /><b>Endnotes:</b><br />' << sql_select_endnotes
else
end
- #text_objects_body
+ @hostpath="#{@hosturl_files}/#{@stub}"
+ @ln='en'
+ def output_dir_structure
+ def by_language_code?
+ true
+ end
+ def by_filetype?
+ false
+ end
+ def by_filename?
+ false
+ end
+ self
+ end
+ def path_manifest(fn,ln=nil)
+ if output_dir_structure.by_language_code?
+ manifest_at="#{@hostpath}/#{ln}/manifest/#{fn}.manifest.html"
+ elsif output_dir_structure.by_filetype?
+ manifest_at="#{@hostpath}/manifest/#{fn}.manifest.html"
+ elsif output_dir_structure.by_filename?
+ manifest_at="#{@hostpath}/#{fn}/manifest.html"
+ end
+ end
+ def path_html_seg(fn,ln=nil)
+ if output_dir_structure.by_language_code?
+ html_at="#{@hostpath}/#{ln}/html/#{fn}"
+ elsif output_dir_structure.by_filetype?
+ html_at="#{@hostpath}/html/#{fn}"
+ elsif output_dir_structure.by_filename?
+ html_at="#{@hostpath}/#{fn}"
+ end
+ end
+ def path_html_doc(fn,ln=nil)
+ if output_dir_structure.by_language_code?
+ html_at="#{@hostpath}/#{ln}/html/#{fn}.html"
+ elsif output_dir_structure.by_filetype?
+ html_at="#{@hostpath}/html/#{fn}.html"
+ elsif output_dir_structure.by_filename?
+ html_at="#{@hostpath}/#{fn}/doc.html"
+ end
+ end
+ #% text_objects_body
s_contents.each do |c| #% text body
location=c['src_filename'][/(.+?)\.(?:ssm\.sst|sst)$/,1]
file_suffix=c['src_filename'][/.+?\.(_?sst|ssm)$/,1]
@@ -837,13 +878,13 @@ module SiSU_CGI_sql
l=".#{l}"
else ''
end
- #metadata_found_body
+ #% metadata_found_body
if c['tid'].to_i != oldtid.to_i
ti=c['title']
can_txt_srch=(cgi['view']=~/index/) \
? %{<a href="#{@canned_base_url}&fns=#{c['src_filename']}&view=text"><img border="0" width="24" height="16" src="#{@image_src}/b_search.png" alt="search"></a>&nbsp;} \
: %{<a href="#{@canned_base_url}&fns=#{c['src_filename']}&view=index"><img border="0" width="24" height="16" src="#{@image_src}/b_search.png" alt="search"></a>&nbsp;}
- title=%{<span style="background-color: #{@color_heading}"><a href="#{@hosturl_files}/#{@stub}/#{location}/toc#{lang}.html"><img border="0" width="15" height="18" src="#{@image_src}/b_toc.png" alt="toc html">&nbsp;#{ti}</a></span> by #{c['creator_author']} #{can_txt_srch}<a href="#{@hosturl_files}/#{@stub}/#{location}/toc#{lang}.html"><img border="0" width="15" height="18" src="#{@image_src}/b_toc.png" alt="toc html"></a>&nbsp;<a href="#{@hosturl_files}/#{@stub}/epub/#{location}#{lang}.epub"><img border="0" width="15" height="15" src="#{@image_src}/b_epub.png" alt="epub"></a>&nbsp;<a href="#{@hosturl_files}/#{@stub}/#{location}/portrait#{lang}.pdf"><img border="0" width="15" height="18" src="#{@image_src}/b_pdf.png" alt="pdf portrait"></a>&nbsp;<a href="#{@hosturl_files}/#{@stub}/#{location}/landscape#{lang}.pdf"><img border="0" width="18" height="15" src="#{@image_src}/b_pdf.png" alt="pdf landscape"></a></a>&nbsp;<a href="#{@hosturl_files}/#{@stub}/#{location}/opendocument#{lang}.odt"><img border="0" width="15" height="15" src="#{@image_src}/b_odf.png" alt="odf"></a>&nbsp;<a href="#{@hosturl_files}/#{@stub}/#{location}/sisu_manifest#{lang}.html"><img border="0" width="15" height="15" src="#{@image_src}/b_info.png" alt="manifest"></a><br />} if file_suffix=~/s/ #hmm watch file_suffix
+ title=%{<span style="background-color: #{@color_heading}"><a href="#{path_html_seg(location,@ln)}/toc.html"><img border="0" width="15" height="18" src="#{@image_src}/b_toc.png" alt="toc html">&nbsp;#{ti}</a></span> by #{c['creator_author']} #{can_txt_srch}<a href="#{path_html_seg(location,@ln)}/toc.html"><img border="0" width="15" height="18" src="#{@image_src}/b_toc.png" alt="toc html"></a>&nbsp;<a href="#{path_manifest(location,@ln)}"><img border="0" width="15" height="15" src="#{@image_src}/b_info.png" alt="manifest"></a><br />} if file_suffix=~/s/ #hmm watch file_suffix
title=@text_search_flag \
? '<br /><hr>'+title \
: '<br />'+title
@@ -880,7 +921,7 @@ module SiSU_CGI_sql
matched_para=(@search_regx.to_s.class==String && @search_regx.to_s=~/\S\S+/) \
? (c['body'].gsub(/(<a\s+href="https?:\/\/[^><\s]+#{@search_regx}[^>]+?>|#{@search_regx})/mi,%{<span style="background-color: #{@color_match}">\\1</span>})) \
: c['body']
- %{<hr><p><font size="2">ocn <b><a href="#{@hosturl_files}/#{@stub}/#{location}/#{c['seg']}#{lang}.html##{c['ocn']}">#{c['ocn']}</a></b>:</font></p>#{matched_para}}
+ %{<hr><p><font size="2">ocn <b><a href="#{path_html_seg(location,@ln)}/#{c['seg']}#{lang}.html##{c['ocn']}">#{c['ocn']}</a></b>:</font></p>#{matched_para}}
elsif c['suffix'] =~/1/ #doc
%{#{title}<hr><p><font size="2">ocn #{c['ocn']}:#{c['body']}}
end
@@ -888,9 +929,9 @@ module SiSU_CGI_sql
output=title+text
else #elsif cgi['view']=~/index/ #% idx body
if c['suffix'] !~/1/ #seg
- index=%{<a href="#{@hosturl_files}/#{@stub}/#{location}/#{c['seg']}#{lang}.html##{c['ocn']}">#{c['ocn']}</a>, } if @text_search_flag
- elsif c['suffix'] =~/1/ #doc
- index=%{<a href="#{@hosturl_files}/#{@stub}/#{location}/doc#{lang}.html##{c['ocn']}">#{c['ocn']}</a>, }
+ index=%{<a href="#{path_html_seg(location,@ln)}/#{c['seg']}#{lang}.html##{c['ocn']}">#{c['ocn']}</a>, } if @text_search_flag
+ elsif c['suffix'] =~/1/ #doc #FIX
+ index=%{<a href="#{path_html_doc(location,@ln)}##{c['ocn']}">#{c['ocn']}</a>, }
end
if c['seg'] =~/\S+/
if @text_search_flag
@@ -936,7 +977,7 @@ module SiSU_CGI_sql
can_txt_srch=(cgi['view']=~/index/) \
? %{<a href="#{@canned_base_url}&fns=#{e['src_filename']}&view=text"><img border="0" width="24" height="16" src="#{@image_src}/b_search.png" alt="search"></a>&nbsp;} \
: %{<a href="#{@canned_base_url}&fns=#{e['src_filename']}&view=index"><img border="0" width="24" height="16" src="#{@image_src}/b_search.png" alt="search"></a>&nbsp;}
- title=%{<br /><hr><span style="background-color: #{@color_heading}"><a href="#{@hosturl_files}/#{@stub}/#{location}/toc#{lang}.html"><img border="0" width="15" height="18" src="#{@image_src}/b_toc.png" alt="toc html">&nbsp;#{ti}</a></span> by #{e['creator_author']} #{can_txt_srch}<a href="#{@hosturl_files}/#{@stub}/#{location}/toc#{lang}.html"><img border="0" width="15" height="18" src="#{@image_src}/b_toc.png" alt="toc html"></a>&nbsp;<a href="#{@hosturl_files}/#{@stub}/epub/#{location}#{lang}.epub"><img border="0" width="15" height="15" src="#{@image_src}/b_epub.png" alt="epub"></a>&nbsp;<a href="#{@hosturl_files}/#{@stub}/#{location}/portrait.pdf"><img border="0" width="15" height="18" src="#{@image_src}/b_pdf.png" alt="pdf portrait"></a>&nbsp;<a href="#{@hosturl_files}/#{@stub}/#{location}/landscape.pdf"><img border="0" width="18" height="15" src="#{@image_src}/b_pdf.png" alt="pdf landscape"></a>&nbsp;<a href="#{@hosturl_files}/#{@stub}/#{location}/opendocument#{lang}.odt"><img border="0" width="15" height="15" src="#{@image_src}/b_odf.png" alt="odf"></a>&nbsp;<a href="#{@hosturl_files}/#{@stub}/#{location}/sisu_manifest#{lang}.html"><img border="0" width="15" height="15" src="#{@image_src}/b_info.png" alt="manifest"></a><br />} if file_suffix=~/s/
+ title=%{<br /><hr><span style="background-color: #{@color_heading}"><a href="#{path_html_seg(location,@ln)}/toc.html"><img border="0" width="15" height="18" src="#{@image_src}/b_toc.png" alt="toc html">&nbsp;#{ti}</a></span> by #{e['creator_author']} #{can_txt_srch}<a href="#{path_html_seg(location,@ln)}/toc.html"><img border="0" width="15" height="18" src="#{@image_src}/b_toc.png" alt="toc html"></a>&nbsp;<a href="#{path_manifest(location,@ln)}"><img border="0" width="15" height="15" src="#{@image_src}/b_info.png" alt="manifest"></a><br />} if file_suffix=~/s/
@counter_endn_doc+=1
oldtid=e['metadata_tid'].to_i
else title = ''
@@ -947,10 +988,10 @@ module SiSU_CGI_sql
matched_endnote=(@search_regx.to_s.class==String && @search_regx.to_s=~/\S\S+/) \
? matched=e['body'].gsub(/(<a\s+href="https?:\/\/[^><\s]+#{@search_regx}[^>]+?>|#{@search_regx})/mi,%{<span style="background-color: #{@color_match}">\\1</span>}) \
: e['body']
- output=%{#{title}<hr><font size="2">note <b><a href="#{@hosturl_files}/#{@stub}/#{location}/endnotes.html#_#{e['nr']}">#{e['nr']}</a></b> referred to from ocn <a href="#{@hosturl_files}/#{@stub}/#{location}/doc.html##{e['ocn']}">#{e['ocn']}</a>:</font> #{matched_endnote}}
- else #elsif cgi['view']=~/index/ #% idx endnotes
+ output=%{#{title}<hr><font size="2">note <b><a href="#{path_html_seg(location,@ln)}/endnotes.html#_#{e['nr']}">#{e['nr']}</a></b> referred to from ocn <a href="#{path_html_doc(location,@ln)}##{e['ocn']}">#{e['ocn']}</a>:</font> #{matched_endnote}}
+ else #elsif cgi['view']=~/index/ #doc #FIX #% idx endnotes
@counter_endn_ocn+=1
- output=%{#{title}<a href="#{@hosturl_files}/#{@stub}/#{location}/endnotes.html#_#{e['nr']}">#{e['nr']}</a> [&sect; <a href="#{@hosturl_files}/#{@stub}/#{location}/doc.html##{e['ocn']}">#{e['ocn']}</a>], }
+ output=%{#{title}<a href="#{path_html_seg(location,@ln)}/endnotes.html#_#{e['nr']}">#{e['nr']}</a> [&sect; <a href="#{path_html_doc(location,@ln)}##{e['ocn']}">#{e['ocn']}</a>], }
end
@counters_endn=if @counter_endn_doc > 0
if checked_stats =~/\S/
@@ -964,7 +1005,7 @@ module SiSU_CGI_sql
end
end
@endnotes << output #+ details
- else @endnotes=[] #does not take out yet
+ else @endnotes='' #does not take out yet
end
end
offset=dbi_statement.sql_offset.to_s
@@ -974,7 +1015,7 @@ module SiSU_CGI_sql
? dbi_statement.pre_next(true,@image_src).to_s \
: dbi_statement.pre_next(false,@image_src).to_s
limit=dbi_statement.sql_match_limit.to_s
- cgi.out{@header + @counters_txt + @counters_endn + canned + @body_main.join + @endnotes.join + canned + @tail} #% print cgi_output_header+counters+body+endnotes
+ cgi.out{@header + @counters_txt + @counters_endn + canned + @body_main + @endnotes + canned + @tail} #% print cgi_output_header+counters+body+endnotes
end
rescue Exception => e
s='<pre>' + CGI::escapeHTML(e.backtrace.reverse.join("\n"))