From 363a1c71795d6034a996eb3b4a52b20c6dedca95 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Tue, 30 Jul 2013 21:25:48 -0400 Subject: v5: output structure by, add monolingual alt for :filetype & :filename, step 1 --- lib/sisu/v5/sysenv.rb | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'lib/sisu/v5/sysenv.rb') diff --git a/lib/sisu/v5/sysenv.rb b/lib/sisu/v5/sysenv.rb index 973e0dcc..dcf0a671 100644 --- a/lib/sisu/v5/sysenv.rb +++ b/lib/sisu/v5/sysenv.rb @@ -441,6 +441,32 @@ module SiSU_Env end @fnn,@fnb,@fnt,@flv,@fnz=@@fnn,@@fnb,@@fnt,@@flv,@@fnz end + def default_language? + if @rc + if defined? @rc['language_default'] \ + && (@rc['language_default'] =~/#{Px[:lng_lst_rgx]}/) + @rc['language_default'] + else + 'en' + end + else + 'en' + end + end + def mono_multi_lingual? + if @rc + if defined? @rc['lingual'] \ + && (@rc['lingual'] =~/mono(?:lingual)?/) + :mono + elsif defined? @rc['lingual'] \ + && (@rc['lingual'] =~/multi(?:lingual)?/) + :multi + else + :multi + end + else :multi + end + end def output_dir_structure def by? output_structure=:filename #set default output structure @@ -5703,6 +5729,28 @@ WOK self end end + class FilenameLanguageCodeInsert + def initialize(opt,lng=nil) + @opt,@lng=opt,lng + @opt=opt + @lng=lng ||=@opt.lng + end + def language_code_insert + if @opt.dir_structure_by ==:language \ + or ((@opt.dir_structure_by ==:filetype \ + || @opt.dir_structure_by ==:filename) \ + and (@opt.lingual ==:mono \ + && @opt.lng == @opt.act[:default_language][:code])) + '' + elsif (@opt.dir_structure_by ==:filetype \ + || @opt.dir_structure_by ==:filename) \ + and not @opt.lingual ==:mono + ".#{@lng}" + else + ".#{@lng}" + end + end + end class CreateFile Date: Tue, 30 Jul 2013 21:30:36 -0400 Subject: v5: output structure by, monolingual alternative for :filetype or :filename * filename without language code, if document is in default language * set a default language, 'en' or as specified * set in rc file or from command line instruction * command line e.g. sisu -hv --monolingual --by-filename sisu_markup.sst sisu -3v --monolingual --by-filetype sisu_manual.ssm * sisurc.yml lingual: 'mono' | 'multi' lingual: 'mono' * note: output by :filetype is roughly equivalent to what monolingual output by :language would be * allow command line setting of default language using language code --default-language='en' --default-lang-en if used together with --monolingual and --by-filetype or --by-filename the selected default language document will not have a language code in the output filename --- lib/sisu/v5/sysenv.rb | 680 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 485 insertions(+), 195 deletions(-) (limited to 'lib/sisu/v5/sysenv.rb') diff --git a/lib/sisu/v5/sysenv.rb b/lib/sisu/v5/sysenv.rb index dcf0a671..63981be3 100644 --- a/lib/sisu/v5/sysenv.rb +++ b/lib/sisu/v5/sysenv.rb @@ -470,27 +470,31 @@ module SiSU_Env def output_dir_structure def by? output_structure=:filename #set default output structure - output_structure=if defined? @rc['output_dir_structure_by'] - output_structure=if (@rc['output_dir_structure_by'] =~/dump/) \ - or ((defined? @rc['output_structure']['dump']) \ - && @rc['output_structure']['dump'] ==true) - :dump - elsif (@rc['output_dir_structure_by'] =~/redirect/) \ - or ((defined? @rc['output_structure']['redirect']) \ - && @rc['output_structure']['redirect'] ==true) - :redirect - elsif (@rc['output_dir_structure_by'] =~/language/) \ - or ((defined? @rc['output_structure']['by_language']) \ - && @rc['output_structure']['by_language'] ==true) - :language - elsif (@rc['output_dir_structure_by'] =~/filetype/) \ - or ((defined? @rc['output_structure']['by_filetype']) \ - && @rc['output_structure']['by_filetype'] ==true) - :filetype - elsif (@rc['output_dir_structure_by'] =~/filename/) \ - or ((defined? @rc['output_structure']['by_filename']) \ - && @rc['output_structure']['by_filename'] ==true) - :filename + if @rc + output_structure=if defined? @rc['output_dir_structure_by'] + output_structure=if (@rc['output_dir_structure_by'] =~/dump/) \ + or ((defined? @rc['output_structure']['dump']) \ + && @rc['output_structure']['dump'] ==true) + :dump + elsif (@rc['output_dir_structure_by'] =~/redirect/) \ + or ((defined? @rc['output_structure']['redirect']) \ + && @rc['output_structure']['redirect'] ==true) + :redirect + elsif (@rc['output_dir_structure_by'] =~/language/) \ + or ((defined? @rc['output_structure']['by_language']) \ + && @rc['output_structure']['by_language'] ==true) + :language + elsif (@rc['output_dir_structure_by'] =~/filetype/) \ + or ((defined? @rc['output_structure']['by_filetype']) \ + && @rc['output_structure']['by_filetype'] ==true) + :filetype + elsif (@rc['output_dir_structure_by'] =~/filename/) \ + or ((defined? @rc['output_structure']['by_filename']) \ + && @rc['output_structure']['by_filename'] ==true) + :filename + else #set default + :language + end else #set default :language end @@ -4657,245 +4661,531 @@ WOK self end def base_filename - def txt - ft='.txt' - if output_dir_structure.by_language_code? - @md.fnb + ft - elsif output_dir_structure.by_filetype? - @md.fnb + @md.lang_code_insert + ft + def i18n(f) + f=default_hash.merge(f) + (@md.opt.act[:i18n][:set]==:mono \ + || ((mono_multi_lingual? ==:mono)) \ + && (@md.opt.lng == default_language?)) \ + || f[:lng]==nil \ + ? f[:fn] + f[:ft] + : f[:fn] + f[:lng] + f[:ft] + end + def default_hash + { + fn: @md.fnb, + lng: @md.lang_code_insert, + } + end + def default_hash_build(fh,sfx) + if fh.is_a?(Hash) + fh[:fn] ||=@md.fnb + fh[:lng] ||= @md.lang_code_insert + fh[:ft]=sfx + fh else - 'plain' + @md.lang_code_insert + ft - end - end - def html_scroll - ft='.html' - if output_dir_structure.by_language_code? - @md.fnb + ft + { + fn: @md.fnb, + lng: @md.lang_code_insert, + ft: sfx, + } + end + end + def txt(fh=nil) + fh=default_hash_build(fh,Sfx[:txt]) + fnh=if output_dir_structure.by_language_code? + { + fn: fh[:fn], + ft: fh[:ft], + } + elsif output_dir_structure.by_filetype? + { + fn: fh[:fn], + ft: fh[:ft], + lng: fh[:lng], + } + else + { + fn: 'plain', + ft: fh[:ft], + lng: fh[:lng], + } + end + i18n(fnh) + end + def html_scroll(fh=nil) + fh=default_hash_build(fh,Sfx[:html]) + fnh=if output_dir_structure.by_language_code? + { + fn: fh[:fn], + ft: fh[:ft], + } elsif output_dir_structure.by_filetype? - @md.fnb + @md.lang_code_insert + ft + { + fn: fh[:fn], + ft: fh[:ft], + lng: fh[:lng], + } else - 'scroll' + @md.lang_code_insert + ft - end - end - def html_seg_index - ft='.html' - if output_dir_structure.by_language_code? - 'index' + ft + { + fn: 'scroll', + ft: fh[:ft], + lng: fh[:lng], + } + end + i18n(fnh) + end + def html_seg_index(fh=nil) + fh=default_hash_build(fh,Sfx[:html]) + fnh=if output_dir_structure.by_language_code? + { + fn: 'index', + ft: fh[:ft], + } else - 'index' + @md.lang_code_insert + ft - end - end - def html_segtoc - ft='.html' - if output_dir_structure.dump_or_redirect? - @md.fnb + '.toc' + ft + { + fn: 'index', + ft: fh[:ft], + lng: fh[:lng], + } + end + i18n(fnh) + end + def html_segtoc(fh=nil) + fh=default_hash_build(fh,Sfx[:html]) + fnh=if output_dir_structure.dump_or_redirect? + { + fn: fh[:fn] + '.toc', + ft: fh[:ft], + } elsif output_dir_structure.by_language_code? - 'toc' + ft + { + fn: 'toc', + ft: fh[:ft], + } else - 'toc' + @md.lang_code_insert + ft + { + fn: 'toc', + ft: fh[:ft], + lng: fh[:lng], + } + end + i18n(fnh) + end + def html_seg(fh) + fh=default_hash_build(fh,Sfx[:html]) + fnh=if output_dir_structure.by_language_code? + { + fn: fh[:fn], + ft: fh[:ft] + } + elsif output_dir_structure.by_filetype? + { + fn: fh[:fn], + ft: fh[:ft], + lng: fh[:lng] + } + else + { + fn: 'scroll', + ft: fh[:ft], + lng: fh[:lng] + } end + i18n(fnh) end def html_book_index - ft='.html' - if output_dir_structure.by_language_code? - 'book_index' + ft + ft=Sfx[:html] + fnh=if output_dir_structure.by_language_code? + { + fn: 'book_index', + ft: ft, + } else - 'book_index' + @md.lang_code_insert + ft + { + fn: 'book_index', + ft: ft, + lng: @md.lang_code_insert + } end + i18n(fnh) end def html_concordance - ft='.html' - if output_dir_structure.dump_or_redirect? + ft=Sfx[:html] + fnh=if output_dir_structure.dump_or_redirect? @md.fnb + '.concordance' + ft elsif output_dir_structure.by_language_code? - 'concordance' + ft + { + fn: 'concordance', + ft: ft, + } else - 'concordance' + @md.lang_code_insert + ft - end - end - def xhtml - ft= '.xhtml' - if output_dir_structure.by_language_code? - @md.fnb + ft + { + fn: 'concordance', + ft: ft, + lng: @md.lang_code_insert + } + end + i18n(fnh) + end + def xhtml(fh=nil) + fh=default_hash_build(fh,Sfx[:xhtml]) + fnh=if output_dir_structure.by_language_code? + { + fn: fh[:fn], + ft: fh[:ft], + } elsif output_dir_structure.by_filetype? - @md.fnb + @md.lang_code_insert + ft + { + fn: fh[:fn], + ft: fh[:ft], + lng: fh[:lng] + } else - 'scroll' + @md.lang_code_insert + ft - end - end - def epub - ft='.epub' - if output_dir_structure.by_language_code? - @md.fnb + ft + { + fn: 'scroll', + ft: fh[:ft], + lng: fh[:lng] + } + end + i18n(fnh) + end + def epub(fh=nil) + fh=default_hash_build(fh,Sfx[:epub]) + fnh=if output_dir_structure.by_language_code? + { + fn: fh[:fn], + ft: fh[:ft], + } else - @md.fnb + @md.lang_code_insert + ft - end - end - def odt - ft='.odt' - if output_dir_structure.by_language_code? - @md.fnb + ft + { + fn: fh[:fn], + ft: fh[:ft], + lng: fh[:lng], + } + end + i18n(fnh) + end + def odt(fh=nil) + fh=default_hash_build(fh,Sfx[:odt]) + fnh=if output_dir_structure.by_language_code? + { + fn: fh[:fn], + ft: fh[:ft], + } elsif output_dir_structure.by_filetype? - @md.fnb + @md.lang_code_insert + ft + { + fn: fh[:fn], + ft: fh[:ft], + lng: fh[:lng], + } else - 'opendocument' + @md.lang_code_insert + ft - end - end - def xml_sax - ft='.sax.xml' - if output_dir_structure.by_language_code? - @md.fnb + ft + { + fn: 'opendocument', + ft: fh[:ft], + lng: fh[:lng], + } + end + i18n(fnh) + end + def xml_sax(fh=nil) + fh=default_hash_build(fh,Sfx[:xml_sax]) + fnh=if output_dir_structure.by_language_code? + { + fn: fh[:fn], + ft: fh[:ft], + } elsif output_dir_structure.by_filetype? - @md.fnb + @md.lang_code_insert + ft + { + fn: fh[:fn], + ft: fh[:ft], + lng: fh[:lng], + } else - 'scroll' + @md.lang_code_insert + ft - end - end - def xml_dom - ft='.dom.xml' - if output_dir_structure.by_language_code? - @md.fnb + ft + { + fn: 'scroll', + ft: fh[:ft], + lng: fh[:lng], + } + end + i18n(fnh) + end + def xml_dom(fh=nil) + fh=default_hash_build(fh,Sfx[:xml_dom]) + fnh=if output_dir_structure.by_language_code? + { + fn: fh[:fn], + ft: fh[:ft], + } elsif output_dir_structure.by_filetype? - @md.fnb + @md.lang_code_insert + ft + { + fn: fh[:fn], + ft: fh[:ft], + lng: fh[:lng], + } else - 'scroll' + @md.lang_code_insert + ft + { + fn: 'scroll', + ft: fh[:ft], + lng: fh[:lng], + } end + i18n(fnh) end - def pdf_p + def pdf_p(fh=nil) + fh=default_hash_build(fh,Sfx[:pdf]) if output_dir_structure.by_language_code? - @md.fnb + '.portrait.' - else 'portrait' + @md.lang_code_insert + '.' + fh[:fn] + '.portrait.' + else + (@md.opt.lingual==:mono \ + && (@md.opt.lng == default_language?)) \ + ? ('portrait' + '.') + : ('portrait' + fh[:lng] + '.') end end - def pdf_l + def pdf_l(fh=nil) + fh=default_hash_build(fh,Sfx[:pdf]) if output_dir_structure.by_language_code? - @md.fnb + '.landscape.' - else 'landscape' + @md.lang_code_insert + '.' + fh[:fn] + '.landscape.' + else + (@md.opt.lingual==:mono \ + && (@md.opt.lng == default_language?)) \ + ? ('landscape' + '.') + : ('landscape' + fh[:lng] + '.') + #'landscape' + @md.lang_code_insert + '.' end end - def pdf_p_a4 - pdf_p + @md.fn[:pdf_p_a4] + def pdf_p_a4(fh=nil) + pdf_p(fh) + @md.fn[:pdf_p_a4] end - def pdf_p_a5 - pdf_p + @md.fn[:pdf_p_a5] + def pdf_p_a5(fh=nil) + pdf_p(fh) + @md.fn[:pdf_p_a5] end - def pdf_p_b5 - pdf_p + @md.fn[:pdf_p_b5] + def pdf_p_b5(fh=nil) + pdf_p(fh) + @md.fn[:pdf_p_b5] end - def pdf_p_letter - pdf_p + @md.fn[:pdf_p_letter] + def pdf_p_letter(fh=nil) + pdf_p(fh) + @md.fn[:pdf_p_letter] end - def pdf_p_legal - pdf_p + @md.fn[:pdf_p_legal] + def pdf_p_legal(fh=nil) + pdf_p(fh) + @md.fn[:pdf_p_legal] end - def pdf_l_a4 - pdf_l + @md.fn[:pdf_l_a4] + def pdf_l_a4(fh=nil) + pdf_l(fh) + @md.fn[:pdf_l_a4] end - def pdf_l_a5 - pdf_l + @md.fn[:pdf_l_a5] + def pdf_l_a5(fh=nil) + pdf_l(fh) + @md.fn[:pdf_l_a5] end - def pdf_l_b5 - pdf_l + @md.fn[:pdf_l_b5] + def pdf_l_b5(fh=nil) + pdf_l(fh) + @md.fn[:pdf_l_b5] end - def pdf_l_letter - pdf_l + @md.fn[:pdf_l_letter] + def pdf_l_letter(fh=nil) + pdf_l(fh) + @md.fn[:pdf_l_letter] end - def pdf_l_legal - pdf_l + @md.fn[:pdf_l_legal] + def pdf_l_legal(fh=nil) + pdf_l(fh) + @md.fn[:pdf_l_legal] end - def manpage - ft='1' - if output_dir_structure.by_language_code? - @md.fnb + '.' + ft + def manpage(fh=nil) + fh=default_hash_build(fh,Sfx[:manpage]) + fnh=if output_dir_structure.by_language_code? + { + fn: fh[:fn], + ft: fh[:ft], + } else - @md.fnb + '.' + @md.opt.f_pth[:lng_is] + '.' + ft - end - end - def info - ft='info' - if output_dir_structure.by_language_code? - @md.fnb + '.' + ft + { + fn: fh[:fn], + ft: fh[:ft], + lng: fh[:lng], + } + end + i18n(fnh) + end + def info(fh=nil) + fh=default_hash_build(fh,Sfx[:info]) + fnh=if output_dir_structure.by_language_code? + { + fn: fh[:fn], + ft: fh[:ft], + } else - @md.fnb + '.' + @md.opt.f_pth[:lng_is] + '.' + ft - end - end - def texinfo - ft='texinfo' - if output_dir_structure.by_language_code? - @md.fnb + '.' + ft + { + fn: fh[:fn], + ft: fh[:ft], + lng: fh[:lng], + } + end + i18n(fnh) + end + def texinfo(fh=nil) + fh=default_hash_build(fh,Sfx[:texinfo]) + fnh=if output_dir_structure.by_language_code? + { + fn: fh[:fn], + ft: fh[:ft], + } else - @md.fnb + '.' + @md.opt.f_pth[:lng_is] + '.' + ft - end - end - def sqlite_discrete - ft='.sql.db' - if output_dir_structure.by_language_code? - @md.fnb + ft + { + fn: fh[:fn], + ft: fh[:ft], + lng: fh[:lng], + } + end + i18n(fnh) + end + def sqlite_discrete(fh=nil) + fh=default_hash_build(fh,Sfx[:sql]) + fnh=if output_dir_structure.by_language_code? + { + fn: fh[:fn], + ft: fh[:ft], + } else - @md.fnb + @md.lang_code_insert + ft - end - end - def hash_digest - ft='.txt' - if output_dir_structure.by_language_code? - @md.fnb + '.hash_digest' + ft + { + fn: fh[:fn], + ft: fh[:ft], + lng: fh[:lng], + } + end + i18n(fnh) + end + def hash_digest(fh=nil) + fh=default_hash_build(fh,Sfx[:txt]) + fnh=if output_dir_structure.by_language_code? + { + fn: fh[:fn] + '.hash_digest', + ft: fh[:ft], + } elsif output_dir_structure.by_filetype? - @md.fnb + @md.lang_code_insert + ft + { + fn: fh[:fn], + ft: fh[:ft], + lng: fh[:lng], + } else - 'digest' + @md.lang_code_insert + ft - end - end - def sitemap - ft='.xml' - if output_dir_structure.by_language_code? - @md.fnb + '.sitemap' + ft + { + fn: 'digest', + ft: fh[:ft], + lng: fh[:lng], + } + end + i18n(fnh) + end + def sitemap(fh=nil) + fh=default_hash_build(fh,Sfx[:xml]) + fnh=if output_dir_structure.by_language_code? + { + fn: fh[:fn] + '.sitemap', + ft: fh[:ft], + } elsif output_dir_structure.by_filetype? - @md.fnb + @md.lang_code_insert + ft + { + fn: fh[:fn], + ft: fh[:ft], + lng: fh[:lng], + } else - 'sitemap' + @md.lang_code_insert + ft + { + fn: 'sitemap', + ft: fh[:ft], + lng: fh[:lng], + } end + i18n(fnh) end def qrcode_title + fn=@md.fnb ft='.title.png' - if output_dir_structure.by_language_code? - @md.fnb + ft + fnh=if output_dir_structure.by_language_code? + { + fn: fn, + ft: ft, + } elsif output_dir_structure.by_filetype? - @md.fnb + @md.lang_code_insert + ft - else #fix - 'sisu_manifest' + @md.lang_code_insert + ft + { + fn: fn, + ft: ft, + lng: @md.lang_code_insert + } + else + { + fn: 'sisu_manifest', + ft: ft, + lng: @md.lang_code_insert + } end + i18n(fnh) end def qrcode_md + fn=@md.fnb ft='.md.png' - if output_dir_structure.by_language_code? - @md.fnb + ft + fnh=if output_dir_structure.by_language_code? + { + fn: fn, + ft: ft, + } elsif output_dir_structure.by_filetype? - @md.fnb + @md.lang_code_insert + ft - else #fix - 'sisu_manifest' + @md.lang_code_insert + ft - end - end - def manifest_txt - ft='.txt' - if output_dir_structure.by_language_code? - @md.fnb + ft + { + fn: fn, + ft: ft, + lng: @md.lang_code_insert + } + else + { + fn: 'sisu_manifest', + ft: ft, + lng: @md.lang_code_insert + } + end + i18n(fnh) + end + def manifest_txt(fh=nil) + fh=default_hash_build(fh,Sfx[:txt]) + fnh=if output_dir_structure.by_language_code? + { + fn: fh[:fn], + ft: fh[:ft], + } elsif output_dir_structure.by_filetype? - @md.fnb + @md.lang_code_insert + ft - else #fix - 'sisu_manifest' + @md.lang_code_insert + ft - end - end - def manifest - ft='.html' - if output_dir_structure.dump_or_redirect? - @md.fnb + '.manifest' + ft + { + fn: fh[:fn], + ft: fh[:ft], + lng: fh[:lng], + } + else + { + fn: 'sisu_manifest', + ft: fh[:ft], + lng: fh[:lng], + } + end + i18n(fnh) + end + def manifest(fh=nil) + fh=default_hash_build(fh,Sfx[:html]) + fnh=if output_dir_structure.dump_or_redirect? + { + fn: fh[:fn] + '.manifest', + ft: fh[:ft], + } elsif output_dir_structure.by_language_code? - @md.fnb + ft + { + fn: fh[:fn], + ft: fh[:ft], + } elsif output_dir_structure.by_filetype? - @md.fnb + @md.lang_code_insert + ft - else #fix - 'sisu_manifest' + @md.lang_code_insert + ft + { + fn: fh[:fn], + ft: fh[:ft], + lng: fh[:lng], + } + else + { + fn: 'sisu_manifest', + ft: fh[:ft], + lng: fh[:lng], + } end + i18n(fnh) end def src @md.fno -- cgit v1.2.3 From 9e8a84f55ed79c58b3309e7fef4ec7242fb4c5e2 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Tue, 30 Jul 2013 21:38:47 -0400 Subject: v5: cgi helper script, sample search form, single form, monolingual option * single cgi form, (with different internal variables set for output types) * monolingual output search form option --- lib/sisu/v5/sysenv.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/sisu/v5/sysenv.rb') diff --git a/lib/sisu/v5/sysenv.rb b/lib/sisu/v5/sysenv.rb index 63981be3..9ddc763e 100644 --- a/lib/sisu/v5/sysenv.rb +++ b/lib/sisu/v5/sysenv.rb @@ -2519,8 +2519,8 @@ WOK /(?:https?:\/\/\S+?)\/([^\/]+?\.cgi)$/.match(@rc['search']['sisu']['action'])[1] else (opt.mod.inspect =~/--db[=-]["']?sqlite/) \ - ? 'sisu_sqlite.cgi' \ - : 'sisu_pgsql.cgi' + ? "#{Db[:name_prefix_db]}sqlite.cgi" \ + : "#{Db[:name_prefix_db]}pgsql.cgi" end end def sample_search_form_title(organised_by=:language) -- cgit v1.2.3