poi 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 44694a12e47bdb3b334a9e1ef172503cafa14680
4
- data.tar.gz: '085a47ef6eb40e1028cc9df04358271e46f03447'
3
+ metadata.gz: 38232b10544797b3db3c2733a4a2470d52c24ffe
4
+ data.tar.gz: a88f75afa600c06d6985bda512dd809b6370497b
5
5
  SHA512:
6
- metadata.gz: a7415865174562e9559e859c3716c6e9e13f0a52a0994209c3359d338aa8ae34b6b203c672c1f183ab66b9e24fd76c25517ab36b80ce6e780dd5570864e73505
7
- data.tar.gz: c7bd66e7c160d0c8afb2d2a9249b43a42852ddf1ecc2c92ccb2b453655151fe5188c91ded0d7d504cf05080676373395df5862617f223008c62f6cb2eca0153c
6
+ metadata.gz: 3f937c496eccc80f81785d7a9a1b2b58aeaf45fa3541f2f412061315ace8fe6135bb38a7e40dd45d514c10dc3808d00e4e4863c031eab15fdae1d232d3d7baf4
7
+ data.tar.gz: a5d4490f9316bd455f4f271e5237b49b6e135624d41c849f0f383b33a4d59950aa8cb5cc3801a4f575ff2ad07400827859f7445e7ba2f6b99674111e74d4761a
data/bin/poi CHANGED
@@ -1,103 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'rubygems'
4
- require 'fileutils'
5
- require 'mustache'
6
- require 'json'
7
- require 'optparse'
8
- require 'open-uri'
3
+ require 'poi'
9
4
 
10
- POI_DEFAULTS = ".poi_defaults"
5
+ app = POI::App.new
11
6
 
