overapp 0.4.2 → 0.5.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/lib/overapp/files.rb +11 -6
- data/lib/overapp/from_command.rb +0 -13
- data/lib/overapp/load/base.rb +9 -4
- data/lib/overapp/load/instance.rb +3 -11
- data/lib/overapp/load/types/command.rb +11 -7
- data/lib/overapp/load/types/empty.rb +0 -9
- data/lib/overapp/load/types/local_dir.rb +2 -2
- data/lib/overapp/load/types/project.rb +5 -3
- data/lib/overapp/load/types/raw_dir.rb +10 -8
- data/lib/overapp/load/types/repo.rb +1 -1
- data/lib/overapp/project/config.rb +5 -0
- data/lib/overapp/project/write.rb +1 -1
- data/lib/overapp/project.rb +15 -7
- data/lib/overapp/template_file/body_mod.rb +56 -0
- data/lib/overapp/template_file/params.rb +75 -0
- data/lib/overapp/template_file/var_obj.rb +24 -0
- data/lib/overapp/template_file.rb +25 -84
- data/lib/overapp/util/dir.rb +9 -2
- data/lib/overapp/util/tmp_dir.rb +6 -2
- data/lib/overapp/var.rb +18 -0
- data/lib/overapp.rb +6 -1
- data/overapp.gemspec +11 -2
- data/spec/command_replacement_spec.rb +33 -0
- data/spec/from_command_spec.rb +29 -0
- data/spec/git_spec.rb +12 -0
- data/spec/nesting_spec.rb +0 -44
- data/spec/project_context_spec.rb +131 -0
- data/spec/project_note_spec.rb +33 -101
- data/spec/spec_helper.rb +1 -1
- data/spec/support/project.rb +134 -0
- data/spec/template_spec.rb +73 -0
- metadata +11 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MGVjNDY1MjViY2YwMGE5MzQ1ZGViODNkZGU5YWMwNWZlZjAzYTJhZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
Njg5MWYwNGY0Yzk0ODFlYWE5OGFlMDIxNjI2NWRlZjU0MThmMTAxYg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YTgwNjQ0OTI3Y2VjMGVjMWUxZWM1NTVmNDJjMzBhMTYyNGQ2MjIxYTlmOGEw
|
10
|
+
MDExYTM1OWI5YTA0ZWI0ZDJmODExOTYxMjM3NGIzZTAxYzFhZWU4Yzg0YTY2
|
11
|
+
NDVmMzAyMGM0MTg0MGY3MDU4ODIzNzliYjFhZWE0MTA3ZWQzYmE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZDg2NTIyNTM1N2UxMTZlOGRkYjQ1OWQwNTE3MzU2MWVjZWRhNTk1YmRhYmVh
|
14
|
+
YzE3ZDViYmZjMjhmZDZlMmM3ODNiY2ZjMGE1ZjYzMjZmNzczMTgxNTQzNjMz
|
15
|
+
YzQ0OGEzNDU3NzliYzc1NjdjNTI5ODg5MmY1YWE4NjU0OTFlM2Y=
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
data/lib/overapp/files.rb
CHANGED
@@ -3,7 +3,7 @@ module Overapp
|
|
3
3
|
include FromHash
|
4
4
|
attr_accessor :top_file, :base
|
5
5
|
def message
|
6
|
-
res = "Cannot overlay onto missing file #{top_file.path}\nBase File Count: #{base.files.size}\n"
|
6
|
+
res = "Cannot overlay onto missing file #{top_file.path}\nBase File Count: #{base.files.size}\n#{top_file.params_obj.note_params.inspect}"
|
7
7
|
res += base.map { |x| x.path }.join("\n")
|
8
8
|
res
|
9
9
|
end
|
@@ -19,9 +19,13 @@ module Overapp
|
|
19
19
|
def size
|
20
20
|
files.size
|
21
21
|
end
|
22
|
-
def apply(on_top)
|
22
|
+
def apply(on_top,ops={})
|
23
23
|
res = files.clone
|
24
24
|
on_top.each do |top_file|
|
25
|
+
if ops[:vars] && ops[:vars].size > 0
|
26
|
+
#raise ops[:vars].inspect
|
27
|
+
top_file.vars = ops[:vars]
|
28
|
+
end
|
25
29
|
existing = res.find { |x| x.path == top_file.path }
|
26
30
|
if existing
|
27
31
|
res -= [existing]
|
@@ -30,7 +34,7 @@ module Overapp
|
|
30
34
|
elsif top_file.has_note?
|
31
35
|
raise MissingBaseFileError.new(:top_file => top_file, :base => self)
|
32
36
|
else
|
33
|
-
res << top_file
|
37
|
+
res << top_file.parsed
|
34
38
|
end
|
35
39
|
end
|
36
40
|
self.class.new(:files => res)
|
@@ -46,9 +50,10 @@ module Overapp
|
|
46
50
|
self
|
47
51
|
end
|
48
52
|
|
49
|
-
|
50
|
-
|
51
|
-
|
53
|
+
def with_tmp(&b)
|
54
|
+
Overapp::TmpDir.with do |dir|
|
55
|
+
write_to! dir
|
56
|
+
b[dir]
|
52
57
|
end
|
53
58
|
end
|
54
59
|
end
|
data/lib/overapp/from_command.rb
CHANGED
@@ -1,13 +0,0 @@
|
|
1
|
-
module Overapp
|
2
|
-
class FromCommand
|
3
|
-
include FromHash
|
4
|
-
attr_accessor :command, :path
|
5
|
-
|
6
|
-
fattr(:files) do
|
7
|
-
Overapp.with_tmp_dir do |dir|
|
8
|
-
Overapp.ec command, :silent => true
|
9
|
-
Files.load [dir,path].select { |x| x.present? }.join("/"), :file_class => BasicFile
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
data/lib/overapp/load/base.rb
CHANGED
@@ -4,16 +4,21 @@ module Overapp
|
|
4
4
|
include FromHash
|
5
5
|
attr_accessor :descriptor
|
6
6
|
|
7
|
-
def
|
8
|
-
|
7
|
+
def initialize(ops={})
|
8
|
+
raise "no descriptor" unless ops[:descriptor].present?
|
9
|
+
from_hash(ops)
|
9
10
|
end
|
10
11
|
|
11
12
|
def commit_message
|
12
13
|
"Message Pending"
|
13
14
|
end
|
14
15
|
|
15
|
-
def
|
16
|
-
|
16
|
+
def load_full(base,ops={})
|
17
|
+
res = load(base,ops)
|
18
|
+
while res.kind_of?(Overapp::Load::Base)
|
19
|
+
res = res.load(base,ops)
|
20
|
+
end
|
21
|
+
res
|
17
22
|
end
|
18
23
|
end
|
19
24
|
end
|
@@ -3,14 +3,10 @@ module Overapp
|
|
3
3
|
class Instance
|
4
4
|
include FromHash
|
5
5
|
attr_accessor :path, :overlays
|
6
|
+
fattr(:vars) { {} }
|
6
7
|
|
7
8
|
fattr(:starting_files) do
|
8
|
-
|
9
|
-
if Overapp.dir_files(path).empty?
|
10
|
-
Overapp::Files.new
|
11
|
-
else
|
12
|
-
RawDir.new(:descriptor => path).load(nil,{})
|
13
|
-
end
|
9
|
+
Overapp::Files.new
|
14
10
|
end
|
15
11
|
|
16
12
|
fattr(:combined_files) do
|
@@ -24,11 +20,7 @@ module Overapp
|
|
24
20
|
end
|
25
21
|
|
26
22
|
def apply_overlay(base,overlay)
|
27
|
-
|
28
|
-
overlay.apply_to(base, :path => path).tap do |res|
|
29
|
-
res.write_to! path
|
30
|
-
end
|
31
|
-
end.tap { |res| raise "nil return" unless res }
|
23
|
+
overlay.load_full(base,:vars => vars)
|
32
24
|
end
|
33
25
|
end
|
34
26
|
end
|
@@ -3,15 +3,19 @@ module Overapp
|
|
3
3
|
class Command < Base
|
4
4
|
attr_accessor :relative_output_path
|
5
5
|
def command; descriptor; end
|
6
|
-
|
6
|
+
|
7
|
+
def target_path(dir)
|
7
8
|
if relative_output_path.present?
|
8
|
-
|
9
|
-
Overapp.ec "cd #{dir} && #{command}", :silent => false
|
10
|
-
RawDir.new(:descriptor => "#{dir}/#{relative_output_path}").load(base,ops)
|
11
|
-
end
|
9
|
+
"#{dir}/#{relative_output_path}"
|
12
10
|
else
|
13
|
-
|
14
|
-
|
11
|
+
dir
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def load(base,ops={})
|
16
|
+
base.with_tmp do |dir|
|
17
|
+
Overapp.ec "cd #{dir} && #{command}", :silent => true
|
18
|
+
RawDir.new(:descriptor => target_path(dir))
|
15
19
|
end
|
16
20
|
end
|
17
21
|
end
|
@@ -5,9 +5,9 @@ module Overapp
|
|
5
5
|
|
6
6
|
def load(base,ops)
|
7
7
|
if Overapp::Project.project? path
|
8
|
-
Project.new(:descriptor => path)
|
8
|
+
Project.new(:descriptor => path)
|
9
9
|
else
|
10
|
-
RawDir.new(:descriptor => path)
|
10
|
+
RawDir.new(:descriptor => path)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
@@ -2,10 +2,12 @@ module Overapp
|
|
2
2
|
module Load
|
3
3
|
class Project < Base
|
4
4
|
def path; descriptor; end
|
5
|
+
fattr(:project) do
|
6
|
+
Overapp::Project.load(:path => path)
|
7
|
+
end
|
5
8
|
def load(base,ops={})
|
6
|
-
|
7
|
-
|
8
|
-
RawDir.new(:descriptor => ops[:path]).load(base,ops)
|
9
|
+
instance = Load::Instance.new(:overlays => project.overapps, :starting_files => base)
|
10
|
+
instance.combined_files
|
9
11
|
end
|
10
12
|
end
|
11
13
|
end
|
@@ -2,21 +2,23 @@ module Overapp
|
|
2
2
|
module Load
|
3
3
|
class RawDir < Base
|
4
4
|
def dir; Overapp.to_proper_dir(descriptor); end
|
5
|
-
def
|
5
|
+
def load_independent
|
6
6
|
ops = {}
|
7
7
|
raise "Bad dir" unless dir.present?
|
8
|
-
|
8
|
+
|
9
9
|
res = Files.new
|
10
10
|
res.file_class = ops[:file_class] if ops[:file_class]
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
raise "bad #{f}" if f == full_file
|
15
|
-
res.add :file => f, :body => File.read(full_file)
|
16
|
-
end
|
11
|
+
|
12
|
+
Overapp.dir_files_full(dir).each do |f|
|
13
|
+
res.add(f)
|
17
14
|
end
|
15
|
+
|
18
16
|
res
|
19
17
|
end
|
18
|
+
|
19
|
+
def load(base,ops={})
|
20
|
+
base.apply(load_independent,ops)
|
21
|
+
end
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
@@ -3,6 +3,7 @@ module Overapp
|
|
3
3
|
include FromHash
|
4
4
|
attr_accessor :body, :base_ops
|
5
5
|
fattr(:overapps) { [] }
|
6
|
+
fattr(:vars) { {} }
|
6
7
|
|
7
8
|
def base(*args)
|
8
9
|
overapp(*args)
|
@@ -20,6 +21,10 @@ module Overapp
|
|
20
21
|
self.overapps << ConfigEntry.new(:descriptor => cmd, :type => :command, :entry_ops => ops)
|
21
22
|
end
|
22
23
|
|
24
|
+
def var(k,v)
|
25
|
+
vars[k] = v
|
26
|
+
end
|
27
|
+
|
23
28
|
def load!
|
24
29
|
c = self
|
25
30
|
eval(body)
|
@@ -5,7 +5,7 @@ module Overapp
|
|
5
5
|
attr_accessor :output_path, :project
|
6
6
|
|
7
7
|
fattr(:instance) do
|
8
|
-
Load::Instance.new(:
|
8
|
+
Load::Instance.new(:overlays => project.overapps, :vars => Overapp::Var.vars.merge(project.vars))
|
9
9
|
end
|
10
10
|
|
11
11
|
def combined_files
|
data/lib/overapp/project.rb
CHANGED
@@ -2,6 +2,7 @@ module Overapp
|
|
2
2
|
class Project
|
3
3
|
include FromHash
|
4
4
|
attr_accessor :path
|
5
|
+
fattr(:vars) { config.vars }
|
5
6
|
|
6
7
|
class << self
|
7
8
|
def project_files
|
@@ -9,11 +10,16 @@ module Overapp
|
|
9
10
|
end
|
10
11
|
|
11
12
|
def project?(path)
|
13
|
+
raise "checking for project, path doesn't exist #{path}" unless FileTest.exist?(path)
|
12
14
|
!!project_files.map { |x| "#{path}/#{x}" }.find { |x| FileTest.exist?(x) }
|
13
15
|
end
|
16
|
+
|
17
|
+
def load(*args)
|
18
|
+
new(*args)
|
19
|
+
end
|
14
20
|
end
|
15
21
|
|
16
|
-
|
22
|
+
fattr(:config_body) do
|
17
23
|
file = klass.project_files.map { |x| "#{path}/#{x}" }.find { |x| FileTest.exist?(x) }
|
18
24
|
if file
|
19
25
|
File.read(file)
|
@@ -31,7 +37,7 @@ module Overapp
|
|
31
37
|
|
32
38
|
def overapp_entries
|
33
39
|
res = config.overapps
|
34
|
-
local = config.overapps.find { |x| x.descriptor == "." }
|
40
|
+
local = config.overapps.find { |x| x.descriptor == "." || x.descriptor == :self }
|
35
41
|
if local
|
36
42
|
local.descriptor = path
|
37
43
|
res
|
@@ -40,12 +46,15 @@ module Overapp
|
|
40
46
|
end
|
41
47
|
end
|
42
48
|
|
49
|
+
fattr(:load_factory_class) { Load::Factory }
|
50
|
+
fattr(:load_raw_dir_class) { Load::RawDir }
|
51
|
+
|
43
52
|
def overapps
|
44
53
|
overapp_entries.map do |entry|
|
45
54
|
if path == entry.descriptor
|
46
|
-
|
55
|
+
load_raw_dir_class.new(:descriptor => path)
|
47
56
|
else
|
48
|
-
|
57
|
+
load_factory_class.new(:descriptor => entry.descriptor, :type => entry.type, :entry_ops => entry.entry_ops).loader
|
49
58
|
end
|
50
59
|
end
|
51
60
|
end
|
@@ -54,9 +63,8 @@ module Overapp
|
|
54
63
|
Write.new(:output_path => output_path, :project => self).write!
|
55
64
|
end
|
56
65
|
|
57
|
-
def combined_files
|
58
|
-
|
59
|
-
Write.new(:output_path => output_path, :project => self).combined_files
|
66
|
+
def combined_files
|
67
|
+
Write.new(:project => self).combined_files
|
60
68
|
end
|
61
69
|
end
|
62
70
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Overapp
|
2
|
+
class TemplateFile
|
3
|
+
class BodyMod
|
4
|
+
class Single
|
5
|
+
include FromHash
|
6
|
+
attr_accessor :match, :transform
|
7
|
+
def match?(params)
|
8
|
+
match[params]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class List
|
13
|
+
fattr(:list) { [] }
|
14
|
+
def register(match_proc, transform_proc)
|
15
|
+
self.list << Single.new(match: match_proc, transform: transform_proc)
|
16
|
+
end
|
17
|
+
|
18
|
+
def transform(base_body,body,params)
|
19
|
+
single = list.find { |x| x.match?(params) }
|
20
|
+
raise "bad #{params.inspect}" unless single
|
21
|
+
res = single.transform[base_body,body,params]
|
22
|
+
raise "no change" if res == base_body
|
23
|
+
res
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class << self
|
28
|
+
def register(*args)
|
29
|
+
instance.register(*args)
|
30
|
+
end
|
31
|
+
def transform(*args)
|
32
|
+
instance.transform(*args)
|
33
|
+
end
|
34
|
+
fattr(:instance) { List.new }
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
register lambda { |params| params[:action] == 'append' },
|
39
|
+
lambda { |base_body,body,params| base_body + body }
|
40
|
+
|
41
|
+
register lambda { |params| params[:action] == 'insert' && params[:after] },
|
42
|
+
lambda { |base_body,body,params| base_body.gsub(params[:after],"#{params[:after]}#{body}") }
|
43
|
+
|
44
|
+
register lambda { |params| params[:action] == 'insert' && params[:before] },
|
45
|
+
lambda { |base_body,body,params| base_body.gsub(params[:before],"#{body}#{params[:before]}") }
|
46
|
+
|
47
|
+
register lambda { |params| params[:action] == 'replace' && params[:base] },
|
48
|
+
lambda { |base_body,body,params| base_body.gsub(params[:base],body) }
|
49
|
+
|
50
|
+
register lambda { |params| params[:action] == 'delete' },
|
51
|
+
lambda { |base_body,body,params| :delete }
|
52
|
+
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Overapp
|
2
|
+
class TemplateFile
|
3
|
+
class Params
|
4
|
+
include FromHash
|
5
|
+
attr_accessor :full_body
|
6
|
+
def body; full_body; end
|
7
|
+
include Enumerable
|
8
|
+
def each(&b)
|
9
|
+
note_params.each(&b)
|
10
|
+
end
|
11
|
+
|
12
|
+
def split_note_and_body
|
13
|
+
res = []
|
14
|
+
remaining_body = full_body
|
15
|
+
while remaining_body
|
16
|
+
if remaining_body =~ /^<over(?:lay|app)>(.+)<\/over(?:lay|app)>(.*)(<over(?:lay|app)>.+)/m
|
17
|
+
note = $1
|
18
|
+
rest = $2
|
19
|
+
remaining_body = $3
|
20
|
+
res << {:note => note, :body => rest}
|
21
|
+
elsif remaining_body =~ /^<over(?:lay|app)>(.+)<\/over(?:lay|app)>(.*)/m
|
22
|
+
note = $1
|
23
|
+
rest = $2
|
24
|
+
remaining_body = nil
|
25
|
+
res << {:note => note, :body => rest}
|
26
|
+
else
|
27
|
+
res << {:note => nil, :body => remaining_body}
|
28
|
+
remaining_body = nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
res
|
32
|
+
rescue => exp
|
33
|
+
puts "Error in split_note_and_body #{path}"
|
34
|
+
raise exp
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
def note_params_single(one)
|
39
|
+
res = {}
|
40
|
+
note = one[:note]
|
41
|
+
res[:body] = one[:body]
|
42
|
+
|
43
|
+
if note
|
44
|
+
lines = note.split("\n").select { |x| x.present? }
|
45
|
+
if (lines.size == 1) && !(lines.first =~ /[a-z]+:/)
|
46
|
+
res[:action] = lines.first.strip
|
47
|
+
else
|
48
|
+
lines.each do |line|
|
49
|
+
parts = line.split(":").select { |x| x.present? }
|
50
|
+
if parts.size > 2
|
51
|
+
parts = [parts[0],parts[1..-1].join(":")]
|
52
|
+
end
|
53
|
+
parts = parts.map { |x| x.strip }
|
54
|
+
raise "bad #{path} #{parts.inspect}" unless parts.size == 2
|
55
|
+
res[parts[0].to_sym] = parts[1]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
res
|
60
|
+
end
|
61
|
+
|
62
|
+
fattr(:split_parts) { split_note_and_body }
|
63
|
+
|
64
|
+
fattr(:note_params) do
|
65
|
+
split_parts.map do |one|
|
66
|
+
note_params_single(one)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def has_note?
|
71
|
+
note_params.any? { |x| x[:action].present? }
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Overapp
|
2
|
+
class TemplateFile
|
3
|
+
class VarObj
|
4
|
+
include FromHash
|
5
|
+
attr_accessor :file
|
6
|
+
|
7
|
+
def method_missing(sym,*args,&b)
|
8
|
+
if file.vars.has_key?(sym)
|
9
|
+
file.vars[sym]
|
10
|
+
elsif file.vars.has_key?(sym.to_s)
|
11
|
+
file.vars[sym.to_s]
|
12
|
+
else
|
13
|
+
raise "not found #{sym}, options are #{file.vars.inspect}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def render(body)
|
18
|
+
require 'erb'
|
19
|
+
erb = ERB.new(body)
|
20
|
+
erb.result(binding)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -3,102 +3,38 @@ module Overapp
|
|
3
3
|
include FromHash
|
4
4
|
attr_accessor :path, :full_body
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
remaining_body = full_body
|
9
|
-
while remaining_body
|
10
|
-
if remaining_body =~ /^<over(?:lay|app)>(.+)<\/over(?:lay|app)>(.*)(<over(?:lay|app)>.+)/m
|
11
|
-
note = $1
|
12
|
-
rest = $2
|
13
|
-
remaining_body = $3
|
14
|
-
res << {:note => note, :body => rest}
|
15
|
-
elsif remaining_body =~ /^<over(?:lay|app)>(.+)<\/over(?:lay|app)>(.*)/m
|
16
|
-
note = $1
|
17
|
-
rest = $2
|
18
|
-
remaining_body = nil
|
19
|
-
res << {:note => note, :body => rest}
|
20
|
-
else
|
21
|
-
res << {:note => nil, :body => remaining_body}
|
22
|
-
remaining_body = nil
|
23
|
-
end
|
24
|
-
end
|
25
|
-
res
|
26
|
-
rescue => exp
|
27
|
-
puts "Error in split_note_and_body #{path}"
|
28
|
-
raise exp
|
6
|
+
fattr(:params_obj) do
|
7
|
+
Params.new(:full_body => full_body)
|
29
8
|
end
|
30
9
|
|
31
|
-
|
32
|
-
|
33
|
-
res = {}
|
34
|
-
note = one[:note]
|
35
|
-
res[:body] = one[:body]
|
36
|
-
|
37
|
-
if note
|
38
|
-
lines = note.split("\n").select { |x| x.present? }
|
39
|
-
if lines.size == 1 && !(lines.first =~ /action:/)
|
40
|
-
res[:action] = lines.first.strip
|
41
|
-
else
|
42
|
-
lines.each do |line|
|
43
|
-
parts = line.split(":").select { |x| x.present? }
|
44
|
-
if parts.size > 2
|
45
|
-
parts = [parts[0],parts[1..-1].join(":")]
|
46
|
-
end
|
47
|
-
parts = parts.map { |x| x.strip }
|
48
|
-
raise "bad #{path} #{parts.inspect}" unless parts.size == 2
|
49
|
-
res[parts[0].to_sym] = parts[1]
|
50
|
-
end
|
51
|
-
end
|
52
|
-
else
|
53
|
-
# do nothing
|
54
|
-
end
|
55
|
-
res
|
10
|
+
def has_note?
|
11
|
+
params_obj.has_note?
|
56
12
|
end
|
57
13
|
|
58
|
-
def
|
59
|
-
|
60
|
-
|
14
|
+
def templated_body(params)
|
15
|
+
body = params[:body]
|
16
|
+
if params[:template] == 'erb'
|
17
|
+
v = VarObj.new(:file => self)
|
18
|
+
body = v.render(body)
|
61
19
|
end
|
20
|
+
body
|
62
21
|
end
|
63
22
|
|
23
|
+
def body_after_action(base_body,params)
|
24
|
+
body = templated_body(params)
|
25
|
+
BodyMod.transform(base_body,body,params)
|
26
|
+
end
|
64
27
|
|
65
28
|
def apply_body_to(base_body)
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
base_body + body
|
72
|
-
elsif params[:action] == 'insert' && params[:after]
|
73
|
-
base_body.gsub(params[:after],"#{params[:after]}#{body}").tap do |subbed|
|
74
|
-
if subbed == base_body
|
75
|
-
raise "no change, couldn't find #{params[:after]} to insert #{body} in \n#{base_body}"
|
76
|
-
end
|
77
|
-
end
|
78
|
-
elsif params[:action] == 'insert' && params[:before]
|
79
|
-
base_body.gsub(params[:before],"#{body}#{params[:before]}").tap do |subbed|
|
80
|
-
if subbed == base_body
|
81
|
-
raise "no change, couldn't find #{params[:before]} in \n#{base_body}"
|
82
|
-
end
|
83
|
-
end
|
84
|
-
elsif params[:action] == 'replace' && params[:base]
|
85
|
-
base_body.gsub(params[:base],body).tap do |subbed|
|
86
|
-
if subbed == base_body
|
87
|
-
raise "no change, couldn't find #{params[:base]} to replace with #{body} in \n#{base_body}"
|
88
|
-
end
|
89
|
-
end
|
90
|
-
elsif params[:action] == 'delete'
|
91
|
-
:delete
|
29
|
+
params_obj.inject(base_body) do |new_base_body,params|
|
30
|
+
if params[:action].blank?
|
31
|
+
templated_body(params)
|
32
|
+
elsif params[:action]
|
33
|
+
body_after_action(new_base_body,params)
|
92
34
|
else
|
93
|
-
raise "bad
|
35
|
+
raise "bad"
|
94
36
|
end
|
95
37
|
end
|
96
|
-
base_body
|
97
|
-
end
|
98
|
-
|
99
|
-
fattr(:split_parts) { split_note_and_body }
|
100
|
-
def has_note?
|
101
|
-
split_parts.any? { |x| x[:note].present? }
|
102
38
|
end
|
103
39
|
|
104
40
|
def body
|
@@ -120,6 +56,11 @@ module Overapp
|
|
120
56
|
`mkdir -p #{d}`
|
121
57
|
File.create "#{dir}/#{path}",body
|
122
58
|
end
|
59
|
+
|
60
|
+
fattr(:vars) { {} }
|
61
|
+
def parsed
|
62
|
+
combined(OpenStruct.new(:full_body => ""))
|
63
|
+
end
|
123
64
|
end
|
124
65
|
|
125
66
|
class BasicFile < TemplateFile
|
data/lib/overapp/util/dir.rb
CHANGED
@@ -4,8 +4,15 @@ module Overapp
|
|
4
4
|
res = Dir["#{dir}/**/*"] + Dir["#{dir}/**/.*"]
|
5
5
|
res = res - [".","..",".git"]
|
6
6
|
res.reject { |x| FileTest.file?(x) && File.binary?(x) && !(x =~ /\.txt/) }
|
7
|
-
|
8
|
-
|
7
|
+
res.select { |x| FileTest.file?(x) }
|
8
|
+
end
|
9
|
+
def dir_files_full(dir)
|
10
|
+
raise "Dir not there #{dir}" unless FileTest.exist?(dir)
|
11
|
+
dir_files(dir).map do |full_file|
|
12
|
+
f = full_file.gsub("#{dir}/","")
|
13
|
+
raise "bad #{f}" if f == full_file
|
14
|
+
{:file => f, :body => File.read(full_file)}
|
15
|
+
end
|
9
16
|
end
|
10
17
|
|
11
18
|
def with_local_path(overapp_path,&b)
|