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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MTUyNDEwNWY4M2NlM2I4MjQ4M2RlMGY0NzMyM2YzYzQ0YmE4YWE4MQ==
4
+ ZWIyODU5Y2M4OWMyZTJkMzFmMDBjNGI3NDZhMmZlZGJhOTVkMDBhYQ==
5
5
  data.tar.gz: !binary |-
6
- ODY2MjliZjgzYjU2MDk5ZTMxYzRmZTExZmU5NzA1NzAxNGM1NzdiMg==
6
+ NjA3Mjg0ZmFlNGVhMDgxNjc3NDFkMWM0Yjk3MTBiMDAyZDBkYWViYw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NzNhYTMwYWViNDA5ZDdiODdjZTkwZTFkNjRhNTYwNGE3Y2FiYmI5MjIyOTVl
10
- NWNmMmY0NzllNmM1YWM1OWRhNzZjMjcwZTAxNWE1NTBlZjM5ZTliMTAyOTc1
11
- OGVhMTgzNGRmMzBlMmY4ODdiMmNiYWE2ZDYyYWY5N2JhZmZjMDg=
9
+ MzU1NTQ4MTVkMTRiYWM3ZmRlOTU5ZWQ1YjE0NWIyMzA0YjI2ZDk5MjJmMmVm
10
+ ZTVlYjRkYTcwMTJkOWU0NjQzODg2ZDIxNTA3ZWFkNjBlMGY2ZWFjODg1ZGZm
11
+ MjBlMDExY2YxYmJjY2MzYWUxMzU1Y2RmNDkyZjljZWEzYTFhYjA=
12
12
  data.tar.gz: !binary |-
13
- OWUyMDY2M2JiYWE3NDAxNzRmYmNiMTgzMzI3NjM4NzdkZjE5M2Y3N2U3NDAx
14
- OWE0MjhhZjAyMTFiZmRhZTkwYWMxOGI0ZDg1MmEwOWE3YTg0ZTU2M2RhZGM4
15
- Mzg1OGRjZmRhYjA1YWMyYWU5ZGU5YjRmZTE1YmI3NzBkZWQ5ODE=
13
+ YjcwMWZiODA2ZmMyZjY4ZTMyZjJiYjlmYjg3ZGQxZGVlMGM1N2UxOTQ5NWIy
14
+ NmJlNDMwNzNhMzgyYzcwZWIyYTJlZTg1NzU4NzE0ODk0YmRjNjE0YTM4MzNl
15
+ NmMwMDVlZGY3Y2I1YWYzMzZkNGE1OTA4NTkzNzJkYjYyMTVjZWM=
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
data/bin/overapp CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- load File.dirname(__FILE__) + "/../lib/fs_template.rb"
3
+ load File.dirname(__FILE__) + "/../lib/overapp.rb"
4
4
 
5
- FsTemplate.write_project ARGV[0],ARGV[1]
5
+ Overapp.write_project ARGV[0],ARGV[1]
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
- res << top_file.combined(existing)
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
@@ -97,6 +97,10 @@ module Overapp
97
97
  self.overapps << name
98
98
  end
99
99
 
100
+ def overlay(name)
101
+ overapp(name)
102
+ end
103
+
100
104
  def command(cmd,phase=:after)
101
105
  self.commands << {:command => cmd, :phase => phase}
102
106
  end
@@ -3,45 +3,73 @@ module Overapp
3
3
  include FromHash
4
4
  attr_accessor :path, :full_body
5
5
 
6
- module NewWay
7
- def split_note_and_body_long
8
- if full_body =~ /<overapp>(.+)<\/overapp>/m
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 = full_body.gsub(/<overapp>.+<\/overapp>/m,"")
11
- {:note => note, :body => rest, :format => :long}
12
- elsif full_body =~ /<overlay>(.+)<\/overlay>/m
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 = full_body.gsub(/<overlay>.+<\/overlay>/m,"")
15
- {:note => note, :body => rest, :format => :long}
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
- def note_params
22
- res = {}
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(":").map { |x| x.strip }.select { |x| x.present? }
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
- res
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
- def apply_body_to_long(base_body)
38
- params = note_params
39
- if note == 'append'
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
- include OldWay
92
- include NewWay
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
- fattr(:split_parts) { split_note_and_body }
103
-
104
- fattr(:body) { split_parts[:body] }
105
- fattr(:note) { split_parts[:note] }
106
- fattr(:format) { split_parts[:format] }
101
+ def body
102
+ full_body
103
+ end
107
104
 
108
- def apply_body_to(base_body)
109
- if note.present?
110
- m = "apply_body_to_#{format}"
111
- send(m,base_body)
105
+ def combined(base)
106
+ b = apply_body_to(base.full_body)
107
+ if b == :delete
108
+ nil
112
109
  else
113
- body
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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "overapp"
8
- s.version = "0.2.0"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Mike Harris"]
data/spec/overapp_spec.rb CHANGED
@@ -57,12 +57,14 @@ describe "dotfile" do
57
57
  end
58
58
  end
59
59
 
60
- describe "combine - append" do
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","FSTMODE:append\nother"
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 - append format2" do
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","here"
82
- on_top_file "b.txt","<overapp>append</overapp>\nother"
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 == "here\nother"
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","a\nb\nc\nd"
99
- on_top_file "b.txt","FSTMODE:insert:line:2\nother\n"
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 == "a\nother\nb\nc\nd"
109
+ f.body.should == "123\n45: 6\nabc\n789"
108
110
  end
109
111
  end
110
112
 
111
- describe "combine - insert after" do
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\nafter: 456</overapp>\nabc"
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\nabc\n789"
126
+ f.body.should == "123\nabc\n456\n789"
125
127
  end
126
128
  end
127
129
 
128
- describe "combine - insert before" do
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: insert\nbefore: 456</overapp>abc\n"
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 == "123\nabc\n456\n789"
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 - error" do
188
+ describe "combine - insert to nothing" do
175
189
  include_context "setup"
176
190
 
177
- base_file "a.txt","stuff"
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 'combined size' do
193
+ it 'errors' do
181
194
  lambda { combined.size }.should raise_error
182
195
  end
183
196
  end
197
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: overapp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Harris