project_templater 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # Project Templater
2
+
3
+ __V0.1.0__
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ gem install project_templater
9
+ ```
10
+
11
+ Adds the `project_templater` executable.
12
+
13
+ ## Usage
14
+
15
+ ```
16
+ project_templater {generator} {path}
17
+ ```
18
+
19
+ Templates are listed within `lib/generators`.
20
+
21
+ Will default to the PWD if you don't define a path.
22
+
23
+ ## Examples
24
+
25
+ ```
26
+ project_templater sinatra_basic
27
+ ```
28
+
29
+ Run the `sinatra_basic` generator and output to the current directory
30
+
31
+ ```
32
+ project_templater sinatra_basic foo/
33
+ ```
34
+
35
+ Run the `sinatra_basic` generator and output to the `pwd/foo/ directory`.
36
+
37
+ ## Available Generators
38
+ - `sinatra_basic`
39
+ - `js_project`
40
+ - `ruby_project`
41
+
42
+ ## Adding a Generator
43
+
44
+ These exist within `lib/generators`. Create a new `.rb` file. The class must extend from `Generator`, and you need to define an instance method `run`.
45
+
46
+ You have two methods available to you, `make_file` and `make_dir`.
47
+
48
+ The best way to do it is to copy an existing one - they are all in `lib/generators`.
49
+
50
+ Define a `run` method that will be called. There are two methods available:
51
+
52
+ - `make_file` can be called with just the file to create, and optionally a block. Whatever is returned from the block is then stored as the contents of the file.
53
+ - `make_dir` will create a new directory.
54
+
55
+ You can also define a `post_install` method that is run after the `run` method has. You also have access to the `@base` variable, which is the directory the generator was run in.
56
+
57
+
58
+
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ require "project_templater"
5
+
6
+ template = ARGV[0]
7
+ base_dir = ARGV[1]
8
+
9
+ pt = ProjectTemplater.new(template)
10
+ pt.run(base_dir)
@@ -0,0 +1,23 @@
1
+ require "fileutils"
2
+
3
+ class Generator
4
+ def initialize(base_dir)
5
+ @base = base_dir
6
+ unless @base[-1, 1] == "/"
7
+ @base = @base + "/"
8
+ end
9
+ end
10
+
11
+ def post_install
12
+ end
13
+
14
+ def make_file(path, &block)
15
+ contents = ""
16
+ contents = block.call if block_given?
17
+ File.open(@base + path, 'w') {|f| f.write(contents) }
18
+ end
19
+
20
+ def make_dir(path)
21
+ FileUtils.mkdir_p(@base + path)
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ require_relative "./generator.rb"
2
+
3
+ class JsProject < Generator
4
+ def run
5
+ make_file("package.json")
6
+ make_file("README.md")
7
+ make_dir("test")
8
+ make_dir("src")
9
+ make_dir("demo")
10
+
11
+ end
12
+
13
+ def post_install
14
+ `cd #{@base} && git init`
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ require_relative "./generator.rb"
2
+
3
+ class RubyProject < Generator
4
+ def run
5
+ make_file("Gemfile") {
6
+ "source 'http://rubygems.org'\ngem 'rspec'"
7
+ }
8
+ make_file(".rspec") {
9
+ "--color"
10
+ }
11
+ make_file(".gitignore")
12
+ make_dir("spec")
13
+ end
14
+
15
+ def post_install
16
+ `cd #{@base} && git init && bundle`
17
+ end
18
+ end
@@ -0,0 +1,29 @@
1
+ require_relative "./generator.rb"
2
+
3
+ class SinatraBasic < Generator
4
+ def run
5
+ make_file("Gemfile") {
6
+ "source 'http://rubygems.org'\ngem 'sinatra'"
7
+ }
8
+ make_file("app.rb") {
9
+ "require 'sinatra'"
10
+ }
11
+ make_file("config.ru") {
12
+ "require './app'\nrun Sinatra::Application"
13
+ }
14
+ make_file("README.md")
15
+
16
+ make_dir("public")
17
+ make_dir("public/css")
18
+ make_dir("public/js")
19
+ make_dir("public/views")
20
+ make_file("public/css/style.css")
21
+ make_file("public/js/app.js")
22
+ make_file("public/views/layout.erb")
23
+ end
24
+
25
+ def post_install
26
+ `cd #{@base} && git init && bundle`
27
+ `cd #{@base}/public/js && nodefetch jquery`
28
+ end
29
+ end
@@ -0,0 +1,26 @@
1
+ class String
2
+ def camel_case
3
+ return self if self !~ /_/ && self =~ /[A-Z]+.*/
4
+ split('_').map{|e| e.capitalize}.join
5
+ end
6
+ end
7
+
8
+
9
+ require "generators/generator.rb"
10
+
11
+ class ProjectTemplater
12
+ def initialize(template)
13
+ @template = template
14
+ # load in the right generator
15
+ require "generators/#{@template}.rb"
16
+ end
17
+
18
+ def run(base_dir)
19
+ base_dir = Dir.pwd + "/" + (base_dir ||= "")
20
+ class_name = @template.camel_case
21
+ instance = Object::const_get(class_name).new(base_dir)
22
+ instance.run
23
+ instance.post_install
24
+ end
25
+ end
26
+
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: project_templater
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jack Franklin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-30 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A gem for creating file and folder structures.
15
+ email: jack@jackfranklin.net
16
+ executables:
17
+ - project_templater
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/generators/generator.rb
22
+ - lib/generators/js_project.rb
23
+ - lib/generators/ruby_project.rb
24
+ - lib/generators/sinatra_basic.rb
25
+ - lib/project_templater.rb
26
+ - bin/project_templater
27
+ - README.md
28
+ homepage: http://github.com/jackfranklin/project_templater
29
+ licenses: []
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubyforge_project:
48
+ rubygems_version: 1.8.23
49
+ signing_key:
50
+ specification_version: 3
51
+ summary: Project Templating
52
+ test_files: []