template_builder 0.1.0
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.
- data/History.txt +4 -0
- data/README.txt +46 -0
- data/Rakefile +18 -0
- data/bin/template_builder +13 -0
- data/conf/authentication.yml +22 -0
- data/conf/css.yml +17 -0
- data/conf/database.yml +21 -0
- data/conf/integration_testing.yml +9 -0
- data/conf/javascript.yml +14 -0
- data/conf/orm.yml +59 -0
- data/conf/parameter_file.yml +27 -0
- data/conf/templating.yml +25 -0
- data/conf/unit_testing.yml +10 -0
- data/lib/template_builder/app/command.rb +211 -0
- data/lib/template_builder/app/file_analyzer.rb +90 -0
- data/lib/template_builder/app/file_manager.rb +73 -0
- data/lib/template_builder/app/helper/framework.rb +49 -0
- data/lib/template_builder/app/helper/parameter.rb +10 -0
- data/lib/template_builder/app/new.rb +63 -0
- data/lib/template_builder/app/show.rb +58 -0
- data/lib/template_builder/app.rb +118 -0
- data/lib/template_builder.rb +67 -0
- data/test/test_template_builder.rb +0 -0
- data/version.txt +1 -0
- metadata +109 -0
data/History.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
template_builder
|
2
|
+
by Anthony Laibe
|
3
|
+
https://github.com/alaibe/template_builder
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Generate a template for your ruby on rails project
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
|
12
|
+
== SYNOPSIS:
|
13
|
+
|
14
|
+
template_builder foo
|
15
|
+
|
16
|
+
== REQUIREMENTS:
|
17
|
+
|
18
|
+
|
19
|
+
== INSTALL:
|
20
|
+
|
21
|
+
gem install template_builder
|
22
|
+
|
23
|
+
== LICENSE:
|
24
|
+
|
25
|
+
(The MIT License)
|
26
|
+
|
27
|
+
Copyright (c) 2009
|
28
|
+
|
29
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
30
|
+
a copy of this software and associated documentation files (the
|
31
|
+
'Software'), to deal in the Software without restriction, including
|
32
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
33
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
34
|
+
permit persons to whom the Software is furnished to do so, subject to
|
35
|
+
the following conditions:
|
36
|
+
|
37
|
+
The above copyright notice and this permission notice shall be
|
38
|
+
included in all copies or substantial portions of the Software.
|
39
|
+
|
40
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
41
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
42
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
43
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
44
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
45
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
46
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
begin
|
3
|
+
require 'bones'
|
4
|
+
rescue LoadError
|
5
|
+
abort '### Please install the "bones" gem ###'
|
6
|
+
end
|
7
|
+
|
8
|
+
task :default => 'test:run'
|
9
|
+
task 'gem:release' => 'test:run'
|
10
|
+
|
11
|
+
Bones {
|
12
|
+
name 'template_builder'
|
13
|
+
authors 'Anthony'
|
14
|
+
email 'anthony.laibe@gmail.com'
|
15
|
+
url 'https://github.com/alaibe/template_builder'
|
16
|
+
ignore_file '.gitignore'
|
17
|
+
}
|
18
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
4
|
+
|
5
|
+
begin
|
6
|
+
require File.join(root, %w[lib template_builder])
|
7
|
+
rescue LoadError
|
8
|
+
require 'template_builder'
|
9
|
+
end
|
10
|
+
|
11
|
+
TemplateBuilder::App.initialize_plugins
|
12
|
+
TemplateBuilder::App.run
|
13
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
devise :
|
2
|
+
devise :
|
3
|
+
version :
|
4
|
+
source :
|
5
|
+
command :
|
6
|
+
action : [generate 'devise:install',
|
7
|
+
"case template['orm']\n
|
8
|
+
when 'mongo_mapper'\n
|
9
|
+
gem 'mm-devise'\n
|
10
|
+
gsub_file 'config/intializers/devise.rb', 'devise/orm/active_record', 'devise/orm/mongo_mapper_active_model'\n
|
11
|
+
when 'mongoid'\n
|
12
|
+
gsub_file 'config/intializers/devise.rb', 'devise/orm/active_record', 'devise/orm/mongoid'\n
|
13
|
+
when 'active_record'\n\n",
|
14
|
+
generate 'devise user']
|
15
|
+
|
16
|
+
omniauth :
|
17
|
+
omniauth :
|
18
|
+
version :
|
19
|
+
source :
|
20
|
+
command :
|
21
|
+
action : ["file \"app/controllers/sessions_controller.rb\", \"class SessionsController < ApplicationController\n def callback\n auth \n end\n\n def auth; request.env['omniauth'] end\nend\"",
|
22
|
+
"route \"match '/auth/:provider/callback', :to => 'sessions#callback'\""]
|
data/conf/css.yml
ADDED
data/conf/database.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
sqlite :
|
2
|
+
command : sqlite3
|
3
|
+
action : []
|
4
|
+
oracle :
|
5
|
+
command : -d oracle
|
6
|
+
action : []
|
7
|
+
mongo :
|
8
|
+
command :
|
9
|
+
action : []
|
10
|
+
ibm_db :
|
11
|
+
command : -d ibm_db
|
12
|
+
action : []
|
13
|
+
redis :
|
14
|
+
command :
|
15
|
+
action : []
|
16
|
+
postgres :
|
17
|
+
command : -d postgresql
|
18
|
+
action : []
|
19
|
+
mysql :
|
20
|
+
command : -d mysql
|
21
|
+
action : []
|
data/conf/javascript.yml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
prototype :
|
2
|
+
command :
|
3
|
+
action : []
|
4
|
+
|
5
|
+
jquery :
|
6
|
+
command : -J
|
7
|
+
action : ['get "https://github.com/rails/jquery-ujs/raw/master/src/rails.js" , "public/javascript/rails.js"',
|
8
|
+
'get http://code.jquery.com/jquery-1.4.2.min.js, "public/javascript/jquery.js"']
|
9
|
+
|
10
|
+
mootools :
|
11
|
+
command : -J
|
12
|
+
action : ['get http://ajax.googleapis.com/ajax/libs/mootools/1.2.5/mootools-yui-compressed.js, "public/javascript/mootools.js"',
|
13
|
+
'get https://github.com/kevinvaldek/mootools-ujs/raw/master/Source/rails.js, "public/javascript/rails.js"',
|
14
|
+
'gsub_file "config/application.rb", "jquery", "mootools"']
|
data/conf/orm.yml
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
active_record :
|
2
|
+
command :
|
3
|
+
action : []
|
4
|
+
|
5
|
+
data_mapper:
|
6
|
+
dm-migrations:
|
7
|
+
version :
|
8
|
+
source :
|
9
|
+
dm-types:
|
10
|
+
version :
|
11
|
+
source :
|
12
|
+
dm-validations:
|
13
|
+
version :
|
14
|
+
source :
|
15
|
+
dm-constraints:
|
16
|
+
version :
|
17
|
+
source :
|
18
|
+
dm-transactions:
|
19
|
+
version :
|
20
|
+
source :
|
21
|
+
dm-aggregates:
|
22
|
+
version :
|
23
|
+
source :
|
24
|
+
dm-timestamps:
|
25
|
+
version :
|
26
|
+
source :
|
27
|
+
dm-observer:
|
28
|
+
version :
|
29
|
+
source :
|
30
|
+
command : -O
|
31
|
+
action : []
|
32
|
+
|
33
|
+
mongo_mapper :
|
34
|
+
mongo_mapper-rails3 :
|
35
|
+
version :
|
36
|
+
source :
|
37
|
+
action : gsub_file 'config/initializers/session_store.rb', 'active_record_store', 'mongo_mapper_store'
|
38
|
+
bson_ext :
|
39
|
+
version :
|
40
|
+
source :
|
41
|
+
mongo_mapper :
|
42
|
+
source :
|
43
|
+
version :
|
44
|
+
command : -O
|
45
|
+
action : [generate 'mongo_mapper:config']
|
46
|
+
|
47
|
+
mongoid :
|
48
|
+
mongoid :
|
49
|
+
version : >= 2.0.0.beta.19
|
50
|
+
source :
|
51
|
+
bson_ext :
|
52
|
+
version :
|
53
|
+
source :
|
54
|
+
mongo_session_store :
|
55
|
+
source :
|
56
|
+
version :
|
57
|
+
action : gsub_file 'config/initializers/session_store.rb', 'active_record_store', 'mongoid_store'
|
58
|
+
command : -O
|
59
|
+
action : [generate 'mongoid:config']
|
@@ -0,0 +1,27 @@
|
|
1
|
+
database :
|
2
|
+
help : set the database you want to use
|
3
|
+
priority : 1
|
4
|
+
orm :
|
5
|
+
help : set the orm framework you want to use
|
6
|
+
priority : 2
|
7
|
+
javascript :
|
8
|
+
help : set the javascript framework you want to use
|
9
|
+
priority : 2
|
10
|
+
templating :
|
11
|
+
help : set the templating framework you want to use
|
12
|
+
priority : 2
|
13
|
+
css :
|
14
|
+
help : set the css framework you want to use
|
15
|
+
priority : 2
|
16
|
+
unit_testing :
|
17
|
+
help : set the unit testing framework you want to use
|
18
|
+
priority : 3
|
19
|
+
integration_testing :
|
20
|
+
help : set the integration testing framework you want to use
|
21
|
+
priority : 3
|
22
|
+
authentication :
|
23
|
+
help : set the authentication framework you want to use
|
24
|
+
priority : 4
|
25
|
+
|
26
|
+
|
27
|
+
|
data/conf/templating.yml
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
erb :
|
2
|
+
command :
|
3
|
+
action : []
|
4
|
+
haml :
|
5
|
+
haml:
|
6
|
+
version : >= 3.0.0
|
7
|
+
source :
|
8
|
+
haml-rails :
|
9
|
+
version :
|
10
|
+
source :
|
11
|
+
rails3-generators :
|
12
|
+
version :
|
13
|
+
source : git => 'git://github.com/indirect/rails3-generators.git'
|
14
|
+
command :
|
15
|
+
action : []
|
16
|
+
|
17
|
+
slim :
|
18
|
+
slim:
|
19
|
+
version :
|
20
|
+
source :
|
21
|
+
slim-rails :
|
22
|
+
version :
|
23
|
+
source :
|
24
|
+
command :
|
25
|
+
action : []
|
@@ -0,0 +1,211 @@
|
|
1
|
+
|
2
|
+
module TemplateBuilder::App
|
3
|
+
class Command
|
4
|
+
|
5
|
+
# :startdoc:
|
6
|
+
attr_reader :stdout
|
7
|
+
attr_reader :stderr
|
8
|
+
attr_reader :config
|
9
|
+
|
10
|
+
def initialize( opts = {} )
|
11
|
+
@stdout = opts[:stdout] || $stdout
|
12
|
+
@stderr = opts[:stderr] || $stderr
|
13
|
+
|
14
|
+
@config = {:name => nil, :force => nil, :verbose =>nil}
|
15
|
+
@config_param = {}
|
16
|
+
@command = []
|
17
|
+
standard_parameters.each_key{ |key| @config_param[key] = TemplateBuilder::App::Helper::Parameter.new(:priority=>priority(key)) }
|
18
|
+
end
|
19
|
+
|
20
|
+
def run( args )
|
21
|
+
raise NotImplementedError
|
22
|
+
end
|
23
|
+
|
24
|
+
def priority(key)
|
25
|
+
FileAnalyzer.load_priority key
|
26
|
+
end
|
27
|
+
# The project name from the command line.
|
28
|
+
#
|
29
|
+
def name
|
30
|
+
@config[:name]
|
31
|
+
end
|
32
|
+
|
33
|
+
def force
|
34
|
+
@config[:force]
|
35
|
+
end
|
36
|
+
|
37
|
+
# Returns +true+ if the user has requested verbose messages.
|
38
|
+
#
|
39
|
+
def verbose?
|
40
|
+
@config[:verbose]
|
41
|
+
end
|
42
|
+
#
|
43
|
+
#
|
44
|
+
def standard_options
|
45
|
+
Command.standard_options
|
46
|
+
end
|
47
|
+
|
48
|
+
def standard_parameters
|
49
|
+
Command.standard_parameters
|
50
|
+
end
|
51
|
+
|
52
|
+
#
|
53
|
+
#
|
54
|
+
def parse( args )
|
55
|
+
opts = OptionParser.new
|
56
|
+
|
57
|
+
opts.banner = 'NAME'
|
58
|
+
opts.separator " template_builder v#{::TemplateBuilder.version}"
|
59
|
+
opts.separator ''
|
60
|
+
if self.class.synopsis
|
61
|
+
opts.separator 'SYNOPSIS'
|
62
|
+
self.class.synopsis.split("\n").each { |line| opts.separator " #{line.strip}" }
|
63
|
+
opts.separator ''
|
64
|
+
end
|
65
|
+
|
66
|
+
if self.class.description
|
67
|
+
opts.separator 'DESCRIPTION'
|
68
|
+
self.class.description.split("\n").each { |line| opts.separator " #{line.strip}" }
|
69
|
+
opts.separator ''
|
70
|
+
end
|
71
|
+
if self.class.parameters and not self.class.parameters.empty?
|
72
|
+
opts.separator 'PARAMETER'
|
73
|
+
self.class.parameters.each { |parameter|
|
74
|
+
case parameter
|
75
|
+
when Array
|
76
|
+
parameter << method(parameter.pop) if parameter.last =~ %r/^__/
|
77
|
+
opts.on(*parameter)
|
78
|
+
when String
|
79
|
+
opts.separator(" #{parameter.strip}")
|
80
|
+
else opts.separator('') end
|
81
|
+
}
|
82
|
+
opts.separator ''
|
83
|
+
end
|
84
|
+
if self.class.options and not self.class.options.empty?
|
85
|
+
opts.separator 'OPTION'
|
86
|
+
self.class.options.each { |option|
|
87
|
+
case option
|
88
|
+
when Array
|
89
|
+
option << method(option.pop) if option.last =~ %r/^__/
|
90
|
+
opts.on(*option)
|
91
|
+
when String
|
92
|
+
opts.separator(" #{option.strip}")
|
93
|
+
else opts.separator('') end
|
94
|
+
}
|
95
|
+
opts.separator ''
|
96
|
+
end
|
97
|
+
opts.separator ' Common Options:'
|
98
|
+
opts.on_tail( '-h', '--help', 'show this message' ) {
|
99
|
+
stdout.puts opts
|
100
|
+
exit
|
101
|
+
}
|
102
|
+
opts.on_tail ''
|
103
|
+
opts.parse! args
|
104
|
+
return opts
|
105
|
+
end
|
106
|
+
|
107
|
+
#
|
108
|
+
#
|
109
|
+
def self.standard_options
|
110
|
+
@standard_options = {:verbose => ['-v', '--verbose', 'Enable verbose output.',
|
111
|
+
lambda { config[:verbose] = true }],
|
112
|
+
:force => ['-f', '--force', 'Force creating file.',
|
113
|
+
lambda { config[:force] = true }] }
|
114
|
+
end
|
115
|
+
|
116
|
+
def self.standard_parameters
|
117
|
+
return @standard_parameters if @standard_parameters
|
118
|
+
@standard_parameters = FileAnalyzer.load_standard_parameters
|
119
|
+
@standard_parameters
|
120
|
+
end
|
121
|
+
|
122
|
+
def ask_for(framework_name)
|
123
|
+
all_frameworks = FileAnalyzer.all_frameworks_for framework_name
|
124
|
+
puts "Choose your "+framework_name.to_s+" framework ? (enter 0 for none)"
|
125
|
+
until @config_param[framework_name].name
|
126
|
+
all_frameworks.each_with_index{ |value,index| puts "("+(index+1).to_s+") "+value.to_s+"\r\n" }
|
127
|
+
answer = STDIN.gets
|
128
|
+
@config_param[framework_name].name = all_frameworks[answer.to_i-1] if (1..all_frameworks.length).include? answer.to_i
|
129
|
+
@config_param[framework_name] = "none" if 0 == answer
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
133
|
+
|
134
|
+
def run_framework(fileManager, opts = {})
|
135
|
+
framework = FileAnalyzer.load_framework opts
|
136
|
+
fileManager.write_framework_introduction opts[:name]
|
137
|
+
framework.run fileManager
|
138
|
+
special_case_data_mapper fileManager if @config_param[:orm].name == "data_mapper"
|
139
|
+
@command << framework.command
|
140
|
+
end
|
141
|
+
|
142
|
+
def special_case_data_mapper(fileManager)
|
143
|
+
fileManager.write "gem 'dm-"+@config_param[:database].name.to_s+"-adapter'"
|
144
|
+
end
|
145
|
+
|
146
|
+
module ClassMethods
|
147
|
+
def synopsis( *args )
|
148
|
+
@synopsis = args.join("\n") unless args.empty?
|
149
|
+
@synopsis
|
150
|
+
end
|
151
|
+
|
152
|
+
def description( *args )
|
153
|
+
@description = args.join("\n") unless args.empty?
|
154
|
+
@description
|
155
|
+
end
|
156
|
+
|
157
|
+
def summary( *args )
|
158
|
+
@summary = args.join("\n") unless args.empty?
|
159
|
+
@summary
|
160
|
+
end
|
161
|
+
|
162
|
+
def option( *args, &block )
|
163
|
+
args.flatten!
|
164
|
+
block = args.pop if block.nil? and Proc === args.last
|
165
|
+
if block
|
166
|
+
args.each { |val|
|
167
|
+
next unless val.instance_of? String
|
168
|
+
next unless val =~ %r/^--(\w+)/
|
169
|
+
args << "__#$1"
|
170
|
+
define_method(args.last.to_sym, &block)
|
171
|
+
options << args
|
172
|
+
break
|
173
|
+
}
|
174
|
+
else
|
175
|
+
options << (args.length > 1 ? args : args.first )
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
def parameter(*args)
|
180
|
+
args.flatten!
|
181
|
+
block = args.pop if block.nil? and Proc === args.last
|
182
|
+
if block
|
183
|
+
args.each { |val|
|
184
|
+
next unless val.instance_of? String
|
185
|
+
next unless val =~ %r/^--(\w+)/
|
186
|
+
args << "__#$1"
|
187
|
+
define_method(args.last.to_sym, &block)
|
188
|
+
parameters << args
|
189
|
+
break
|
190
|
+
}
|
191
|
+
else
|
192
|
+
parameters << (args.length > 1 ? args : args.first )
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
def parameters
|
197
|
+
@parameters ||= []
|
198
|
+
end
|
199
|
+
|
200
|
+
def options
|
201
|
+
@options ||= []
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
def self.inherited( other )
|
206
|
+
other.extend ClassMethods
|
207
|
+
end
|
208
|
+
|
209
|
+
end # class TemplateBuilder::App::Command
|
210
|
+
end
|
211
|
+
# EOF
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require "singleton"
|
2
|
+
|
3
|
+
module TemplateBuilder::App::FileAnalyzer
|
4
|
+
|
5
|
+
def self.load_standard_parameters
|
6
|
+
FileParameter.instance.parameters
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.all_parameters
|
10
|
+
FileParameter.instance.parameters_names
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.load_priority(type_name)
|
14
|
+
FileParameter.instance.priority type_name
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.load_conf_file(file_name)
|
18
|
+
YAML.load_file(File.join(TemplateBuilder::PATH,"/conf/"+file_name.to_s+".yml"))
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.all_frameworks_for(name)
|
22
|
+
FileFramework.new(name).all_frameworks
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.load_framework(opts = {})
|
26
|
+
FileFramework.new(opts[:type]).load_framework opts[:name]
|
27
|
+
end
|
28
|
+
|
29
|
+
class FileParameter
|
30
|
+
include Singleton
|
31
|
+
|
32
|
+
attr_reader :parameters
|
33
|
+
|
34
|
+
def initialize
|
35
|
+
@parameters = {}
|
36
|
+
load_conf_file
|
37
|
+
analyse_file
|
38
|
+
end
|
39
|
+
|
40
|
+
def analyse_file
|
41
|
+
@config_file.each{ |k,v| @parameters[k.to_sym] = ["-#{k[0..0].to_s}", "--#{k} FRAMEWORK", "#{v['help'].capitalize} .",
|
42
|
+
lambda { |item| @config_param[k.to_sym] = Parameter.new :priority=>0,:name=>item }] }
|
43
|
+
end
|
44
|
+
|
45
|
+
def load_conf_file
|
46
|
+
@config_file = TemplateBuilder::App::FileAnalyzer.load_conf_file "parameter_file"
|
47
|
+
end
|
48
|
+
|
49
|
+
def parameters_names
|
50
|
+
@parameters.each_key.to_a
|
51
|
+
end
|
52
|
+
|
53
|
+
def priority(type_name)
|
54
|
+
@config_file[type_name.to_s]["priority"]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class FileFramework
|
59
|
+
|
60
|
+
def initialize(args)
|
61
|
+
@name = args
|
62
|
+
load_conf_file
|
63
|
+
end
|
64
|
+
|
65
|
+
def all_frameworks
|
66
|
+
@config_file.each_key.to_a
|
67
|
+
end
|
68
|
+
|
69
|
+
def load_conf_file
|
70
|
+
@config_file = TemplateBuilder::App::FileAnalyzer.load_conf_file @name
|
71
|
+
end
|
72
|
+
|
73
|
+
def load_framework(name)
|
74
|
+
opts = {:name => name, :gems =>[]}
|
75
|
+
puts name
|
76
|
+
@config_file[name].each do |key, value|
|
77
|
+
if ["command","action"].include? key
|
78
|
+
opts[key.to_sym] = value
|
79
|
+
else
|
80
|
+
gem = {:name => key}
|
81
|
+
value.each {|key,value| gem[key.to_sym] = value}
|
82
|
+
opts[:gems] << gem
|
83
|
+
end
|
84
|
+
end
|
85
|
+
TemplateBuilder::App::Helper.framework_factory opts
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module TemplateBuilder::App
|
2
|
+
class FileManager
|
3
|
+
|
4
|
+
Error = Class.new(StandardError)
|
5
|
+
|
6
|
+
attr_accessor :file, :verbose, :file_name
|
7
|
+
alias :verbose? :verbose
|
8
|
+
|
9
|
+
def initialize( opts = {} )
|
10
|
+
self.file_name = opts[:file]
|
11
|
+
self.verbose = opts[:verbose]
|
12
|
+
self.file = File.new(self.file_name, "w+")
|
13
|
+
@out = opts[:stdout] || $stdout
|
14
|
+
@err = opts[:stderr] || $stderr
|
15
|
+
end
|
16
|
+
|
17
|
+
def start_file(config_file)
|
18
|
+
write "# This template was generated by template_builder, the amazing and awesome Rails
|
19
|
+
# application builder.
|
20
|
+
#
|
21
|
+
initializer 'generators.rb', <<-RUBY
|
22
|
+
Rails.application.config.generators do |g|
|
23
|
+
end
|
24
|
+
RUBY"
|
25
|
+
|
26
|
+
template = "template = {"
|
27
|
+
config_file.each do |key, value|
|
28
|
+
template += "'"+key.to_s+"'=>'"+value.name+"',"
|
29
|
+
end
|
30
|
+
write template[0..template.length-2]+"}"
|
31
|
+
|
32
|
+
write"recipes = template.values.flatten
|
33
|
+
|
34
|
+
@after = []
|
35
|
+
def after_bundler(&block); @after << block; end"
|
36
|
+
end
|
37
|
+
|
38
|
+
def end_file(name, command)
|
39
|
+
write "
|
40
|
+
# >-----------------------------[ Run Bundler ]-------------------------------<
|
41
|
+
|
42
|
+
say 'Running Bundler install. This will take a while.'
|
43
|
+
run 'bundle install'
|
44
|
+
say 'Running after Bundler callbacks.'
|
45
|
+
@after.each{|b| b.call}
|
46
|
+
|
47
|
+
# >---------------------------[ Install Command ]-----------------------------<
|
48
|
+
# rails new APP_NAME -m "+name+" "+command.to_s+" -f
|
49
|
+
# >---------------------------------------------------------------------------<"
|
50
|
+
end
|
51
|
+
|
52
|
+
def write(content)
|
53
|
+
self.file.write content+"\n"
|
54
|
+
end
|
55
|
+
|
56
|
+
def write_gem(gem)
|
57
|
+
write "gem "+gem
|
58
|
+
end
|
59
|
+
|
60
|
+
def write_action(action)
|
61
|
+
write "after_bundler do\n"
|
62
|
+
action.each{ |act| write "\t"+act.to_s }
|
63
|
+
write "end"
|
64
|
+
end
|
65
|
+
|
66
|
+
def write_framework_introduction(name)
|
67
|
+
write "
|
68
|
+
# ---------------------------------------------------------------------------
|
69
|
+
# >----------------------------[ "+name+"]------------------------------<"
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
|
2
|
+
module TemplateBuilder::App::Helper
|
3
|
+
|
4
|
+
def self.framework_factory(opts = {})
|
5
|
+
gems = []
|
6
|
+
opts[:gems].each { |gem| gems<< Gem.new(gem) }
|
7
|
+
opts[:gems] = gems
|
8
|
+
Framework.new opts
|
9
|
+
end
|
10
|
+
|
11
|
+
class Framework
|
12
|
+
attr_reader :command
|
13
|
+
def initialize(opts = {})
|
14
|
+
@name = opts[:name]
|
15
|
+
@gems = opts[:gems]
|
16
|
+
@action = opts[:action]
|
17
|
+
@command = opts[:command]
|
18
|
+
end
|
19
|
+
|
20
|
+
def run(fileManager)
|
21
|
+
@gems.each { |gem| fileManager.write_gem gem.to_s }
|
22
|
+
fileManager.write_action action if action.length>0
|
23
|
+
end
|
24
|
+
|
25
|
+
def action
|
26
|
+
ret = []
|
27
|
+
@gems.each { |gem| ret << gem.action if gem.action}
|
28
|
+
@action.each { |act| ret << act if act}
|
29
|
+
ret
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class Gem
|
34
|
+
attr_reader :action
|
35
|
+
def initialize(opts = {})
|
36
|
+
@version = opts[:version]
|
37
|
+
@source = opts[:source]
|
38
|
+
@name = opts[:name]
|
39
|
+
@action = opts[:action]
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_s
|
43
|
+
gem = "'"+@name+"'"
|
44
|
+
gem += ", '"+@version+"'" if @version
|
45
|
+
gem += ", :"+@source+"" if @source
|
46
|
+
gem
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
|
2
|
+
module TemplateBuilder::App
|
3
|
+
class New < Command
|
4
|
+
|
5
|
+
def self.initialize_new
|
6
|
+
synopsis 'template_builder new [name] [parameter type parameter type] [options]'
|
7
|
+
|
8
|
+
summary 'create a new template for your rails application.'
|
9
|
+
|
10
|
+
description <<-__
|
11
|
+
create a new template for your rails application. You can add a lot
|
12
|
+
of option as the database, the javascript framework etc ..
|
13
|
+
__
|
14
|
+
|
15
|
+
FileAnalyzer.all_parameters.each {|item|
|
16
|
+
parameter(standard_parameters[item])
|
17
|
+
}
|
18
|
+
option(standard_options[:verbose])
|
19
|
+
option(standard_options[:force])
|
20
|
+
end
|
21
|
+
|
22
|
+
def run
|
23
|
+
raise Error, "File #{name} already exists." if !force and test ?e, name
|
24
|
+
file_manager = FileManager.new(
|
25
|
+
:file => name,
|
26
|
+
:stdout => stdout,
|
27
|
+
:stderr => stderr,
|
28
|
+
:verbose => verbose?
|
29
|
+
)
|
30
|
+
announce
|
31
|
+
sorted_param = @config_param.sort{|a,b| a[1].priority <=> b[1].priority }.map
|
32
|
+
sorted_param.each{ |k,v| ask_for k unless v.name }
|
33
|
+
|
34
|
+
file_manager.start_file sorted_param
|
35
|
+
|
36
|
+
sorted_param.each{ |k,v| run_framework file_manager, :type=>k, :name=>v.name unless v.name == "none"}
|
37
|
+
|
38
|
+
file_manager.end_file name, @command
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
def parse( args )
|
43
|
+
opts = super args
|
44
|
+
config[:name] = args.empty? ? nil : args.join('_')
|
45
|
+
if name.nil?
|
46
|
+
stdout.puts opts
|
47
|
+
exit 1
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def announce
|
52
|
+
complete_name = name.split("/")
|
53
|
+
file = complete_name.last
|
54
|
+
output_dir = complete_name[0..complete_name.length-2]
|
55
|
+
msg = "Created '#{file}'"
|
56
|
+
msg << " in directory '#{output_dir}'" if name.to_s != output_dir.to_s
|
57
|
+
stdout.puts msg
|
58
|
+
end
|
59
|
+
|
60
|
+
end # class Create
|
61
|
+
end # module TemplateBuilder::App
|
62
|
+
|
63
|
+
# EOF
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module TemplateBuilder::App
|
2
|
+
class Show < Command
|
3
|
+
def self.initialize_show
|
4
|
+
synopsis 'template_builder show [parameter]'
|
5
|
+
|
6
|
+
summary 'Show all kind of awesome framework available .'
|
7
|
+
|
8
|
+
description <<-__
|
9
|
+
Show all kind of awesome framework available you can use with template builder
|
10
|
+
and for each type, can show you a description of all plugin available
|
11
|
+
__
|
12
|
+
|
13
|
+
FileAnalyzer.all_parameters.each {|item|
|
14
|
+
parameter(item.to_s)
|
15
|
+
}
|
16
|
+
option(standard_options[:verbose])
|
17
|
+
option(standard_options[:force])
|
18
|
+
end
|
19
|
+
|
20
|
+
def run
|
21
|
+
# raise Error, "File #{name} doesn't exists." if !force and !test ?e, name
|
22
|
+
# file_manager = FileManager.new(
|
23
|
+
# :file => name,
|
24
|
+
# :stdout => stdout,
|
25
|
+
# :stderr => stderr,
|
26
|
+
# :verbose => verbose?
|
27
|
+
# )
|
28
|
+
# announce
|
29
|
+
# sorted_param = @config_param.sort{|a,b| a[1].priority <=> b[1].priority }.map
|
30
|
+
# sorted_param.each{ |k,v| ask_for k unless v.name }
|
31
|
+
#
|
32
|
+
# file_manager.start_file sorted_param
|
33
|
+
#
|
34
|
+
# sorted_param.each{ |k,v| run_framework file_manager, :type=>k, :name=>v.name unless v.name == "none"}
|
35
|
+
#
|
36
|
+
# file_manager.end_file name, @command
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
def parse( args )
|
41
|
+
opts = super args
|
42
|
+
config[:name] = args.empty? ? nil : args.join('_')
|
43
|
+
if name.nil?
|
44
|
+
stdout.puts opts
|
45
|
+
exit 1
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def announce
|
50
|
+
complete_name = name.split("/")
|
51
|
+
file = complete_name.last
|
52
|
+
output_dir = complete_name[0..complete_name.length-2]
|
53
|
+
msg = "Editing '#{file}'"
|
54
|
+
msg << " in directory '#{output_dir}'" if name.to_s != output_dir.to_s
|
55
|
+
stdout.puts msg
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
module TemplateBuilder::App
|
5
|
+
extend LittlePlugger(:path => 'template_builder/app', :module => TemplateBuilder::App)
|
6
|
+
|
7
|
+
disregard_plugins :command, :file_manager, :file_analyzer
|
8
|
+
|
9
|
+
Error = Class.new(StandardError)
|
10
|
+
|
11
|
+
# Create a new instance of Main, and run the +template_builder+ application given
|
12
|
+
# the command line _args_.
|
13
|
+
#
|
14
|
+
def self.run( args = nil )
|
15
|
+
args ||= ARGV.dup.map! { |v| v.dup }
|
16
|
+
::TemplateBuilder::App::Main.new.run args
|
17
|
+
end
|
18
|
+
|
19
|
+
class Main
|
20
|
+
attr_reader :stdout
|
21
|
+
attr_reader :stderr
|
22
|
+
|
23
|
+
# Create a new Main application instance. Options can be passed to
|
24
|
+
# configuret he stdout and stderr IO streams (very useful for testing).
|
25
|
+
#
|
26
|
+
def initialize( opts = {} )
|
27
|
+
opts[:stdout] ||= $stdout
|
28
|
+
opts[:stderr] ||= $stderr
|
29
|
+
|
30
|
+
@opts = opts
|
31
|
+
@stdout = opts[:stdout]
|
32
|
+
@stderr = opts[:stderr]
|
33
|
+
end
|
34
|
+
|
35
|
+
# Parse the desired user command and run that command object.
|
36
|
+
#
|
37
|
+
def run( args )
|
38
|
+
commands = []
|
39
|
+
@all_commands = ::TemplateBuilder::App.plugins
|
40
|
+
@all_commands.each { |k,v| commands << k.to_s if v < ::TemplateBuilder::App::Command }
|
41
|
+
cmd_str = args.shift
|
42
|
+
cmd = case cmd_str
|
43
|
+
when *commands
|
44
|
+
key = cmd_str.to_sym
|
45
|
+
@all_commands[key].new @opts
|
46
|
+
when nil, '-h', '--help'
|
47
|
+
help
|
48
|
+
when '-v', '--version'
|
49
|
+
stdout.puts "TemplateBuilder v#{::TemplateBuilder.version}"
|
50
|
+
else
|
51
|
+
help
|
52
|
+
raise Error, "Unknown command #{cmd_str.inspect}"
|
53
|
+
end
|
54
|
+
|
55
|
+
if cmd
|
56
|
+
cmd.parse args
|
57
|
+
cmd.run
|
58
|
+
end
|
59
|
+
|
60
|
+
# rescue TemplateBuilder::App::Error => err
|
61
|
+
# stderr.puts "ERROR: While executing template builder ..."
|
62
|
+
# stderr.puts " #{err.message}"
|
63
|
+
# exit 1
|
64
|
+
# rescue StandardError => err
|
65
|
+
# stderr.puts "ERROR: While executing template builder ... (#{err.class})"
|
66
|
+
# stderr.puts " #{err.to_s}"
|
67
|
+
# exit 1
|
68
|
+
end
|
69
|
+
|
70
|
+
# Show the toplevel Template builder help message.
|
71
|
+
#
|
72
|
+
def help
|
73
|
+
msg = <<-MSG
|
74
|
+
NAME
|
75
|
+
Template_builder v#{::TemplateBuilder.version}
|
76
|
+
|
77
|
+
DESCRIPTION
|
78
|
+
Template-builder is a handy tool that builds a template for your new Ruby
|
79
|
+
on Rails projects. The template contains all you need to build the RoR
|
80
|
+
project that you want.
|
81
|
+
|
82
|
+
Usage:
|
83
|
+
template_builder -h/--help
|
84
|
+
template_builder -v/--version
|
85
|
+
template_builder [command] [parameter type parameter type] [options]
|
86
|
+
|
87
|
+
Examples:
|
88
|
+
template_builder new <new_template_file>
|
89
|
+
template_builder edit<old_template_file>
|
90
|
+
|
91
|
+
Commands:
|
92
|
+
MSG
|
93
|
+
fmt = lambda { |cmd|
|
94
|
+
if @all_commands[cmd] < ::TemplateBuilder::App::Command
|
95
|
+
msg << " template_builder %-15s %s\n" % [cmd, @all_commands[cmd].summary]
|
96
|
+
puts msg
|
97
|
+
end
|
98
|
+
}
|
99
|
+
ary = [:new, :show]
|
100
|
+
ary.each(&fmt)
|
101
|
+
(@all_commands.keys - ary).each(&fmt)
|
102
|
+
msg.concat <<-MSG
|
103
|
+
|
104
|
+
Further Help:
|
105
|
+
Each command has a '--help' option that will provide detailed
|
106
|
+
information for that command.
|
107
|
+
|
108
|
+
http://github.com/alaibe/template_builder
|
109
|
+
|
110
|
+
MSG
|
111
|
+
|
112
|
+
stdout.puts msg
|
113
|
+
end
|
114
|
+
|
115
|
+
end # class Main
|
116
|
+
end # module Bones::App
|
117
|
+
|
118
|
+
# EOF
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'little-plugger'
|
4
|
+
|
5
|
+
module TemplateBuilder
|
6
|
+
|
7
|
+
# :stopdoc:
|
8
|
+
LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
|
9
|
+
PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
|
10
|
+
# :startdoc:
|
11
|
+
|
12
|
+
# Returns the version string for the library.
|
13
|
+
#
|
14
|
+
def self.version
|
15
|
+
@version ||= File.read(path('version.txt')).strip
|
16
|
+
end
|
17
|
+
|
18
|
+
# Returns the library path for the module. If any arguments are given,
|
19
|
+
# they will be joined to the end of the libray path using
|
20
|
+
# <tt>File.join</tt>.
|
21
|
+
#
|
22
|
+
def self.libpath( *args, &block )
|
23
|
+
rv = args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
|
24
|
+
if block
|
25
|
+
begin
|
26
|
+
$LOAD_PATH.unshift LIBPATH
|
27
|
+
rv = block.call
|
28
|
+
ensure
|
29
|
+
$LOAD_PATH.shift
|
30
|
+
end
|
31
|
+
end
|
32
|
+
return rv
|
33
|
+
end
|
34
|
+
|
35
|
+
# Returns the lpath for the module. If any arguments are given,
|
36
|
+
# they will be joined to the end of the path using
|
37
|
+
# <tt>File.join</tt>.
|
38
|
+
#
|
39
|
+
def self.path( *args, &block )
|
40
|
+
rv = args.empty? ? PATH : ::File.join(PATH, args.flatten)
|
41
|
+
if block
|
42
|
+
begin
|
43
|
+
$LOAD_PATH.unshift PATH
|
44
|
+
rv = block.call
|
45
|
+
ensure
|
46
|
+
$LOAD_PATH.shift
|
47
|
+
end
|
48
|
+
end
|
49
|
+
return rv
|
50
|
+
end
|
51
|
+
|
52
|
+
# Utility method used to require all files ending in .rb that lie in the
|
53
|
+
# directory below this file that has the same name as the filename passed
|
54
|
+
# in. Optionally, a specific _directory_ name can be passed in such that
|
55
|
+
# the _filename_ does not have to be equivalent to the directory.
|
56
|
+
#
|
57
|
+
def self.require_all_libs_relative_to( fname, dir = nil )
|
58
|
+
dir ||= ::File.basename(fname, '.*')
|
59
|
+
search_me = ::File.expand_path(
|
60
|
+
::File.join(::File.dirname(fname), dir, '**', '*.rb'))
|
61
|
+
Dir.glob(search_me).sort.each {|rb| require rb}
|
62
|
+
end
|
63
|
+
|
64
|
+
end # module TemplateBuilder
|
65
|
+
|
66
|
+
TemplateBuilder.require_all_libs_relative_to(__FILE__)
|
67
|
+
|
File without changes
|
data/version.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: template_builder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Anthony
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-12-20 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: bones
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 17
|
30
|
+
segments:
|
31
|
+
- 3
|
32
|
+
- 5
|
33
|
+
- 1
|
34
|
+
version: 3.5.1
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
description: Generate a template for your ruby on rails project
|
38
|
+
email: anthony.laibe@gmail.com
|
39
|
+
executables:
|
40
|
+
- template_builder
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files:
|
44
|
+
- History.txt
|
45
|
+
- README.txt
|
46
|
+
- bin/template_builder
|
47
|
+
- version.txt
|
48
|
+
files:
|
49
|
+
- History.txt
|
50
|
+
- README.txt
|
51
|
+
- Rakefile
|
52
|
+
- bin/template_builder
|
53
|
+
- conf/authentication.yml
|
54
|
+
- conf/css.yml
|
55
|
+
- conf/database.yml
|
56
|
+
- conf/integration_testing.yml
|
57
|
+
- conf/javascript.yml
|
58
|
+
- conf/orm.yml
|
59
|
+
- conf/parameter_file.yml
|
60
|
+
- conf/templating.yml
|
61
|
+
- conf/unit_testing.yml
|
62
|
+
- lib/template_builder.rb
|
63
|
+
- lib/template_builder/app.rb
|
64
|
+
- lib/template_builder/app/command.rb
|
65
|
+
- lib/template_builder/app/file_analyzer.rb
|
66
|
+
- lib/template_builder/app/file_manager.rb
|
67
|
+
- lib/template_builder/app/helper/framework.rb
|
68
|
+
- lib/template_builder/app/helper/parameter.rb
|
69
|
+
- lib/template_builder/app/new.rb
|
70
|
+
- lib/template_builder/app/show.rb
|
71
|
+
- version.txt
|
72
|
+
- test/test_template_builder.rb
|
73
|
+
has_rdoc: true
|
74
|
+
homepage: https://github.com/alaibe/template_builder
|
75
|
+
licenses: []
|
76
|
+
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options:
|
79
|
+
- --main
|
80
|
+
- README.txt
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
hash: 3
|
89
|
+
segments:
|
90
|
+
- 0
|
91
|
+
version: "0"
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
hash: 3
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
version: "0"
|
101
|
+
requirements: []
|
102
|
+
|
103
|
+
rubyforge_project: template_builder
|
104
|
+
rubygems_version: 1.3.7
|
105
|
+
signing_key:
|
106
|
+
specification_version: 3
|
107
|
+
summary: Generate a template for your ruby on rails project
|
108
|
+
test_files:
|
109
|
+
- test/test_template_builder.rb
|