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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YjY4MjM5OGZmY2MwN2RhYWJhZjU4YzY5ZGZmNDkwYWEwNDkwYWJkNA==
4
+ MGVjNDY1MjViY2YwMGE5MzQ1ZGViODNkZGU5YWMwNWZlZjAzYTJhZA==
5
5
  data.tar.gz: !binary |-
6
- NGZhYjcwNWEzYTg2MDBkZTY2OWRiNTNjMTE4NWE5NjEzYjZkOTNmNw==
6
+ Njg5MWYwNGY0Yzk0ODFlYWE5OGFlMDIxNjI2NWRlZjU0MThmMTAxYg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZjIzN2MwZWJiNzZiNGE3NWU1MGJkOGJiZWM3YmU1YTU0NDUxNGFlZDhmNGEz
10
- OThjNzc3YWNjYzFiMWVjMDA3MDk1NTI5ZmE0MmRkMWQwMDMwZWIzMmViM2I5
11
- NTZhOTg2Y2EwODlhMDdmNWI5MjJkMWQ5MGQyNjBlODA2NTY1Y2M=
9
+ YTgwNjQ0OTI3Y2VjMGVjMWUxZWM1NTVmNDJjMzBhMTYyNGQ2MjIxYTlmOGEw
10
+ MDExYTM1OWI5YTA0ZWI0ZDJmODExOTYxMjM3NGIzZTAxYzFhZWU4Yzg0YTY2
11
+ NDVmMzAyMGM0MTg0MGY3MDU4ODIzNzliYjFhZWE0MTA3ZWQzYmE=
12
12
  data.tar.gz: !binary |-
13
- YWZlNTg4ZmYyZmM3MWYwMjg1YmIwMWMyYWE4MjkzMmJiZWNhNDI3OGM0YmJl
14
- NTM4N2M3ZTM3NmIzNjNmM2ViMjhmOWM3MDA5YzUzZDI2Mjk4MjY3MDUzZjc5
15
- YTE0NjUzYjU1ZDBjMWU0NjI2OTdhOWFhZTNmNzBlODA0NDU0OGI=
13
+ ZDg2NTIyNTM1N2UxMTZlOGRkYjQ1OWQwNTE3MzU2MWVjZWRhNTk1YmRhYmVh
14
+ YzE3ZDViYmZjMjhmZDZlMmM3ODNiY2ZjMGE1ZjYzMjZmNzczMTgxNTQzNjMz
15
+ YzQ0OGEzNDU3NzliYzc1NjdjNTI5ODg5MmY1YWE4NjU0OTFlM2Y=
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.2
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
- class << self
50
- def load_command(cmd,ops)
51
- FromCommand.new(:command => cmd, :path => ops[:path]||".").files
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
@@ -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
@@ -4,16 +4,21 @@ module Overapp
4
4
  include FromHash
5
5
  attr_accessor :descriptor
6
6
 
7
- def apply_to(base,ops)
8
- base.apply(load(base,ops))
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 load(*args)
16
- raise "load unimplemented"
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
- raise "path doesn't exist #{path}" unless FileTest.exist?(path)
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
- Overapp::Git.commit(path,overlay.commit_message) do
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
- def load(base,ops={})
6
+
7
+ def target_path(dir)
7
8
  if relative_output_path.present?
8
- TmpDir.with do |dir|
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
- Overapp.ec "cd #{ops[:path]} && #{command}", :silent => false
14
- RawDir.new(:descriptor => ops[:path]).load(base,ops)
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
@@ -1,9 +0,0 @@
1
- module Overapp
2
- module Load
3
- class Empty
4
- def load(base,ops)
5
- Overapp::Files.new
6
- end
7
- end
8
- end
9
- 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).load(base,ops)
8
+ Project.new(:descriptor => path)
9
9
  else
10
- RawDir.new(:descriptor => path).load(base,ops)
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
- project = Overapp::Project.new(:path => path)
7
- project.write_to! ops[:path]
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 load(base,ops)
5
+ def load_independent
6
6
  ops = {}
7
7
  raise "Bad dir" unless dir.present?
8
- raise "Dir not there #{dir}" unless FileTest.exist?(dir)
8
+
9
9
  res = Files.new
10
10
  res.file_class = ops[:file_class] if ops[:file_class]
11
- Overapp.dir_files(dir).each do |full_file|
12
- if FileTest.file?(full_file)
13
- f = full_file.gsub("#{dir}/","")
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
@@ -5,7 +5,7 @@ module Overapp
5
5
 
6
6
  def load(base,ops)
7
7
  TmpDir.with_repo_path(url) do |dir|
8
- LocalDir.new(:descriptor => dir).load(base,ops)
8
+ LocalDir.new(:descriptor => dir)
9
9
  end
10
10
  end
11
11
  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(:path => output_path, :overlays => project.overapps)
8
+ Load::Instance.new(:overlays => project.overapps, :vars => Overapp::Var.vars.merge(project.vars))
9
9
  end
10
10
 
11
11
  def combined_files
@@ -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
- def config_body
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
- Load::RawDir.new(:descriptor => path)
55
+ load_raw_dir_class.new(:descriptor => path)
47
56
  else
48
- Load::Factory.new(:descriptor => entry.descriptor, :type => entry.type, :entry_ops => entry.entry_ops).loader
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(output_path)
58
- raise 'here'
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
- 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
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
- def note_params_single(one)
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 note_params
59
- split_parts.map do |one|
60
- note_params_single(one)
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
- note_params.each do |params|
67
- body = params[:body]
68
- base_body = if params[:action].blank?
69
- body
70
- elsif params[:action] == 'append'
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 #{params.inspect}"
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
@@ -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
- #raise rej.inspect unless rej.empty?
8
- #res - rej
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)