gn 0.0.1.alpha

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.
Files changed (4) hide show
  1. data/LICENSE +19 -0
  2. data/Readme.md +51 -0
  3. data/bin/gn +52 -0
  4. metadata +63 -0
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2012 Leandro López, Michel Martens and Lucas Florio.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE
data/Readme.md ADDED
@@ -0,0 +1,51 @@
1
+ # gn
2
+
3
+ ## Description
4
+
5
+ gn is the simplest file/folder/structure/whatever generator you could ever find.
6
+
7
+ ## Usage
8
+
9
+ Say you want to generate always a typical README file, like this one, you should do the following:
10
+
11
+ * Create a folder named (for instance) readme on your current folder
12
+ * Inside of that folder, create a file named init.rb and fill it like this:
13
+
14
+ module Plan
15
+ module Readme
16
+
17
+ def name
18
+ "CHANGEME"
19
+ end
20
+
21
+ def destination
22
+ "readme"
23
+ end
24
+ end
25
+ end
26
+
27
+ * Create a templates folder and the template itself.
28
+
29
+ mkdir readme/templates
30
+ touch readme/templates/readme
31
+
32
+ * Inside the readme template, put your typical Readme content.
33
+ * To include dynamic data, just use {{variable}}, where variable is a public method on Plan::Readme. So writing {{name}} will produce CHANGEME.
34
+
35
+ * Run the generator like this:
36
+
37
+ gn readme
38
+
39
+ * Your existing editor will pop open, allowing you to change the content of the module.
40
+ * Close the editor.
41
+ * You'll end up having a file named readme in the current directory, with the changes you made on the init.rb file, but your original init.rb file will be intact.
42
+
43
+ ## Other usages
44
+
45
+ You can use gn to generate different things. In our case, we design it so we could generate basic crud/scaffolds for cuba, but you could use for whatever you want.
46
+
47
+ See the folder named examples for some ideas.
48
+
49
+ ## Installation
50
+
51
+ gem install gn
data/bin/gn ADDED
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby
2
+ require 'mote'
3
+ require 'fileutils'
4
+ require 'tempfile'
5
+
6
+ class Gn
7
+
8
+ attr_reader :name
9
+
10
+ def initialize(name)
11
+ @name = name
12
+ run
13
+ end
14
+
15
+ def run
16
+ load_plan
17
+ Plan.constants.each do |constant|
18
+ blueprint = Plan.const_get(constant).new
19
+ template = File.join(templates_location, constant.to_s.downcase)
20
+ FileUtils.mkdir_p(File.dirname(blueprint.destination))
21
+ File.open(blueprint.destination, "w") do |f|
22
+ f.write Mote.parse(File.read(template), blueprint).call
23
+ end
24
+ end
25
+ end
26
+
27
+ def location
28
+ @location ||= [name, "#{ENV['HOME']}.plans/#{name}", "./plans/#{name}"].select do |path|
29
+ Dir.exists?(path)
30
+ end
31
+ end
32
+
33
+ def templates_location
34
+ File.join(@location, "templates")
35
+ end
36
+
37
+ def load_plan
38
+ file = Tempfile.new('plan_init')
39
+ file.write(File.read(File.join(location, "init.rb")))
40
+ file.close
41
+ open_with_editor(file)
42
+ load file.path
43
+ end
44
+
45
+ def open_with_editor(file)
46
+ editor = ENV['EDITOR'] || "vi"
47
+ system("#{editor} #{file.path}")
48
+ end
49
+
50
+ end
51
+
52
+ Gn.new(ARGV.first)
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gn
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.alpha
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - Leandro López
9
+ - Michel Martens
10
+ - Lucas Florio
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2012-05-12 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: mote
18
+ requirement: &70096710185500 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
23
+ version: '0'
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *70096710185500
27
+ description: Simple Generator for the masses
28
+ email:
29
+ - lucasefe@gmail.com
30
+ executables:
31
+ - gn
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - bin/gn
36
+ - LICENSE
37
+ - Readme.md
38
+ homepage: http://lucasefe.github.com/gn
39
+ licenses:
40
+ - MIT
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>'
55
+ - !ruby/object:Gem::Version
56
+ version: 1.3.1
57
+ requirements: []
58
+ rubyforge_project:
59
+ rubygems_version: 1.8.11
60
+ signing_key:
61
+ specification_version: 3
62
+ summary: Simple Generator for the masses
63
+ test_files: []