tooler 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/License CHANGED
@@ -1,8 +1,8 @@
1
1
  The MIT License (MIT)
2
- Copyright (c) 2012 Revath S Kumar
2
+ Copyright (c) 2013 Revath S Kumar
3
3
 
4
4
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
5
 
6
6
  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
7
 
8
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Tooler
1
+ # Tooler [![Build Status](https://travis-ci.org/revathskumar/tooler.png?branch=master)](https://travis-ci.org/revathskumar/tooler)
2
2
  ## Ruby Project bolerplater
3
3
 
4
4
  ### What it does
@@ -9,13 +9,18 @@
9
9
  * Add Gemfile
10
10
  * Add Procfile
11
11
 
12
+ ### Usage
13
+ $ cd project/directory
14
+ $ tooler [cuba/sinatra]
15
+ $ thin -R config.ru start
16
+
12
17
  ### Current Support
13
18
  * Cuba
14
19
  * Sinatra
15
20
 
16
21
  ### TODO
17
22
  * Initialize git
18
- * Ask some questions from users
23
+ * Get input from users.
19
24
  * Add support to create a ruby gem
20
25
  * Write tests for tooler
21
26
  * Generate test template
@@ -23,4 +28,4 @@
23
28
 
24
29
 
25
30
  ### License
26
- Please see [License](License)
31
+ Please see [License](https://github.com/revathskumar/tooler/blob/master/License)
data/bin/tooler CHANGED
@@ -2,10 +2,7 @@
2
2
 
3
3
  # Now load
4
4
  require "fileutils"
5
- require "template"
6
5
  require "tooler"
7
- require "error"
8
-
9
6
 
10
7
  # And run with ARGV
11
8
  begin
@@ -15,7 +12,8 @@ rescue Interrupt
15
12
  p "Quitting..."
16
13
  exit 1
17
14
  rescue Tooler::Error => error
18
- p error.message
19
- p "------------------"
15
+ print error.message
16
+ print "\n"
17
+ print Tooler.help
20
18
  exit 1
21
19
  end
data/lib/tooler.rb CHANGED
@@ -1,44 +1,4 @@
1
-
2
- module Tooler
3
- class CLI
4
- include Tooler::Template
5
-
6
- def initialize args
7
- @options = {template: "", name: ""}
8
- parse args[:arguments]
9
- @options[:pwd] = ::FileUtils.pwd + "/"
10
- @options[:name] = @options[:pwd].split('/').last
11
- @options[:template_path] = File.dirname(__FILE__) + "/../templates/"
12
- end
13
-
14
- def start
15
- p "Initializing #{@options[:template]}"
16
- p "Project Name #{@options[:name]}"
17
- begin
18
- require "#{@options[:template]}_template"
19
- rescue LoadError
20
- p "Invalid template name"
21
- end
22
- send("copy_template_#{@options[:template]}")
23
- end
24
-
25
- private
26
-
27
- def parse args
28
- @options[:template] = args[0].downcase
29
- end
30
-
31
- def get_name
32
-
33
- end
34
-
35
- def method_missing method_name, args
36
- p "method_missing #{method}"
37
- if method_name[/^copy_template_/]
38
- raise Tooler::Error, "Invalid template"
39
- else
40
- super
41
- end
42
- end
43
- end
44
- end
1
+ require "tooler/template"
2
+ require "tooler/helper"
3
+ require "tooler/cli"
4
+ require "tooler/error"
data/lib/tooler/cli.rb ADDED
@@ -0,0 +1,42 @@
1
+
2
+ module Tooler
3
+ class CLI
4
+ include Tooler::Template
5
+
6
+ def initialize args
7
+ @options = {template: "", name: ""}
8
+ parse args[:arguments]
9
+ @options[:pwd] = ::FileUtils.pwd + "/"
10
+ @options[:name] = @options[:pwd].split('/').last
11
+ @options[:root_path] = Tooler.root
12
+ @options[:template_path] = @options[:root_path] + "/templates/"
13
+ end
14
+
15
+ def start
16
+ begin
17
+ require "tooler/#{@options[:template]}_template"
18
+ rescue LoadError
19
+ raise Tooler::Error, "Invalid template"
20
+ end
21
+ send("copy_template_#{@options[:template]}")
22
+ end
23
+
24
+ private
25
+
26
+ def parse args
27
+ if args.empty?
28
+ raise Tooler::Error, "Should specify a template"
29
+ end
30
+ @options[:template] = args[0].downcase
31
+ end
32
+
33
+ def method_missing method_name, *args, &block
34
+ p "method_missing #{method_name}"
35
+ if method_name[/^copy_template_/]
36
+ raise Tooler::Error, "Invalid template"
37
+ else
38
+ super
39
+ end
40
+ end
41
+ end
42
+ end
File without changes
File without changes
@@ -0,0 +1,17 @@
1
+ module Tooler
2
+ def self.root
3
+ File.expand_path "../../..", __FILE__
4
+ end
5
+
6
+ def self.help
7
+ <<HELP_MESSAGE
8
+
9
+ $ tooler template_name
10
+
11
+ Available templates
12
+ 1. cuba
13
+ 2. sinatra
14
+
15
+ HELP_MESSAGE
16
+ end
17
+ end
@@ -14,19 +14,18 @@ module Tooler
14
14
  end
15
15
 
16
16
  def license name=nil
17
- p "Copying license"
18
- ::FileUtils.cp @options[:template_path]+"license/#{name||'mit'}.txt", @options[:pwd]+"/License"
17
+ contents = file_read @options[:template_path]+"license/#{name||'mit'}.txt"
18
+ contents = contents % {username: @options[:username] || "[Replace your fullname]", year: Time.new.strftime("%Y")}
19
+ file_write @options[:pwd]+"/License", contents
19
20
  end
20
21
 
21
22
  def readme
22
- p "Copying README"
23
23
  contents = file_read @options[:template_path]+"README.md"
24
24
  contents = contents % {name: @options[:name], description: ""}
25
25
  file_write @options[:pwd]+"/README.md", contents
26
26
  end
27
27
 
28
28
  def create_dir name
29
- p "create dir #{name}"
30
29
  ::FileUtils.mkdir @options[:pwd]+"/"+name
31
30
  end
32
31
 
@@ -0,0 +1,3 @@
1
+ module Tooler
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,5 @@
1
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
2
+
3
+ require "tooler"
4
+ require "rspec"
5
+
@@ -0,0 +1,15 @@
1
+ require "spec_helper"
2
+
3
+ describe Tooler::CLI do
4
+
5
+ it "raise exception when no template is passed" do
6
+ expect { Tooler::CLI.new({arguments: []}) }.to raise_error(Tooler::Error, "Should specify a template")
7
+ end
8
+
9
+ describe "#start" do
10
+ it "raise exception when invalid template is passed" do
11
+ cli = Tooler::CLI.new({arguments: ["c"]})
12
+ expect { cli.start }.to raise_error(Tooler::Error, "Invalid template")
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,75 @@
1
+ require "spec_helper"
2
+
3
+ describe Tooler::Template do
4
+ before :each do
5
+ args = {arguments: ["cuba"]}
6
+ @cli = Tooler::CLI.new args
7
+ options = @cli.instance_variable_get(:@options)
8
+ options.merge!({pwd: Tooler.root + "/tmp/"})
9
+ @cli.instance_variable_set(:@options, options)
10
+ end
11
+
12
+ describe "#gemfile" do
13
+ it "create gemfile" do
14
+ @cli.gemfile
15
+ File.exists?("tmp/Gemfile").should == true
16
+ end
17
+ end
18
+
19
+ describe "#procfile" do
20
+ it "create procfile" do
21
+ @cli.procfile
22
+ File.exists?("tmp/Procfile").should == true
23
+ end
24
+ end
25
+
26
+ describe "#license" do
27
+ it "create license" do
28
+ @cli.license
29
+ File.exists?("License").should == true
30
+ end
31
+
32
+ it "default to MIT license" do
33
+ @cli.license
34
+ File.open("tmp/License",'r').read.should match /The MIT License/
35
+ end
36
+ end
37
+
38
+ describe "#readme" do
39
+ it "create readme" do
40
+ @cli.readme
41
+ File.exists?("tmp/README.md").should == true
42
+ end
43
+ end
44
+
45
+ describe "#create_dir" do
46
+ it "create dir with name passed" do
47
+ @cli.create_dir "tmp"
48
+ File.directory?("tmp/tmp/").should == true
49
+ end
50
+ end
51
+
52
+ describe "#file_read" do
53
+ before :each do
54
+ File.open("tmp/sample_file.txt", "w+") do |f |
55
+ f.puts "This is a sample file"
56
+ end
57
+ end
58
+
59
+ it "read a file and return contents" do
60
+ @cli.file_read("tmp/sample_file.txt").should == "This is a sample file\n"
61
+ end
62
+ end
63
+
64
+ describe "#file_write" do
65
+ it "writes content into a file" do
66
+ @cli.file_write "tmp/sample_write.txt", "This is a sample file"
67
+ File.read("tmp/sample_write.txt").should == "This is a sample file\n"
68
+ end
69
+ end
70
+
71
+ after :all do
72
+ FileUtils.rm_rf Dir.glob('tmp/*')
73
+ FileUtils.touch "tmp/.gitkeep"
74
+ end
75
+ end
@@ -1,8 +1,8 @@
1
1
  The MIT License (MIT)
2
- Copyright (c) 2012 Revath S Kumar
2
+ Copyright (c) %{year} %{username}
3
3
 
4
4
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
5
 
6
6
  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
7
 
8
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/tooler.gemspec CHANGED
@@ -2,24 +2,25 @@
2
2
  lib = File.expand_path('../lib',__FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
- require "version"
5
+ require "tooler/version"
6
6
 
7
7
  Gem::Specification.new do |s|
8
- s.name = 'tooler'
9
- s.version = Tooler::VERSION
10
- s.date = Time.new.strftime("%Y-%m-%d")
11
- s.summary = "Tooler"
12
- s.description = "Ruby boilerplater"
13
- s.authors = ["Revath S Kumar"]
14
- s.email = ["rsk@revathskumar.com"]
15
- s.homepage = "http://blog.revathskumar.com"
16
- s.files = ["License", "README.md","tooler.gemspec"]
17
- s.files += Dir.glob("lib/*.rb")
18
- s.files += Dir.glob("templates/*")
19
- s.files += Dir.glob("templates/**/*")
20
- s.files += Dir.glob("bin/*")
21
- s.license = 'MIT'
22
- s.bindir = 'bin'
8
+ s.name = 'tooler'
9
+ s.version = Tooler::VERSION
10
+ s.date = Time.new.strftime("%Y-%m-%d")
11
+ s.summary = "Tooler"
12
+ s.description = "Ruby boilerplater"
13
+ s.authors = ["Revath S Kumar"]
14
+ s.email = ["rsk@revathskumar.com"]
15
+ s.homepage = "http://revathskumar.github.com/tooler/"
16
+ s.files = ["License", "README.md","tooler.gemspec"]
17
+ s.files += Dir.glob("lib/**/*")
18
+ s.files += Dir.glob("templates/**/*")
19
+ s.files += Dir.glob("bin/*")
20
+ s.files += Dir.glob("spec/**/*")
21
+ s.license = 'MIT'
22
+ s.bindir = 'bin'
23
23
  s.require_paths = ['lib']
24
- s.executables = %w(tooler)
24
+ s.executables = %w(tooler)
25
+ s.test_files = Dir.glob("spec/**/*")
25
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tooler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-13 00:00:00.000000000 Z
12
+ date: 2013-02-14 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Ruby boilerplater
15
15
  email:
@@ -22,14 +22,14 @@ files:
22
22
  - License
23
23
  - README.md
24
24
  - tooler.gemspec
25
- - lib/version.rb
26
- - lib/template.rb
27
- - lib/cuba_template.rb
25
+ - lib/tooler/version.rb
26
+ - lib/tooler/template.rb
27
+ - lib/tooler/helper.rb
28
+ - lib/tooler/cuba_template.rb
29
+ - lib/tooler/cli.rb
30
+ - lib/tooler/error.rb
31
+ - lib/tooler/sinatra_template.rb
28
32
  - lib/tooler.rb
29
- - lib/error.rb
30
- - lib/sinatra_template.rb
31
- - templates/gitignore
32
- - templates/README.md
33
33
  - templates/license/mit.txt
34
34
  - templates/sinatra/config.ru
35
35
  - templates/sinatra/template.rb
@@ -39,8 +39,13 @@ files:
39
39
  - templates/cuba/cuba_template.rb
40
40
  - templates/cuba/Procfile
41
41
  - templates/cuba/Gemfile
42
+ - templates/gitignore
43
+ - templates/README.md
42
44
  - bin/tooler
43
- homepage: http://blog.revathskumar.com
45
+ - spec/tooler/template_spec.rb
46
+ - spec/tooler/cli_spec.rb
47
+ - spec/spec_helper.rb
48
+ homepage: http://revathskumar.github.com/tooler/
44
49
  licenses:
45
50
  - MIT
46
51
  post_install_message:
@@ -65,5 +70,8 @@ rubygems_version: 1.8.10
65
70
  signing_key:
66
71
  specification_version: 3
67
72
  summary: Tooler
68
- test_files: []
73
+ test_files:
74
+ - spec/tooler/template_spec.rb
75
+ - spec/tooler/cli_spec.rb
76
+ - spec/spec_helper.rb
69
77
  has_rdoc:
data/lib/version.rb DELETED
@@ -1,3 +0,0 @@
1
- module Tooler
2
- VERSION = "0.0.1"
3
- end