grancher 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ v0.1. First version.
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2008 Magnus Holm
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,7 @@
1
+ CHANGELOG
2
+ LICENSE
3
+ README
4
+ lib/grancher/task.rb
5
+ lib/grancher.rb
6
+ Rakefile
7
+ Manifest
data/README ADDED
@@ -0,0 +1,4 @@
1
+ = Grancher, easily copy folders and files to other Git branches
2
+
3
+ Please see http://judofyr.github.com/grancher or the documentation in
4
+ lib/grancher.rb!
@@ -0,0 +1,19 @@
1
+ require 'echoe'
2
+ require 'hanna/rdoctask'
3
+ require 'lib/grancher/task'
4
+
5
+ Echoe.new('grancher') do |p|
6
+ p.project = "dojo"
7
+ p.author = "Magnus Holm"
8
+ p.email = "judofyr@gmail.com"
9
+ p.summary = "Easily copy folders and files to other Git branches"
10
+ p.runtime_dependencies = ["gash"]
11
+ p.rdoc_options += ["--main", "Grancher", "--title", "Grancher"]
12
+ end
13
+
14
+ Grancher::Task.new do |g|
15
+ g.branch = 'gh-pages'
16
+ g.push_to = 'origin'
17
+
18
+ g.directory 'doc'
19
+ end
@@ -0,0 +1,37 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{grancher}
5
+ s.version = "0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Magnus Holm"]
9
+ s.date = %q{2008-12-20}
10
+ s.description = %q{Easily copy folders and files to other Git branches}
11
+ s.email = %q{judofyr@gmail.com}
12
+ s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README", "lib/grancher/task.rb", "lib/grancher.rb"]
13
+ s.files = ["CHANGELOG", "LICENSE", "README", "lib/grancher/task.rb", "lib/grancher.rb", "Rakefile", "Manifest", "grancher.gemspec"]
14
+ s.has_rdoc = true
15
+ s.homepage = %q{}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Grancher", "--main", "README", "--main", "Grancher", "--title", "Grancher"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{dojo}
19
+ s.rubygems_version = %q{1.3.1}
20
+ s.summary = %q{Easily copy folders and files to other Git branches}
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 2
25
+
26
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ s.add_runtime_dependency(%q<gash>, [">= 0"])
28
+ s.add_development_dependency(%q<echoe>, [">= 0"])
29
+ else
30
+ s.add_dependency(%q<gash>, [">= 0"])
31
+ s.add_dependency(%q<echoe>, [">= 0"])
32
+ end
33
+ else
34
+ s.add_dependency(%q<gash>, [">= 0"])
35
+ s.add_dependency(%q<echoe>, [">= 0"])
36
+ end
37
+ end
@@ -0,0 +1,174 @@
1
+ require 'gash'
2
+
3
+ # == What is Grancher?
4
+ #
5
+ # With Grancher you can easily copy folders and files to a Git branch.
6
+ #
7
+ # === How?
8
+ # ==== As a library
9
+ #
10
+ # require 'grancher'
11
+ # grancher = Grancher.new do |g|
12
+ # g.branch = 'gh-pages'
13
+ # g.push_to = 'origin'
14
+ # g.repo = 'some_repo' # defaults to '.'
15
+ # g.message = 'Updated website' # defaults to 'Updated files.'
16
+ #
17
+ # # Put the website-directory in the root
18
+ # g.directory 'website'
19
+ #
20
+ # # doc -> doc
21
+ # g.directory 'doc', 'doc'
22
+ #
23
+ # # README -> README
24
+ # g.file 'README'
25
+ #
26
+ # # AUTHORS -> authors.txt
27
+ # g.file 'AUTHORS', 'authors.txt'
28
+ #
29
+ # # CHANGELOG -> doc/CHANGELOG
30
+ # g.file 'CHANGELOG', 'doc/'
31
+ # end
32
+ #
33
+ # grancher.commit
34
+ # grancher.push
35
+ #
36
+ # ==== As a Raketask
37
+ #
38
+ # Instead of:
39
+ #
40
+ # require 'grancher'
41
+ # Grancher.new do |g|
42
+ # ...
43
+ # end
44
+ #
45
+ # Do:
46
+ #
47
+ # require 'grancher/task'
48
+ # Grancher::Task.new do |g|
49
+ # ...
50
+ # end
51
+ #
52
+ # See Grancher::Task for more information.
53
+ #
54
+ # === Keeping the files already in the branch
55
+ #
56
+ # By default, Grancher will remove any files already in the branch. Use
57
+ # keep and keep_all to change this behaviour:
58
+ #
59
+ # Grancher.new do |g|
60
+ # # Only keep some files/folders:
61
+ # g.keep 'index.html', 'test', 'lib/grancer'
62
+ #
63
+ # # Keep all the files in the repo:
64
+ # g.keep_all
65
+ # end
66
+ #
67
+ #
68
+ class Grancher
69
+ attr_accessor :branch, :push_to, :repo, :message
70
+ attr_reader :gash, :files, :directories
71
+
72
+ def initialize(&blk)
73
+ @directories = {}
74
+ @files = {}
75
+ @keep = []
76
+ @repo = '.'
77
+ @message = 'Updated files.'
78
+
79
+ if blk.arity == 1
80
+ blk.call(self)
81
+ else
82
+ self.instance_eval(&blk)
83
+ end
84
+ end
85
+
86
+ # Returns our Gash-object
87
+ def gash
88
+ @gash ||= Gash.new(@repo, @branch)
89
+ end
90
+
91
+ # Stores the directory +from+ at +to+.
92
+ def directory(from, to = nil)
93
+ @directories[from.chomp('/')] = to
94
+ end
95
+
96
+ # Stores the file +from+ at +to+.
97
+ def file(from, to = nil)
98
+ @files[from] = to
99
+ end
100
+
101
+ # Keeps the files (or directories) given.
102
+ def keep(*files)
103
+ @keep.concat(files)
104
+ end
105
+
106
+ # Keep all the files in the branch.
107
+ def keep_all
108
+ @keep_all = true
109
+ end
110
+
111
+ # Pushes the branch to the remote.
112
+ def push
113
+ gash.send(:git, 'push', @push_to, @branch + ':refs/heads/' + @branch)
114
+ end
115
+
116
+ # Commits the changes.
117
+ def commit(message = nil)
118
+ build.commit(message || message())
119
+ end
120
+
121
+ private
122
+
123
+ def build
124
+ clear_all_but_kept unless @keep_all
125
+ add_directories
126
+ add_files
127
+ gash
128
+ end
129
+
130
+ def clear_all_but_kept
131
+ kept = {}
132
+ @keep.each do |thing|
133
+ kept[thing] = gash[thing]
134
+ end
135
+
136
+ gash.clear
137
+
138
+ kept.each do |path, thing|
139
+ gash[path] = thing
140
+ end
141
+ end
142
+
143
+ def add_directories
144
+ @directories.each do |from, to|
145
+ Dir[from + '/**/*'].each do |file|
146
+ next if File.directory?(file)
147
+ content = File.read(file)
148
+ base = if to
149
+ file[0...from.length] = to
150
+ file
151
+ else
152
+ file[from.length + 1..-1]
153
+ end
154
+ gash[base] = content
155
+ end
156
+ end
157
+ end
158
+
159
+ def add_files
160
+ @files.each do |from, to|
161
+ content = File.read(from)
162
+ base = if to
163
+ if to[-1] == ?/
164
+ to + from
165
+ else
166
+ to
167
+ end
168
+ else
169
+ from
170
+ end
171
+ gash[base] = content
172
+ end
173
+ end
174
+ end
@@ -0,0 +1,28 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'grancher')
2
+
3
+ class Grancher
4
+ class Task
5
+ # Defines a task named +name+ where the block given behaves like a
6
+ # Grancher-object.
7
+ #
8
+ # If +push_to+ is set, it will automatically push the branch when done.
9
+ def initialize(name = 'publish', &blk)
10
+ @grancher = Grancher.new(&blk)
11
+ define_task(name)
12
+ end
13
+
14
+ private
15
+
16
+ def define_task(name)
17
+ desc(if @grancher.push_to
18
+ "Builds and pushes the #{@grancher.branch}-branch"
19
+ else
20
+ "Builds the #{@grancher.branch}-branch"
21
+ end)
22
+ task(name) do
23
+ @grancher.commit
24
+ @grancher.push if @grancher.push_to
25
+ end
26
+ end
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grancher
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.1"
5
+ platform: ruby
6
+ authors:
7
+ - Magnus Holm
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-20 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: gash
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: echoe
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description: Easily copy folders and files to other Git branches
36
+ email: judofyr@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - CHANGELOG
43
+ - LICENSE
44
+ - README
45
+ - lib/grancher/task.rb
46
+ - lib/grancher.rb
47
+ files:
48
+ - CHANGELOG
49
+ - LICENSE
50
+ - README
51
+ - lib/grancher/task.rb
52
+ - lib/grancher.rb
53
+ - Rakefile
54
+ - Manifest
55
+ - grancher.gemspec
56
+ has_rdoc: true
57
+ homepage: ""
58
+ post_install_message:
59
+ rdoc_options:
60
+ - --line-numbers
61
+ - --inline-source
62
+ - --title
63
+ - Grancher
64
+ - --main
65
+ - README
66
+ - --main
67
+ - Grancher
68
+ - --title
69
+ - Grancher
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: "0"
77
+ version:
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: "1.2"
83
+ version:
84
+ requirements: []
85
+
86
+ rubyforge_project: dojo
87
+ rubygems_version: 1.3.1
88
+ signing_key:
89
+ specification_version: 2
90
+ summary: Easily copy folders and files to other Git branches
91
+ test_files: []
92
+