From c7c3ab1b867f615344cd36925d5bcd886535bb0e Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Wed, 4 May 2011 23:52:51 -0400 Subject: 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] --- lib/sisu/v3/cgi_pgsql.rb | 6 +-- lib/sisu/v3/cgi_sql_common.rb | 93 +++++++++++++++++++++++++++++++------------ lib/sisu/v3/cgi_sqlite.rb | 16 ++++---- 3 files changed, 79 insertions(+), 36 deletions(-) (limited to 'lib') 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 WOK #eg = %{canned search e.g.:
#{url}
find: #{analyze}
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 << '



Endnotes:
' << 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/) \ ? %{search } \ : %{search } - title=%{toc html #{ti} by #{c['creator_author']} #{can_txt_srch}toc html epub pdf portrait pdf landscape odf manifest
} if file_suffix=~/s/ #hmm watch file_suffix + title=%{toc html #{ti} by #{c['creator_author']} #{can_txt_srch}toc html manifest
} if file_suffix=~/s/ #hmm watch file_suffix title=@text_search_flag \ ? '

'+title \ : '
'+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(/(<\s]+#{@search_regx}[^>]+?>|#{@search_regx})/mi,%{\\1})) \ : c['body'] - %{

ocn #{c['ocn']}:

#{matched_para}} + %{

ocn #{c['ocn']}:

#{matched_para}} elsif c['suffix'] =~/1/ #doc %{#{title}

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=%{#{c['ocn']}, } if @text_search_flag - elsif c['suffix'] =~/1/ #doc - index=%{#{c['ocn']}, } + index=%{#{c['ocn']}, } if @text_search_flag + elsif c['suffix'] =~/1/ #doc #FIX + index=%{#{c['ocn']}, } end if c['seg'] =~/\S+/ if @text_search_flag @@ -936,7 +977,7 @@ module SiSU_CGI_sql can_txt_srch=(cgi['view']=~/index/) \ ? %{search } \ : %{search } - title=%{


toc html #{ti} by #{e['creator_author']} #{can_txt_srch}toc html epub pdf portrait pdf landscape odf manifest
} if file_suffix=~/s/ + title=%{

toc html #{ti} by #{e['creator_author']} #{can_txt_srch}toc html manifest
} 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(/(<\s]+#{@search_regx}[^>]+?>|#{@search_regx})/mi,%{\\1}) \ : e['body'] - output=%{#{title}
note #{e['nr']} referred to from ocn #{e['ocn']}: #{matched_endnote}} - else #elsif cgi['view']=~/index/ #% idx endnotes + output=%{#{title}
note #{e['nr']} referred to from ocn #{e['ocn']}: #{matched_endnote}} + else #elsif cgi['view']=~/index/ #doc #FIX #% idx endnotes @counter_endn_ocn+=1 - output=%{#{title}#{e['nr']}#{e['ocn']}], } + output=%{#{title}#{e['nr']}#{e['ocn']}], } 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='
' + 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)
-- 
cgit v1.2.3