12
- options = {}
13
-
14
- optparser = OptionParser.new do |opts|
15
-
16
- opts.banner = "Usage: poi -f [FILE / URL] [-d]"
17
-
18
- opts.on('-f', '--file FILE / URL', 'Generate using .poi file.') do |file|
19
- options[:file] = file
20
- end
21
-
22
- opts.on('-d', '--delete', 'Delete all generated file') do
23
- options[:delete] = true
24
- end
25
-
26
- opts.on('-p', '--pack [PACK]', 'Pack .poipack file into .poi') do |pack|
27
- options[:pack] = pack || '.poipack'
28
- end
29
-
30
- opts.on('-t', '--target TARGET', 'Packaging target') do |target|
31
- options[:target] = target
32
- end
33
-
34
- opts.on('-h', '--help', "Print help message") do
35
- options[:help] = true
36
- puts opts
37
- end
38
- end
39
-
40
- optparser.parse!
41
-
42
- if (options[:pack])
43
- target = options[:target] ? File.open(options[:target], "w") : STDOUT
44
- if (File.exists?(options[:pack]))
45
- File.readlines(options[:pack]).map {|l| l.strip }.map {|l| Dir.glob(l)}.flatten
46
- .tap {|fs| fs.insert(0, POI_DEFAULTS) if File.exists?(POI_DEFAULTS) and !fs.include?(POI_DEFAULTS)}
47
- .select {|l| l != options[:target]}.each do |l|
48
- file = l.strip
49
- content = File.readlines(file)
50
- target.puts("#{file} #{content.size}")
51
- target.puts(content.join) if (!content.empty?)
52
- target.puts
53
- end
54
- end
55
- target.puts(".")
56
- target.close if target != STDOUT
57
- exit
58
- end
59
-
60
- if (!options[:file])
61
- puts optparser if (!options[:help])
62
- exit
63
- end
64
-
65
- def parents(path)
66
- segs = path.split("/")
67
- parent_segs = segs[0...-1];
68
-
69
- if (parent_segs.empty?)
70
- return "."
71
- end
72
- return parent_segs.join("/")
73
- end
74
-
75
- lines = open(options[:file]).readlines
76
- data = {};
77
- x = 0;
78
-
79
- while lines[x].strip != '.' && x < lines.size do
80
- data = JSON.load(File.read(POI_DEFAULTS)) if File.exists? POI_DEFAULTS
81
- data.merge!(JSON.load(File.read(".poi_vars"))) if File.exists? ".poi_vars"
82
- line = lines[x].strip
83
- if (line =~ /^(.+)\s(\d+)$/)
84
- file = $1.strip
85
- size = $2.to_i
86
- texts = lines[x+1, size]
87
- parent = parents(file);
88
- FileUtils.mkdir_p(parent)
89
- if (options[:delete])
90
- File.delete(file) if File.exists?(file)
91
- while (parent.size >= 0 && Dir.open(parent).count <= 2) do
92
- Dir.delete(parent)
93
- parent = parents(parent)
94
- end
95
- else
96
- File.open(file, "w") do |f|
97
- f << Mustache.render(texts.join, data)
98
- end
99
- end
100
- x += size
101
- end
102
- x += 1
103
- end
7
+ app.run(ARGV)
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'poi/pois'
4
+
5
+ app = POI::Pois.new
6
+
7
+ app.run(ARGV)
@@ -0,0 +1 @@
1
+ require 'poi/app'
@@ -0,0 +1,92 @@
1
+
2
+ require 'poi/opt'
3
+ require 'poi/constants'
4
+ require 'poi/utils'
5
+
6
+ require 'rubygems'
7
+ require 'fileutils'
8
+ require 'mustache'
9
+ require 'json'
10
+ require 'open-uri'
11
+
12
+
13
+ module POI
14
+ class App
15
+ include POI::Constants
16
+ include POI::Utils
17
+
18
+ def run(argv)
19
+ @opt = POI::Opt.new
20
+ @opt.parse(argv)
21
+ dispatch(@opt.options)
22
+ end
23
+
24
+ def pack(options)
25
+ target = options[:target] ? File.open(options[:target], "w") : STDOUT
26
+ if (File.exists?(options[:pack]))
27
+ File.readlines(options[:pack]).map {|l| l.strip }.map {|l| Dir.glob(l)}.flatten
28
+ .tap {|fs| fs.insert(0, POI_DEFAULTS) if File.exists?(POI_DEFAULTS) and !fs.include?(POI_DEFAULTS)}
29
+ .select {|l| l != options[:target]}.each do |l|
30
+ file = l.strip
31
+ unless File.directory?(file)
32
+ puts "Packing #{file} ..." unless target == STDOUT
33
+ content = File.readlines(file)
34
+ target.puts("#{file} #{content.size}")
35
+ target.puts(content.join) if (!content.empty?)
36
+ target.puts
37
+ end
38
+ end
39
+ end
40
+ target.print(".")
41
+ puts "Done" unless target == STDOUT
42
+ target.close unless target == STDOUT
43
+ end
44
+
45
+ def dispatch(options)
46
+ if (options[:pack])
47
+ pack(options)
48
+ elsif (!options[:file])
49
+ puts @opt.optparser if (!options[:help])
50
+ else
51
+ expand(options)
52
+ end
53
+ end
54
+
55
+ def expand(options)
56
+ lines = open(options[:file]).readlines
57
+ data = {};
58
+ x = 0;
59
+
60
+ while lines[x].strip != '.' && x < lines.size do
61
+ data = JSON.load(File.read(POI_DEFAULTS)) if File.exists? POI_DEFAULTS
62
+ data.merge!(JSON.load(File.read(".poi_vars"))) if File.exists? ".poi_vars"
63
+ line = lines[x].strip
64
+ if (line =~ /^(.+)\s(\d+)$/)
65
+ file = $1.strip
66
+ size = $2.to_i
67
+ texts = lines[x+1, size]
68
+ parent = parents(file);
69
+ FileUtils.mkdir_p(parent)
70
+ if (options[:delete])
71
+ File.delete(file) if File.exists?(file)
72
+ puts "Deleting #{file} ..."
73
+ while (parent.size > 0 && Dir.open(parent).count <= 2 && parent != ".") do
74
+ Dir.delete(parent)
75
+ puts "Deleting #{parent} ..."
76
+ parent = parents(parent)
77
+ end
78
+ else
79
+ File.open(file, "w") do |f|
80
+ puts "Generating #{file} ..."
81
+ f << Mustache.render(texts.join, data)
82
+ end
83
+ end
84
+ x += size
85
+ end
86
+ x += 1
87
+ end
88
+ puts "Done!"
89
+ end
90
+
91
+ end
92
+ end
@@ -0,0 +1,6 @@
1
+
2
+ module POI
3
+ module Constants
4
+ POI_DEFAULTS = ".poi_defaults"
5
+ end
6
+ end
@@ -0,0 +1,41 @@
1
+ require 'optparse'
2
+
3
+ module POI
4
+ class Opt
5
+ attr_reader :options, :optparser
6
+ def initialize
7
+ @options = {}
8
+ @optparser = OptionParser.new do |opts|
9
+
10
+ opts.banner = "Usage: poi -f [FILE / URL] [-d]"
11
+
12
+ opts.on('-f', '--file FILE / URL', 'Generate using .poi file.') do |file|
13
+ @options[:file] = file
14
+ end
15
+
16
+ opts.on('-d', '--delete', 'Delete all generated file') do
17
+ @options[:delete] = true
18
+ end
19
+
20
+ opts.on('-p', '--pack [PACK]', 'Pack .poipack file into .poi') do |pack|
21
+ @options[:pack] = pack || '.poipack'
22
+ end
23
+
24
+ opts.on('-t', '--target TARGET', 'Packaging target') do |target|
25
+ @options[:target] = target
26
+ end
27
+
28
+ opts.on('-h', '--help', "Print help message") do
29
+ @options[:help] = true
30
+ puts opts
31
+ exit
32
+ end
33
+ end
34
+ end
35
+
36
+ def parse(argv)
37
+ @optparser.parse!(argv)
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,29 @@
1
+
2
+ require 'poi/app'
3
+ require 'optparse'
4
+
5
+ module POI
6
+ class Pois
7
+ def run(argv)
8
+ options = []
9
+ OptionParser.new do |opts|
10
+ opts.banner = "Usage: pois -f [host poi] [-d]"
11
+ opts.on('-f', '--file FILE / URL', 'Generate using .poi file.') do |file|
12
+ options << "-f"
13
+ options << "https://raw.githubusercontent.com/poi-templates/pois/master/#{file.strip}.poi"
14
+ end
15
+
16
+ opts.on('-d', '--delete', 'Delete all generated file') do
17
+ options << "-d"
18
+ end
19
+
20
+ opts.on('-h', '--help', "Print help message") do
21
+ puts opts
22
+ exit
23
+ end
24
+ end.parse!(argv)
25
+
26
+ POI::App.new.run(options)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,13 @@
1
+ module POI
2
+ module Utils
3
+ def parents(path)
4
+ segs = path.split("/")
5
+ parent_segs = segs[0...-1];
6
+
7
+ if (parent_segs.empty?)
8
+ return "."
9
+ end
10
+ return parent_segs.join("/")
11
+ end
12
+ end
13
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: poi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kimmy Leo
@@ -34,10 +34,18 @@ description: A simple tools to initialize project files and structure.
34
34
  email: kenpusney@gmail.com
35
35
  executables:
36
36
  - poi
37
+ - pois
37
38
  extensions: []
38
39
  extra_rdoc_files: []
39
40
  files:
40
41
  - bin/poi
42
+ - bin/pois
43
+ - lib/poi.rb
44
+ - lib/poi/app.rb
45
+ - lib/poi/constants.rb
46
+ - lib/poi/opt.rb
47
+ - lib/poi/pois.rb
48
+ - lib/poi/utils.rb
41
49
  homepage: http://rubygems.org/gems/poi
42
50
  licenses:
43
51
  - MIT