poi 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/bin/poi +103 -0
- metadata +66 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 44694a12e47bdb3b334a9e1ef172503cafa14680
|
4
|
+
data.tar.gz: '085a47ef6eb40e1028cc9df04358271e46f03447'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a7415865174562e9559e859c3716c6e9e13f0a52a0994209c3359d338aa8ae34b6b203c672c1f183ab66b9e24fd76c25517ab36b80ce6e780dd5570864e73505
|
7
|
+
data.tar.gz: c7bd66e7c160d0c8afb2d2a9249b43a42852ddf1ecc2c92ccb2b453655151fe5188c91ded0d7d504cf05080676373395df5862617f223008c62f6cb2eca0153c
|
data/bin/poi
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'mustache'
|
6
|
+
require 'json'
|
7
|
+
require 'optparse'
|
8
|
+
require 'open-uri'
|
9
|
+
|
10
|
+
POI_DEFAULTS = ".poi_defaults"
|
11
|
+
|
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
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: poi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kimmy Leo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-04-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mustache
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.0.5
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.0'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.0.5
|
33
|
+
description: A simple tools to initialize project files and structure.
|
34
|
+
email: kenpusney@gmail.com
|
35
|
+
executables:
|
36
|
+
- poi
|
37
|
+
extensions: []
|
38
|
+
extra_rdoc_files: []
|
39
|
+
files:
|
40
|
+
- bin/poi
|
41
|
+
homepage: http://rubygems.org/gems/poi
|
42
|
+
licenses:
|
43
|
+
- MIT
|
44
|
+
metadata:
|
45
|
+
source_code_uri: https://github.com/kenpusney/poi
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 2.6.12
|
63
|
+
signing_key:
|
64
|
+
specification_version: 4
|
65
|
+
summary: Project Init Utility
|
66
|
+
test_files: []
|