mack 0.4.6 → 0.4.7
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +16 -0
- data/bin/mack +5 -43
- data/lib/errors/errors.rb +3 -0
- data/lib/generators/genosaurus_helpers.rb +38 -0
- data/lib/generators/mack_application_generator/mack_application_generator.rb +7 -0
- data/lib/generators/mack_application_generator/manifest.yml +71 -0
- data/{bin → lib/generators/mack_application_generator}/templates/Rakefile.template +1 -1
- data/{bin → lib/generators/mack_application_generator}/templates/app/controllers/default_controller.rb.template +0 -0
- data/{bin → lib/generators/mack_application_generator}/templates/app/helpers/application_helper.rb.template +0 -0
- data/{bin → lib/generators/mack_application_generator}/templates/app/views/default/index.html.erb.template +0 -0
- data/{bin → lib/generators/mack_application_generator}/templates/app/views/layouts/application.html.erb.template +0 -0
- data/lib/generators/mack_application_generator/templates/config/app_config/default.yml.template +5 -0
- data/{bin → lib/generators/mack_application_generator}/templates/config/app_config/development.yml.template +0 -0
- data/{bin → lib/generators/mack_application_generator}/templates/config/app_config/production.yml.template +0 -0
- data/{bin → lib/generators/mack_application_generator}/templates/config/app_config/test.yml.template +0 -0
- data/{bin → lib/generators/mack_application_generator}/templates/config/database.yml.template +6 -6
- data/{bin → lib/generators/mack_application_generator}/templates/config/initializers/gems.rb.template +0 -0
- data/{bin → lib/generators/mack_application_generator}/templates/config/routes.rb.template +0 -0
- data/{bin → lib/generators/mack_application_generator}/templates/config/thin.ru.template +0 -0
- data/{bin → lib/generators/mack_application_generator}/templates/config/thin.yml.template +0 -0
- data/{bin/templates/public/favicon.ico → lib/generators/mack_application_generator/templates/public/favicon.ico.template} +0 -0
- data/{bin → lib/generators/mack_application_generator}/templates/public/stylesheets/scaffold.css.template +0 -0
- data/{bin → lib/generators/mack_application_generator}/templates/test/test_helper.rb.template +1 -1
- data/lib/generators/migration_generator/migration_generator.rb +3 -9
- data/lib/generators/migration_generator/templates/{migration.rb.template → db/migrations/<%=@migration_name%>.rb.template} +0 -0
- data/lib/generators/model_column.rb +1 -1
- data/lib/generators/model_generator/manifest.yml +11 -0
- data/lib/generators/model_generator/model_generator.rb +16 -19
- data/lib/generators/model_generator/templates/{app/models/active_record.rb.template → active_record.rb.template} +0 -0
- data/lib/generators/model_generator/templates/{app/models/data_mapper.rb.template → data_mapper.rb.template} +3 -1
- data/lib/generators/model_generator/templates/test.rb.template +9 -0
- data/lib/generators/plugin_generator/plugin_generator.rb +3 -17
- data/lib/generators/plugin_generator/templates/vendor/plugins/<%= @plugin_name %>/init.rb.template +1 -0
- data/lib/generators/plugin_generator/templates/vendor/plugins/<%= @plugin_name %>/lib/<%= @plugin_name %>.rb.template +1 -0
- data/lib/generators/plugin_generator/templates/vendor/plugins/<%= @plugin_name %>/lib/tasks/<%= @plugin_name %>_tasks.rake.template +1 -0
- data/lib/generators/scaffold_generator/manifest.yml +31 -0
- data/lib/generators/scaffold_generator/scaffold_generator.rb +13 -27
- data/lib/generators/scaffold_generator/templates/no_orm/{app/controllers/controller.rb.template → controller.rb.template} +0 -0
- data/lib/generators/scaffold_generator/templates/test.rb.template +9 -0
- data/lib/initialization/initializer.rb +16 -1
- data/lib/initialization/initializers/orm_support.rb +48 -33
- data/lib/mack.rb +12 -6
- data/lib/mack_tasks.rb +2 -2
- data/lib/routing/route_map.rb +2 -0
- data/lib/sea_level/helpers/view_helpers/html_helpers.rb +8 -0
- data/lib/sea_level/request.rb +21 -8
- data/lib/sea_level/uploaded_file.rb +56 -0
- data/lib/tasks/generator_tasks.rake +18 -0
- data/lib/tasks/rake_rules.rake +1 -2
- data/lib/utils/html.rb +8 -0
- metadata +49 -28
- data/bin/templates/config/app_config/default.yml.template +0 -7
- data/lib/generators/base.rb +0 -94
- data/lib/generators/migration/base.rb +0 -26
- data/lib/generators/plugin_generator/templates/init.rb.template +0 -1
- data/lib/generators/plugin_generator/templates/lib/plugin.rb.template +0 -1
data/CHANGELOG
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
===0.4.7
|
2
|
+
* Added Mack::Request::UploadFile class to make dealing with file uploads easy.
|
3
|
+
* Fixed bug where if a controller didn't exist it wasn't checking the public directory.
|
4
|
+
* Generated DataMapper models no longer extend DataMapper::Base, but rather 'include DataMapper::Persistence'. This corresponds to the 0.9.0 upcoming release of DataMapper.
|
5
|
+
* Fixed a bug in request.params that was making file uploads into strings.
|
6
|
+
* Namespaced resourced routes, such as Admin::UserController, now work.
|
7
|
+
* Added rake generator:list task to list all the available generators.
|
8
|
+
* scaffold generator now creates a stub functional test.
|
9
|
+
* model generator now creates a stub unit test.
|
10
|
+
* Rake tasks in plugins now show up in the Rake tasks list.
|
11
|
+
* All generators, including the 'mack' binary are now using Genosaurus.
|
12
|
+
* [dsutedja] initializer will load MACK_APP/controllers/default_controller.rb if it exists
|
13
|
+
* [dsutedja] added link_image_to and image_tag to html helper.
|
14
|
+
* gem: thin 0.8.1
|
15
|
+
* gem: genosaurus 1.1.1
|
16
|
+
|
1
17
|
===0.4.6
|
2
18
|
* Mack now uses Erubis, http://www.kuwata-lab.com/erubis/, for it's rendering engine instead of ERB. This makes Mack even faster now! Yippie!
|
3
19
|
* Added rake generate:model name=<model_name> (optional: cols=<col_1>:<col_1_type>,<col_2>:<col_2_type>) This will also create a migration for you.
|
data/bin/mack
CHANGED
@@ -5,12 +5,15 @@ require 'optparse/time'
|
|
5
5
|
require 'ostruct'
|
6
6
|
require 'pp'
|
7
7
|
require 'erb'
|
8
|
+
require 'genosaurus'
|
9
|
+
require File.join(File.dirname(__FILE__), "..", "lib", "generators", "mack_application_generator", "mack_application_generator")
|
8
10
|
|
9
11
|
app = ARGV[0]
|
10
12
|
raise "You must specify a name for this application!" if app.nil?
|
11
13
|
|
12
14
|
options = OpenStruct.new
|
13
|
-
options.orm =
|
15
|
+
options.orm = "data_mapper"
|
16
|
+
options.version = "0.4.7"
|
14
17
|
|
15
18
|
opts = OptionParser.new do |opts|
|
16
19
|
|
@@ -22,45 +25,4 @@ end
|
|
22
25
|
|
23
26
|
opts.parse!(ARGV)
|
24
27
|
|
25
|
-
|
26
|
-
|
27
|
-
def mack_version
|
28
|
-
"0.4.6"
|
29
|
-
end
|
30
|
-
|
31
|
-
def create_dir(dir)
|
32
|
-
mkdir_p(dir)
|
33
|
-
puts "Created: #{dir}"
|
34
|
-
end
|
35
|
-
|
36
|
-
# Create directories:
|
37
|
-
create_dir(File.join(app, "app", "controllers"))
|
38
|
-
create_dir(File.join(app, "app", "helpers"))
|
39
|
-
create_dir(File.join(app, "app", "models"))
|
40
|
-
create_dir(File.join(app, "app", "views", "default"))
|
41
|
-
create_dir(File.join(app, "app", "views", "layouts"))
|
42
|
-
create_dir(File.join(app, "config", "app_config"))
|
43
|
-
create_dir(File.join(app, "config", "initializers"))
|
44
|
-
create_dir(File.join(app, "lib", "tasks"))
|
45
|
-
create_dir(File.join(app, "log"))
|
46
|
-
create_dir(File.join(app, "public", "images"))
|
47
|
-
create_dir(File.join(app, "public", "stylesheets"))
|
48
|
-
create_dir(File.join(app, "public", "javascripts"))
|
49
|
-
create_dir(File.join(app, "test", "unit"))
|
50
|
-
create_dir(File.join(app, "test", "functional"))
|
51
|
-
create_dir(File.join(app, "vendor", "plugins"))
|
52
|
-
|
53
|
-
# Copy over templates:
|
54
|
-
erb_files = Dir.glob(File.join(File.dirname(__FILE__), "templates", "**/*.template"))
|
55
|
-
|
56
|
-
erb_files.each do |fl|
|
57
|
-
if fl.match("database.yml") && !options.orm
|
58
|
-
else
|
59
|
-
res = ERB.new(File.open(fl).read, nil, "->").result(binding)
|
60
|
-
n = fl.gsub(File.join(File.dirname(__FILE__), "templates"), app).gsub(".template", "")
|
61
|
-
File.open(n, "w") {|f| f.puts res}
|
62
|
-
puts "Created: #{n}"
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
cp(File.join(File.dirname(__FILE__), "templates", "public", "favicon.ico"), File.join(app, "public", "favicon.ico"))
|
28
|
+
MackApplicationGenerator.run({"orm" => options.orm, "version" => options.version, "app" => app})
|
data/lib/errors/errors.rb
CHANGED
@@ -42,6 +42,9 @@ module Mack
|
|
42
42
|
end
|
43
43
|
end # ResourceNotFound
|
44
44
|
|
45
|
+
class UnknownController < NameError
|
46
|
+
end
|
47
|
+
|
45
48
|
# Raised when a route that matches the pattern of the incoming route AND the method of the request can't be found.
|
46
49
|
# It's important to note that BOTH the PATTERN and the HTTP METHOD HAVE to match for a route to be found!
|
47
50
|
class UndefinedRoute < StandardError
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Mack
|
2
|
+
module Genosaurus
|
3
|
+
module Helpers
|
4
|
+
|
5
|
+
def columns(name = param(:name))
|
6
|
+
ivar_cache("form_columns") do
|
7
|
+
cs = []
|
8
|
+
cols = (param(:cols) || param(:columns))
|
9
|
+
if cols
|
10
|
+
cols.split(",").each do |x|
|
11
|
+
cs << Mack::Genosaurus::ModelColumn.new(name, x)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
cs
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def db_directory
|
19
|
+
File.join(MACK_ROOT, "db")
|
20
|
+
end
|
21
|
+
|
22
|
+
def migrations_directory
|
23
|
+
File.join(db_directory, "migrations")
|
24
|
+
end
|
25
|
+
|
26
|
+
def next_migration_number
|
27
|
+
last = Dir.glob(File.join(migrations_directory, "*.rb")).last
|
28
|
+
if last
|
29
|
+
return File.basename(last).match(/^\d+/).to_s.succ
|
30
|
+
end
|
31
|
+
return "001"
|
32
|
+
end
|
33
|
+
|
34
|
+
::Genosaurus.send(:include, self)
|
35
|
+
|
36
|
+
end # Helpers
|
37
|
+
end # Genosaurus
|
38
|
+
end # Mack
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# Files:
|
2
|
+
default_controller:
|
3
|
+
type: file
|
4
|
+
template_path: <%= File.join(templates_directory_path, "app", "controllers", "default_controller.rb.template") %>
|
5
|
+
output_path: <%= File.join(app_name, "app", "controllers", "default_controller.rb") %>
|
6
|
+
application_helper:
|
7
|
+
type: file
|
8
|
+
template_path: <%= File.join(templates_directory_path, "app", "helpers", "application_helper.rb.template") %>
|
9
|
+
output_path: <%= File.join(app_name, "app", "helpers", "application_helper.rb") %>
|
10
|
+
index_view:
|
11
|
+
type: file
|
12
|
+
template_path: <%= File.join(templates_directory_path, "app", "views", "default", "index.html.erb.template") %>
|
13
|
+
output_path: <%= File.join(app_name, "app", "views", "default", "index.html.erb") %>
|
14
|
+
application_layout:
|
15
|
+
type: file
|
16
|
+
template_path: <%= File.join(templates_directory_path, "app", "views", "layouts", "application.html.erb.template") %>
|
17
|
+
output_path: <%= File.join(app_name, "app", "views", "layouts", "application.html.erb") %>
|
18
|
+
<% ["default", "development", "production", "test"].each do |env| -%>
|
19
|
+
<%= env %>_yml:
|
20
|
+
type: file
|
21
|
+
template_path: <%= File.join(templates_directory_path, "config", "app_config", "#{env}.yml.template") %>
|
22
|
+
output_path: <%= File.join(app_name, "config", "app_config", "#{env}.yml") %>
|
23
|
+
<% end -%>
|
24
|
+
<% ["database.yml", "routes.rb", "thin.ru", "thin.yml"].each do |f| -%>
|
25
|
+
<%= f %>_config_file:
|
26
|
+
type: file
|
27
|
+
template_path: <%= File.join(templates_directory_path, "config", "#{f}.template") %>
|
28
|
+
output_path: <%= File.join(app_name, "config", f) %>
|
29
|
+
<% end -%>
|
30
|
+
gems_rb:
|
31
|
+
type: file
|
32
|
+
template_path: <%= File.join(templates_directory_path, "config", "initializers", "gems.rb.template") %>
|
33
|
+
output_path: <%= File.join(app_name, "config", "initializers", "gems.rb") %>
|
34
|
+
favicon:
|
35
|
+
type: file
|
36
|
+
template_path: <%= File.join(templates_directory_path, "public", "favicon.ico.template") %>
|
37
|
+
output_path: <%= File.join(app_name, "public", "favicon.ico") %>
|
38
|
+
scaffold_css:
|
39
|
+
type: file
|
40
|
+
template_path: <%= File.join(templates_directory_path, "public", "stylesheets", "scaffold.css.template") %>
|
41
|
+
output_path: <%= File.join(app_name, "public", "stylesheets", "scaffold.css") %>
|
42
|
+
rakefile:
|
43
|
+
type: file
|
44
|
+
template_path: <%= File.join(templates_directory_path, "Rakefile.template") %>
|
45
|
+
output_path: <%= File.join(app_name, "Rakefile") %>
|
46
|
+
test_helper:
|
47
|
+
type: file
|
48
|
+
template_path: <%= File.join(templates_directory_path, "test", "test_helper.rb.template") %>
|
49
|
+
output_path: <%= File.join(app_name, "test", "test_helper.rb") %>
|
50
|
+
|
51
|
+
# Directories:
|
52
|
+
models:
|
53
|
+
type: directory
|
54
|
+
output_path: <%= File.join(app_name, "app", "models") %>
|
55
|
+
lib_tasks:
|
56
|
+
type: directory
|
57
|
+
output_path: <%= File.join(app_name, "lib", "tasks") %>
|
58
|
+
<% ["images", "javascripts"].each do |f| -%>
|
59
|
+
public_<%= f %>:
|
60
|
+
type: directory
|
61
|
+
output_path: <%= File.join(app_name, "public", f) %>
|
62
|
+
<% end -%>
|
63
|
+
test_functional:
|
64
|
+
type: directory
|
65
|
+
output_path: <%= File.join(app_name, "test", "functional") %>
|
66
|
+
test_unit:
|
67
|
+
type: directory
|
68
|
+
output_path: <%= File.join(app_name, "test", "unit") %>
|
69
|
+
vendor_plugins:
|
70
|
+
type: directory
|
71
|
+
output_path: <%= File.join(app_name, "vendor", "plugins") %>
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/{bin → lib/generators/mack_application_generator}/templates/config/app_config/test.yml.template
RENAMED
File without changes
|
data/{bin → lib/generators/mack_application_generator}/templates/config/database.yml.template
RENAMED
@@ -1,32 +1,32 @@
|
|
1
1
|
# development:
|
2
2
|
# adapter: mysql
|
3
|
-
# database: <%= app.downcase %>_development
|
3
|
+
# database: <%= @options["app"].downcase %>_development
|
4
4
|
# host: localhost
|
5
5
|
# username: root
|
6
6
|
# password:
|
7
7
|
#
|
8
8
|
# test:
|
9
9
|
# adapter: mysql
|
10
|
-
# database: <%= app.downcase %>_test
|
10
|
+
# database: <%= @options["app"].downcase %>_test
|
11
11
|
# host: localhost
|
12
12
|
# username: root
|
13
13
|
# password:
|
14
14
|
#
|
15
15
|
# production:
|
16
16
|
# adapter: mysql
|
17
|
-
# database: <%= app.downcase %>_production
|
17
|
+
# database: <%= @options["app"].downcase %>_production
|
18
18
|
# host: localhost
|
19
19
|
# username: root
|
20
20
|
# password:
|
21
21
|
|
22
22
|
development:
|
23
23
|
adapter: sqlite3
|
24
|
-
database: db/<%= app.downcase %>_development.db
|
24
|
+
database: db/<%= @options["app"].downcase %>_development.db
|
25
25
|
|
26
26
|
test:
|
27
27
|
adapter: sqlite3
|
28
|
-
database: db/<%= app.downcase %>_test.db
|
28
|
+
database: db/<%= @options["app"].downcase %>_test.db
|
29
29
|
|
30
30
|
production:
|
31
31
|
adapter: sqlite3
|
32
|
-
database: db/<%= app.downcase %>_production.db
|
32
|
+
database: db/<%= @options["app"].downcase %>_production.db
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -55,19 +55,13 @@
|
|
55
55
|
# drop_table :users
|
56
56
|
# end
|
57
57
|
# end
|
58
|
-
class MigrationGenerator <
|
58
|
+
class MigrationGenerator < Genosaurus
|
59
59
|
|
60
60
|
require_param :name
|
61
61
|
|
62
|
-
def
|
63
|
-
directory(migrations_directory)
|
64
|
-
|
65
|
-
template_dir = File.join(File.dirname(__FILE__), "templates")
|
66
|
-
|
62
|
+
def setup
|
67
63
|
@table_name = param(:name).underscore.plural.gsub("create_", "")
|
68
|
-
|
69
|
-
template(File.join(template_dir, "migration.rb.template"), File.join(migrations_directory, "#{next_migration_number}_#{param(:name)}.rb"), :force => param(:force))
|
70
|
-
|
64
|
+
@migration_name = "#{next_migration_number}_#{param(:name).underscore}"
|
71
65
|
end
|
72
66
|
|
73
67
|
end
|
File without changes
|
@@ -0,0 +1,11 @@
|
|
1
|
+
models_directory:
|
2
|
+
type: directory
|
3
|
+
output_path: <%= File.join("app", "models") %>
|
4
|
+
model_template:
|
5
|
+
type: file
|
6
|
+
template_path: <%= File.join(templates_directory_path, "#{app_config.orm}.rb.template") %>
|
7
|
+
output_path: <%= File.join("app", "models", "#{param(:name).singular.underscore}.rb") %>
|
8
|
+
test_template:
|
9
|
+
type: file
|
10
|
+
template_path: <%= File.join(templates_directory_path, "test.rb.template") %>
|
11
|
+
output_path: <%= File.join("test", "unit", "#{param(:name).singular.underscore}_test.rb") %>
|
@@ -17,7 +17,9 @@
|
|
17
17
|
#
|
18
18
|
# If using DataMapper generates:
|
19
19
|
# app/models/user.rb:
|
20
|
-
# class User
|
20
|
+
# class User
|
21
|
+
# include DataMapper::Persistence
|
22
|
+
#
|
21
23
|
# end
|
22
24
|
# db/migrations/<number>_create_users.rb:
|
23
25
|
# class CreateUsers < DataMapper::Migration
|
@@ -51,7 +53,9 @@
|
|
51
53
|
#
|
52
54
|
# If using DataMapper generates:
|
53
55
|
# app/models/user.rb:
|
54
|
-
# class User
|
56
|
+
# class User
|
57
|
+
# include DataMapper::Persistence
|
58
|
+
#
|
55
59
|
# property :username, :string
|
56
60
|
# property :email_address, :string
|
57
61
|
# property :created_at, :datetime
|
@@ -71,26 +75,19 @@
|
|
71
75
|
# drop_table :users
|
72
76
|
# end
|
73
77
|
# end
|
74
|
-
class ModelGenerator <
|
78
|
+
class ModelGenerator < Genosaurus
|
75
79
|
|
76
80
|
require_param :name
|
77
81
|
|
78
|
-
def generate
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
@columns << "property :#{x.first}, :#{x.last}\n "
|
88
|
-
end
|
89
|
-
@columns.strip!
|
90
|
-
end
|
91
|
-
|
92
|
-
template(File.join(File.dirname(__FILE__), "templates", "app", "models", "#{app_config.orm}.rb.template"), File.join(MACK_APP, "models", "#{param(:name).singular.underscore}.rb"), :force => param(:force))
|
93
|
-
MigrationGenerator.new(@env.merge({"name" => "create_#{param(:name).plural}"})).generate
|
82
|
+
# def generate
|
83
|
+
# directory(File.join(MACK_APP, "models"))
|
84
|
+
#
|
85
|
+
# template(File.join(File.dirname(__FILE__), "templates", "app", "models", "#{app_config.orm}.rb.template"), File.join(MACK_APP, "models", "#{param(:name).singular.underscore}.rb"), :force => param(:force))
|
86
|
+
# MigrationGenerator.new(@env.merge({"name" => "create_#{param(:name).plural}"})).generate
|
87
|
+
# end
|
88
|
+
|
89
|
+
def after_generate
|
90
|
+
MigrationGenerator.run(@options.merge({"name" => "create_#{param(:name).plural}"}))
|
94
91
|
end
|
95
92
|
|
96
93
|
end
|
File without changes
|
@@ -7,26 +7,12 @@
|
|
7
7
|
# vendor/plugins/my_cool_plugin/init.rb
|
8
8
|
# vendor/plugins/my_cool_plugin/lib
|
9
9
|
# vendor/plugins/my_cool_plugin/lib/my_cool_plugin.rb
|
10
|
-
class PluginGenerator <
|
10
|
+
class PluginGenerator < Genosaurus
|
11
11
|
|
12
12
|
require_param :name
|
13
13
|
|
14
|
-
def
|
15
|
-
|
16
|
-
template_dir = File.join(File.dirname(__FILE__), "templates")
|
17
|
-
|
18
|
-
# create vendor/plugins/<name>
|
19
|
-
directory(plugin_dir)
|
20
|
-
# create vendor/plugins/<name>/lib
|
21
|
-
directory(File.join(plugin_dir, "lib"))
|
22
|
-
# create vendor/plugins/<name>/lib/tasks
|
23
|
-
directory(File.join(plugin_dir, "lib", "tasks"))
|
24
|
-
|
25
|
-
# create vendor/plugins/<name>/init.rb
|
26
|
-
template(File.join(template_dir, "init.rb.template"), File.join(plugin_dir, "init.rb"), :force => param(:force))
|
27
|
-
# create vendor/plugins/<name>/lib/<name>.rb
|
28
|
-
template(File.join(template_dir, "lib", "plugin.rb.template"), File.join(plugin_dir, "lib", "#{param(:name).downcase}.rb"), :force => param(:force))
|
29
|
-
|
14
|
+
def setup
|
15
|
+
@plugin_name = param(:name).underscore.downcase
|
30
16
|
end
|
31
17
|
|
32
18
|
end
|