diff options
author | Ralph Amissah <ralph@amissah.com> | 2012-10-03 00:24:45 -0400 |
---|---|---|
committer | Ralph Amissah <ralph@amissah.com> | 2012-10-03 00:24:45 -0400 |
commit | f38a6456d0e3f352b0adf7792effeec9bad7819c (patch) | |
tree | 1ea909e78313ff15fa8db94f7be0a202586344cf /lib | |
parent | v4: param (header make), pdf, footer (diff) |
v4: param, common independent document @make: header file
* ./_sisu/v4/sisu_document_make
* contains @make: header
* can contain @links: header
* @links:+ append links
* @links: default, overwritten if document contains links
Diffstat (limited to 'lib')
-rw-r--r-- | lib/sisu/v4/dal_syntax.rb | 55 | ||||
-rw-r--r-- | lib/sisu/v4/options.rb | 80 | ||||
-rw-r--r-- | lib/sisu/v4/param.rb | 522 | ||||
-rw-r--r-- | lib/sisu/v4/param_make.rb | 636 | ||||
-rw-r--r-- | lib/sisu/v4/sysenv.rb | 43 |
5 files changed, 856 insertions, 480 deletions
diff --git a/lib/sisu/v4/dal_syntax.rb b/lib/sisu/v4/dal_syntax.rb index fba2e765..b62fbad8 100644 --- a/lib/sisu/v4/dal_syntax.rb +++ b/lib/sisu/v4/dal_syntax.rb @@ -63,15 +63,15 @@ module SiSU_DAL_Syntax end class Markup def initialize(md='',data='') - @data,@md=data,md + @md,@data=md,data @vz=SiSU_Viz::Defaults.new @data_new=[] url_and_stub=SiSU_Env::InfoEnv.new.url @output_url="#{url_and_stub.remote}" @env=SiSU_Env::InfoEnv.new - emph_set=if defined? @md.make.emphasis \ - and not @md.make.emphasis.nil? - @md.make.emphasis + emph_set=if defined? @md.emphasis_set_to \ + and not @md.emphasis_set_to.nil? + @md.emphasis_set_to else @env.markup_emphasis end @emph=case emph_set @@ -94,25 +94,22 @@ module SiSU_DAL_Syntax tail_m_bold=%{(?:(?:#{Mx[:fa_italics_c]})?(?:\s|[.,;:?!'")]|~\^|~\\\{\s|$))?} bold_line=%{^!_\s.+?(?:#{Mx[:br_line]}|\n|$)} ital_line=%{^/_\s.+?(?:#{Mx[:br_line]}|\n|$)} - @line_scan_ital=if defined? @md.make.italics[:str] \ - and defined? @vz.markup_make_italic[:str] - /#{@http_m}|#{bold_line}|#{@manmkp_ital}#{tail_m_ital}|(?:#{@md.make.italics[:str]}|#{@vz.markup_make_italic[:str]})#{tail_m_ital}|\S+|\n/i - elsif defined? @md.make.italics[:str] - /#{@http_m}|#{bold_line}|#{@manmkp_ital}#{tail_m_ital}|#{@md.make.italics[:str]}#{tail_m_ital}|\S+|\n/i + @line_scan_ital=if defined? @md.italics_match_list[:str] + /#{@http_m}|#{bold_line}|#{@manmkp_ital}#{tail_m_ital}|#{@md.italics_match_list[:str]}#{tail_m_ital}|\S+|\n/i elsif defined? @vz.markup_make_italic[:str] /#{@http_m}|#{bold_line}|#{@manmkp_ital}#{tail_m_ital}|#{@vz.markup_make_italic[:str]}#{tail_m_ital}|\S+|\n/i end @manmkp_bold=emph_italics \ ? '^!_\s.+?(?:\n|$)|[!b]\\{.+?\\}[*!b]|[*!][a-zA-Z0-9\-_]+[!]' : '^!_\s.+?(?:\n|$)|[*!b]\\{.+?\\}[*!b]|[*!][a-zA-Z0-9\-_]+[*!]' - @line_scan_bold=if (defined? @md.make.bold[:str] \ - and @md.make.bold[:str]) \ + @line_scan_bold=if (defined? @md.bold_match_list[:str] \ + and @md.bold_match_list[:str]) \ and (defined? @vz.markup_make_bold[:str] \ and @vz.markup_make_bold[:str]) - /#{@http_m}|#{bold_line}|(?:#{@manmkp_bold}|#{@md.make.bold[:str]}|#{@vz.markup_make_bold[:str]})#{tail_m_bold}|\S+|\n/i - elsif defined? @md.make.bold[:str] \ - and @md.make.bold[:str] - /#{@http_m}|#{bold_line}|(?:#{@manmkp_bold}|#{@md.make.bold[:str]})#{tail_m_bold}|\S+|\n/i + /#{@http_m}|#{bold_line}|(?:#{@manmkp_bold}|#{@md.bold_match_list[:str]}|#{@vz.markup_make_bold[:str]})#{tail_m_bold}|\S+|\n/i + elsif defined? @md.bold_match_list[:str] \ + and @md.bold_match_list[:str] + /#{@http_m}|#{bold_line}|(?:#{@manmkp_bold}|#{@md.bold_match_list[:str]})#{tail_m_bold}|\S+|\n/i elsif defined? @vz.markup_make_bold[:str] \ and @vz.markup_make_bold[:str] /#{@http_m}|#{bold_line}|(?:#{@manmkp_bold}|#{@vz.markup_make_bold[:str]})#{tail_m_bold}|\S+|\n/i @@ -152,8 +149,8 @@ module SiSU_DAL_Syntax end def wordlist_italics(dob) dob=dob.dup - if (defined? @md.make.italics[:str] \ - and @md.make.italics[:str]) \ + if (defined? @md.italics_match_list[:str] \ + and @md.italics_match_list[:str]) \ or (defined? @vz.markup_make_italic[:str] \ and @vz.markup_make_italic[:str]) dob.obj=if dob.is !=:meta \ @@ -166,9 +163,9 @@ module SiSU_DAL_Syntax line_array=[] word.each do |w| unless /#{@manmkp_ital}|#{@http_m}/.match(w) - if defined? @md.make.italics[:regx] \ - and @md.make.italics[:regx] - w=w.gsub(@md.make.italics[:regx], + if defined? @md.italics_match_list[:regx] \ + and @md.italics_match_list[:regx] + w=w.gsub(@md.italics_match_list[:regx], "#{Mx[:fa_italics_o]}\\1#{Mx[:fa_italics_c]}") elsif defined? @vz.markup_make_italic \ and @vz.markup_make_italic @@ -237,15 +234,15 @@ module SiSU_DAL_Syntax end def substitutions(dob) dob=dob.dup - dob=if defined? @md.make.substitute[:match_and_replace] \ - and @md.make.substitute[:match_and_replace].is_a?(Array) + dob=if defined? @md.substitution_match_list[:match_and_replace] \ + and @md.substitution_match_list[:match_and_replace].is_a?(Array) dob=if dob.is !=:meta \ && dob.is !=:heading_insert \ && dob.is !=:code \ && dob.is !=:comment \ && dob.is !=:table - if dob.obj =~/#{@md.make.substitute[:matches]}/ - @md.make.substitute[:match_and_replace].each do |x| + if dob.obj =~/#{@md.substitution_match_list[:matches]}/ + @md.substitution_match_list[:match_and_replace].each do |x| dob.obj=if x[:case_s]==:i dob.obj.gsub(/#{x[:match]}/mi,x[:replace]) else @@ -262,8 +259,8 @@ module SiSU_DAL_Syntax end def wordlist_bold(dob) dob=dob.dup - if (defined? @md.make.bold[:str] \ - and @md.make.bold[:str]) \ + if (defined? @md.bold_match_list[:str] \ + and @md.bold_match_list[:str]) \ or (defined? @vz.markup_make_bold[:str] \ and @vz.markup_make_bold[:str]) dob.obj=if dob.is !=:meta \ @@ -277,9 +274,9 @@ module SiSU_DAL_Syntax word=word.flatten.compact word.each do |w| unless /#{@manmkp_bold}|#{@http_m}/.match(w) - if defined? @md.make.bold[:regx] \ - and @md.make.bold[:regx] #document header: @bold: [bold word list] - w=w.gsub(@md.make.bold[:regx],"#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}") + if defined? @md.bold_match_list[:regx] \ + and @md.bold_match_list[:regx] #document header: @bold: [bold word list] + w=w.gsub(@md.bold_match_list[:regx],"#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}") elsif defined? @vz.markup_make_bold \ and @vz.markup_make_bold #defaults adjusted bold word list w=w.gsub(@vz.markup_make_bold,"#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}") diff --git a/lib/sisu/v4/options.rb b/lib/sisu/v4/options.rb index d2898bfd..ddf9737b 100644 --- a/lib/sisu/v4/options.rb +++ b/lib/sisu/v4/options.rb @@ -59,9 +59,77 @@ module SiSU_Commandline require 'pathname' require_relative 'sysenv' # sysenv.rb + require_relative 'param_make' # param_make.rb @@sisu_call_origin_path=nil + class HeaderCommon + def sisu_document_make_instructions + @pagenew=@pagebreak=@toc=@lv1=@lv2=@lv3=@lv4=@lv5=@lv6=@num_top=@i18n=@man_section=@emphasis_set_to=@bold_match_list=@italics_match_list=@substitution_match_list=@footer_links=@home_button_links=@links=nil + @makeset=false + make_instruct_array=SiSU_Env::GetInit.new.sisu_document_make.makefile + if make_instruct_array + make_instruct_array.each do |para| #% scan document + if para =~/^(?:@make:|@links:)[+-]?\s/ + case para + when /^@make:(.+)/m #% * header processing - make + @env=SiSU_Env::InfoEnv.new + @make=SiSU_Param_Make::MdMake.new($1.strip,@opt,@env).make + makes=SiSU_Param_Make::MakeHead.new(@make).make_instruct + @makeset=true + @pagenew=makes[:pagenew] + @pagebreak=makes[:pagenew] + @toc=makes[:toc] + @lv1=makes[:lv1] + @lv2=makes[:lv2] + @lv3=makes[:lv3] + @lv4=makes[:lv4] + @lv5=makes[:lv5] + @lv6=makes[:lv6] + @num_top=makes[:num_top] + @i18n=makes[:i18n] + @man_section=makes[:man_section] + @emphasis_set_to=makes[:emphasis_set_to] + @bold_match_list=makes[:bold_match_list] + @italics_match_list=makes[:italics_match_list] + @substitution_match_list=makes[:substitution_match_list] + @footer_links=makes[:footer_links] + @home_button_links=makes[:home_button_links] + @home_button_image=makes[:home_button_image] + @cover_image=makes[:cover_image] + when /^@links:(.+)/m #% header processing - make + make_links=SiSU_Param::Parameters::MdMake.new($1.strip,@opt,@env).make_links + @links,@links_append=make_links.links,make_links.append? + end + end + end #% here endeth the common header loop + end + { makeset: @makeset, + pagenew: @pagenew, + pagebreak: @pagebreak, + toc: @toc, + lv1: @lv1, + lv2: @lv2, + lv3: @lv3, + lv4: @lv4, + lv5: @lv5, + lv6: @lv6, + num_top: @num_top, + i18n: @i18n, + man_section: @man_section, + emphasis_set_to: @emphasis_set_to, + bold_match_list: @bold_match_list, + italics_match_list: @italics_match_list, + substitution_match_list: @substitution_match_list, + footer_links: @footer_links, + home_button_links: @home_button_links, + home_button_image: @home_button_image, + cover_image: @cover_image, + links: @links, + links_append: @links_append + } + end + end class Options - attr_accessor :cmd,:mod,:act,:dir_structure_by,:f_pths,:files,:files_mod,:base_path,:base_stub,:sub_location,:paths,:lngs,:f_pth,:pth,:fno,:fns,:fnb,:fnc,:fng,:fncb,:lng,:lng_base,:what + attr_accessor :cmd,:mod,:act,:dir_structure_by,:f_pths,:files,:files_mod,:base_path,:base_stub,:sub_location,:paths,:lngs,:f_pth,:pth,:fno,:fns,:fnb,:fnc,:fng,:fncb,:lng,:lng_base,:what,:make_instructions @@act=nil def initialize(a) @cmd,@f_pth,@pth,@fno,@fns,@fnb,@fnc,@fng,@fncb,@what,@lng,@lng_base,@base_path,@base_stub,@sub_location='','','','','','','','','','','','','','' @@ -76,6 +144,7 @@ module SiSU_Commandline @base_stub=@base_path.gsub(u,'\1') @a=sisu_glob_rules(a) @a.freeze + @make_instructions=HeaderCommon.new.sisu_document_make_instructions init end def find_all(find_flag,opt) @@ -868,9 +937,6 @@ module SiSU_Commandline end end __END__ -note usually named @opt -is carried in Param usually as @md -@opt is a subset of @md -where @md is passed, contents of @opt are available -passing @opt as well is duplication -check for fns & fnb +note usually named @opt is carried in Param usually as @md @opt is a subset of +@md where @md is passed, contents of @opt are available as @md.opt passing @opt +as well is duplication check for fns & fnb diff --git a/lib/sisu/v4/param.rb b/lib/sisu/v4/param.rb index f9607df2..925723f8 100644 --- a/lib/sisu/v4/param.rb +++ b/lib/sisu/v4/param.rb @@ -60,6 +60,7 @@ module SiSU_Param require 'pstore' require_relative 'sysenv' # sysenv.rb include SiSU_Env + require_relative 'param_make' # param_make.rb require_relative 'param_identify_markup' # param_identify_markup.rb require_relative 'help' # help.rb include SiSU_Help @@ -159,6 +160,8 @@ module SiSU_Param self end end + class MdMake < SiSU_Param_Make::MdMake + end class Md def initialize(str,opt,env) @s,@opt,@env=str,opt,env @@ -736,349 +739,6 @@ module SiSU_Param # end # self #end - def make - a=@s.split(/\n%\s.+?$|[ ]*\n[ ]*/m) - @h=build_hash(a) - def headings - lv=[] - x=@h['headings'] - x=((x =~/;/) ? (x.split(/;\s*/)) : [ x ]) - lv[0]=x - lv1=x[0] ||='1~ ' #some arbitrary changes made - lv[1]=/^#{lv1}/ - lv2=x[1] ||='2~ ' - lv[2]=/^#{lv2}/ - lv3=x[2] ||='3~ ' - lv[3]=/^#{lv3}/ - lv4=x[3] ||='4~ ' - lv[4]=/^#{lv4}/ - lv5=x[4] ||='5~ ' - lv[5]=/^#{lv5}/ - lv6=x[5] ||='6~ ' - lv[6]=/^#{lv6}/ - lv - end - def num_top - @h['num_top'] - end - def breaks - pagebreaks=((@h['breaks'] =~/;/) \ - ? (@h['breaks'].split(/;\s*/)) - : [ @h['breaks'] ]) - page_new,page_break=nil,nil - pagebreaks.each do |x| - page_new=x[/(:?[\dA-C],?)+/] if x=~/new|clear/ - page_break=x[/(:?[\dA-C],?)+/] if x =~/break/ - end - { page_new: page_new, page_break: page_break } - end - def language - l=if @h['language'] && (@h['language']=~/\S{2,}/) - ((@h['language'] =~/,/) \ - ? (@h['language'].split(/,\s*/)) - : [ @h['language'] ]) - else [ 'en' ] - end - end - def bold - m=@h['bold'] - i=(m=~/\/i$/)? 'i' : '' - z=if m - x=m.gsub(/^\/(.+?)\/i?/,'\1'). - gsub(/\((?:\?:)?/,'(?:') # avoid need to escape use of brackets within regex provided - rgx='\b(' + x + ')\b' - y=((i =~/i/) ? (/#{rgx}/i) : (/#{rgx}/)) - { str: '\b(?:' + x + ')\b', regx: y, i: i } - else nil - end - end - def italics - m=@h['italics'] - i=((m=~/\/i$/) ? 'i' : '') - z=if m - x=m.gsub(/^\/(.+?)\/i?/,'\1'). - gsub(/\((?:\?:)?/,'(?:') # avoid need to escape use of brackets within regex provided - rgx='\b(' + x + ')\b' - y=((i =~/i/) ? (/#{rgx}/i) : (/#{rgx}/)) - { str: '\b(?:' + x + ')\b', regx: y, i: i } - else nil - end - end - def emphasis - if @h['emphasis'] =~/bold/ then 'bold' - elsif @h['emphasis'] =~/italics?/ then 'italics' - elsif @h['emphasis'] =~/under(?:line|score)/ then 'underscore' - else nil - end - end - def substitute - m=@h['substitute'] - z=if m - w=m.scan(/\/(.+?)\/(i?,)\s*'(.+?)'(?:\s+|\s*;\s*|$)/) - arr_hash=[] - matches='' - w.each do |x| - c=(x[1] =~/[i],/) ? :i : :s - matches=matches + x[0].gsub(/([${}])/,'\\\\\1') + '|' - arr_hash << { - match: x[0].gsub(/([${}])/,'\\\\\1'), - replace: x[2], - case_s: c - } - end - matches.chop! - { match_and_replace: arr_hash, matches: matches } - else nil - end - end - def plaintext_wrap - if @h['plaintext_wrap'].to_s =~/\d\d+/ \ - and @h['plaintext_wrap'].to_i > 19 \ - and @h['plaintext_wrap'].to_i < 201 - @h['plaintext_wrap'].to_i - else nil - end - end - def omit - m=@h['omit'] - @m=m ? (m.split(/,\s+/)) : nil - def list - @m - end - self - end - def ocn? - (omit.list.inspect =~/"ocn"/) \ - ? :off - : :na - end - def toc? - (omit.list.inspect =~/"toc"/) \ - ? :off - : :na - end - def manifest? - (omit.list.inspect =~/"manifest"/) \ - ? :off - : :na - end - def links_to_manifest? - (omit.list.inspect =~/"manifest_links"|"links_to_manifest"/) \ - ? :off - : :na - end - def metadata? - (omit.list.inspect =~/"metadata"/) \ - ? :off - : :na - end - def minitoc? - (omit.list.inspect =~/"minitoc"/) \ - ? :off - : :na - end - def html_minitoc? - (omit.list.inspect =~/"html_minitoc"/) \ - ? :off - : :na - end - def html_top_band? - (omit.list.inspect =~/"html_top_band"/) \ - ? :off - : :na - end - def html_navigation? - (omit.list.inspect =~/"html_navigation"/) \ - ? :off - : :na - end - def html_navigation_bar? - (omit.list.inspect =~/"html_navigation_bar"/) \ - ? :off - : :na - end - def segsubtoc? - (omit.list.inspect =~/"segsubtoc"/) \ - ? :off - : :na - end - def search_form? - (omit.list.inspect =~/"search_form"/) \ - ? :off - : :na - end - def html_search_form? - (omit.list.inspect =~/"html_search_form"/) \ - ? :off - : :na - end - def html_right_pane? - (omit.list.inspect =~/"html_right_column"|"html_right_pane"/) \ - ? :off - : :na - end - def manifest_minitoc? - (omit.list.inspect =~/"manifest_minitoc"/) \ - ? :off - : :na - end - def cover_image? - (omit.list.inspect =~/"cover_image"/) \ - ? :off - : :na - end - def home_button_image? - (omit.list.inspect =~/"home_button_image"/) \ - ? :off - : :na - end - def texpdf_font - def main - @h['texpdf_font'] \ - && (@h['texpdf_font']=~/\S{3,}/) \ - ? @h['texpdf_font'] - : @env.font.texpdf.main - end - def sans # not used - @h['texpdf_font_sans'] \ - && (@h['texpdf_font_sans']=~/\S{3,}/) \ - ? @h['texpdf_font_sans'] - : @env.font.texpdf.sans - end - def serif # not used - @h['texpdf_font_serif'] \ - && (@h['texpdf_font_serif']=~/\S{3,}/) \ - ? @h['texpdf_font_serif'] - : @env.font.texpdf.serif - end - def mono - @h['texpdf_font_mono'] \ - && (@h['texpdf_font_mono']=~/\S{3,}/) \ - ? @h['texpdf_font_mono'] - : @env.font.texpdf.mono - end - self - end - def promo - @h['promo'] - end - def ad - @h['ad'] - end - def manpage - manpage={} - if @h['manpage'] - if @h['manpage'] =~/;/m - man=@h['manpage'].split(/;/m) - man.each do |x| - m=(x=~/=/m) ? x.split(/=/m) : nil - if m - manpage[m[0].strip] = m[1].split(/ \. /) - end - end - end - end - if manpage['name'] - manpage['name']=manpage['name'].join("\n.br\n"). - gsub(/(-)/m,"\\\\\\1"). - gsub(/\A/,"\n.br\n.SH NAME\n.br\n") - else - manpage['name']='man page "name/whatis" information not provided, set in header @man: name=[whatis information]' - end - if manpage['synopsis'] - manpage['synopsis']=manpage['synopsis'].join("\n\n.br\n"). - gsub(/(-)/m,"\\\\\\1"). - gsub(/\A/,"\n.br\n.SH SYNOPSIS\n.br\n") - else - manpage['synopsis']='' - end - unless manpage['section'] - manpage['section']=1 - end - manpage - end - def get_image_dimentions(img) - imgk=SiSU_Env::SystemCall.new.imagemagick - gmgk=SiSU_Env::SystemCall.new.graphicksmagick - if imgk or gmgk - img_pth=@env.path.image_source_include - if imgk - imgsys=`identify #{img_pth}/#{img}`.strip #system call - elsif gmgk - imgsys=`gm identify #{img_pth}/#{img}`.strip #system call - end - w,h=/(\d+)x(\d+)/m.match(imgsys)[1,2] - else - w,h='600','800' - end - {w: w, h: h} - end - def home_button_text - s=if @h['home_button_text'] - @h['home_button_text'].split(/\s*;\s*/) - else nil - end - #l,n=Db[:home_button],'make.home_button_text' - #validate_length(s,l,n) - end - def home_button_image - s=nil - s=if @h['home_button_image'] - s=@h['home_button_image'].split(/\s*;\s*/) - s0=s[0] #if - image={} - s=if s0 =~/{(\S+\.(?:jpg|png|gif))(?:\s+(\d+x\d+))?\s*}(?:(http:\/\/\S+)|image)/ - image[:home_button]=$1 - if $2 - image[:dimentions]=$2 - image[:w],image[:h]=/(\d+)x(\d+)/m.match(image[:dimentions])[1,2] - else - d=get_image_dimentions(image[:home_button]) - image[:w],image[:h]=d[:w],d[:h] - image[:dimentions]="#{d[:w]}x#{d[:h]}" - end - image[:link]=$3 - image - end - else nil - end - end - def cover_image - s=nil - if @h['cover_image'] - s=@h['cover_image'].split(/\s*;\s*/) - s=s[0] #if - image={} - if s =~/{(\S+\.(?:jpg|png|gif))(?:\s+(\d+x\d+))?\s+(?:"(.+?)")?\s*}image/ - image[:cover]=$1 - if $2 - image[:dimentions]=$2 - image[:w],image[:h]=/(\d+)x(\d+)/m.match(image[:dimentions])[1,2] - else - d=get_image_dimentions(image[:cover]) - image[:w],image[:h]=d[:w],d[:h] - image[:dimentions]="#{d[:w]}x#{d[:h]}" - end - image[:note]=$3 - elsif s =~/(\S+\.(?:jpg|png|gif))/ - image[:cover]=$1 - d=get_image_dimentions(image[:cover]) - image[:w],image[:h]=d[:w],d[:h] - image[:dimentions]="#{d[:w]}x#{d[:h]}" - image[:note]=nil - end - image - else nil - end - end - def footer - s=if @h['footer'] - @h['footer'].split(/\s*;\s*/) - else nil - end - end - self - end def current_publisher @s end @@ -1117,9 +777,6 @@ module SiSU_Param end self end - def links - a=@s.split(/\n%\s.+?$|[ ]*\n[ ]*/m) - end def notes a=@s.split(/\n%\s.+?$|[ ]*\n[ ]*/m) @h=build_hash(a) @@ -1145,9 +802,9 @@ module SiSU_Param @doc={ lv: [] } @doc[:fns],@doc[:fnb],@doc[:scr_suffix]='','','' @@publisher='SiSU scribe' - attr_accessor :make,:env,:path,:file,:fn,:fns,:fno,:fnb,:fnn,:fnt,:fnl,:flv,:fnz,:fnstex,:ocn,:sfx_src,:pdf,:file_type,:dir_out,:dir_tex,:dir_lout,:txt_path,:sisu,:sisu_version,:ruby_version,:title,:subtitle,:full_title,:html_title,:subtitle_tex,:creator,:classify,:author_home,:author,:author_title,:author_nationality,:authors,:authorship,:translator,:illustrator,:prepared_by,:digitized_by,:subject,:description,:publisher,:current_publisher,:contributor,:date,:date_created,:date_issued,:date_available,:date_valid,:date_modified,:date_translated,:date_added_to_site,:date_scheme,:date_created_scheme,:date_issued_scheme,:date_available_scheme,:date_valid_scheme,:date_modified_scheme,:type,:format,:identifier,:source,:language,:language_original,:relation,:coverage,:rights,:keywords,:comments,:abstract,:cls_loc,:cls_dewey,:cls_pg,:cls_isbn,:papersize,:papersize_array,:toc,:lv1,:lv2,:lv3,:lv4,:lv5,:lv6,:lvs,:pagenew,:pagebreak,:num_top,:toc_lev_limit,:flag_endnotes,:flag_auto_endnotes,:flag_separate_endnotes,:flag_separate_endnotes_make,:markup,:markup_instruction,:markup_version,:markup_declared,:flag_tables,:vocabulary,:doc_css,:yaml,:lnk,:links,:prefix_a,:prefix_b,:suffix,:information,:contact,:icon,:image,:ad_url,:ad_png,:ad_alt,:ad_began,:flag_promo,:promo,:ad_home,:stmp,:stmpd,:sc_filename,:sc_number,:sc_date,:sc_time,:sc_info,:yamladdr,:locale,:wc_lines,:wc_words,:wc_bytes,:file_encoding,:filesize,:user,:home,:hostname,:pwd,:firstseg,:programs,:author_copymark,:i18n,:lang,:lang_code_insert,:en,:notes,:dgst,:generated,:tags,:tag_array,:concord_make,:seg_names,:seg_autoname_safe,:set_header_title,:set_heading_top,:set_heading_seg,:heading_seg_first,:heading_seg_first_flag,:base_program,:ec,:opt,:sem_tag,:book_idx,:topic_register,:topic_register_array,:original,:writing_focus,:audio,:daisy,:home_button_image,:home_button_links,:footer_links,:cover_image,:man_section + attr_accessor :make,:env,:path,:file,:fn,:fns,:fno,:fnb,:fnn,:fnt,:fnl,:flv,:fnz,:fnstex,:ocn,:sfx_src,:pdf,:file_type,:dir_out,:dir_tex,:dir_lout,:txt_path,:sisu,:sisu_version,:ruby_version,:title,:subtitle,:full_title,:html_title,:subtitle_tex,:creator,:classify,:author_home,:author,:author_title,:author_nationality,:authors,:authorship,:translator,:illustrator,:prepared_by,:digitized_by,:subject,:description,:publisher,:current_publisher,:contributor,:date,:date_created,:date_issued,:date_available,:date_valid,:date_modified,:date_translated,:date_added_to_site,:date_scheme,:date_created_scheme,:date_issued_scheme,:date_available_scheme,:date_valid_scheme,:date_modified_scheme,:type,:format,:identifier,:source,:language,:language_original,:relation,:coverage,:rights,:keywords,:comments,:abstract,:cls_loc,:cls_dewey,:cls_pg,:cls_isbn,:papersize,:papersize_array,:toc,:lv1,:lv2,:lv3,:lv4,:lv5,:lv6,:lvs,:pagenew,:pagebreak,:num_top,:bold_match_list,:italics_match_list,:substitution_match_list,:emphasis_set_to,:toc_lev_limit,:flag_endnotes,:flag_auto_endnotes,:flag_separate_endnotes,:flag_separate_endnotes_make,:markup,:markup_instruction,:markup_version,:markup_declared,:flag_tables,:vocabulary,:doc_css,:yaml,:lnk,:links,:prefix_a,:prefix_b,:suffix,:information,:contact,:icon,:image,:ad_url,:ad_png,:ad_alt,:ad_began,:flag_promo,:promo,:ad_home,:stmp,:stmpd,:sc_filename,:sc_number,:sc_date,:sc_time,:sc_info,:yamladdr,:locale,:wc_lines,:wc_words,:wc_bytes,:file_encoding,:filesize,:user,:home,:hostname,:pwd,:firstseg,:programs,:author_copymark,:i18n,:lang,:lang_code_insert,:en,:notes,:dgst,:generated,:tags,:tag_array,:concord_make,:seg_names,:seg_autoname_safe,:set_header_title,:set_heading_top,:set_heading_seg,:heading_seg_first,:heading_seg_first_flag,:base_program,:ec,:opt,:sem_tag,:book_idx,:topic_register,:topic_register_array,:original,:writing_focus,:audio,:daisy,:home_button_image,:home_button_links,:footer_links,:cover_image,:man_section def initialize(fns_array,opt) - @env=@path,@file=@fn=@fns=@fno=@fnb=@fnn=@fnt=@fnl=@flv=@fnz=@fnstex=@ocn=@sfx_src=@pdf=@file_type=@dir_out=@dir_tex=@dir_lout=@txt_path=@make=@flag_endnotes=@flag_auto_endnotes=@flag_separate_endnotes=@flag_separate_endnotes_make=@sisu=@sisu_version=@ruby_version=@title=@subtitle=@full_title=@html_title=@subtitle_tex=@creator=@classify=@author_home=@author=@author_title=@author_nationality=@translator=@illustrator=@prepared_by=@digitized_by=@subject=@description=@publisher=@current_publisher=@contributor=@date=@date_created=@date_issued=@date_available=@date_valid=@date_modified=@date_translated=@date_added_to_site=@date_scheme=@date_created_scheme=@date_issued_scheme=@date_available_scheme=@date_valid_scheme=@date_modified_scheme=@type=@format=@identifier=@source=@language=@language_original=@relation=@coverage=@rights=@keywords=@comments=@abstract=@cls_loc=@cls_dewey=@cls_pg=@cls_isbn=@papersize=@toc=@lv1=@lv2=@lv3=@lv4=@lv5=@lv6=@pagenew=@pagebreak=@num_top=@toc_lev_limit=@flag_tables=@vocabulary=@doc_css=@yaml=@lnk=@links=@prefix_a=@prefix_b=@suffix=@information=@contact=@icon=@ad_url=@ad_png=@ad_alt=@ad_began=@promo=@ad_home=@stmp=@stmpd=@sc_filename=@sc_number=@sc_date=@sc_time=@sc_info=@yamladdr=@locale=@wc_lines=@wc_words=@wc_bytes=@file_encoding=@filesize=@firstseg=@programs=@author_copymark=@i18n=@lang=@lang_code_insert=@en=@notes=@dgst=@generated=@heading_seg_first=@base_program=@topic_register=@original=@writing_focus=@audio=@home_button_image=@home_button_links=@cover_image=@man_section=nil + @env=@path,@file=@fn=@fns=@fno=@fnb=@fnn=@fnt=@fnl=@flv=@fnz=@fnstex=@ocn=@sfx_src=@pdf=@file_type=@dir_out=@dir_tex=@dir_lout=@txt_path=@make=@flag_endnotes=@flag_auto_endnotes=@flag_separate_endnotes=@flag_separate_endnotes_make=@sisu=@sisu_version=@ruby_version=@title=@subtitle=@full_title=@html_title=@subtitle_tex=@creator=@classify=@author_home=@author=@author_title=@author_nationality=@translator=@illustrator=@prepared_by=@digitized_by=@subject=@description=@publisher=@current_publisher=@contributor=@date=@date_created=@date_issued=@date_available=@date_valid=@date_modified=@date_translated=@date_added_to_site=@date_scheme=@date_created_scheme=@date_issued_scheme=@date_available_scheme=@date_valid_scheme=@date_modified_scheme=@type=@format=@identifier=@source=@language=@language_original=@relation=@coverage=@rights=@keywords=@comments=@abstract=@cls_loc=@cls_dewey=@cls_pg=@cls_isbn=@papersize=@toc=@lv1=@lv2=@lv3=@lv4=@lv5=@lv6=@pagenew=@pagebreak=@num_top=@bold_match_list=@italics_match_list=@substitution_match_list=@emphasis_set_to=@toc_lev_limit=@flag_tables=@vocabulary=@doc_css=@yaml=@lnk=@links=@prefix_a=@prefix_b=@suffix=@information=@contact=@icon=@ad_url=@ad_png=@ad_alt=@ad_began=@promo=@ad_home=@stmp=@stmpd=@sc_filename=@sc_number=@sc_date=@sc_time=@sc_info=@yamladdr=@locale=@wc_lines=@wc_words=@wc_bytes=@file_encoding=@filesize=@firstseg=@programs=@author_copymark=@i18n=@lang=@lang_code_insert=@en=@notes=@dgst=@generated=@heading_seg_first=@base_program=@topic_register=@original=@writing_focus=@audio=@home_button_image=@home_button_links=@cover_image=@man_section=nil @data,@path,@fns,@fno,@opt=fns_array,opt.pth,opt.fns,opt.fno,opt #@data used as data @flag_tables,@set_header_title,@set_heading_top,@set_heading_seg,@heading_seg_first_flag,@flag_promo,@book_idx=false,false,false,false,false,false,false @seg_autoname_safe=true @@ -1158,6 +815,7 @@ module SiSU_Param @flv,@lang,@seg_names,@tags,@tag_array,@tag_a,@ec[:image],@ec[:audio],@ec[:multimedia]=Array.new(9){[]} @authors,@topic_register_array,@papersize_array=[],[],[] @lvs=[nil,0,0,0,0,0,0] + @emphasis_set_to='bold' @lang_code_insert=if @opt.act[:output_by][:set]==:language '' elsif @opt.act[:output_by][:set]==:filetype \ @@ -1180,6 +838,32 @@ module SiSU_Param end ensure end + @header_make_links_append=:no + common_makes=@opt.make_instructions + if common_makes[:makeset] + @pagenew=common_makes[:pagenew] + @pagebreak=common_makes[:pagenew] + @toc=common_makes[:toc] + @lv1=common_makes[:lv1] + @lv2=common_makes[:lv2] + @lv3=common_makes[:lv3] + @lv4=common_makes[:lv4] + @lv5=common_makes[:lv5] + @lv6=common_makes[:lv6] + @num_top=common_makes[:num_top] + @i18n=common_makes[:i18n] + @man_section=common_makes[:man_section] + @emphasis_set_to=common_makes[:emphasis_set_to] + @bold_match_list=common_makes[:bold_match_list] + @italics_match_list=common_makes[:italics_match_list] + @substitution_match_list=common_makes[:substitution_match_list] + @footer_links=common_makes[:footer_links] + @home_button_links=common_makes[:home_button_links] + @home_button_image=common_makes[:home_button_image] + @cover_image=common_makes[:cover_image] + @lnk=@links=common_makes[:links] + @header_make_links_append=common_makes[:links_append] + end end #protected def determine_papersize(l) @@ -1323,91 +1007,65 @@ module SiSU_Param when /^@notes?:\s(.+)\Z/m #% * header metadata - notes @notes=SiSU_Param::Parameters::Md.new($1.strip,@opt,@env).notes when /^@links:\s+(.+?)\Z/m #% * header metadata - links - doc_links=SiSU_Param::Parameters::Md.new($1.strip,@opt,@env).links - a_idx=0 - @links=[] - doc_links.each do |doc_link| - if doc_link=~/\{.+?\}(?:(?:https?|file|ftp):\/|\.\.)\/\S+(?:\s|$)/ - @links[a_idx]={} - @links[a_idx][:say],@links[a_idx][:url]=/\{\s*(.+?)\s*\}((?:(?:https?|file|ftp):\/|\.\.)\/\S+)/im.match(doc_link)[1,2] - a_idx +=1 - end + links=SiSU_Param::Parameters::MdMake.new($1.strip,@opt,@env).make_links.links + @lnk=@links=if @header_make_links_append == :yes + (links) \ + ? (links + @links) + : @links + else + (links) \ + ? (links) + : @links end - @lnk=@links when /^@make:(.+)/m #% * header processing - make - @make=SiSU_Param::Parameters::Md.new($1.strip,@opt,@env).make - if defined? @make.breaks \ - and @make.breaks[:page_new] #clearpage - @pagenew=@make.breaks[:page_new] - end - if defined? @make.breaks \ - and @make.breaks[:page_break] #newpage - @pagebreak=@make.breaks[:page_break] - end - if defined? @make.headings \ - and @make.headings - @toc=@make.headings[0] - @lv1=@make.headings[1] - @lv2=@make.headings[2] - @lv3=@make.headings[3] - @lv4=@make.headings[4] - @lv5=@make.headings[5] - @lv6=@make.headings[6] - end - if defined? @make.num_top \ - and @make.num_top - @num_top=@make.num_top # remove @num_top - end - if defined? @make.language \ - and @make.language[0] - @i18n=@make.language - end - if defined? @make.manpage \ - and @make.manpage - @man_section=(defined? @make.manpage.section) \ - ? @make.manpage.section - : 1 - end - if defined? @make.footer \ - and @make.footer.is_a?(Array) - @footer_links= { left: { say: '', url: '' }, center: { say: '', url: '' } } #already set - @footer_links[:left]=if @make.footer[0]=~/\{.+?\}(?:(?:https?|file|ftp):\/|\.\.)\/\S+(?:\s|$)/ - say,url=/\{\s*(.+?)\s*\}((?:(?:https?|file|ftp):\/|\.\.)\/\S+)/im.match(@make.footer[0])[1,2] - { say: say, url: url } - else - { say: '', url: '' } - end - @footer_links[:center]=if @make.footer[1]=~/\{.+?\}(?:(?:https?|file|ftp):\/|\.\.)\/\S+(?:\s|$)/ - say,url=/\{\s*(.+?)\s*\}((?:(?:https?|file|ftp):\/|\.\.)\/\S+)/im.match(@make.footer[1])[1,2] - { say: say, url: url } - else - { say: '', url: '' } - end - @footer_links - else #already set - @footer_links= { left: { say: '', url: '' }, center: { say: '', url: '' } } - end - if defined? @make.home_button_text \ - and @make.home_button_text.is_a?(Array) - a_idx=0 - @home_button_links=[] - @make.home_button_text.each do |doc_link| - if doc_link=~/\{.+?\}(?:(?:https?|file|ftp):\/|\.\.)\/\S+(?:\s|$)/ - @home_button_links[a_idx]={} - @home_button_links[a_idx][:say],@home_button_links[a_idx][:url]=/\{\s*(.+?)\s*\}((?:(?:https?|file|ftp):\/|\.\.)\/\S+)/im.match(doc_link)[1,2] - a_idx +=1 - end - end - @home_button_links - end - if defined? @make.home_button_image \ - and @make.home_button_image.is_a?(Hash) - @home_button_image=@make.home_button_image - end - if defined? @make.cover_image \ - and @make.cover_image.is_a?(Hash) - @cover_image=@make.cover_image - end + @make=SiSU_Param::Parameters::MdMake.new($1.strip,@opt,@env).make + makes=SiSU_Param_Make::MakeHead.new(@make).make_instruct + @pagenew=(makes[:pagenew]) \ + ? (makes[:pagenew]) \ + : @pagenew + @pagebreak=(makes[:pagebreak]) \ + ? (makes[:pagebreak]) \ + : @pagebreak + @toc=(makes[:toc]) ? (makes[:toc]) : @toc + @lv1=(makes[:lv1]) ? (makes[:lv1]) : @lv1 + @lv2=(makes[:lv2]) ? (makes[:lv2]) : @lv2 + @lv3=(makes[:lv3]) ? (makes[:lv3]) : @lv3 + @lv4=(makes[:lv4]) ? (makes[:lv4]) : @lv4 + @lv5=(makes[:lv5]) ? (makes[:lv5]) : @lv5 + @lv6=(makes[:lv6]) ? (makes[:lv6]) : @lv6 + @num_top=(makes[:num_top]) \ + ? (makes[:num_top]) \ + : @num_top + @substitution_match_list=(makes[:substitution_match_list]) \ + ? (makes[:substitution_match_list]) \ + : @substitution_match_list + @bold_match_list=(makes[:bold_match_list]) \ + ? (makes[:bold_match_list]) \ + : @bold_match_list + @italics_match_list=(makes[:italics_match_list]) \ + ? (makes[:italics_match_list]) \ + : @italics_match_list + @emphasis_set_to=(makes[:emphasis_set_to]) \ + ? (makes[:emphasis_set_to]) \ + : @emphasis_set_to + @i18n=(makes[:i18n]) \ + ? (makes[:i18n]) \ + : @i18n + @man_section=(makes[:man_section]) \ + ? (makes[:man_section]) \ + : @man_section + @footer_links=(makes[:footer_links]) \ + ? (makes[:footer_links]) \ + : @footer_links + @home_button_links=(makes[:home_button_links]) \ + ? (makes[:home_button_links]) \ + : @home_button_links + @home_button_image=(makes[:home_button_image]) \ + ? (makes[:home_button_image]) \ + : @home_button_image + @cover_image=(makes[:cover_image]) \ + ? (makes[:cover_image]) \ + : @cover_image end @lv1 ||=/^1~/ @lv2 ||=/^2~/ @@ -1531,7 +1189,7 @@ module SiSU_Param if @opt.cmd =~/[VM]/ SiSU_Screen::Ansi.new(@opt.cmd,'@make:','header absent').warn end - @make=SiSU_Param::Parameters::Md.new('@make: ',@opt,@env).make + @make=SiSU_Param::Parameters::MdMake.new('@make: ',@opt,@env).make end if @cover_image \ and @cover_image.is_a?(Hash) \ diff --git a/lib/sisu/v4/param_make.rb b/lib/sisu/v4/param_make.rb new file mode 100644 index 00000000..a1bda002 --- /dev/null +++ b/lib/sisu/v4/param_make.rb @@ -0,0 +1,636 @@ +# encoding: utf-8 +=begin + + * Name: SiSU + + * Description: a framework for document structuring, publishing and search + + * Author: Ralph Amissah + + * Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, + 2007, 2008, 2009, 2010, 2011, 2012 Ralph Amissah, All Rights Reserved. + + * License: GPL 3 or later: + + SiSU, a framework for document structuring, publishing and search + + Copyright (C) Ralph Amissah + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public Lic/home/ralph/live-manual/build/manual/manifest/live-manual.ca.htmlense for + more details. + + You should have received a copy of the GNU General Public License along with + this program. If not, see <http://www.gnu.org/licenses/>. + + If you have Internet connection, the latest version of the GPL should be + available at these locations: + <http://www.fsf.org/licensing/licenses/gpl.html> + <http://www.gnu.org/licenses/gpl.html> + + <http://www.sisudoc.org/sisu/en/manifest/gpl.fsf.html> + + * SiSU uses: + * Standard SiSU markup syntax, + * Standard SiSU meta-markup syntax, and the + * Standard SiSU object citation numbering and system + + * Hompages: + <http://www.jus.uio.no/sisu> + <http://www.sisudoc.org> + + * Download: + <http://www.sisudoc.org/sisu/en/SiSU/download.html> + + * Ralph Amissah + <ralph@amissah.com> + <ralph.amissah@gmail.com> + + ** Description: make parameters extracted for program use + +=end + +module SiSU_Param_Make + class MdMake + def initialize(str,opt,env) + @s,@opt,@env=str,opt,env + end + def validate_length(s,l,n) + #s=(s.length <= l) ? s : nil + s=if s.is_a?(String) \ + and s.length <= l + s + elsif s.is_a?(NilClass) + nil + elsif s.class !=String + STDERR.puts "#{n} is #{s.class}: programming error, String expected #{__FILE__}:#{__LINE__}" + s + else + SiSU_Screen::Ansi.new('v',"*WARN* #{n} length #{s.length} exceeds set db field length #{l}, metadata dropped",@opt.fns).warn unless @opt.cmd =~/q/ + nil + end + end + def name_format(name) + if name + name=name.strip + @name_a_h=[] + authors=name.scan(/[^;]+/) + authors.each_with_index do |a,i| + b=((a =~/\s*\|\s*/) ? (a.split(/\|/)) : [a]) + if b[0] =~/"(.+?)"/ + @name_a_h << { the: $1 } + else + x=b[0].scan(/[^,]+/) + if x.length==1 + @name_a_h << { the: x[0].strip } + elsif x.length==2 + @name_a_h << { the: x[0].strip, others: x[1].strip } + else #p x.length + end + end + b.delete_at(0) + b.each do |d| + k,c=nil + k,c=/^(\S+)\s+(.*)/.match(d)[1,2] if d + @name_a_h[i][:hon]=c.strip if k=='hon' + @name_a_h[i][:affiliation]=c.strip if k=='affiliation' + @name_a_h[i][:nationality]=c.strip if k=='nationality' + end + end + l=@name_a_h.length + name_str='' + @name_a_h.each_with_index do |a,i| + name_str += if a[:others] + z=(((l - i) > 1) ? ', ' : '') + "#{a[:others].strip} #{a[:the].strip}" + z + else + z=(((l - i) > 2) ? ', ' : '') + "#{a[:the].strip}" + z + end + end + { name_a_h: @name_a_h, name_str: name_str } + else nil + end + end + def build_hash(arr) + @h={} + arr.each_with_index do |x,i| + a,b=nil,nil + if x =~/^%[:\s]/ #ignore comment + elsif x =~/:(\S+?):\s+(.+)/ + a,b=/:(\S+?):\s+(.+)\Z/m.match(x)[1,2] + elsif i == 0 + a='main' + b=x + else + end + @h[a]=b + end + @h + end + def make + a=@s.split(/\n%\s.+?$|[ ]*\n[ ]*/m) + @h=build_hash(a) + def headings + lv=[] + x=@h['headings'] + x=((x =~/;/) ? (x.split(/;\s*/)) : [ x ]) + lv[0]=x + lv1=x[0] ||='1~ ' #some arbitrary changes made + lv[1]=/^#{lv1}/ + lv2=x[1] ||='2~ ' + lv[2]=/^#{lv2}/ + lv3=x[2] ||='3~ ' + lv[3]=/^#{lv3}/ + lv4=x[3] ||='4~ ' + lv[4]=/^#{lv4}/ + lv5=x[4] ||='5~ ' + lv[5]=/^#{lv5}/ + lv6=x[5] ||='6~ ' + lv[6]=/^#{lv6}/ + lv + end + def num_top + @h['num_top'] + end + def breaks + pagebreaks=((@h['breaks'] =~/;/) \ + ? (@h['breaks'].split(/;\s*/)) + : [ @h['breaks'] ]) + page_new,page_break=nil,nil + pagebreaks.each do |x| + page_new=x[/(:?[\dA-C],?)+/] if x=~/new|clear/ + page_break=x[/(:?[\dA-C],?)+/] if x =~/break/ + end + { page_new: page_new, page_break: page_break } + end + def language + l=if @h['language'] && (@h['language']=~/\S{2,}/) + ((@h['language'] =~/,/) \ + ? (@h['language'].split(/,\s*/)) + : [ @h['language'] ]) + else [ 'en' ] + end + end + def bold + m=@h['bold'] + i=(m=~/\/i$/)? 'i' : '' + z=if m + x=m.gsub(/^\/(.+?)\/i?/,'\1'). + gsub(/\((?:\?:)?/,'(?:') # avoid need to escape use of brackets within regex provided + rgx='\b(' + x + ')\b' + y=((i =~/i/) ? (/#{rgx}/i) : (/#{rgx}/)) + { str: '\b(?:' + x + ')\b', regx: y, i: i } + else nil + end + end + def italics + m=@h['italics'] + i=((m=~/\/i$/) ? 'i' : '') + z=if m + x=m.gsub(/^\/(.+?)\/i?/,'\1'). + gsub(/\((?:\?:)?/,'(?:') # avoid need to escape use of brackets within regex provided + rgx='\b(' + x + ')\b' + y=((i =~/i/) ? (/#{rgx}/i) : (/#{rgx}/)) + { str: '\b(?:' + x + ')\b', regx: y, i: i } + else nil + end + end + def emphasis + if @h['emphasis'] =~/bold/ then 'bold' + elsif @h['emphasis'] =~/italics?/ then 'italics' + elsif @h['emphasis'] =~/under(?:line|score)/ then 'underscore' + else nil + end + end + def substitute + m=@h['substitute'] + z=if m + w=m.scan(/\/(.+?)\/(i?,)\s*'(.+?)'(?:\s+|\s*;\s*|$)/) + arr_hash=[] + matches='' + w.each do |x| + c=(x[1] =~/[i],/) ? :i : :s + matches=matches + x[0].gsub(/([${}])/,'\\\\\1') + '|' + arr_hash << { + match: x[0].gsub(/([${}])/,'\\\\\1'), + replace: x[2], + case_s: c + } + end + matches.chop! + { match_and_replace: arr_hash, matches: matches } + else nil + end + end + def plaintext_wrap + if @h['plaintext_wrap'].to_s =~/\d\d+/ \ + and @h['plaintext_wrap'].to_i > 19 \ + and @h['plaintext_wrap'].to_i < 201 + @h['plaintext_wrap'].to_i + else nil + end + end + def omit + m=@h['omit'] + @m=m ? (m.split(/,\s+/)) : nil + def list + @m + end + self + end + def ocn? + (omit.list.inspect =~/"ocn"/) \ + ? :off + : :na + end + def toc? + (omit.list.inspect =~/"toc"/) \ + ? :off + : :na + end + def manifest? + (omit.list.inspect =~/"manifest"/) \ + ? :off + : :na + end + def links_to_manifest? + (omit.list.inspect =~/"manifest_links"|"links_to_manifest"/) \ + ? :off + : :na + end + def metadata? + (omit.list.inspect =~/"metadata"/) \ + ? :off + : :na + end + def minitoc? + (omit.list.inspect =~/"minitoc"/) \ + ? :off + : :na + end + def html_minitoc? + (omit.list.inspect =~/"html_minitoc"/) \ + ? :off + : :na + end + def html_top_band? + (omit.list.inspect =~/"html_top_band"/) \ + ? :off + : :na + end + def html_navigation? + (omit.list.inspect =~/"html_navigation"/) \ + ? :off + : :na + end + def html_navigation_bar? + (omit.list.inspect =~/"html_navigation_bar"/) \ + ? :off + : :na + end + def segsubtoc? + (omit.list.inspect =~/"segsubtoc"/) \ + ? :off + : :na + end + def search_form? + (omit.list.inspect =~/"search_form"/) \ + ? :off + : :na + end + def html_search_form? + (omit.list.inspect =~/"html_search_form"/) \ + ? :off + : :na + end + def html_right_pane? + (omit.list.inspect =~/"html_right_column"|"html_right_pane"/) \ + ? :off + : :na + end + def manifest_minitoc? + (omit.list.inspect =~/"manifest_minitoc"/) \ + ? :off + : :na + end + def cover_image? + (omit.list.inspect =~/"cover_image"/) \ + ? :off + : :na + end + def home_button_image? + (omit.list.inspect =~/"home_button_image"/) \ + ? :off + : :na + end + def texpdf_font + def main + @h['texpdf_font'] \ + && (@h['texpdf_font']=~/\S{3,}/) \ + ? @h['texpdf_font'] + : @env.font.texpdf.main + end + def sans # not used + @h['texpdf_font_sans'] \ + && (@h['texpdf_font_sans']=~/\S{3,}/) \ + ? @h['texpdf_font_sans'] + : @env.font.texpdf.sans + end + def serif # not used + @h['texpdf_font_serif'] \ + && (@h['texpdf_font_serif']=~/\S{3,}/) \ + ? @h['texpdf_font_serif'] + : @env.font.texpdf.serif + end + def mono + @h['texpdf_font_mono'] \ + && (@h['texpdf_font_mono']=~/\S{3,}/) \ + ? @h['texpdf_font_mono'] + : @env.font.texpdf.mono + end + self + end + def promo + @h['promo'] + end + def ad + @h['ad'] + end + def manpage + manpage={} + if @h['manpage'] + if @h['manpage'] =~/;/m + man=@h['manpage'].split(/;/m) + man.each do |x| + m=(x=~/=/m) ? x.split(/=/m) : nil + if m + manpage[m[0].strip] = m[1].split(/ \. /) + end + end + end + end + if manpage['name'] + manpage['name']=manpage['name'].join("\n.br\n"). + gsub(/(-)/m,"\\\\\\1"). + gsub(/\A/,"\n.br\n.SH NAME\n.br\n") + else + manpage['name']='man page "name/whatis" information not provided, set in header @man: name=[whatis information]' + end + if manpage['synopsis'] + manpage['synopsis']=manpage['synopsis'].join("\n\n.br\n"). + gsub(/(-)/m,"\\\\\\1"). + gsub(/\A/,"\n.br\n.SH SYNOPSIS\n.br\n") + else + manpage['synopsis']='' + end + unless manpage['section'] + manpage['section']=1 + end + manpage + end + def get_image_dimensions(img) + imgk=SiSU_Env::SystemCall.new.imagemagick + gmgk=SiSU_Env::SystemCall.new.graphicksmagick + img_pth={ + sst: @env.path.image_source_include, + pod: File.expand_path("../../../sisupod/image" ) + } + path_img=if FileTest.file?("#{img_pth[:pod]}/#{img}") + "#{img_pth[:pod]}/#{img}" + elsif FileTest.file?("#{img_pth[:sst]}/#{img}") + "#{img_pth[:sst]}/#{img}" + else nil + end + if path_img + if imgk or gmgk + if imgk + imgsys=`identify #{path_img}`.strip #system call + elsif gmgk + imgsys=`gm identify #{path_img}`.strip #system call + end + w,h=/(\d+)x(\d+)/m.match(imgsys)[1,2] + else + w,h='600','800' + end + else + w,h=nil,nil + end + {w: w, h: h} + end + def home_button_text + s=if @h['home_button_text'] + @h['home_button_text'].split(/\s*;\s*/) + else nil + end + #l,n=Db[:home_button],'make.home_button_text' + #validate_length(s,l,n) + end + def home_button_image + s=nil + s=if @h['home_button_image'] + s=@h['home_button_image'].split(/\s*;\s*/) + s0=s[0] #if + image={} + s=if s0 =~/{(\S+\.(?:jpg|png|gif))(?:\s+(\d+x\d+))?\s*}(?:(http:\/\/\S+)|image)/ + image[:home_button]=$1 + if $2 + image[:dimensions]=$2 + image[:w],image[:h]=/(\d+)x(\d+)/m.match(image[:dimensions])[1,2] + else + d=get_image_dimensions(image[:home_button]) + image[:w],image[:h]=d[:w],d[:h] + image[:dimensions]="#{d[:w]}x#{d[:h]}" + end + image[:link]=$3 + image + end + else nil + end + end + def cover_image + s=nil + if @h['cover_image'] + s=@h['cover_image'].split(/\s*;\s*/) + s=s[0] #if + image={} + if s =~/{(\S+\.(?:jpg|png|gif))(?:\s+(\d+x\d+))?\s+(?:"(.+?)")?\s*}image/ + image[:cover]=$1 + if $2 + image[:dimensions]=$2 + image[:w],image[:h]=/(\d+)x(\d+)/m.match(image[:dimensions])[1,2] + else + d=get_image_dimensions(image[:cover]) + image[:w],image[:h]=d[:w],d[:h] + image[:dimensions]="#{d[:w]}x#{d[:h]}" + end + image[:note]=$3 + elsif s =~/(\S+\.(?:jpg|png|gif))/ + image[:cover]=$1 + d=get_image_dimensions(image[:cover]) + image[:w],image[:h]=d[:w],d[:h] + image[:dimensions]="#{d[:w]}x#{d[:h]}" + image[:note]=nil + end + image + else nil + end + end + def footer + s=if @h['footer'] + @h['footer'].split(/\s*;\s*/) + else nil + end + end + self + end + def make_links + @doc_links=@s.split(/\n%\s.+?$|[ ]*\n[ ]*/m) + def links + lnks,a_idx=[],0 + @doc_links.each do |doc_link| + if doc_link=~/\{.+?\}(?:(?:https?|file|ftp):\/|\.\.)\/\S+(?:\s|$)/ + say,url=/\{\s*(.+?)\s*\}((?:(?:https?|file|ftp):\/|\.\.)\/\S+)/im.match(doc_link)[1,2] + lnks[a_idx]={ say: say, url: url } + a_idx +=1 + end + end + lnks + end + def append? + (@doc_links[0]=='+') \ + ? :yes + : :no + end + self + end + end + class MakeHead + attr_accessor :pagenew,:pagebreak,:toc,:lv1,:lv2,:lv3,:lv4,:lv5,:lv6,:num_top,:i18n,:man_section,:substitution_match_list,:bold_match_list,:italics_match_list,:emphasis_set_to,:footer_links,:home_button_links,:home_button_image,:cover_image + def initialize(make) + @make=make + end + def clear + @pagenew=@pagebreak=@toc=@lv1=@lv2=@lv3=@lv4=@lv5=@lv6=@num_top=@i18n=@man_section=@footer_links=@substitution_match_list=@bold_match_list=@italics_match_list=@emphasis_set_to=@home_button_links=@home_button_image=@cover_image=nil + end + def make_instruct + clear + if defined? @make.breaks \ + and @make.breaks[:page_new] #clearpage + @pagenew=@make.breaks[:page_new] + end + if defined? @make.breaks \ + and @make.breaks[:page_break] #newpage + @pagebreak=@make.breaks[:page_break] + end + if defined? @make.headings \ + and @make.headings + @toc=@make.headings[0] + @lv1=@make.headings[1] + @lv2=@make.headings[2] + @lv3=@make.headings[3] + @lv4=@make.headings[4] + @lv5=@make.headings[5] + @lv6=@make.headings[6] + end + if defined? @make.num_top \ + and @make.num_top + @num_top=@make.num_top # remove @num_top + end + if defined? @make.language \ + and @make.language[0] + @i18n=@make.language + end + if defined? @make.manpage \ + and @make.manpage + @man_section=(defined? @make.manpage.section) \ + ? @make.manpage.section + : 1 + end + if defined? @make.substitute \ + and @make.substitute + @substitution_match_list=@make.substitute + end + if defined? @make.bold \ + and @make.bold + @bold_match_list=@make.bold + end + if defined? @make.italics \ + and @make.italics + @italics_match_list=@make.italics + end + if defined? @make.emphasis \ + and @make.emphasis + @emphasis_set_to=@make.emphasis + end + if defined? @make.footer \ + and @make.footer.is_a?(Array) + @footer_links= { left: { say: '', url: '' }, center: { say: '', url: '' } } #already set + @footer_links[:left]=if @make.footer[0]=~/\{.+?\}(?:(?:https?|file|ftp):\/|\.\.)\/\S+(?:\s|$)/ + say,url=/\{\s*(.+?)\s*\}((?:(?:https?|file|ftp):\/|\.\.)\/\S+)/im.match(@make.footer[0])[1,2] + { say: say, url: url } + else + { say: '', url: '' } + end + @footer_links[:center]=if @make.footer[1]=~/\{.+?\}(?:(?:https?|file|ftp):\/|\.\.)\/\S+(?:\s|$)/ + say,url=/\{\s*(.+?)\s*\}((?:(?:https?|file|ftp):\/|\.\.)\/\S+)/im.match(@make.footer[1])[1,2] + { say: say, url: url } + else + { say: '', url: '' } + end + @footer_links + else #already set + @footer_links= { left: { say: '', url: '' }, center: { say: '', url: '' } } + end + if defined? @make.home_button_text \ + and @make.home_button_text.is_a?(Array) + a_idx=0 + @home_button_links=[] + @make.home_button_text.each do |doc_link| + if doc_link=~/\{.+?\}(?:(?:https?|file|ftp):\/|\.\.)\/\S+(?:\s|$)/ + say,url=/\{\s*(.+?)\s*\}((?:(?:https?|file|ftp):\/|\.\.)\/\S+)/im.match(doc_link)[1,2] + @home_button_links[a_idx]= { say: say, url: url } + a_idx +=1 + end + end + @home_button_links + end + if defined? @make.home_button_image \ + and @make.home_button_image.is_a?(Hash) + @home_button_image=@make.home_button_image + end + if defined? @make.cover_image \ + and @make.cover_image.is_a?(Hash) + @cover_image=@make.cover_image + end + { pagenew: @pagenew, + pagebreak: @pagebreak, + toc: @toc, + lv1: @lv1, + lv2: @lv2, + lv3: @lv3, + lv4: @lv4, + lv5: @lv5, + lv6: @lv6, + num_top: @num_top, + i18n: @i18n, + emphasis_set_to: @emphasis_set_to, + bold_match_list: @bold_match_list, + italics_match_list: @italics_match_list, + substitution_match_list: @substitution_match_list, + man_section: @man_section, + footer_links: @footer_links, + home_button_links: @home_button_links, + home_button_image: @home_button_image, + cover_image: @cover_image, + } + end + end +end +__END__ diff --git a/lib/sisu/v4/sysenv.rb b/lib/sisu/v4/sysenv.rb index d43bba91..22a520f6 100644 --- a/lib/sisu/v4/sysenv.rb +++ b/lib/sisu/v4/sysenv.rb @@ -266,7 +266,7 @@ module SiSU_Env end class GetInit < InfoSystemGen @@noyaml=false - @@rc,@@sisurc_path,@@tx=nil,nil,nil + @@rc,@@sisu_doc_makefile,@@sisurc_path,@@tx=nil,nil,nil,nil @@ad={ promo: nil, promo_list: nil, flag_promo: false } @@sdmd=nil attr_accessor :yaml @@ -282,20 +282,39 @@ module SiSU_Env def tex @@tx ||=SiSU_Viz::TeX.new end + def rc_path_options + @rc_path=[ + "#{$sisu_document_markup_directory}/.sisu/#{SiSU_version_dir}", + "#{$sisu_document_markup_directory}/.sisu", + "#{$sisu_document_markup_directory}/_sisu/#{SiSU_version_dir}", + "#{$sisu_document_markup_directory}/_sisu", + "#{@@home}/.sisu/#{SiSU_version_dir}", + "#{@@home}/.sisu", + "#{@@sisu_etc}/#{SiSU_version_dir}", + "#{@@sisu_etc}", + ] + end + def sisu_document_make + def makefile + #if @markup_dir_changed_ + rc_path_options.each do |v| + f='sisu_document_make' + if FileTest.exist?("#{v}/#{f}") + @@sisu_make_path=v + sisu_doc_makefile=IO.read("#{@@sisu_make_path}/#{f}", mode: 'r:utf-8') + @@sisu_doc_makefile=sisu_doc_makefile.split(/\s*\n\s*\n/m) + break + end + end + #end + @@sisu_doc_makefile + end + self + end def sisu_yaml def rc if @markup_dir_changed_ - @rc_path=[ - "#{$sisu_document_markup_directory}/.sisu/#{SiSU_version_dir}", - "#{$sisu_document_markup_directory}/.sisu", - "#{$sisu_document_markup_directory}/_sisu/#{SiSU_version_dir}", - "#{$sisu_document_markup_directory}/_sisu", - "#{@@home}/.sisu/#{SiSU_version_dir}", - "#{@@home}/.sisu", - "#{@@sisu_etc}/#{SiSU_version_dir}", - "#{@@sisu_etc}", - ] - @rc_path.each do |v| + rc_path_options.each do |v| if @@noyaml \ or FileTest.exist?("#{v}/noyaml") STDERR.puts "WARNING - YAML loading switched off, to enable delete the file:\n\t#{v}/noyaml\n\n" unless @@noyaml |