overapp 0.2.0 → 0.3.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 +8 -8
- data/VERSION +1 -1
- data/bin/overapp +2 -2
- data/lib/overapp/files.rb +4 -1
- data/lib/overapp/project.rb +4 -0
- data/lib/overapp/template_file.rb +62 -71
- data/overapp.gemspec +1 -1
- data/spec/overapp_spec.rb +34 -20
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZWIyODU5Y2M4OWMyZTJkMzFmMDBjNGI3NDZhMmZlZGJhOTVkMDBhYQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NjA3Mjg0ZmFlNGVhMDgxNjc3NDFkMWM0Yjk3MTBiMDAyZDBkYWViYw==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MzU1NTQ4MTVkMTRiYWM3ZmRlOTU5ZWQ1YjE0NWIyMzA0YjI2ZDk5MjJmMmVm
|
10
|
+
ZTVlYjRkYTcwMTJkOWU0NjQzODg2ZDIxNTA3ZWFkNjBlMGY2ZWFjODg1ZGZm
|
11
|
+
MjBlMDExY2YxYmJjY2MzYWUxMzU1Y2RmNDkyZjljZWEzYTFhYjA=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YjcwMWZiODA2ZmMyZjY4ZTMyZjJiYjlmYjg3ZGQxZGVlMGM1N2UxOTQ5NWIy
|
14
|
+
NmJlNDMwNzNhMzgyYzcwZWIyYTJlZTg1NzU4NzE0ODk0YmRjNjE0YTM4MzNl
|
15
|
+
NmMwMDVlZGY3Y2I1YWYzMzZkNGE1OTA4NTkzNzJkYjYyMTVjZWM=
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/bin/overapp
CHANGED
data/lib/overapp/files.rb
CHANGED
@@ -16,7 +16,10 @@ module Overapp
|
|
16
16
|
existing = res.find { |x| x.path == top_file.path }
|
17
17
|
if existing
|
18
18
|
res -= [existing]
|
19
|
-
|
19
|
+
new_file = top_file.combined(existing)
|
20
|
+
res << new_file if new_file
|
21
|
+
elsif top_file.has_note?
|
22
|
+
raise "cannot overlay onto missing file #{top_file.path}"
|
20
23
|
else
|
21
24
|
res << top_file
|
22
25
|
end
|
data/lib/overapp/project.rb
CHANGED
@@ -3,45 +3,73 @@ module Overapp
|
|
3
3
|
include FromHash
|
4
4
|
attr_accessor :path, :full_body
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
def split_note_and_body
|
7
|
+
res = []
|
8
|
+
remaining_body = full_body
|
9
|
+
while remaining_body
|
10
|
+
if remaining_body =~ /^<over(?:lay|app)>(.+)<\/over(?:lay|app)>(.*)(<over(?:lay|app)>.+)/m
|
9
11
|
note = $1
|
10
|
-
rest =
|
11
|
-
|
12
|
-
|
12
|
+
rest = $2
|
13
|
+
remaining_body = $3
|
14
|
+
res << {:note => note, :body => rest}
|
15
|
+
elsif remaining_body =~ /^<over(?:lay|app)>(.+)<\/over(?:lay|app)>(.*)/m
|
13
16
|
note = $1
|
14
|
-
rest =
|
15
|
-
|
17
|
+
rest = $2
|
18
|
+
remaining_body = nil
|
19
|
+
res << {:note => note, :body => rest}
|
16
20
|
else
|
17
|
-
nil
|
21
|
+
res << {:note => nil, :body => remaining_body}
|
22
|
+
remaining_body = nil
|
18
23
|
end
|
19
24
|
end
|
25
|
+
res
|
26
|
+
end
|
27
|
+
|
20
28
|
|
21
|
-
|
22
|
-
|
29
|
+
def note_params_single(one)
|
30
|
+
res = {}
|
31
|
+
note = one[:note]
|
32
|
+
res[:body] = one[:body]
|
33
|
+
|
34
|
+
if note
|
23
35
|
lines = note.split("\n").select { |x| x.present? }
|
24
|
-
if lines.size == 1
|
36
|
+
if lines.size == 1 && !(lines.first =~ /action:/)
|
25
37
|
res[:action] = lines.first.strip
|
26
38
|
else
|
27
39
|
lines.each do |line|
|
28
|
-
parts = line.split(":").
|
40
|
+
parts = line.split(":").select { |x| x.present? }
|
41
|
+
if parts.size > 2
|
42
|
+
parts = [parts[0],parts[1..-1].join(":")]
|
43
|
+
end
|
44
|
+
parts = parts.map { |x| x.strip }
|
29
45
|
raise "bad #{path} #{parts.inspect}" unless parts.size == 2
|
30
46
|
res[parts[0].to_sym] = parts[1]
|
31
47
|
end
|
32
48
|
end
|
33
|
-
|
49
|
+
else
|
50
|
+
# do nothing
|
34
51
|
end
|
52
|
+
res
|
53
|
+
end
|
35
54
|
|
55
|
+
def note_params
|
56
|
+
split_parts.map do |one|
|
57
|
+
note_params_single(one)
|
58
|
+
end
|
59
|
+
end
|
36
60
|
|
37
|
-
|
38
|
-
|
39
|
-
|
61
|
+
|
62
|
+
def apply_body_to(base_body)
|
63
|
+
note_params.each do |params|
|
64
|
+
body = params[:body]
|
65
|
+
base_body = if params[:action].blank?
|
66
|
+
body
|
67
|
+
elsif params[:action] == 'append'
|
40
68
|
base_body + body
|
41
69
|
elsif params[:action] == 'insert' && params[:after]
|
42
70
|
base_body.gsub(params[:after],"#{params[:after]}#{body}").tap do |subbed|
|
43
71
|
if subbed == base_body
|
44
|
-
raise "no change, couldn't find #{params[:after]} in \n#{base_body}"
|
72
|
+
raise "no change, couldn't find #{params[:after]} to insert #{body} in \n#{base_body}"
|
45
73
|
end
|
46
74
|
end
|
47
75
|
elsif params[:action] == 'insert' && params[:before]
|
@@ -53,73 +81,36 @@ module Overapp
|
|
53
81
|
elsif params[:action] == 'replace' && params[:base]
|
54
82
|
base_body.gsub(params[:base],body).tap do |subbed|
|
55
83
|
if subbed == base_body
|
56
|
-
raise "no change, couldn't find #{params[:base]} in \n#{base_body}"
|
84
|
+
raise "no change, couldn't find #{params[:base]} to replace with #{body} in \n#{base_body}"
|
57
85
|
end
|
58
86
|
end
|
87
|
+
elsif params[:action] == 'delete'
|
88
|
+
:delete
|
59
89
|
else
|
60
|
-
raise "bad"
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
module OldWay
|
66
|
-
def split_note_and_body_short
|
67
|
-
if full_body =~ /^FSTMODE:([a-z:0-9]+)\s/m
|
68
|
-
note = $1
|
69
|
-
rest = full_body.gsub(/^FSTMODE:#{note}/,"")
|
70
|
-
{:note => note, :body => rest, :format => :short}
|
71
|
-
else
|
72
|
-
nil
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def apply_body_to_short(base_body)
|
77
|
-
note_parts = note.to_s.split(":")
|
78
|
-
if note == 'append'
|
79
|
-
base_body + body
|
80
|
-
elsif note_parts[0] == 'insert'
|
81
|
-
raise "bad" unless note_parts[1] == 'line'
|
82
|
-
base_lines = base_body.split("\n")
|
83
|
-
i = note_parts[2].to_i - 1
|
84
|
-
base_lines[0...i].join("\n") + body + base_lines[i..-1].join("\n")
|
85
|
-
else
|
86
|
-
raise "unknown note #{note}"
|
90
|
+
raise "bad #{params.inspect}"
|
87
91
|
end
|
88
92
|
end
|
93
|
+
base_body
|
89
94
|
end
|
90
95
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
def split_note_and_body
|
95
|
-
[:split_note_and_body_short,:split_note_and_body_long].each do |meth|
|
96
|
-
res = send(meth)
|
97
|
-
return res if res
|
98
|
-
end
|
99
|
-
{:note => nil, :body => full_body}
|
96
|
+
fattr(:split_parts) { split_note_and_body }
|
97
|
+
def has_note?
|
98
|
+
split_parts.any? { |x| x[:note].present? }
|
100
99
|
end
|
101
100
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
fattr(:note) { split_parts[:note] }
|
106
|
-
fattr(:format) { split_parts[:format] }
|
101
|
+
def body
|
102
|
+
full_body
|
103
|
+
end
|
107
104
|
|
108
|
-
def
|
109
|
-
|
110
|
-
|
111
|
-
|
105
|
+
def combined(base)
|
106
|
+
b = apply_body_to(base.full_body)
|
107
|
+
if b == :delete
|
108
|
+
nil
|
112
109
|
else
|
113
|
-
|
110
|
+
self.class.new(:path => path, :full_body => b)
|
114
111
|
end
|
115
112
|
end
|
116
113
|
|
117
|
-
|
118
|
-
|
119
|
-
def combined(base)
|
120
|
-
self.class.new(:path => path, :full_body => apply_body_to(base.body))
|
121
|
-
end
|
122
|
-
|
123
114
|
def write_to!(dir)
|
124
115
|
raise "bad path" if path.blank?
|
125
116
|
d = File.dirname("#{dir}/#{path}")
|
data/overapp.gemspec
CHANGED
data/spec/overapp_spec.rb
CHANGED
@@ -57,12 +57,14 @@ describe "dotfile" do
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
|
60
|
+
|
61
|
+
|
62
|
+
describe "combine - append format2" do
|
61
63
|
include_context "setup"
|
62
64
|
|
63
65
|
base_file "a.txt","stuff"
|
64
66
|
base_file "b.txt","here"
|
65
|
-
on_top_file "b.txt","
|
67
|
+
on_top_file "b.txt","<overapp>append</overapp>\nother"
|
66
68
|
|
67
69
|
it 'combined size' do
|
68
70
|
combined.size.should == 2
|
@@ -74,12 +76,12 @@ describe "combine - append" do
|
|
74
76
|
end
|
75
77
|
end
|
76
78
|
|
77
|
-
describe "combine -
|
79
|
+
describe "combine - insert after" do
|
78
80
|
include_context "setup"
|
79
81
|
|
80
82
|
base_file "a.txt","stuff"
|
81
|
-
base_file "b.txt","
|
82
|
-
on_top_file "b.txt","<overapp>
|
83
|
+
base_file "b.txt","123\n456\n789"
|
84
|
+
on_top_file "b.txt","<overapp>action: insert\nafter: 456</overapp>\nabc"
|
83
85
|
|
84
86
|
it 'combined size' do
|
85
87
|
combined.size.should == 2
|
@@ -87,16 +89,16 @@ describe "combine - append format2" do
|
|
87
89
|
|
88
90
|
it 'combined file should overwrite' do
|
89
91
|
f = combined.files.find { |x| x.path == "b.txt" }
|
90
|
-
f.body.should == "
|
92
|
+
f.body.should == "123\n456\nabc\n789"
|
91
93
|
end
|
92
94
|
end
|
93
95
|
|
94
|
-
describe "combine - insert" do
|
96
|
+
describe "combine - insert after with colon" do
|
95
97
|
include_context "setup"
|
96
98
|
|
97
99
|
base_file "a.txt","stuff"
|
98
|
-
base_file "b.txt","
|
99
|
-
on_top_file "b.txt","
|
100
|
+
base_file "b.txt","123\n45: 6\n789"
|
101
|
+
on_top_file "b.txt","<overapp>action: insert\nafter: 45: 6</overapp>\nabc"
|
100
102
|
|
101
103
|
it 'combined size' do
|
102
104
|
combined.size.should == 2
|
@@ -104,16 +106,16 @@ describe "combine - insert" do
|
|
104
106
|
|
105
107
|
it 'combined file should overwrite' do
|
106
108
|
f = combined.files.find { |x| x.path == "b.txt" }
|
107
|
-
f.body.should == "
|
109
|
+
f.body.should == "123\n45: 6\nabc\n789"
|
108
110
|
end
|
109
111
|
end
|
110
112
|
|
111
|
-
describe "combine - insert
|
113
|
+
describe "combine - insert before" do
|
112
114
|
include_context "setup"
|
113
115
|
|
114
116
|
base_file "a.txt","stuff"
|
115
117
|
base_file "b.txt","123\n456\n789"
|
116
|
-
on_top_file "b.txt","<overapp>action: insert\
|
118
|
+
on_top_file "b.txt","<overapp>action: insert\nbefore: 456</overapp>abc\n"
|
117
119
|
|
118
120
|
it 'combined size' do
|
119
121
|
combined.size.should == 2
|
@@ -121,16 +123,28 @@ describe "combine - insert after" do
|
|
121
123
|
|
122
124
|
it 'combined file should overwrite' do
|
123
125
|
f = combined.files.find { |x| x.path == "b.txt" }
|
124
|
-
f.body.should == "123\n456\
|
126
|
+
f.body.should == "123\nabc\n456\n789"
|
125
127
|
end
|
126
128
|
end
|
127
129
|
|
128
|
-
describe "combine -
|
130
|
+
describe "combine - delete" do
|
129
131
|
include_context "setup"
|
130
132
|
|
131
133
|
base_file "a.txt","stuff"
|
132
134
|
base_file "b.txt","123\n456\n789"
|
133
|
-
on_top_file "b.txt","<overapp>action:
|
135
|
+
on_top_file "b.txt","<overapp>action: delete\n</overapp>abc\n"
|
136
|
+
|
137
|
+
it 'combined size' do
|
138
|
+
combined.size.should == 1
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe "combine - multiple directives" do
|
143
|
+
include_context "setup"
|
144
|
+
|
145
|
+
base_file "a.txt","stuff"
|
146
|
+
base_file "b.txt","123\n456\n789"
|
147
|
+
on_top_file "b.txt","<overapp>action: replace\nbase: 123\n</overapp>abc<overapp>action: replace\nbase: 456\n</overapp>def"
|
134
148
|
|
135
149
|
it 'combined size' do
|
136
150
|
combined.size.should == 2
|
@@ -138,7 +152,7 @@ describe "combine - insert before" do
|
|
138
152
|
|
139
153
|
it 'combined file should overwrite' do
|
140
154
|
f = combined.files.find { |x| x.path == "b.txt" }
|
141
|
-
f.body.should == "
|
155
|
+
f.body.should == "abc\ndef\n789"
|
142
156
|
end
|
143
157
|
end
|
144
158
|
|
@@ -171,13 +185,13 @@ describe "combine - top file in new dir" do
|
|
171
185
|
end
|
172
186
|
end
|
173
187
|
|
174
|
-
describe "combine -
|
188
|
+
describe "combine - insert to nothing" do
|
175
189
|
include_context "setup"
|
176
190
|
|
177
|
-
|
178
|
-
on_top_file "a.txt","FSTMODE:fgdfgdfg\nstuff"
|
191
|
+
on_top_file "b.txt","<overapp>action: insert\nafter: 456</overapp>abc"
|
179
192
|
|
180
|
-
it '
|
193
|
+
it 'errors' do
|
181
194
|
lambda { combined.size }.should raise_error
|
182
195
|
end
|
183
196
|
end
|
197
|
+
|