lepidoptera 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +51 -42
- data/bin/lep +32 -7
- data/lepidoptera.gemspec +8 -3
- data/lib/base.rb +29 -0
- data/lib/butterfly.rb +14 -9
- data/lib/options.rb +33 -5
- data/lib/stub_generators/stub/INFO +17 -0
- data/lib/stub_generators/stub/stub_generator.rb +17 -0
- data/lib/stub_generators/stub/templates/generator-type_INFO +4 -0
- data/lib/stub_generators/stub/templates/generator-type_README.txt +2 -0
- data/lib/stub_generators/stub/templates/generator-type_generator.rb +15 -0
- metadata +8 -3
data/README.md
CHANGED
@@ -10,16 +10,18 @@ Lepidoptera /ˌlɛpɪˈdɒptərə/
|
|
10
10
|
What is lepidoptera?
|
11
11
|
--------------------
|
12
12
|
|
13
|
-
Lepidoptera is a
|
13
|
+
Lepidoptera is a simple and easy to extend __code generator for common every day projects__.
|
14
14
|
Technically, Lepidoptera is a wrapper for [rubigen][r] which allows setting up code templates for arbitrary projects.
|
15
15
|
|
16
|
-
|
16
|
+
Lepidopteras code generators are structured in __generator groups__. A generators group is just a container for multiple generators, where as a generator is also called a __generator type__.
|
17
17
|
|
18
|
-
For the time being, Lepidoptera has code generators for the following
|
18
|
+
For the time being, Lepidoptera has code generators for the following project types (more to come):
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
* [jquery][j] generators:
|
21
|
+
* jquery plugin
|
22
|
+
* [heroku][h] generators:
|
23
|
+
* static pages
|
24
|
+
* a [sinatra][s] application
|
23
25
|
|
24
26
|
Installation
|
25
27
|
------------
|
@@ -28,68 +30,75 @@ Installation
|
|
28
30
|
|
29
31
|
As [lep][wiki-2] (/ˈlɛp/) is a short for [lepidoptera][wiki-1], this gem will install an executable `lep`
|
30
32
|
|
31
|
-
For aesthetic
|
33
|
+
For aesthetic reason, you may also set a synonym alias `butterfly` in your `.bashrc` file:
|
32
34
|
|
33
|
-
|
35
|
+
alias butterfly='lep $1'
|
34
36
|
|
35
37
|
Usage
|
36
38
|
-----
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
-
lep [options] <generator-group> <generator-type> <project-name>
|
41
|
-
|
42
|
-
or for ungrouped code generators:
|
43
|
-
|
44
|
-
lep [options] <generator-type> <project-name>
|
40
|
+
$ lep [options] <generator-group> <generator-type> <project-name>
|
45
41
|
|
46
42
|
with the following __options__:
|
47
43
|
|
48
44
|
-q, --quiet Suppress status output.
|
45
|
+
-n, --new Create a new code generator stub in ~/.lepidoptera.
|
49
46
|
-g, --git Create a git repository after code generation.
|
50
|
-
-n, --new Add a new code generator in ~/.lepidoptera
|
51
47
|
-h, --help Print generator's options and usage.
|
52
48
|
|
53
|
-
|
49
|
+
### Helpers
|
54
50
|
|
55
|
-
|
56
|
-
heroku sinatra
|
57
|
-
jquery plugin
|
58
|
-
|
59
|
-
Helpers
|
60
|
-
-------
|
61
|
-
|
62
|
-
Get a list of all code generators grouped by generator-groups:
|
51
|
+
Get a list of all local code generator groups:
|
63
52
|
|
64
53
|
$ lep
|
65
54
|
|
66
|
-
Get a list of all code
|
55
|
+
Get a list of all code generators for a given generator group:
|
67
56
|
|
68
57
|
$ lep <generator-group>
|
69
58
|
|
70
|
-
Extending Code Generators
|
71
|
-
|
59
|
+
Extending with own Code Generators
|
60
|
+
----------------------------------
|
72
61
|
|
73
62
|
Since lepidoptera is based on _Nic Williams_ Ruby generator framework [rubigen][r], it is very simple to add new own private code generators.
|
74
63
|
|
75
|
-
|
64
|
+
### 1. Manual creation of new a code generator
|
65
|
+
|
66
|
+
Your own private code generators must reside in a folder `~/.lepidoptera`.
|
67
|
+
|
68
|
+
A new generator must satisfy the following code structure:
|
76
69
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
70
|
+
.lepidoptera
|
71
|
+
└─ <generator-group>_generators
|
72
|
+
└─ <generator-type>
|
73
|
+
├─ INFO
|
74
|
+
├─ <generator-type>_generator.rb
|
75
|
+
└─ templates
|
76
|
+
├─ ...
|
77
|
+
└─ ...
|
85
78
|
|
86
|
-
|
79
|
+
whereas every code generator type must contain the following files:
|
80
|
+
|
81
|
+
* an optional `INFO` file containing some additional project info to be displayed after the generation.
|
82
|
+
* a required generator file `<generator-type>_generator.rb` which contains the generation rules.
|
83
|
+
* a required templates folder `templates` which may contain multiple ERB templates for the code to be generated.
|
84
|
+
These ERB templates may contain variables as placeholders for the following information:
|
85
|
+
* `<%= name %>`: Name of the project.
|
86
|
+
* `<%= author %>`: Author of the project (OS Username).
|
87
|
+
|
88
|
+
### 2. Automatic creation of new a code generator
|
89
|
+
|
90
|
+
An easier way to create a new code generator is to automatically generate the above code generator stub into `~/.lepidoptera`.
|
91
|
+
|
92
|
+
To create a new code generator stub, use the `--new` option and provide a __generator group__ and a __generator type__:
|
93
|
+
|
94
|
+
$ lep -n <generator-group> <generator-type>
|
95
|
+
|
96
|
+
If the generator group does not exist already, a group folder `<generator-group>_generators` will be created.
|
87
97
|
|
88
|
-
|
89
|
-
|
98
|
+
Embedded Code Generators
|
99
|
+
========================
|
90
100
|
|
91
|
-
|
92
|
-
==========================
|
101
|
+
The following code generators are currently embedded within this project:
|
93
102
|
|
94
103
|
jQuery Generators
|
95
104
|
-----------------
|
data/bin/lep
CHANGED
@@ -23,6 +23,7 @@ YELLOW = "\033[0;33m"
|
|
23
23
|
RED = "\033[0;31m"
|
24
24
|
|
25
25
|
|
26
|
+
|
26
27
|
### Set up generators
|
27
28
|
|
28
29
|
# get code generators
|
@@ -38,6 +39,37 @@ parser = Butterfly::Options::Parser.new(generators)
|
|
38
39
|
options = parser.parse(ARGV)
|
39
40
|
|
40
41
|
|
42
|
+
|
43
|
+
### new-option? create a new code generator stub
|
44
|
+
if options[:new] then
|
45
|
+
|
46
|
+
# show common help if no argument is provided
|
47
|
+
parser.ask_for_new_generator if ARGV.empty?
|
48
|
+
|
49
|
+
# show prticular help if only a generator group is provideds
|
50
|
+
parser.ask_for_new_generator_type(ARGV[0]) if ARGV.length == 1
|
51
|
+
|
52
|
+
# create dotfolder for local code generators if not exist already
|
53
|
+
dot_folder = File.join(Dir.home, Butterfly::DOTFOLDER)
|
54
|
+
Dir.mkdir(dot_folder) if !Dir.exists?(dot_folder)
|
55
|
+
|
56
|
+
|
57
|
+
generator_group = ARGV[0]
|
58
|
+
generator_type = ARGV[1]
|
59
|
+
generator_type_folder = File.join(dot_folder, "#{generator_group}_generators", generator_type)
|
60
|
+
|
61
|
+
if !Dir.exists?(generator_type_folder)
|
62
|
+
stub_generator = RubiGen::PathSource.new(:app, File.dirname(__FILE__) + "/../lib/stub_generators")
|
63
|
+
RubiGen::Base.prepend_sources(stub_generator)
|
64
|
+
RubiGen::Scripts::Generate.new.run([generator_type_folder], :generator => 'stub')
|
65
|
+
else
|
66
|
+
raise Butterfly::GeneratorFolderExists, "#{RED}generator '#{generator_group}_generators/#{generator_type}' does already exist!#{WHITE}"
|
67
|
+
end
|
68
|
+
exit
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
|
41
73
|
# After parsing the options,
|
42
74
|
# * first argument should be <generator-group>
|
43
75
|
# * second argument should be <generator-type>
|
@@ -98,13 +130,6 @@ end
|
|
98
130
|
project_name = ARGV[0]
|
99
131
|
|
100
132
|
|
101
|
-
# DEBUG
|
102
|
-
#puts "generator group: #{generator_group}"
|
103
|
-
#puts "generator type: #{generator_type}"
|
104
|
-
#puts "project name: #{project_name}"
|
105
|
-
#puts "options: #{options}"
|
106
|
-
|
107
|
-
|
108
133
|
### generate code!
|
109
134
|
|
110
135
|
# Add only the code generator of the selected generator-group to the beginning of a list of sources.
|
data/lepidoptera.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{lepidoptera}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Thomas Duerr"]
|
12
|
-
s.date = %q{2010-11-
|
12
|
+
s.date = %q{2010-11-10}
|
13
13
|
s.default_executable = %q{lep}
|
14
14
|
s.description = %q{Lepidoptera is a very simple and easy extensible code generator for common every day projects.}
|
15
15
|
s.email = %q{thomduerr@gmail.com}
|
@@ -43,7 +43,12 @@ Gem::Specification.new do |s|
|
|
43
43
|
"lepidoptera.gemspec",
|
44
44
|
"lib/base.rb",
|
45
45
|
"lib/butterfly.rb",
|
46
|
-
"lib/options.rb"
|
46
|
+
"lib/options.rb",
|
47
|
+
"lib/stub_generators/stub/INFO",
|
48
|
+
"lib/stub_generators/stub/stub_generator.rb",
|
49
|
+
"lib/stub_generators/stub/templates/generator-type_INFO",
|
50
|
+
"lib/stub_generators/stub/templates/generator-type_README.txt",
|
51
|
+
"lib/stub_generators/stub/templates/generator-type_generator.rb"
|
47
52
|
]
|
48
53
|
s.homepage = %q{http://github.com/thomd/lepidoptera/}
|
49
54
|
s.rdoc_options = ["--charset=UTF-8"]
|
data/lib/base.rb
CHANGED
@@ -45,4 +45,33 @@ module Butterfly
|
|
45
45
|
|
46
46
|
end
|
47
47
|
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
module Butterfly
|
52
|
+
module Stub
|
53
|
+
|
54
|
+
# extend Base class wwith base functionality for the code stub generator generator
|
55
|
+
class Base < RubiGen::Base
|
56
|
+
|
57
|
+
attr_reader :target, :name, :author, :group, :date
|
58
|
+
|
59
|
+
def initialize(runtime_args, runtime_options = {})
|
60
|
+
super
|
61
|
+
@destination_root = File.expand_path(args.shift)
|
62
|
+
@name = base_name
|
63
|
+
@author = ENV['USER']
|
64
|
+
@target = @destination_root
|
65
|
+
@group = @destination_root.match(/\/(\w+)_generators\//)[1]
|
66
|
+
@date = Time.now.strftime("%Y-%m-%d")
|
67
|
+
end
|
68
|
+
|
69
|
+
# do some final things after generation
|
70
|
+
def after_generate
|
71
|
+
info = File.read(File.join(spec.path, 'INFO')) rescue ''
|
72
|
+
template = ERB.new(info, nil, '<>')
|
73
|
+
puts "\n#{template.result(binding)}"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
48
77
|
end
|
data/lib/butterfly.rb
CHANGED
@@ -7,20 +7,26 @@ require 'rubigen'
|
|
7
7
|
module Butterfly
|
8
8
|
|
9
9
|
# Current version
|
10
|
-
VERSION = '0.
|
10
|
+
VERSION = '0.3.0'
|
11
|
+
|
12
|
+
# local lepidoptera folder
|
13
|
+
DOTFOLDER = '.lepidoptera'
|
11
14
|
|
12
15
|
# path of build-in code generators
|
13
|
-
|
16
|
+
GENERATOR_GROUPS = File.join(File.dirname(__FILE__), '..', '*_generators')
|
14
17
|
|
15
|
-
# path of user code
|
16
|
-
|
18
|
+
# path of user code generator groups
|
19
|
+
USER_GROUPS = File.join(Dir.home, DOTFOLDER, '*_generators')
|
17
20
|
|
18
21
|
|
19
22
|
# Error handling
|
20
23
|
class GeneratorError < StandardError
|
21
24
|
end
|
22
25
|
|
23
|
-
class GeneratorSourceMissingError <
|
26
|
+
class GeneratorSourceMissingError < GeneratorError
|
27
|
+
end
|
28
|
+
|
29
|
+
class GeneratorFolderExists < GeneratorError
|
24
30
|
end
|
25
31
|
|
26
32
|
|
@@ -32,8 +38,8 @@ module Butterfly
|
|
32
38
|
def initialize
|
33
39
|
@generators = []
|
34
40
|
|
35
|
-
# loop through build in code
|
36
|
-
[
|
41
|
+
# loop through build in code generator groups and user code generator groups
|
42
|
+
[GENERATOR_GROUPS, USER_GROUPS].each do |path|
|
37
43
|
Dir[path].each do |file|
|
38
44
|
@generators.push(GeneratorGroup.new(file)) if File.directory?(file)
|
39
45
|
end
|
@@ -74,13 +80,12 @@ module Butterfly
|
|
74
80
|
# a generator-group contains a generator name, its path and its generator-types
|
75
81
|
class GeneratorGroup
|
76
82
|
|
77
|
-
attr_accessor :name, :source, :types
|
83
|
+
attr_accessor :name, :source, :types
|
78
84
|
|
79
85
|
def initialize(file)
|
80
86
|
@name = File.basename(file).gsub(/_generators$/, '')
|
81
87
|
@source = RubiGen::PathSource.new(:app, file)
|
82
88
|
@types = @source.names(:visible)
|
83
|
-
@label = @source.label
|
84
89
|
end
|
85
90
|
end
|
86
91
|
|
data/lib/options.rb
CHANGED
@@ -11,20 +11,24 @@ class OptionParser
|
|
11
11
|
def add_default(opts)
|
12
12
|
self.separator ""
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
self.on("-n", "--new", "Create a new code generator stub in ~/.lepidoptera") do
|
15
|
+
opts[:new] = true
|
16
|
+
end
|
17
17
|
|
18
18
|
self.on("-q", "--quiet", "Suppress status output") do
|
19
19
|
opts[:quiet] = true
|
20
20
|
end
|
21
21
|
|
22
|
-
self.on("-g", "--git","Create a git repository after code generation") do
|
22
|
+
self.on("-g", "--git", "Create a git repository after code generation") do
|
23
23
|
opts[:gitinit] = true
|
24
24
|
end
|
25
25
|
|
26
|
-
# self.on("-s", "--svn [URL]","Initial import into a given svn repository") do |url|
|
26
|
+
# self.on("-s", "--svn [URL]", "Initial import into a given svn repository") do |url|
|
27
27
|
# opts[:svnimport] = url
|
28
|
+
# end
|
29
|
+
|
30
|
+
# self.on("-l", "--list", "List all code generators") do
|
31
|
+
# opts[:list] = true
|
28
32
|
# end
|
29
33
|
|
30
34
|
self.on("-h", "--help", "Show help") do
|
@@ -107,6 +111,30 @@ module Butterfly
|
|
107
111
|
exit
|
108
112
|
end
|
109
113
|
|
114
|
+
def ask_for_new_generator
|
115
|
+
parser = OptionParser.new do |opts|
|
116
|
+
opts.banner = "Usage: #{PURPLE}#{File.basename($0)}#{WHITE} --new #{BLUE}<generator-group>#{WHITE} #{BLUE}<generator-type>#{WHITE}"
|
117
|
+
opts.separator ""
|
118
|
+
opts.define_head "Go, create a new code generator!"
|
119
|
+
opts.define_head ""
|
120
|
+
opts.separator "#{BLUE}Please enter a <generator-group> name and a <generator-type> name#{WHITE}"
|
121
|
+
end
|
122
|
+
parser.parse(["-h"])
|
123
|
+
exit
|
124
|
+
end
|
125
|
+
|
126
|
+
def ask_for_new_generator_type(generator_group)
|
127
|
+
parser = OptionParser.new do |opts|
|
128
|
+
opts.banner = "Usage: #{PURPLE}#{File.basename($0)}#{WHITE} --new #{generator_group} #{BLUE}<generator-type>#{WHITE}"
|
129
|
+
opts.separator ""
|
130
|
+
opts.define_head "Go, create a new code generator in the #{generator_group} group!"
|
131
|
+
opts.define_head ""
|
132
|
+
opts.separator "#{BLUE}Please enter a <generator-type> name#{WHITE}"
|
133
|
+
end
|
134
|
+
parser.parse(["-h"])
|
135
|
+
exit
|
136
|
+
end
|
137
|
+
|
110
138
|
end
|
111
139
|
end
|
112
140
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
----------
|
2
|
+
|
3
|
+
(1) now, copy all your template files into:
|
4
|
+
<%= target %>
|
5
|
+
|
6
|
+
(2) edit your templates and insert some placeholders.
|
7
|
+
you have the following ERB placeholders available in your templates:
|
8
|
+
|
9
|
+
<%%= group %>: name of the generator group (<%= group %>)
|
10
|
+
<%%= name %>: name of the generator (<%= name %>)
|
11
|
+
<%%= author %>: author of the project (<%= author %>)
|
12
|
+
|
13
|
+
(3) write some INFO which will then be displayed after code generation.
|
14
|
+
|
15
|
+
(4) test your new <%= name %> code generator:
|
16
|
+
$ lep <%= group %>
|
17
|
+
$ lep <%= group %> <%= name %> <project-name>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class StubGenerator < Butterfly::Stub::Base
|
2
|
+
|
3
|
+
def manifest
|
4
|
+
record do |m|
|
5
|
+
|
6
|
+
# create templates folder
|
7
|
+
m.directory "templates"
|
8
|
+
|
9
|
+
# create templates
|
10
|
+
m.template "generator-type_INFO", "INFO"
|
11
|
+
m.template "generator-type_generator.rb", "#{name}_generator.rb"
|
12
|
+
m.template "generator-type_README.txt", "templates/README.txt"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 3
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.3.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Thomas Duerr
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-11-
|
17
|
+
date: 2010-11-10 00:00:00 +01:00
|
18
18
|
default_executable: lep
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -97,6 +97,11 @@ files:
|
|
97
97
|
- lib/base.rb
|
98
98
|
- lib/butterfly.rb
|
99
99
|
- lib/options.rb
|
100
|
+
- lib/stub_generators/stub/INFO
|
101
|
+
- lib/stub_generators/stub/stub_generator.rb
|
102
|
+
- lib/stub_generators/stub/templates/generator-type_INFO
|
103
|
+
- lib/stub_generators/stub/templates/generator-type_README.txt
|
104
|
+
- lib/stub_generators/stub/templates/generator-type_generator.rb
|
100
105
|
has_rdoc: true
|
101
106
|
homepage: http://github.com/thomd/lepidoptera/
|
102
107
|
licenses: []
|