aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu
diff options
context:
space:
mode:
authorRalph Amissah <ralph@amissah.com>2011-05-25 22:54:56 -0400
committerRalph Amissah <ralph@amissah.com>2011-05-29 20:32:16 -0400
commit93cc261ead4f31aeed85d19e68fc0afccb1c771f (patch)
tree7223e967f0d15d582e38973b0611ecbb303b3a7b /lib/sisu
parentv3: i18n, constants, some language info moved to i18n (from constants) (diff)
v3: options --find & --glob (-f -G) added, parses language sub-dirs
* options * filter out files not matching .ss[tm] * with -f -G (--find|--glob) flag glob all .ss[tm] files in dir including language sub-directories sisu3 -3G live-manual * with -f (--find|--glob) flag and find .ss[tm] files that match given string in dir including language subdirectories sisu3 -3GR
Diffstat (limited to 'lib/sisu')
-rw-r--r--lib/sisu/v3/hub.rb8
-rw-r--r--lib/sisu/v3/options.rb76
2 files changed, 75 insertions, 9 deletions
diff --git a/lib/sisu/v3/hub.rb b/lib/sisu/v3/hub.rb
index 651276cd..5eac0b03 100644
--- a/lib/sisu/v3/hub.rb
+++ b/lib/sisu/v3/hub.rb
@@ -153,7 +153,7 @@ module SiSU
when /^xhtml$/; SiSU_XHTML::Source.new(@opt).read # -b xhtml.rb
when /^xml$/; SiSU_XML_SAX::Source.new(@opt).read # -x xml.rb
when /^xml_dom$/; SiSU_XML_DOM::Source.new(@opt).read # -X xml_dom.rb
- when /^xml_fictionbook$/; SiSU_XML_Fictionbook::Source.new(@opt).read # -f
+ #when /^xml_fictionbook$/; SiSU_XML_Fictionbook::Source.new(@opt).read # -f
when /^xml_scaffold$/; SiSU_XML_scaffold::Source.new(@opt).read # -k xml_scaffold.rb
when /^embedded$/; SiSU_Embedded::Source.new(@opt).read # -m embedded.rb (image and other content) #check
when /^manifest$/; SiSU_Manifest::Source.new(@opt).read # -y manifest.rb
@@ -420,9 +420,9 @@ p "here #{__FILE__} #{__LINE__}" if @opt =~/M/
if @opt.act[:xml_dom] #% --xml-dom, -x xml dom type
op('xml_dom','xml dom')
end
- if @opt.act[:fictionbook] #% --fictionbook, -f fictionbook xml
- op('xml_fictionbook','xml fictionbook')
- end
+ #if @opt.act[:fictionbook] #% --fictionbook, -f fictionbook xml
+ # op('xml_fictionbook','xml fictionbook')
+ #end
if @opt.act[:xhtml] #% --xhtml, -b xhtml
op('xhtml','xhtml sax')
end
diff --git a/lib/sisu/v3/options.rb b/lib/sisu/v3/options.rb
index e57bf7fa..96ec3c4a 100644
--- a/lib/sisu/v3/options.rb
+++ b/lib/sisu/v3/options.rb
@@ -64,24 +64,90 @@ module SiSU_commandline
class Options
attr_accessor :cmd,:mod,:act,:dir_structure_by,:f_pths,:files,:base_path,:paths,:lngs,:f_pth,:pth,:fns,:fnb,:fnc,:fncb,:lng,:what
def initialize(a)
- @x=a
@cmd,@f_pth,@pth,@fns,@fnb,@fnc,@fncb,@what,@lng,@base_path='','','','','','','','','','',''
@f_pths,@files,@paths,@mod,@act=Array.new(5){[]}
@env=SiSU_Env::Info_env.new
@dir_structure_by=SiSU_Env::Env_call.new.output_dir_structure.by?
@@base_path ||=Dir.pwd
@base_path=@@base_path
+ @a=sisu_glob_rules(a)
+ @a.freeze
+ init
+ end
+ def find_all(find_flag,opt)
+ if find_flag
+ pwd_set=Dir.pwd
+ x=Dir.glob('*.ss[tm]')
+ Px[:lng_lst].each do |d|
+ if FileTest.directory?(d)
+ x << Dir.glob("#{d}/*.ss[tm]")
+ end
+ end
+ opt + x.flatten!
+ end
+ end
+ def find_select(find_flag,opt)
+ if find_flag
+ pwd_set=Dir.pwd
+ x=[]
+ if opt.inspect =~/"[a-zA-Z][a-zA-Z0-9._-]+?"/
+ opt.each do |g|
+ x <<=if g =~/.ss[tm]/
+ Dir.glob("*#{g}")
+ else
+ Dir.glob("*#{g}*.ss[tm]")
+ end
+
+ Px[:lng_lst].each do |d|
+ if FileTest.directory?(d)
+ x <<=if g =~/.ss[tm]/
+ Dir.glob("#{d}/*#{g}")
+ else
+ Dir.glob("#{d}/*#{g}*.ss[tm]")
+ end
+ end
+ end
+ end
+ end
+ x.flatten!
+ end
+ end
+ def sisu_glob_rules(a)
+ b=[]
+ f=[]
+ find_flag=false
+ a.each do |y|
+ if y =~ /^-/ \
+ or y =~ /\.ss[tm]$/
+ if y =~/^-/ \
+ && y =~/[fG]|--find|--glob/
+ find_flag=true
+ end
+ b << y
+ end
+ if find_flag \
+ && y !~ /^-/ \
+ && y =~ /\S+/
+ f << y
+ elsif y =~ /^-/
+ b << y
+ end
+ end
r=Px[:lng_lst].join('|')
r.gsub!(/\|en\|/,'|')
@lang_regx=%r{(?:#{r})}
- @a=if a.inspect =~/"(?:-\S+?|--\S+?)"/ \
+ z=if find_flag
+ if f.length > 0
+ b + find_select(find_flag,f)
+ else
+ find_all(find_flag,b)
+ end
+ elsif a.inspect =~/"(?:-\S+?|--\S+?)"/ \
&& a.inspect =~/"#{@lang_regx}\/?"/ \
&& a.inspect =~/"en\/\S+?\.ss[tm]"/
init_selected_lang_dirs(a)
- else @x
+ else b
end
- @a.freeze
- init
end
def init_selected_lang_dirs(a)
@z=[]