temp 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.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.2@temp --create
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in temp.gemspec
4
+ gemspec
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,53 @@
1
+ # Temp
2
+
3
+ Temp is a simple command line utility for creating projects from templates.
4
+
5
+ ## Installation
6
+
7
+ You can install Temp with `gem install temp`
8
+
9
+ ## Usage
10
+
11
+ ### Templates
12
+
13
+ By default, Temp will look for templates in `~/.temp`. A template can have a
14
+ `.tempignore` file that contains a newline-separated list of globs to specify
15
+ files that should be ignored.
16
+
17
+ ### Project
18
+
19
+ To create a project from a template, use `temp project_dir template_name`. Temp
20
+ will create a project directory and copy all the files from a template of the
21
+ given name (excluding the ignored files, of course).
22
+
23
+ ## Later
24
+
25
+ Temp isn't very useful at the moment but I do have some features planned for
26
+ later:
27
+
28
+ - A DSL for the templates
29
+ - Passing options to the DSL so that, for example, a file can be ignored if the
30
+ user specifies a certain option on the command line
31
+ - Allow ERB to be used in files
32
+
33
+ ## License
34
+
35
+ Copyright (c) 2011 Austin Gatchell
36
+
37
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
38
+ this software and associated documentation files (the "Software"), to deal in
39
+ the Software without restriction, including without limitation the rights to
40
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
41
+ the Software, and to permit persons to whom the Software is furnished to do so,
42
+ subject to the following conditions:
43
+
44
+ The above copyright notice and this permission notice shall be included in all
45
+ copies or substantial portions of the Software.
46
+
47
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
48
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
49
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
50
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
51
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
52
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
53
+ SOFTWARE.
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+
5
+ require 'temp'
6
+
7
+ Temp::Runner.start
@@ -0,0 +1,3 @@
1
+ require 'temp/copier'
2
+ require 'temp/version'
3
+ require 'temp/runner'
@@ -0,0 +1,69 @@
1
+ require 'fileutils'
2
+
3
+ module Temp
4
+
5
+ # A Copier object provides various functions for creating a project from a
6
+ # template. It can also be given a path to the directory where templates can
7
+ # be found.
8
+ class Copier
9
+
10
+ attr_reader :options
11
+
12
+ def initialize(options = {})
13
+ @options = options
14
+ @template_dir = File.expand_path(options[:template_dir] || '~/.temp')
15
+ end
16
+
17
+ # Creates a new project with the given path from the given template name.
18
+ def create_project(project, template)
19
+ project = File.expand_path(project)
20
+ template_path = File.expand_path(File.join(@template_dir, template))
21
+
22
+ raise 'project already exists' if File.exist? project
23
+ raise 'template does not exist' unless File.exist? template_path
24
+
25
+ ignore = read_tempignore(template)
26
+ files = find_files(template, ignore)
27
+
28
+ FileUtils.mkdir(project)
29
+ files.each do |file|
30
+ p = File.join(project, file)
31
+ t = File.join(template_path, file)
32
+
33
+ if File.directory? t
34
+ FileUtils.mkdir(p)
35
+ else
36
+ FileUtils.cp(t, p)
37
+ end
38
+ end
39
+ end
40
+
41
+ # Returns an array of all files in a template, optionally ignoring all files
42
+ # in ignore.
43
+ def find_files(template, ignore = [])
44
+ template = File.expand_path(File.join(@template_dir, template))
45
+ Dir.glob(File.join(template, '**/*')).map do |file|
46
+ file.sub(template + '/', '')
47
+ end - ignore
48
+ end
49
+
50
+ # Returns an array of files in a template to ignore.
51
+ def read_tempignore(template)
52
+ template = File.expand_path(File.join(@template_dir, template))
53
+ tempignore = File.join(template, '.tempignore')
54
+ files = ['.tempignore']
55
+
56
+ if File.exist? tempignore
57
+ files |= File.read(tempignore).split(?\n).map do |line|
58
+ Dir.glob(File.join(template, line)).map do |file|
59
+ file.sub(template + '/', '')
60
+ end
61
+ end.flatten
62
+ end
63
+
64
+ files
65
+ end
66
+
67
+ end
68
+
69
+ end
@@ -0,0 +1,34 @@
1
+ require 'optparse'
2
+
3
+ module Temp
4
+
5
+ class Runner
6
+
7
+ def self.start
8
+ options = {}
9
+
10
+ begin
11
+ OptionParser.new do |o|
12
+ o.banner = 'Usage: temp [options] [project] [template]'
13
+
14
+ o.on('-v', '--version', 'Show version information') do
15
+ puts "Temp #{Temp::VERSION}"
16
+ end
17
+ end.parse!
18
+
19
+ c = Temp::Copier.new
20
+ if ARGV.size == 0
21
+ raise 'no project directory or template name specified'
22
+ elsif ARGV.size == 1
23
+ raise 'no template name specified'
24
+ else
25
+ c.create_project(ARGV[0], ARGV[1])
26
+ end
27
+ rescue => e
28
+ puts e.message
29
+ end
30
+ end
31
+
32
+ end
33
+
34
+ end
@@ -0,0 +1,3 @@
1
+ module Temp
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,3 @@
1
+ require 'fileutils'
2
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib',
3
+ 'temp.rb'))
@@ -0,0 +1,86 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe Temp::Copier do
4
+
5
+ before :each do
6
+ @dir = File.expand_path(File.dirname(__FILE__))
7
+ @test_dir = File.join(@dir, 'test')
8
+ @temp_dir = File.join(@dir, 'template')
9
+ @template1_name = 'template1'
10
+ @template1 = File.join(@temp_dir, @template1_name)
11
+ FileUtils.mkdir(@test_dir)
12
+ @copier = Temp::Copier.new(:template_dir => @temp_dir)
13
+ end
14
+
15
+ after :each do
16
+ FileUtils.rm_r(@test_dir)
17
+ end
18
+
19
+ describe 'finding files' do
20
+
21
+ before :each do
22
+ @files = Dir.glob(@template1 + '/**/*').map { |f|
23
+ f.sub(@template1 + '/', '') }.sort
24
+ @ignore = ['.tempignore'] | Dir.glob(File.read(File.join(@template1,
25
+ '.tempignore')).split(?\n)).map {
26
+ |f| File.expand_path(f).sub(@template1 + '/', '') }.sort
27
+ end
28
+
29
+ it 'should find all files in a template' do
30
+ @copier.find_files(@template1_name).sort.should == @files.sort
31
+ end
32
+
33
+ it 'should find the correct files to ignore from reading .tempignore' do
34
+ @copier.read_tempignore(@template1_name).sort.should == @ignore
35
+ end
36
+
37
+ it 'should find all files in a template except for files to ignore' do
38
+ @copier.find_files(@template1_name, @ignore).sort.should == @files -
39
+ @ignore
40
+ end
41
+
42
+ end
43
+
44
+ describe 'project creation' do
45
+
46
+ before :each do
47
+ @project_dir = File.join(@test_dir, 'project')
48
+ end
49
+
50
+ describe 'success' do
51
+
52
+ it 'should create a project directory' do
53
+ @copier.create_project(@project_dir, @template1_name)
54
+ File.exist?(@project_dir).should be_true
55
+ end
56
+
57
+ it 'should copy all files from a template' do
58
+ files = @copier.find_files(@template1_name,
59
+ @copier.read_tempignore(@template1_name))
60
+ @copier.create_project(@project_dir, @template1_name)
61
+ Dir.glob(File.join(@project_dir, '**/*')).map { |f|
62
+ f.sub(@project_dir + '/', '') }.sort.should == files.sort
63
+ end
64
+
65
+ end
66
+
67
+ describe 'failure' do
68
+
69
+ it 'should raise an exception if the project to create already exists' do
70
+ FileUtils.mkdir(@project_dir)
71
+ lambda do
72
+ @copier.create_project(@project_dir, @template1_name)
73
+ end.should raise_error
74
+ end
75
+
76
+ it 'should raise an exception if the template does not exist' do
77
+ lambda do
78
+ @copier.create_project(@project_dir, 'fake_template')
79
+ end.should raise_error
80
+ end
81
+
82
+ end
83
+
84
+ end
85
+
86
+ end
@@ -0,0 +1 @@
1
+ **/ignore-me.txt
@@ -0,0 +1 @@
1
+ I should be ignored.
@@ -0,0 +1 @@
1
+ Hello, World!
@@ -0,0 +1 @@
1
+ I should be ignored.
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "temp/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "temp"
7
+ s.version = Temp::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Austin Gatchell"]
10
+ s.email = ["austin@ausgat.com"]
11
+ s.homepage = "https://github.com/ausgat/temp"
12
+ s.summary = %q{A small project creation utility.}
13
+ s.description = %q{Temp is a simple command line utility for creating \
14
+ projects from templates.}
15
+ s.license = 'MIT'
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f|
20
+ File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+
23
+ s.add_development_dependency('rspec')
24
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: temp
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Austin Gatchell
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-07-23 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :development
32
+ version_requirements: *id001
33
+ description: |-
34
+ Temp is a simple command line utility for creating \
35
+ projects from templates.
36
+ email:
37
+ - austin@ausgat.com
38
+ executables:
39
+ - temp
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - .gitignore
46
+ - .rspec
47
+ - .rvmrc
48
+ - Gemfile
49
+ - Rakefile
50
+ - Readme.mdown
51
+ - bin/temp
52
+ - lib/temp.rb
53
+ - lib/temp/copier.rb
54
+ - lib/temp/runner.rb
55
+ - lib/temp/version.rb
56
+ - spec/spec_helper.rb
57
+ - spec/temp_spec.rb
58
+ - spec/template/template1/.tempignore
59
+ - spec/template/template1/foo/bar/baz.txt
60
+ - spec/template/template1/foo/bar/ignore-me.txt
61
+ - spec/template/template1/hello.txt
62
+ - spec/template/template1/ignore-me.txt
63
+ - temp.gemspec
64
+ has_rdoc: true
65
+ homepage: https://github.com/ausgat/temp
66
+ licenses:
67
+ - MIT
68
+ post_install_message:
69
+ rdoc_options: []
70
+
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ requirements: []
90
+
91
+ rubyforge_project:
92
+ rubygems_version: 1.3.7
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: A small project creation utility.
96
+ test_files:
97
+ - spec/spec_helper.rb
98
+ - spec/temp_spec.rb
99
+ - spec/template/template1/.tempignore
100
+ - spec/template/template1/foo/bar/baz.txt
101
+ - spec/template/template1/foo/bar/ignore-me.txt
102
+ - spec/template/template1/hello.txt
103
+ - spec/template/template1/ignore-me.txt