Class: POI::App
Constant Summary
Constants included from Constants
Instance Method Summary collapse
Methods included from Utils
Instance Method Details
#dispatch(options) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/poi/app.rb', line 45 def dispatch() if ([:pack]) pack() elsif (![:file]) puts @opt.optparser if (![:help]) else () end end |
#expand(options) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/poi/app.rb', line 55 def () lines = open([:file]).readlines data = {}; x = 0; while lines[x].strip != '.' && x < lines.size do data = JSON.load(File.read(POI_DEFAULTS)) if File.exists? POI_DEFAULTS data.merge!(JSON.load(File.read(".poi_vars"))) if File.exists? ".poi_vars" line = lines[x].strip if (line =~ /^(.+)\s(\d+)$/) file = $1.strip size = $2.to_i texts = lines[x+1, size] parent = parents(file); FileUtils.mkdir_p(parent) if ([:delete]) File.delete(file) if File.exists?(file) puts "Deleting #{file} ..." while (parent.size > 0 && Dir.open(parent).count <= 2 && parent != ".") do Dir.delete(parent) puts "Deleting #{parent} ..." parent = parents(parent) end else File.open(file, "w") do |f| puts "Generating #{file} ..." f << Mustache.render(texts.join, data) end end x += size end x += 1 end puts "Done!" end |
#pack(options) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/poi/app.rb', line 24 def pack() target = [:target] ? File.open([:target], "w") : STDOUT if (File.exists?([:pack])) File.readlines([:pack]).map {|l| l.strip }.map {|l| Dir.glob(l)}.flatten .tap {|fs| fs.insert(0, POI_DEFAULTS) if File.exists?(POI_DEFAULTS) and !fs.include?(POI_DEFAULTS)} .select {|l| l != [:target]}.each do |l| file = l.strip unless File.directory?(file) puts "Packing #{file} ..." unless target == STDOUT content = File.readlines(file) target.puts("#{file} #{content.size}") target.puts(content.join) if (!content.empty?) target.puts end end end target.print(".") puts "Done" unless target == STDOUT target.close unless target == STDOUT end |
#run(argv) ⇒ Object
18 19 20 21 22 |
# File 'lib/poi/app.rb', line 18 def run(argv) @opt = POI::Opt.new @opt.parse(argv) dispatch(@opt.) end |