basis 0.0.1
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.
- data/History.txt +3 -0
- data/Manifest.txt +23 -0
- data/README.txt +67 -0
- data/Rakefile +8 -0
- data/bin/basis +14 -0
- data/lib/basis/engine.rb +78 -0
- data/lib/basis/errors.rb +29 -0
- data/lib/basis/options.rb +98 -0
- data/lib/basis/templates/base.rb +72 -0
- data/lib/basis/templates/git.rb +15 -0
- data/lib/basis/templates/list.rb +28 -0
- data/lib/basis/templates/local.rb +13 -0
- data/lib/basis/templates/state.rb +27 -0
- data/lib/basis/templates.rb +28 -0
- data/lib/basis/version.rb +3 -0
- data/lib/templates.yml +7 -0
- data/test/basis/engine_test.rb +12 -0
- data/test/basis/options_test.rb +38 -0
- data/test/basis/templates/base_test.rb +85 -0
- data/test/basis/templates_test.rb +19 -0
- data/test/fixtures/local/erb/erb.txt.erb +3 -0
- data/test/fixtures/local/project.name/project.name.txt +0 -0
- data/test/helper.rb +9 -0
- metadata +91 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
README.txt
|
4
|
+
Rakefile
|
5
|
+
bin/basis
|
6
|
+
lib/basis/engine.rb
|
7
|
+
lib/basis/errors.rb
|
8
|
+
lib/basis/options.rb
|
9
|
+
lib/basis/templates.rb
|
10
|
+
lib/basis/templates/base.rb
|
11
|
+
lib/basis/templates/git.rb
|
12
|
+
lib/basis/templates/list.rb
|
13
|
+
lib/basis/templates/local.rb
|
14
|
+
lib/basis/templates/state.rb
|
15
|
+
lib/basis/version.rb
|
16
|
+
lib/templates.yml
|
17
|
+
test/basis/engine_test.rb
|
18
|
+
test/basis/options_test.rb
|
19
|
+
test/basis/templates/base_test.rb
|
20
|
+
test/basis/templates_test.rb
|
21
|
+
test/fixtures/local/erb/erb.txt.erb
|
22
|
+
test/fixtures/local/project.name/project.name.txt
|
23
|
+
test/helper.rb
|
data/README.txt
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
= basis
|
2
|
+
|
3
|
+
* http://github.com/jbarnette/basis
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Basis is smart project skeletons. This is a very, very early release. Basis only
|
8
|
+
knows how to deal with git:// urls and local file paths right now. Also, there's
|
9
|
+
no documentation, no way to track remote template lists, dubious cache update
|
10
|
+
semantics, bad command-line messaging, bad error reporting, and bad code.
|
11
|
+
|
12
|
+
Honestly, installing this gem will probably melt your system.
|
13
|
+
|
14
|
+
Basis owes a ton to Hoe, Mr. Bones, Rubigen, Newgem, and skel.
|
15
|
+
|
16
|
+
== SYNOPSIS:
|
17
|
+
|
18
|
+
# List all available templates:
|
19
|
+
basis list
|
20
|
+
|
21
|
+
# Add a template to the local list:
|
22
|
+
basis add -n rails:example git://github.com/jbarnette/basis-rails.git
|
23
|
+
|
24
|
+
# Remove a template from the local list:
|
25
|
+
basis remove rails:example
|
26
|
+
|
27
|
+
# Show a local template's configuration:
|
28
|
+
basis show rails:example
|
29
|
+
|
30
|
+
# Update a local template (or all, without a template name):
|
31
|
+
basis update rails:example
|
32
|
+
|
33
|
+
# Generate a project in ./monkeys:
|
34
|
+
basis rails:example monkeys
|
35
|
+
|
36
|
+
== REQUIREMENTS:
|
37
|
+
|
38
|
+
* Subversion and Git (for some templates)
|
39
|
+
|
40
|
+
== INSTALL:
|
41
|
+
|
42
|
+
sudo gem install basis
|
43
|
+
|
44
|
+
== LICENSE:
|
45
|
+
|
46
|
+
(The MIT License)
|
47
|
+
|
48
|
+
Copyright (c) 2008 John Barnette <jbarnette@rubyforge.org>
|
49
|
+
|
50
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
51
|
+
a copy of this software and associated documentation files (the
|
52
|
+
'Software'), to deal in the Software without restriction, including
|
53
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
54
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
55
|
+
permit persons to whom the Software is furnished to do so, subject to
|
56
|
+
the following conditions:
|
57
|
+
|
58
|
+
The above copyright notice and this permission notice shall be
|
59
|
+
included in all copies or substantial portions of the Software.
|
60
|
+
|
61
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
62
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
63
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
64
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
65
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
66
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
67
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/bin/basis
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby -w
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
|
5
|
+
require "basis/engine"
|
6
|
+
require "basis/errors"
|
7
|
+
require "basis/options"
|
8
|
+
|
9
|
+
begin
|
10
|
+
options = Basis::Options.parse!(ARGV)
|
11
|
+
Basis::Engine.new.send(options.verb, options)
|
12
|
+
rescue Basis::Errors::Reportable => e
|
13
|
+
abort e.message
|
14
|
+
end
|
data/lib/basis/engine.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
3
|
+
require "basis/templates"
|
4
|
+
|
5
|
+
module Basis
|
6
|
+
class Engine
|
7
|
+
attr_reader :home
|
8
|
+
|
9
|
+
def initialize(home="~/.basis")
|
10
|
+
@home = File.expand_path(home)
|
11
|
+
end
|
12
|
+
|
13
|
+
def list(options)
|
14
|
+
return if templates.empty?
|
15
|
+
|
16
|
+
name_width = templates.collect { |t| t.name.size }.max
|
17
|
+
desc_width = 80 - name_width - 4
|
18
|
+
|
19
|
+
templates.each do |template|
|
20
|
+
desc = template.description || "(no description)"
|
21
|
+
desc = desc[0, desc_width - 3] + "..." if desc.size > desc_width
|
22
|
+
printf("%-#{name_width}s # #{desc}\n", template.name)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def remove(options)
|
27
|
+
templates.reject! { |t| t.name == options.name }
|
28
|
+
templates.write!
|
29
|
+
end
|
30
|
+
|
31
|
+
def add(options)
|
32
|
+
if templates.detect { |t| t.name == options.name || t.url == options.source }
|
33
|
+
raise Errors::TemplateAlreadyExists.new(options.name, options.source)
|
34
|
+
end
|
35
|
+
|
36
|
+
template = Templates.create(self, options.source, :name => options.name)
|
37
|
+
template.update!
|
38
|
+
|
39
|
+
templates << template
|
40
|
+
templates.write!
|
41
|
+
end
|
42
|
+
|
43
|
+
def generate(options)
|
44
|
+
find_template(options.name).generate(options.destination)
|
45
|
+
end
|
46
|
+
|
47
|
+
def update(options)
|
48
|
+
templates.select {|t| options.name.nil? || t.name == options.name }.each { |t| t.update! }
|
49
|
+
end
|
50
|
+
|
51
|
+
def show(options)
|
52
|
+
# FIXME: terrible
|
53
|
+
puts YAML.dump(find_template(options.name))
|
54
|
+
end
|
55
|
+
|
56
|
+
protected
|
57
|
+
|
58
|
+
def find_template(name)
|
59
|
+
template = templates.detect {|t| t.name == name }
|
60
|
+
raise Errors::TemplateNotFound.new(name) unless template
|
61
|
+
template
|
62
|
+
end
|
63
|
+
|
64
|
+
def templates
|
65
|
+
@templates ||= begin
|
66
|
+
template = Pathname.new(__FILE__).dirname + "../templates.yml"
|
67
|
+
file = Pathname.new(@home) + "templates.yml"
|
68
|
+
|
69
|
+
unless file.exist?
|
70
|
+
file.dirname.mkpath
|
71
|
+
FileUtils.cp(template, file)
|
72
|
+
end
|
73
|
+
|
74
|
+
Templates::List.new(self, file)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/lib/basis/errors.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module Basis
|
2
|
+
module Errors
|
3
|
+
class Reportable < StandardError; end
|
4
|
+
|
5
|
+
class TemplateAlreadyExists < Reportable
|
6
|
+
def initialize(name, url)
|
7
|
+
super("'#{name || url}' is already a template")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class DestinationAlreadyExists < Reportable
|
12
|
+
def initialize(destination)
|
13
|
+
super("#{destination} already exists")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class TemplateNotFound < Reportable
|
18
|
+
def initialize(name)
|
19
|
+
super("template not found: #{name}")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class UnknownTemplateScheme < Reportable
|
24
|
+
def initialize(raw_url)
|
25
|
+
super("don't know how to load '#{raw_url}'")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require "optparse"
|
2
|
+
|
3
|
+
require "basis/version"
|
4
|
+
|
5
|
+
module Basis
|
6
|
+
class Options
|
7
|
+
VALID_VERBS = %w(add remove list update show)
|
8
|
+
|
9
|
+
attr_reader :source, :destination, :name, :verb
|
10
|
+
|
11
|
+
class << self
|
12
|
+
alias_method :parse!, :new
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(*args)
|
16
|
+
argv = args.flatten
|
17
|
+
|
18
|
+
parser = OptionParser.new do |parser|
|
19
|
+
parser.banner = "Usage: basis [options] [verb]"
|
20
|
+
parser.version = Basis::VERSION
|
21
|
+
|
22
|
+
parser.on("-h", "-?", "--help", "Show this message") do
|
23
|
+
puts parser
|
24
|
+
exit
|
25
|
+
end
|
26
|
+
|
27
|
+
parser.on("-v", "--version", "Show version") do
|
28
|
+
puts Basis::VERSION
|
29
|
+
exit
|
30
|
+
end
|
31
|
+
|
32
|
+
parser.on("-n", "--name [NAME]", "Override an added template's name") do |name|
|
33
|
+
@name = name
|
34
|
+
end
|
35
|
+
|
36
|
+
# FIXME: This is lame. Document it better and stop misusing parser.separator.
|
37
|
+
|
38
|
+
parser.separator ""
|
39
|
+
parser.separator "# List all available templates:"
|
40
|
+
parser.separator "basis list"
|
41
|
+
|
42
|
+
parser.separator ""
|
43
|
+
parser.separator "# Add a template to the local list:"
|
44
|
+
parser.separator "basis add -n rails:edge git://github.com/jbarnette/basis-rails-edge.git"
|
45
|
+
|
46
|
+
parser.separator ""
|
47
|
+
parser.separator "# Remove a template from the local list:"
|
48
|
+
parser.separator "basis remove rails:edge"
|
49
|
+
|
50
|
+
parser.separator ""
|
51
|
+
parser.separator "# Show a local template's configuration:"
|
52
|
+
parser.separator "basis show rails:edge"
|
53
|
+
|
54
|
+
parser.separator ""
|
55
|
+
parser.separator "# Update a local template (or all, without a template name):"
|
56
|
+
parser.separator "basis update rails:edge"
|
57
|
+
|
58
|
+
parser.separator ""
|
59
|
+
parser.separator "# Generate a project in ./monkeys:"
|
60
|
+
parser.separator "basis rails:edge monkeys"
|
61
|
+
parser.separator ""
|
62
|
+
end
|
63
|
+
|
64
|
+
parser.parse!(argv)
|
65
|
+
|
66
|
+
verb_or_template_name = argv.shift
|
67
|
+
|
68
|
+
if VALID_VERBS.include?(verb_or_template_name)
|
69
|
+
@verb = verb_or_template_name
|
70
|
+
|
71
|
+
case @verb
|
72
|
+
when "add" then @source = shift_required_arg(parser, argv)
|
73
|
+
when "remove" then @name = shift_required_arg(parser, argv)
|
74
|
+
when "show" then @name = shift_required_arg(parser, argv)
|
75
|
+
when "update" then @name = argv.shift
|
76
|
+
end
|
77
|
+
|
78
|
+
else
|
79
|
+
@verb = "generate"
|
80
|
+
@name = verb_or_template_name
|
81
|
+
@destination = shift_required_arg(parser, argv)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
def shift_required_arg(parser, argv)
|
88
|
+
arg = argv.shift
|
89
|
+
|
90
|
+
unless arg
|
91
|
+
puts parser
|
92
|
+
exit 1
|
93
|
+
end
|
94
|
+
|
95
|
+
arg
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require "erb"
|
2
|
+
require "fileutils"
|
3
|
+
require "pathname"
|
4
|
+
|
5
|
+
require "basis/errors"
|
6
|
+
require "basis/templates/state"
|
7
|
+
|
8
|
+
module Basis
|
9
|
+
module Templates
|
10
|
+
class Base
|
11
|
+
attr_reader :url, :name, :description
|
12
|
+
|
13
|
+
def initialize(engine, url, options={})
|
14
|
+
raise ArgumentError, "source URL is required" unless url
|
15
|
+
|
16
|
+
@engine = engine
|
17
|
+
@url = url
|
18
|
+
@name = options[:name] || url.path.split("/").last
|
19
|
+
@description = options[:description]
|
20
|
+
end
|
21
|
+
|
22
|
+
def update!
|
23
|
+
raise NotImplementedError, "implement in subclasses"
|
24
|
+
end
|
25
|
+
|
26
|
+
def generate(destination)
|
27
|
+
srcpath = Pathname.new(cache_dir)
|
28
|
+
destpath = Pathname.new(destination)
|
29
|
+
state = State.new(destpath)
|
30
|
+
|
31
|
+
raise Errors::DestinationAlreadyExists.new(destination) if destpath.exist?
|
32
|
+
update! unless cached?
|
33
|
+
|
34
|
+
|
35
|
+
Pathname.glob(srcpath + "**" + "*").each do |src|
|
36
|
+
next unless src.file?
|
37
|
+
|
38
|
+
dest = destination_for(src, :from => srcpath, :to => destpath)
|
39
|
+
dest.dirname.mkpath
|
40
|
+
|
41
|
+
if erb?(src)
|
42
|
+
dest.open("w") { |d| d.write(ERB.new(src.read).result(state.binding)) }
|
43
|
+
else
|
44
|
+
FileUtils.copy(src, dest)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
protected
|
50
|
+
|
51
|
+
def cached?
|
52
|
+
File.directory?(cache_dir)
|
53
|
+
end
|
54
|
+
|
55
|
+
def cache_dir
|
56
|
+
@cache_dir ||= File.join(@engine.home, "cache", "#{url.path.split("/").last}-#{name.hash.abs}")
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def erb?(path)
|
62
|
+
path.extname == ".erb"
|
63
|
+
end
|
64
|
+
|
65
|
+
def destination_for(src, options={})
|
66
|
+
dest = src.relative_path_from(options[:from]).expand_path(options[:to])
|
67
|
+
dest = dest.dirname + dest.basename.to_s[0...-4] if erb?(src)
|
68
|
+
Pathname.new(dest.to_s.gsub("project.name", options[:to].basename))
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "fileutils"
|
2
|
+
|
3
|
+
module Basis
|
4
|
+
module Templates
|
5
|
+
class Git < Base
|
6
|
+
def update!
|
7
|
+
if File.directory?(cache_dir)
|
8
|
+
Dir.chdir(cache_dir) { system "git pull" }
|
9
|
+
else
|
10
|
+
system "git clone #{url.to_s} #{cache_dir}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "YAML"
|
2
|
+
|
3
|
+
module Basis
|
4
|
+
module Templates
|
5
|
+
class List < Array
|
6
|
+
def initialize(engine, file)
|
7
|
+
@engine = engine
|
8
|
+
@file = file
|
9
|
+
|
10
|
+
YAML.load(IO.read(@file)).each do |name, data|
|
11
|
+
self << Templates.create(@engine, data["url"],
|
12
|
+
:name => name, :description => data["description"])
|
13
|
+
end
|
14
|
+
|
15
|
+
sort! { |a, b| a.name <=> b.name }
|
16
|
+
end
|
17
|
+
|
18
|
+
def write!(file=@file)
|
19
|
+
hashified = {}
|
20
|
+
each { |t| hashified[t.name] = { "url" => t.url.to_s, "description" => t.description } }
|
21
|
+
|
22
|
+
File.open(file, "w") do |f|
|
23
|
+
f.write(YAML.dump(hashified))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Basis
|
2
|
+
module Templates
|
3
|
+
class State
|
4
|
+
public :binding
|
5
|
+
attr_reader :project
|
6
|
+
|
7
|
+
def initialize(destination)
|
8
|
+
@project = Project.new(destination)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
class Project
|
14
|
+
attr_reader :directory, :name
|
15
|
+
|
16
|
+
def initialize(destination)
|
17
|
+
@directory = destination.to_s
|
18
|
+
@name = destination.basename.to_s
|
19
|
+
|
20
|
+
def @name.classify
|
21
|
+
gsub(/(?:^|_)(.)/) { $1.upcase }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "basis/templates/base"
|
2
|
+
require "basis/templates/list"
|
3
|
+
require "basis/templates/state"
|
4
|
+
|
5
|
+
require "basis/templates/local"
|
6
|
+
require "basis/templates/git"
|
7
|
+
|
8
|
+
require "uri"
|
9
|
+
|
10
|
+
module Basis
|
11
|
+
module Templates
|
12
|
+
def self.create(engine, raw_url, options={})
|
13
|
+
uri = URI.parse(raw_url)
|
14
|
+
|
15
|
+
if uri.scheme.nil?
|
16
|
+
uri = URI.parse("file://#{File.expand_path(uri.path)}")
|
17
|
+
end
|
18
|
+
|
19
|
+
klass = case uri.scheme
|
20
|
+
when "file" then Local
|
21
|
+
when "git" then Git
|
22
|
+
else raise Errors::UnknownTemplateScheme.new(raw_url)
|
23
|
+
end
|
24
|
+
|
25
|
+
klass.new(engine, uri, options)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/templates.yml
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "/../helper"))
|
2
|
+
|
3
|
+
require "basis/engine"
|
4
|
+
|
5
|
+
module Basis
|
6
|
+
class EngineTest < Test::Unit::TestCase
|
7
|
+
def test_has_some_sane_defaults_for_home
|
8
|
+
engine = Basis::Engine.new
|
9
|
+
assert_equal(File.expand_path("~/.basis"), engine.home)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "/../helper"))
|
2
|
+
|
3
|
+
require "basis/options"
|
4
|
+
|
5
|
+
module Basis
|
6
|
+
class OptionsTest < Test::Unit::TestCase
|
7
|
+
def test_list
|
8
|
+
opts = Basis::Options.parse!("list")
|
9
|
+
assert_equal("list", opts.verb)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_add
|
13
|
+
opts = Basis::Options.parse!("add", "someurl")
|
14
|
+
assert_equal("add", opts.verb)
|
15
|
+
assert_equal("someurl", opts.source)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_add_with_explicit_name
|
19
|
+
opts = Basis::Options.parse!("add", "-n", "monkeys", "someurl")
|
20
|
+
assert_equal("add", opts.verb)
|
21
|
+
assert_equal("someurl", opts.source)
|
22
|
+
assert_equal("monkeys", opts.name)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_remove
|
26
|
+
opts = Basis::Options.parse!("remove", "sometemplate")
|
27
|
+
assert_equal("remove", opts.verb)
|
28
|
+
assert_equal("sometemplate", opts.name)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_generate
|
32
|
+
opts = Basis::Options.parse!("sometemplate", "whereto")
|
33
|
+
assert_equal("generate", opts.verb)
|
34
|
+
assert_equal("sometemplate", opts.name)
|
35
|
+
assert_equal("whereto", opts.destination)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "/../../helper"))
|
2
|
+
|
3
|
+
require "fileutils"
|
4
|
+
require "tmpdir"
|
5
|
+
require "uri"
|
6
|
+
|
7
|
+
require "basis/templates/base"
|
8
|
+
|
9
|
+
module Basis
|
10
|
+
module Templates
|
11
|
+
class BaseTest < Test::Unit::TestCase
|
12
|
+
PROJECT_NAME = "rendered_project"
|
13
|
+
PROJECT_CLASS_NAME = "RenderedProject"
|
14
|
+
PROJECT_DIR = File.join("/tmp", PROJECT_NAME)
|
15
|
+
|
16
|
+
class MockTemplate < Templates::Base
|
17
|
+
def initialize; super(nil, URI.parse(LOCAL_TEMPLATE_PATH)); end
|
18
|
+
def update!; end
|
19
|
+
def cache_dir; LOCAL_TEMPLATE_PATH; end
|
20
|
+
end
|
21
|
+
|
22
|
+
def setup
|
23
|
+
FileUtils.rm_rf(PROJECT_DIR)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_requires_a_url
|
27
|
+
assert_raise(ArgumentError) { Base.new(nil, nil) }
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_uses_last_path_component_as_name_by_default
|
31
|
+
t = Base.new(nil, URI.parse("~/work/monkeys"))
|
32
|
+
assert_equal("monkeys", t.name)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_can_override_name
|
36
|
+
t = Base.new(nil, URI.parse("~/work/monkeys"), :name => "lemurs")
|
37
|
+
assert_equal("lemurs", t.name)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_can_specify_an_optional_description
|
41
|
+
t = Base.new(nil, URI.parse("~/work/monkeys"), :description => "hai")
|
42
|
+
assert_equal("hai", t.description)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_requires_subclasses_to_implement_update
|
46
|
+
base = Base.new(nil, URI.parse("~/work/monkeys"))
|
47
|
+
base.stubs(:cache_dir).returns(true)
|
48
|
+
|
49
|
+
assert_raise(NotImplementedError) { base.update! }
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_complains_about_generating_if_dest_exists
|
53
|
+
Dir.mkdir(PROJECT_DIR)
|
54
|
+
assert_raise(Errors::DestinationAlreadyExists) { MockTemplate.new.generate(PROJECT_DIR) }
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_transforms_project_name_in_directory_names
|
58
|
+
MockTemplate.new.generate(PROJECT_DIR)
|
59
|
+
|
60
|
+
destdir = File.join(PROJECT_DIR, PROJECT_NAME)
|
61
|
+
assert(File.directory?(destdir), "#{destdir} exists and is a directory")
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_transforms_project_name_in_file_names
|
65
|
+
MockTemplate.new.generate(PROJECT_DIR)
|
66
|
+
|
67
|
+
destfile = File.join(PROJECT_DIR, PROJECT_NAME, "#{PROJECT_NAME}.txt")
|
68
|
+
assert(File.file?(destfile), "#{destfile} exists and is a file")
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_renders_erb_templates
|
72
|
+
MockTemplate.new.generate(PROJECT_DIR)
|
73
|
+
erbfile = Pathname.new(File.join(PROJECT_DIR, "erb", "erb.txt"))
|
74
|
+
assert(erbfile.exist?, "#{erbfile} exists")
|
75
|
+
|
76
|
+
lines = erbfile.readlines.collect { |l| l.chomp }
|
77
|
+
|
78
|
+
assert_equal(3, lines.size)
|
79
|
+
assert_equal(PROJECT_NAME, lines[0])
|
80
|
+
assert_equal(PROJECT_CLASS_NAME, lines[1])
|
81
|
+
assert_equal(PROJECT_DIR, lines[2])
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "/../helper"))
|
2
|
+
|
3
|
+
require "basis/templates"
|
4
|
+
|
5
|
+
module Basis
|
6
|
+
class TemplatesTest < Test::Unit::TestCase
|
7
|
+
def test_local_from_simple_path
|
8
|
+
assert_kind_of(Templates::Local, Templates.create(nil, LOCAL_TEMPLATE_PATH))
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_git_from_git_scheme_url
|
12
|
+
assert_kind_of(Templates::Git, Templates.create(nil, "git://foo"))
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_complains_about_unhandled_url_schemes
|
16
|
+
assert_raise(Errors::UnknownTemplateScheme) { Templates.create(nil, "ether://monkeys") }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
File without changes
|
data/test/helper.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "test/unit"
|
3
|
+
require "mocha"
|
4
|
+
|
5
|
+
%w(../lib).each do |path|
|
6
|
+
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), path)))
|
7
|
+
end
|
8
|
+
|
9
|
+
LOCAL_TEMPLATE_PATH = File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "local"))
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: basis
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Barnette
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-04-17 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hoe
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.5.1
|
23
|
+
version:
|
24
|
+
description: Basis is smart project skeletons. This is a very, very early release. Basis only knows how to deal with git:// urls and local file paths right now. Also, there's no documentation, no way to track remote template lists, dubious cache update semantics, bad command-line messaging, bad error reporting, and bad code. Honestly, installing this gem will probably melt your system. Basis owes a ton to Hoe, Mr. Bones, Rubigen, Newgem, and skel.
|
25
|
+
email:
|
26
|
+
- jbarnette@rubyforge.org
|
27
|
+
executables:
|
28
|
+
- basis
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- History.txt
|
33
|
+
- Manifest.txt
|
34
|
+
- README.txt
|
35
|
+
- test/fixtures/local/project.name/project.name.txt
|
36
|
+
files:
|
37
|
+
- History.txt
|
38
|
+
- Manifest.txt
|
39
|
+
- README.txt
|
40
|
+
- Rakefile
|
41
|
+
- bin/basis
|
42
|
+
- lib/basis/engine.rb
|
43
|
+
- lib/basis/errors.rb
|
44
|
+
- lib/basis/options.rb
|
45
|
+
- lib/basis/templates.rb
|
46
|
+
- lib/basis/templates/base.rb
|
47
|
+
- lib/basis/templates/git.rb
|
48
|
+
- lib/basis/templates/list.rb
|
49
|
+
- lib/basis/templates/local.rb
|
50
|
+
- lib/basis/templates/state.rb
|
51
|
+
- lib/basis/version.rb
|
52
|
+
- lib/templates.yml
|
53
|
+
- test/basis/engine_test.rb
|
54
|
+
- test/basis/options_test.rb
|
55
|
+
- test/basis/templates/base_test.rb
|
56
|
+
- test/basis/templates_test.rb
|
57
|
+
- test/fixtures/local/erb/erb.txt.erb
|
58
|
+
- test/fixtures/local/project.name/project.name.txt
|
59
|
+
- test/helper.rb
|
60
|
+
has_rdoc: true
|
61
|
+
homepage: http://github.com/jbarnette/basis
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options:
|
64
|
+
- --main
|
65
|
+
- README.txt
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: "0"
|
73
|
+
version:
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: "0"
|
79
|
+
version:
|
80
|
+
requirements: []
|
81
|
+
|
82
|
+
rubyforge_project: basis
|
83
|
+
rubygems_version: 1.1.1
|
84
|
+
signing_key:
|
85
|
+
specification_version: 2
|
86
|
+
summary: Basis is smart project skeletons
|
87
|
+
test_files:
|
88
|
+
- test/basis/engine_test.rb
|
89
|
+
- test/basis/options_test.rb
|
90
|
+
- test/basis/templates/base_test.rb
|
91
|
+
- test/basis/templates_test.rb
|