overapp 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MTUyNDEwNWY4M2NlM2I4MjQ4M2RlMGY0NzMyM2YzYzQ0YmE4YWE4MQ==
5
+ data.tar.gz: !binary |-
6
+ ODY2MjliZjgzYjU2MDk5ZTMxYzRmZTExZmU5NzA1NzAxNGM1NzdiMg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NzNhYTMwYWViNDA5ZDdiODdjZTkwZTFkNjRhNTYwNGE3Y2FiYmI5MjIyOTVl
10
+ NWNmMmY0NzllNmM1YWM1OWRhNzZjMjcwZTAxNWE1NTBlZjM5ZTliMTAyOTc1
11
+ OGVhMTgzNGRmMzBlMmY4ODdiMmNiYWE2ZDYyYWY5N2JhZmZjMDg=
12
+ data.tar.gz: !binary |-
13
+ OWUyMDY2M2JiYWE3NDAxNzRmYmNiMTgzMzI3NjM4NzdkZjE5M2Y3N2U3NDAx
14
+ OWE0MjhhZjAyMTFiZmRhZTkwYWMxOGI0ZDg1MmEwOWE3YTg0ZTU2M2RhZGM4
15
+ Mzg1OGRjZmRhYjA1YWMyYWU5ZGU5YjRmZTE1YmI3NzBkZWQ5ODE=
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,31 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "~> 2.8.0"
10
+ gem "rdoc", "~> 3.12"
11
+ gem "bundler", ">= 1.0.0"
12
+ gem "jeweler", "~> 1.8.4"
13
+ #gem "rcov", ">= 0"
14
+
15
+ gem 'guard'
16
+ gem 'guard-rspec'
17
+ gem 'guard-spork'
18
+
19
+ gem 'rb-fsevent', '~> 0.9'
20
+
21
+ gem 'lre'
22
+ end
23
+
24
+ gem 'mharris_ext'
25
+ #gem "rchoice", :path => "/users/mharris717/gems/rchoice-0.2.0"
26
+ #gem 'rchoice','0.2.0'
27
+ #gem 'rchoice', :git => "git@github.com:mharris717/rchoice.git", :branch => "gemdir"
28
+
29
+ gem 'andand'
30
+
31
+ gem 'simplecov', :require => false, :group => :test
data/Gemfile.lock ADDED
@@ -0,0 +1,122 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.3.5)
5
+ andand (1.3.3)
6
+ builder (3.2.2)
7
+ celluloid (0.15.2)
8
+ timers (~> 1.1.0)
9
+ childprocess (0.3.9)
10
+ ffi (~> 1.0, >= 1.0.11)
11
+ coderay (1.0.9)
12
+ diff-lcs (1.1.3)
13
+ facets (2.9.3)
14
+ faraday (0.8.8)
15
+ multipart-post (~> 1.2.0)
16
+ fattr (2.2.1)
17
+ ffi (1.9.0)
18
+ formatador (0.2.4)
19
+ git (1.2.6)
20
+ github_api (0.10.1)
21
+ addressable
22
+ faraday (~> 0.8.1)
23
+ hashie (>= 1.2)
24
+ multi_json (~> 1.4)
25
+ nokogiri (~> 1.5.2)
26
+ oauth2
27
+ guard (2.0.3)
28
+ formatador (>= 0.2.4)
29
+ listen (~> 2.0)
30
+ lumberjack (~> 1.0)
31
+ pry (>= 0.9.12)
32
+ thor (>= 0.18.1)
33
+ guard-rspec (1.2.1)
34
+ guard (>= 1.1)
35
+ guard-spork (1.5.1)
36
+ childprocess (>= 0.2.3)
37
+ guard (>= 1.1)
38
+ spork (>= 0.8.4)
39
+ hashie (2.0.5)
40
+ highline (1.6.19)
41
+ httpauth (0.2.0)
42
+ jeweler (1.8.7)
43
+ builder
44
+ bundler (~> 1.0)
45
+ git (>= 1.2.5)
46
+ github_api (= 0.10.1)
47
+ highline (>= 1.6.15)
48
+ nokogiri (= 1.5.10)
49
+ rake
50
+ rdoc
51
+ json (1.8.1)
52
+ jwt (0.1.8)
53
+ multi_json (>= 1.5)
54
+ listen (2.0.3)
55
+ celluloid (>= 0.15.2)
56
+ rb-fsevent (>= 0.9.3)
57
+ rb-inotify (>= 0.9)
58
+ lre (0.3.0)
59
+ fattr
60
+ mharris_ext
61
+ watchr
62
+ lumberjack (1.0.4)
63
+ method_source (0.8.2)
64
+ mharris_ext (1.7.0)
65
+ facets
66
+ fattr
67
+ multi_json (1.8.2)
68
+ multi_xml (0.5.5)
69
+ multipart-post (1.2.0)
70
+ nokogiri (1.5.10)
71
+ oauth2 (0.9.2)
72
+ faraday (~> 0.8)
73
+ httpauth (~> 0.2)
74
+ jwt (~> 0.1.4)
75
+ multi_json (~> 1.0)
76
+ multi_xml (~> 0.5)
77
+ rack (~> 1.2)
78
+ pry (0.9.12.2)
79
+ coderay (~> 1.0.5)
80
+ method_source (~> 0.8)
81
+ slop (~> 3.4)
82
+ rack (1.5.2)
83
+ rake (10.1.0)
84
+ rb-fsevent (0.9.3)
85
+ rb-inotify (0.9.2)
86
+ ffi (>= 0.5.0)
87
+ rdoc (3.12.2)
88
+ json (~> 1.4)
89
+ rspec (2.8.0)
90
+ rspec-core (~> 2.8.0)
91
+ rspec-expectations (~> 2.8.0)
92
+ rspec-mocks (~> 2.8.0)
93
+ rspec-core (2.8.0)
94
+ rspec-expectations (2.8.0)
95
+ diff-lcs (~> 1.1.2)
96
+ rspec-mocks (2.8.0)
97
+ simplecov (0.7.1)
98
+ multi_json (~> 1.0)
99
+ simplecov-html (~> 0.7.1)
100
+ simplecov-html (0.7.1)
101
+ slop (3.4.6)
102
+ spork (0.9.2)
103
+ thor (0.18.1)
104
+ timers (1.1.0)
105
+ watchr (0.7)
106
+
107
+ PLATFORMS
108
+ ruby
109
+
110
+ DEPENDENCIES
111
+ andand
112
+ bundler (>= 1.0.0)
113
+ guard
114
+ guard-rspec
115
+ guard-spork
116
+ jeweler (~> 1.8.4)
117
+ lre
118
+ mharris_ext
119
+ rb-fsevent (~> 0.9)
120
+ rdoc (~> 3.12)
121
+ rspec (~> 2.8.0)
122
+ simplecov
data/Guardfile ADDED
@@ -0,0 +1,32 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'spork', :rspec_port => 5830 do
5
+ watch('config/application.rb')
6
+ watch('config/environment.rb')
7
+ watch('config/environments/test.rb')
8
+ watch(%r{^config/initializers/.+\.rb$})
9
+ watch('Gemfile')
10
+ watch('Gemfile.lock')
11
+ watch('spec/spec_helper.rb') { :rspec }
12
+ watch('test/test_helper.rb') { :test_unit }
13
+ watch(%r{features/support/}) { :cucumber }
14
+ watch(%r{^spec/support/.+\.rb$})
15
+ end
16
+
17
+
18
+
19
+
20
+ guard 'rspec', :cli => "--drb --drb-port 5830" do
21
+ watch(%r{^spec/.+_spec\.rb$})
22
+ watch(%r{^lib/(.+)\.rb$}) { "spec" } # { |m| "spec/lib/#{m[1]}_spec.rb" }
23
+ watch(%r{^lib/(.+)\.treetop$}) { "spec" }
24
+ watch(%r{^lib/(.+)\.csv$}) { "spec" }
25
+ #watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
26
+ watch('spec/spec_helper.rb') { "spec" }
27
+ end
28
+
29
+
30
+
31
+
32
+
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Mike Harris
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = overapp
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to overapp
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2013 Mike Harris. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,74 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "overapp"
18
+ gem.homepage = "http://github.com/mharris717/overapp"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{overapp}
21
+ gem.description = %Q{overapp}
22
+ gem.email = "mharris717@gmail.com"
23
+ gem.authors = ["Mike Harris"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rdoc/task'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "overapp #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
50
+
51
+ task :rename_to_overapp do
52
+ require 'mharris_ext'
53
+ names = {}
54
+ names["Overlay"] = "Overapp"
55
+ names["overlay"] = "overapp"
56
+
57
+ (Dir["**/*.rb"] + ["overlay.gemspec","README.rdoc"]).select { |x| FileTest.exist?(x) }.each do |f|
58
+ body = File.read(f)
59
+ names.each do |k,v|
60
+ body = body.gsub(k,v)
61
+ end
62
+ File.create f, body
63
+ end
64
+
65
+ Dir["**/*"].select { |x| FileTest.file?(x) }.each do |file|
66
+ base = File.basename(file)
67
+ if base =~ /overlay/
68
+ dest = File.dirname(file) + "/" + base.gsub("overlay","overapp")
69
+ ec "mv #{file} #{dest}"
70
+ end
71
+ end
72
+
73
+ ec "mv lib/overlay lib/overapp" if FileTest.exist?("lib/overlay")
74
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
data/bin/overapp ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ load File.dirname(__FILE__) + "/../lib/fs_template.rb"
4
+
5
+ FsTemplate.write_project ARGV[0],ARGV[1]
@@ -0,0 +1,87 @@
1
+ module Overapp
2
+ class Files
3
+ include FromHash
4
+ include Enumerable
5
+ fattr(:files) { [] }
6
+ fattr(:file_class) { TemplateFile }
7
+ def add(ops)
8
+ files << file_class.new(:path => ops[:file], :full_body => ops[:body])
9
+ end
10
+ def size
11
+ files.size
12
+ end
13
+ def apply(on_top)
14
+ res = files.clone
15
+ on_top.each do |top_file|
16
+ existing = res.find { |x| x.path == top_file.path }
17
+ if existing
18
+ res -= [existing]
19
+ res << top_file.combined(existing)
20
+ else
21
+ res << top_file
22
+ end
23
+ end
24
+ self.class.new(:files => res)
25
+ end
26
+ def each(&b)
27
+ files.each(&b)
28
+ end
29
+
30
+ def write_to!(dir)
31
+ each do |f|
32
+ f.write_to! dir
33
+ end
34
+ end
35
+
36
+ class << self
37
+ def dir_files(dir)
38
+ res = Dir["#{dir}/**/*"] + Dir["#{dir}/**/.*"]
39
+ res - [".","..",".git"]
40
+ end
41
+ def load_dir(dir,ops={})
42
+ raise "Bad dir" unless dir.present?
43
+ raise "Dir not there #{dir}" unless FileTest.exist?(dir)
44
+ res = new
45
+ res.file_class = ops[:file_class] if ops[:file_class]
46
+ dir_files(dir).each do |full_file|
47
+ if FileTest.file?(full_file)
48
+ f = full_file.gsub("#{dir}/","")
49
+ raise "bad #{f}" if f == full_file
50
+ res.add :file => f, :body => File.read(full_file)
51
+ end
52
+ end
53
+ res
54
+ end
55
+
56
+ def load_command(cmd,ops)
57
+ FromCommand.new(:command => cmd, :path => ops[:path]||".").files
58
+ end
59
+
60
+ def load(descriptor, ops={})
61
+ raise "bad #{descriptor}" if descriptor.blank?
62
+ if ops[:type] == :command
63
+ load_command(descriptor,ops)
64
+ elsif descriptor =~ /\.git/
65
+ load_repo(descriptor)
66
+ else
67
+ load_dir(descriptor,ops)
68
+ end
69
+ end
70
+
71
+ def write_combined(base_dir, top_dir, output_dir)
72
+ base = load(base_dir)
73
+ top = load(top_dir)
74
+ combined = base.apply(top)
75
+ combined.write_to! output_dir
76
+ end
77
+
78
+ def load_repo(url)
79
+ dir = "/tmp/#{rand(1000000000000000000)}"
80
+ ec "git clone #{url} #{dir} 2>&1", :silent => true
81
+ load dir
82
+ ensure
83
+ ec "rm -rf #{dir}", :silent => true
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,23 @@
1
+ module Overapp
2
+ class FromCommand
3
+ include FromHash
4
+ attr_accessor :command, :path
5
+
6
+ def with_tmp_dir
7
+ dir = "/tmp/#{rand(1000000000000000000)}"
8
+ `mkdir #{dir}`
9
+ Dir.chdir(dir) do
10
+ yield dir
11
+ end
12
+ ensure
13
+ ec "rm -rf #{dir}", :silent => true
14
+ end
15
+
16
+ fattr(:files) do
17
+ with_tmp_dir do |dir|
18
+ Overapp.ec command, :silent => true
19
+ Files.load [dir,path].select { |x| x.present? }.join("/"), :file_class => BasicFile
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,109 @@
1
+ module Overapp
2
+ class Project
3
+ include FromHash
4
+ attr_accessor :path
5
+
6
+ def config_body
7
+ if FileTest.exist?("#{path}/.fstemplate")
8
+ File.read("#{path}/.fstemplate")
9
+ elsif FileTest.exist?("#{path}/.overapp")
10
+ File.read("#{path}/.overapp")
11
+ elsif FileTest.exist?("#{path}/.overlay")
12
+ File.read("#{path}/.overlay")
13
+ else
14
+ raise "no config"
15
+ end
16
+ end
17
+
18
+ fattr(:config) do
19
+ res = ProjectConfig.new
20
+ res.body = config_body
21
+ res.load!
22
+ res
23
+ end
24
+
25
+ def overapp_paths
26
+ config.overapps + [path]
27
+ end
28
+
29
+ def commands(phase)
30
+ config.commands.select { |x| x[:phase] == phase }.map { |x| x[:command] }
31
+ end
32
+
33
+ fattr(:overapps) do
34
+ overapp_paths.map { |x| Files.load(x) }
35
+ end
36
+
37
+ fattr(:base_files) do
38
+ if config.base
39
+ Files.load(config.base,config.base_ops)
40
+ else
41
+ nil
42
+ end
43
+ end
44
+
45
+ fattr(:combined_files) do
46
+ res = base_files
47
+ overapps.each do |overapp|
48
+ res = res.apply(overapp)
49
+ end
50
+ res
51
+ end
52
+
53
+ def git_commit(output_path,message,init=false)
54
+ if init
55
+ `rm -rf #{output_path}/.git`
56
+ ec "cd #{output_path} && git init && git config user.email johnsmith@fake.com && git config user.name 'John Smith'", :silent => true
57
+ end
58
+ ec "cd #{output_path} && git add . && git commit -m '#{message}'", :silent => true
59
+ end
60
+
61
+
62
+ def write_to!(output_path)
63
+ commands(:before).each do |cmd|
64
+ Overapp.ec "cd #{output_path} && #{cmd}", :silent => true
65
+ git_commit output_path, "Ran Command: #{cmd}"
66
+ end
67
+
68
+ base_files.write_to! output_path
69
+
70
+ git_commit output_path, "Base Files #{config.base}", true
71
+ combined_files.write_to!(output_path)
72
+ git_commit output_path, "Overapp Files #{path}"
73
+
74
+ commands(:after).each do |cmd|
75
+ Overapp.ec "cd #{output_path} && #{cmd}", :silent => true
76
+ git_commit output_path, "Ran Command: #{cmd}"
77
+ end
78
+ end
79
+ end
80
+
81
+ class ProjectConfig
82
+ include FromHash
83
+ attr_accessor :body, :base, :base_ops
84
+ fattr(:overapps) { [] }
85
+ fattr(:commands) { [] }
86
+
87
+ def base(*args)
88
+ if args.empty?
89
+ @base
90
+ else
91
+ @base = args.first
92
+ @base_ops = args[1] || {}
93
+ end
94
+ end
95
+
96
+ def overapp(name)
97
+ self.overapps << name
98
+ end
99
+
100
+ def command(cmd,phase=:after)
101
+ self.commands << {:command => cmd, :phase => phase}
102
+ end
103
+
104
+ def load!
105
+ c = self
106
+ eval(body)
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,136 @@
1
+ module Overapp
2
+ class TemplateFile
3
+ include FromHash
4
+ attr_accessor :path, :full_body
5
+
6
+ module NewWay
7
+ def split_note_and_body_long
8
+ if full_body =~ /<overapp>(.+)<\/overapp>/m
9
+ note = $1
10
+ rest = full_body.gsub(/<overapp>.+<\/overapp>/m,"")
11
+ {:note => note, :body => rest, :format => :long}
12
+ elsif full_body =~ /<overlay>(.+)<\/overlay>/m
13
+ note = $1
14
+ rest = full_body.gsub(/<overlay>.+<\/overlay>/m,"")
15
+ {:note => note, :body => rest, :format => :long}
16
+ else
17
+ nil
18
+ end
19
+ end
20
+
21
+ def note_params
22
+ res = {}
23
+ lines = note.split("\n").select { |x| x.present? }
24
+ if lines.size == 1
25
+ res[:action] = lines.first.strip
26
+ else
27
+ lines.each do |line|
28
+ parts = line.split(":").map { |x| x.strip }.select { |x| x.present? }
29
+ raise "bad #{path} #{parts.inspect}" unless parts.size == 2
30
+ res[parts[0].to_sym] = parts[1]
31
+ end
32
+ end
33
+ res
34
+ end
35
+
36
+
37
+ def apply_body_to_long(base_body)
38
+ params = note_params
39
+ if note == 'append'
40
+ base_body + body
41
+ elsif params[:action] == 'insert' && params[:after]
42
+ base_body.gsub(params[:after],"#{params[:after]}#{body}").tap do |subbed|
43
+ if subbed == base_body
44
+ raise "no change, couldn't find #{params[:after]} in \n#{base_body}"
45
+ end
46
+ end
47
+ elsif params[:action] == 'insert' && params[:before]
48
+ base_body.gsub(params[:before],"#{body}#{params[:before]}").tap do |subbed|
49
+ if subbed == base_body
50
+ raise "no change, couldn't find #{params[:before]} in \n#{base_body}"
51
+ end
52
+ end
53
+ elsif params[:action] == 'replace' && params[:base]
54
+ base_body.gsub(params[:base],body).tap do |subbed|
55
+ if subbed == base_body
56
+ raise "no change, couldn't find #{params[:base]} in \n#{base_body}"
57
+ end
58
+ end
59
+ 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}"
87
+ end
88
+ end
89
+ end
90
+
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}
100
+ end
101
+
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] }
107
+
108
+ def apply_body_to(base_body)
109
+ if note.present?
110
+ m = "apply_body_to_#{format}"
111
+ send(m,base_body)
112
+ else
113
+ body
114
+ end
115
+ end
116
+
117
+
118
+
119
+ def combined(base)
120
+ self.class.new(:path => path, :full_body => apply_body_to(base.body))
121
+ end
122
+
123
+ def write_to!(dir)
124
+ raise "bad path" if path.blank?
125
+ d = File.dirname("#{dir}/#{path}")
126
+ `mkdir -p #{d}`
127
+ File.create "#{dir}/#{path}",body
128
+ end
129
+ end
130
+
131
+ class BasicFile < TemplateFile
132
+ def body
133
+ full_body
134
+ end
135
+ end
136
+ end
File without changes