raubarede/Ruiby

View on GitHub
bin/ruiby

Summary

Maintainability
Test Coverage
#!/usr/bin/ruby
############################################################################
# ruiby : ruiby onliner 
#
#  options :
#    -width, -height : window size
#    -title : title size
#
#  args : fragment of ruiby dsl commands :
#      args while be joined with blanc, and evaluated in a stack do ...code... end
#      characteres '#' or '%' are replaced by a single quote (')
#
############################################################################
#
# Exemple:
#    > ruiby   "button('CouCou') { exit! } ; button('show') { edit 'ruiby' }"
#    > ruiby -width 300 -height 200   chrome(false); button(\' Wait \') { exit! } 
#    > ruby bin/ruiby  -height 400 -width 200 \
#            l=list(%%Samples%%);l.set_data Dir.glob(%%sa*/*.rb%%) ;\
#            buttoni(%%Selected%%) { system(~ruby ~+l.selection)  } ;\
#             buttoni(~Annul~) { exit!(1) }
#
#       > ruiby   field(%%aaaa%%,10,11);field(%%bb%%,10,22);field(%%cccc%%,10,33);button(%%ok%%) { exit!(0) }
#
############################################################################
require_relative '../lib/Ruiby' unless defined?(Ruiby)

if ARGV.size==0 || ARGV[0]=~ /^-+help/i
 puts "Usage: >ruiby -width 300 -height 200  -title boot  button(%% Wait %%) '{ system(%%reboot%%)}'"
 exit!(0)
end

opt={width: 0,height: 0, title: 'Ruiby '+Time.now.to_s}
opt[ARGV.shift[1..-1].to_sym]=ARGV.shift while ARGV[0] && ARGV[0]=~ /^-/
opt=opt.each.inject({}) { |h,(k,v)| h[k]= (v=~ /^[0-9]+$/) ? v.to_i : v ; h}
#p opt

code=<<EEND
Ruiby.app(opt) do 
  stack do 
      #{ARGV.join(" ").
          gsub('#',"'").
          gsub('%%',"'").
          gsub('~',"'")} ; 
  end
end
EEND

#puts code 
eval(code)