diff options
author | Ralph Amissah <ralph@amissah.com> | 2011-05-04 23:52:51 -0400 |
---|---|---|
committer | Ralph Amissah <ralph@amissah.com> | 2011-05-04 23:53:51 -0400 |
commit | c7c3ab1b867f615344cd36925d5bcd886535bb0e (patch) | |
tree | 101530bc3796aab793bd672cc8e8e54f9c44b536 /lib | |
parent | v3: 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')
-rw-r--r-- | lib/sisu/v3/cgi_pgsql.rb | 6 | ||||
-rw-r--r-- | lib/sisu/v3/cgi_sql_common.rb | 93 | ||||
-rw-r--r-- | lib/sisu/v3/cgi_sqlite.rb | 16 |
3 files changed, 79 insertions, 36 deletions
diff --git a/lib/sisu/v3/cgi_pgsql.rb b/lib/sisu/v3/cgi_pgsql.rb index 48211068..fc802f03 100644 --- a/lib/sisu/v3/cgi_pgsql.rb +++ b/lib/sisu/v3/cgi_pgsql.rb @@ -115,12 +115,12 @@ module SiSU_CGI_pgsql a="postgresql db used for present directory: #{@db.psql.db}" b="\n\t(to create and populate postgresql database see 'man sisu' and in particular the -D flag)\n\t[the database to be used for this directory (#{@db.psql.db}) will have to be created manually if it does not exist,\n\tsee 'sisu --help sql'\n\tif you have permission to create databases:\n\t'sisu -d --createdb'\n\tor using postgresql tools directly:\n\t'createdb #{@db.psql.db}'\n\tfor a list of existing databases try 'psql --list']" SiSU_Screen::Ansi.new(@opt.cmd,a,b).txt_cyan - else puts 'failed in attempt to write sisu_pgsql.cgi to present directory, is directory writable?' + else puts 'failed in attempt to write #{@cgi_file_name} to present directory, is directory writable?' end end def header0 <<-WOK_SQL -#!/usr/bin/env ruby +#!/usr/bin/ruby1.8 =begin #{about} * Description: generates naive cgi search form for search of sisu database (pgsql) @@ -145,7 +145,7 @@ module SiSU_CGI_pgsql @l,@t,@q,@c=l,t,q,cse end def string - search={ search: [], flag: false } + search={ :search => [], :flag => false } if @t =~/\S+/ or @q =~/\S+/ if @t =~/\S+/; unescaped_search=CGI.unescape(@t) elsif @q =~/\S+/; unescaped_search=CGI.unescape(@q) 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> } \ : %{<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> } - 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"> #{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> <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> <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> <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> <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> <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"> #{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> <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> } \ : %{<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> } - 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"> #{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> <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> <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> <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> <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> <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"> #{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> <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> [§ <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> [§ <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")) diff --git a/lib/sisu/v3/cgi_sqlite.rb b/lib/sisu/v3/cgi_sqlite.rb index 5a415b0d..4a5838ab 100644 --- a/lib/sisu/v3/cgi_sqlite.rb +++ b/lib/sisu/v3/cgi_sqlite.rb @@ -66,6 +66,7 @@ module SiSU_CGI_sqlite @env=SiSU_Env::Info_env.new('',opt) @image_src="#{@env.url.webserv_cgi}/_sisu/image_sys" @common=SiSU_CGI_sql::SiSU_CGI_common.new(@webserv,@opt.cmd,@image_src,@env) + @cgi_file_name="#{Db[:name_prefix_db]}sqlite.cgi" end def sqlite serve=[] @@ -95,7 +96,7 @@ module SiSU_CGI_sqlite end f3 << %{ else '#{@env.path.webserv}/#{serve[0]}/sisu_sqlite.db'\n end\n} if FileTest.writable?('.') - output=File.open('sisu_sqlite.cgi','w') + output=File.open(@cgi_file_name,'w') output << header0 << header1 << header_desc << header2 << f1 << buttons1 << buttons2 << search_request << search_statement << search_statement_common << search_query1 << @common.pages << search_query2 << @common.tail << @common.main1 << f2 << f3 << dbi_connect << @common.main2 a=%{ generated sisu_sqlite.cgi, BASED ON ALREADY CREATED sisu_sqlite.db OUTPUT, (-d) @@ -104,21 +105,22 @@ module SiSU_CGI_sqlite c=case @webserv when /pwd/; '' else "if necessary make the directory /usr/lib/cgi-bin : - sudo cp -vi #{Dir.pwd}/sisu_sqlite.cgi /usr/lib/cgi-bin/. - sudo chmod -v 755 /usr/lib/cgi-bin/sisu_sqlite.cgi - (copy sisu_sqlite.cgi to your cgi directory) and set file permissions to 755" + sudo cp -vi #{Dir.pwd}/#{@cgi_file_name} /usr/lib/cgi-bin/. + sudo chmod -v 755 /usr/lib/cgi-bin/#{@cgi_file_name} + sudo ln -s /usr/lib/cgi-bin/#{@cgi_file_name} /usr/lib/cgi-bin/sisu_sqlite.cgi + (copy #{@cgi_file_name} to your cgi directory) set file permissions to 755, and make symbolic link to sisu_sqlite.cgi" end a=%{#{c} #{@env.webserv_base_cgi}/cgi-bin/sisu_sqlite.cgi } b='(to create and populate sisu sqlite database see "man sisu" and in particular the -d flag)' SiSU_Screen::Ansi.new(@opt.cmd,a,b).warn - else puts 'failed in attempt to write sisu_sqlite.cgi to present directory, is directory writable?' + else puts "failed in attempt to write #{@cgi_file_name} to present directory, is directory writable?" end end def header0 <<-WOK_SQL -#!/usr/bin/env ruby +#!/usr/bin/ruby1.8 =begin #{about} * Description: generates naive cgi search form for search of sisu database (sqlite) @@ -141,7 +143,7 @@ module SiSU_CGI_sqlite @l,@t,@q=l,t,q end def string - search={ search: [], flag: false } + search={ :search => [], :flag => false } if @t =~/\S+/ or @q =~/\S+/ if @t =~/\S+/; unescaped_search=CGI.unescape(@t) elsif @q =~/\S+/; unescaped_search=CGI.unescape(@q) |