mack 0.4.7 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +21 -2
- data/README +1 -4
- data/bin/mack +2 -2
- data/lib/errors/errors.rb +1 -10
- data/lib/generators/mack_application_generator/manifest.yml +5 -1
- data/lib/generators/mack_application_generator/templates/config/database.yml.template +45 -1
- data/lib/generators/mack_application_generator/templates/test/test_helper.rb.template +1 -1
- data/lib/generators/plugin_generator/templates/vendor/plugins/{<%= @plugin_name %> → %=@plugin_name%}/init.rb.template +0 -0
- data/lib/generators/plugin_generator/templates/vendor/plugins/{<%= @plugin_name %>/lib/<%= @plugin_name %>.rb.template → %=@plugin_name%/lib/%=@plugin_name%.rb.template} +0 -0
- data/lib/generators/plugin_generator/templates/vendor/plugins/{<%= @plugin_name %>/lib/tasks/<%= @plugin_name %>_tasks.rake.template → %=@plugin_name%/lib/tasks/%=@plugin_name%_tasks.rake.template} +0 -0
- data/lib/initialization/configuration.rb +28 -6
- data/lib/initialization/console.rb +2 -0
- data/lib/initialization/initializer.rb +23 -36
- data/lib/initialization/initializers/logging.rb +2 -2
- data/lib/initialization/initializers/orm_support.rb +4 -63
- data/lib/initialization/initializers/plugins.rb +1 -1
- data/lib/initialization/server/simple_server.rb +0 -2
- data/lib/mack.rb +2 -2
- data/lib/mack_tasks.rb +6 -0
- data/lib/rendering/base.rb +1 -1
- data/lib/rendering/classes/action.rb +1 -1
- data/lib/rendering/classes/public.rb +1 -1
- data/lib/rendering/classes/url.rb +1 -0
- data/lib/rendering/classes/xml.rb +1 -1
- data/lib/sea_level/controller_base.rb +19 -10
- data/lib/sea_level/helpers/view_helpers/html_helpers.rb +96 -11
- data/lib/sea_level/helpers/view_helpers/string_helpers.rb +22 -0
- data/lib/sea_level/uploaded_file.rb +1 -0
- data/lib/sea_level/view_binder.rb +14 -11
- data/lib/tasks/cachetastic_tasks.rake +11 -11
- data/lib/tasks/mack_server_tasks.rake +3 -3
- data/lib/tasks/mack_tasks.rake +2 -5
- data/lib/tasks/rake_rules.rake +1 -2
- data/lib/tasks/test_tasks.rake +22 -1
- data/lib/test_extensions/test_case.rb +50 -0
- data/lib/test_extensions/test_helpers.rb +22 -5
- metadata +30 -30
- data/lib/generators/genosaurus_helpers.rb +0 -38
- data/lib/generators/migration_generator/migration_generator.rb +0 -67
- data/lib/generators/migration_generator/templates/db/migrations/<%=@migration_name%>.rb.template +0 -31
- data/lib/generators/model_column.rb +0 -55
- data/lib/generators/model_generator/manifest.yml +0 -11
- data/lib/generators/model_generator/model_generator.rb +0 -93
- data/lib/generators/model_generator/templates/active_record.rb.template +0 -2
- data/lib/generators/model_generator/templates/data_mapper.rb.template +0 -11
- data/lib/generators/model_generator/templates/test.rb.template +0 -9
- data/lib/generators/scaffold_generator/manifest.yml +0 -31
- data/lib/generators/scaffold_generator/scaffold_generator.rb +0 -43
- data/lib/generators/scaffold_generator/templates/generic/app/controllers/controller.rb.template +0 -50
- data/lib/generators/scaffold_generator/templates/generic/app/views/edit.html.erb.template +0 -20
- data/lib/generators/scaffold_generator/templates/generic/app/views/index.html.erb.template +0 -41
- data/lib/generators/scaffold_generator/templates/generic/app/views/new.html.erb.template +0 -19
- data/lib/generators/scaffold_generator/templates/generic/app/views/show.html.erb.template +0 -12
- data/lib/generators/scaffold_generator/templates/no_orm/controller.rb.template +0 -38
- data/lib/generators/scaffold_generator/templates/test.rb.template +0 -9
- data/lib/sea_level/helpers/view_helpers/orm_helpers.rb +0 -87
- data/lib/tasks/db_tasks.rake +0 -94
- data/lib/utils/html.rb +0 -104
data/lib/tasks/mack_tasks.rake
CHANGED
@@ -2,17 +2,14 @@ namespace :mack do
|
|
2
2
|
|
3
3
|
desc "Loads the Mack environment. Default is development."
|
4
4
|
task :environment do
|
5
|
-
|
6
|
-
MACK_ROOT = FileUtils.pwd unless Object.const_defined?("MACK_ROOT")
|
7
|
-
require 'mack'
|
8
|
-
# require File.join(MACK_ROOT, "config", "boot.rb")
|
5
|
+
require File.join(File.dirname(__FILE__), '..', 'mack')
|
9
6
|
end # environment
|
10
7
|
|
11
8
|
desc "Loads an irb console allow you full access to the application w/o a browser."
|
12
9
|
task :console do
|
13
10
|
libs = []
|
14
11
|
libs << "-r irb/completion"
|
15
|
-
libs << "-r #{File.join(File.dirname(__FILE__), '..', 'mack')}"
|
12
|
+
# libs << "-r #{File.join(File.dirname(__FILE__), '..', 'mack')}"
|
16
13
|
libs << "-r #{File.join(File.dirname(__FILE__), '..', 'initialization', 'console')}"
|
17
14
|
exec "irb #{libs.join(" ")} --simple-prompt"
|
18
15
|
end # console
|
data/lib/tasks/rake_rules.rake
CHANGED
data/lib/tasks/test_tasks.rake
CHANGED
@@ -8,9 +8,28 @@ end
|
|
8
8
|
|
9
9
|
namespace :test do
|
10
10
|
|
11
|
+
desc "Report code statistics (KLOCs, etc) from the application. Requires the rcov gem."
|
12
|
+
task :stats do |t|
|
13
|
+
x = `rcov test/**/*_test.rb -T --no-html -x Rakefile,config\/`
|
14
|
+
@print = false
|
15
|
+
x.each do |line|
|
16
|
+
puts line if @print
|
17
|
+
unless @print
|
18
|
+
if line.match(/\d+ tests, \d+ assertions, \d+ failures, \d+ errors/)
|
19
|
+
@print = true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "Generates test coverage from the application. Requires the rcov gem."
|
26
|
+
task :coverage do |t|
|
27
|
+
`rcov test/**/*_test.rb -x Rakefile,config\/`
|
28
|
+
`open coverage/index.html`
|
29
|
+
end
|
30
|
+
|
11
31
|
task :empty do |t|
|
12
32
|
ENV["TEST:EMPTY"] = "true"
|
13
|
-
puts ENV["TEST:EMPTY"]
|
14
33
|
end
|
15
34
|
|
16
35
|
task :raise_exception do |t|
|
@@ -20,3 +39,5 @@ namespace :test do
|
|
20
39
|
end
|
21
40
|
|
22
41
|
alias_task :test, :default
|
42
|
+
alias_task :stats, "test:stats"
|
43
|
+
alias_task :coverage, "test:coverage"
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Test
|
2
|
+
module Unit # :nodoc:
|
3
|
+
class TestCase # :nodoc:
|
4
|
+
|
5
|
+
def name # :nodoc:
|
6
|
+
"#{self.class.name}\t\t#{@method_name}"
|
7
|
+
end
|
8
|
+
|
9
|
+
# Let's alias the run method in the class above us so we can create a new one here
|
10
|
+
# but still reference it.
|
11
|
+
alias_method :super_run, :run # :nodoc:
|
12
|
+
|
13
|
+
# We need to wrap the run method so we can do things like
|
14
|
+
# run a cleanup method if it exists
|
15
|
+
def run(result, &progress_block) # :nodoc:
|
16
|
+
super_run(result) do |state, name|
|
17
|
+
if state == Test::Unit::TestCase::STARTED
|
18
|
+
cleanup if self.respond_to?(:cleanup)
|
19
|
+
log_start(name)
|
20
|
+
else
|
21
|
+
cleanup if self.respond_to?(:cleanup)
|
22
|
+
log_end(name)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def log_start(name = "")
|
28
|
+
@log_start_time = Time.now
|
29
|
+
puts "\n#{format_log_time(@log_start_time)}: Starting\t#{name}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def log_end(name = "")
|
33
|
+
@log_end_time = Time.now
|
34
|
+
puts "#{format_log_time(@log_end_time)}: Ending\t#{name}"
|
35
|
+
et = @log_end_time - @log_start_time
|
36
|
+
suffix = ""
|
37
|
+
et.round.times { suffix += "!" } if et > 1.0
|
38
|
+
if et > 0.5
|
39
|
+
puts "#{suffix}Elapsed Time: #{et} seconds#{suffix}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
def format_log_time(time = Time.now)
|
45
|
+
time.strftime("%I:%M:%S %p")
|
46
|
+
end
|
47
|
+
|
48
|
+
end # TestCase
|
49
|
+
end # Unit
|
50
|
+
end # Test
|
@@ -125,6 +125,20 @@ module Mack
|
|
125
125
|
test_cookies.delete(name)
|
126
126
|
end
|
127
127
|
|
128
|
+
def method_missing(sym, *args)
|
129
|
+
sym = sym.to_s
|
130
|
+
case sym
|
131
|
+
when /^clean_(.+)/
|
132
|
+
captures = sym.match(/^clean_(.+)/).captures
|
133
|
+
thing = eval(captures.first)
|
134
|
+
if File.exists?(thing)
|
135
|
+
FileUtils.rm_rf(thing)
|
136
|
+
end
|
137
|
+
else
|
138
|
+
raise NoMethodError.new(sym)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
128
142
|
private
|
129
143
|
def test_cookies
|
130
144
|
@test_cookies = {} if @test_cookies.nil?
|
@@ -145,12 +159,15 @@ module Mack
|
|
145
159
|
def build_response(res)
|
146
160
|
@responses = [res]
|
147
161
|
strip_cookies_from_response(res)
|
148
|
-
|
149
|
-
|
150
|
-
|
162
|
+
# only retry if it's a redirect request
|
163
|
+
if res.redirect?
|
164
|
+
until res.successful?
|
165
|
+
[res].flatten.each do |r|
|
166
|
+
strip_cookies_from_response(r)
|
167
|
+
end
|
168
|
+
res = request.get(res["Location"])
|
169
|
+
@responses << res
|
151
170
|
end
|
152
|
-
res = request.get(res["Location"])
|
153
|
-
@responses << res
|
154
171
|
end
|
155
172
|
end
|
156
173
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- markbates
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-05-06 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -28,7 +28,7 @@ dependencies:
|
|
28
28
|
requirements:
|
29
29
|
- - "="
|
30
30
|
- !ruby/object:Gem::Version
|
31
|
-
version: 0.1.
|
31
|
+
version: 0.1.23
|
32
32
|
version:
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: application_configuration
|
@@ -100,7 +100,7 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - "="
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 2.
|
103
|
+
version: 2.6.0
|
104
104
|
version:
|
105
105
|
- !ruby/object:Gem::Dependency
|
106
106
|
name: genosaurus
|
@@ -109,7 +109,25 @@ dependencies:
|
|
109
109
|
requirements:
|
110
110
|
- - "="
|
111
111
|
- !ruby/object:Gem::Version
|
112
|
-
version: 1.1.
|
112
|
+
version: 1.1.4
|
113
|
+
version:
|
114
|
+
- !ruby/object:Gem::Dependency
|
115
|
+
name: rcov
|
116
|
+
version_requirement:
|
117
|
+
version_requirements: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - "="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: 0.8.1.2.0
|
122
|
+
version:
|
123
|
+
- !ruby/object:Gem::Dependency
|
124
|
+
name: mack-data_mapper
|
125
|
+
version_requirement:
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - "="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: 0.5.0
|
113
131
|
version:
|
114
132
|
description: Mack is a powerful, yet simple, web application framework. It takes some cues from the likes of Rails and Merb, so it's not entirely unfamiliar. Mack hopes to provide developers a great framework for building, and deploying, portal and distributed applications.
|
115
133
|
email: mark@mackframework.com
|
@@ -129,11 +147,11 @@ files:
|
|
129
147
|
- lib/distributed/routing/urls.rb
|
130
148
|
- lib/distributed/utils/rinda.rb
|
131
149
|
- lib/errors/errors.rb
|
132
|
-
- lib/generators/genosaurus_helpers.rb
|
133
150
|
- lib/generators/mack_application_generator/mack_application_generator.rb
|
134
151
|
- lib/generators/mack_application_generator/manifest.yml
|
135
152
|
- lib/generators/mack_application_generator/templates/app/controllers/default_controller.rb.template
|
136
153
|
- lib/generators/mack_application_generator/templates/app/helpers/application_helper.rb.template
|
154
|
+
- lib/generators/mack_application_generator/templates/app/models.template
|
137
155
|
- lib/generators/mack_application_generator/templates/app/views/default/index.html.erb.template
|
138
156
|
- lib/generators/mack_application_generator/templates/app/views/layouts/application.html.erb.template
|
139
157
|
- lib/generators/mack_application_generator/templates/config/app_config/default.yml.template
|
@@ -152,28 +170,11 @@ files:
|
|
152
170
|
- lib/generators/mack_application_generator/templates/test/test_helper.rb.template
|
153
171
|
- lib/generators/mack_application_generator/templates/test/unit.template
|
154
172
|
- lib/generators/mack_application_generator/templates/vendor/plugins.template
|
155
|
-
- lib/generators/migration_generator/migration_generator.rb
|
156
|
-
- lib/generators/migration_generator/templates/db/migrations/<%=@migration_name%>.rb.template
|
157
|
-
- lib/generators/model_column.rb
|
158
|
-
- lib/generators/model_generator/manifest.yml
|
159
|
-
- lib/generators/model_generator/model_generator.rb
|
160
|
-
- lib/generators/model_generator/templates/active_record.rb.template
|
161
|
-
- lib/generators/model_generator/templates/data_mapper.rb.template
|
162
|
-
- lib/generators/model_generator/templates/test.rb.template
|
163
173
|
- lib/generators/plugin_generator/plugin_generator.rb
|
164
|
-
- lib/generators/plugin_generator/templates/vendor/plugins
|
165
|
-
- lib/generators/plugin_generator/templates/vendor/plugins
|
166
|
-
- lib/generators/plugin_generator/templates/vendor/plugins
|
167
|
-
- lib/generators/plugin_generator/templates/vendor/plugins
|
168
|
-
- lib/generators/scaffold_generator/manifest.yml
|
169
|
-
- lib/generators/scaffold_generator/scaffold_generator.rb
|
170
|
-
- lib/generators/scaffold_generator/templates/generic/app/controllers/controller.rb.template
|
171
|
-
- lib/generators/scaffold_generator/templates/generic/app/views/edit.html.erb.template
|
172
|
-
- lib/generators/scaffold_generator/templates/generic/app/views/index.html.erb.template
|
173
|
-
- lib/generators/scaffold_generator/templates/generic/app/views/new.html.erb.template
|
174
|
-
- lib/generators/scaffold_generator/templates/generic/app/views/show.html.erb.template
|
175
|
-
- lib/generators/scaffold_generator/templates/no_orm/controller.rb.template
|
176
|
-
- lib/generators/scaffold_generator/templates/test.rb.template
|
174
|
+
- lib/generators/plugin_generator/templates/vendor/plugins/%=@plugin_name%/init.rb.template
|
175
|
+
- lib/generators/plugin_generator/templates/vendor/plugins/%=@plugin_name%/lib/%=@plugin_name%.rb.template
|
176
|
+
- lib/generators/plugin_generator/templates/vendor/plugins/%=@plugin_name%/lib/tasks/%=@plugin_name%_tasks.rake.template
|
177
|
+
- lib/generators/plugin_generator/templates/vendor/plugins/%=@plugin_name%/lib/tasks.template
|
177
178
|
- lib/initialization/configuration.rb
|
178
179
|
- lib/initialization/console.rb
|
179
180
|
- lib/initialization/initializer.rb
|
@@ -196,14 +197,13 @@ files:
|
|
196
197
|
- lib/sea_level/cookie_jar.rb
|
197
198
|
- lib/sea_level/filter.rb
|
198
199
|
- lib/sea_level/helpers/view_helpers/html_helpers.rb
|
199
|
-
- lib/sea_level/helpers/view_helpers/
|
200
|
+
- lib/sea_level/helpers/view_helpers/string_helpers.rb
|
200
201
|
- lib/sea_level/request.rb
|
201
202
|
- lib/sea_level/response.rb
|
202
203
|
- lib/sea_level/session.rb
|
203
204
|
- lib/sea_level/uploaded_file.rb
|
204
205
|
- lib/sea_level/view_binder.rb
|
205
206
|
- lib/tasks/cachetastic_tasks.rake
|
206
|
-
- lib/tasks/db_tasks.rake
|
207
207
|
- lib/tasks/gem_tasks.rake
|
208
208
|
- lib/tasks/generator_tasks.rake
|
209
209
|
- lib/tasks/log_tasks.rake
|
@@ -215,11 +215,11 @@ files:
|
|
215
215
|
- lib/tasks/rake_rules.rake
|
216
216
|
- lib/tasks/test_tasks.rake
|
217
217
|
- lib/test_extensions/test_assertions.rb
|
218
|
+
- lib/test_extensions/test_case.rb
|
218
219
|
- lib/test_extensions/test_helpers.rb
|
219
220
|
- lib/utils/crypt/default_worker.rb
|
220
221
|
- lib/utils/crypt/keeper.rb
|
221
222
|
- lib/utils/gem_manager.rb
|
222
|
-
- lib/utils/html.rb
|
223
223
|
- lib/utils/server.rb
|
224
224
|
- CHANGELOG
|
225
225
|
has_rdoc: true
|
@@ -1,38 +0,0 @@
|
|
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
|
@@ -1,67 +0,0 @@
|
|
1
|
-
# This will generate a migration for your application.
|
2
|
-
#
|
3
|
-
# Example without columns:
|
4
|
-
# rake generate:migration name=create_users
|
5
|
-
# If using ActiveRecord generates:
|
6
|
-
# db/migrations/<number>_create_users.rb:
|
7
|
-
# class CreateUsers < ActiveRecord::Migration
|
8
|
-
# self.up
|
9
|
-
# end
|
10
|
-
#
|
11
|
-
# self.down
|
12
|
-
# end
|
13
|
-
# end
|
14
|
-
#
|
15
|
-
# If using DataMapper generates:
|
16
|
-
# db/migrations/<number>_create_users.rb:
|
17
|
-
# class CreateUsers < DataMapper::Migration
|
18
|
-
# self.up
|
19
|
-
# end
|
20
|
-
#
|
21
|
-
# self.down
|
22
|
-
# end
|
23
|
-
# end
|
24
|
-
#
|
25
|
-
# Example with columns:
|
26
|
-
# rake generate:migration name=create_users cols=username:string,email_address:string,created_at:datetime,updated_at:datetime
|
27
|
-
# If using ActiveRecord generates:
|
28
|
-
# db/migrations/<number>_create_users.rb:
|
29
|
-
# class CreateUsers < ActiveRecord::Migration
|
30
|
-
# self.up
|
31
|
-
# create_table :users do |t|
|
32
|
-
# t.column :username, :string
|
33
|
-
# t.column :email_address, :string
|
34
|
-
# t.column :created_at, :datetime
|
35
|
-
# t.column :updated_at, :datetime
|
36
|
-
# end
|
37
|
-
#
|
38
|
-
# self.down
|
39
|
-
# drop_table :users
|
40
|
-
# end
|
41
|
-
# end
|
42
|
-
#
|
43
|
-
# If using DataMapper generates:
|
44
|
-
# db/migrations/<number>_create_users.rb:
|
45
|
-
# class CreateUsers < DataMapper::Migration
|
46
|
-
# self.up
|
47
|
-
# create_table :users do |t|
|
48
|
-
# t.column :username, :string
|
49
|
-
# t.column :email_address, :string
|
50
|
-
# t.column :created_at, :datetime
|
51
|
-
# t.column :updated_at, :datetime
|
52
|
-
# end
|
53
|
-
#
|
54
|
-
# self.down
|
55
|
-
# drop_table :users
|
56
|
-
# end
|
57
|
-
# end
|
58
|
-
class MigrationGenerator < Genosaurus
|
59
|
-
|
60
|
-
require_param :name
|
61
|
-
|
62
|
-
def setup
|
63
|
-
@table_name = param(:name).underscore.plural.gsub("create_", "")
|
64
|
-
@migration_name = "#{next_migration_number}_#{param(:name).underscore}"
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
data/lib/generators/migration_generator/templates/db/migrations/<%=@migration_name%>.rb.template
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
class <%= param(:name).camelcase %> < <%= app_config.orm.camelcase %>::Migration
|
2
|
-
|
3
|
-
def self.up
|
4
|
-
<%
|
5
|
-
unless columns.empty?
|
6
|
-
-%>
|
7
|
-
create_table :<%= @table_name %> do |t|
|
8
|
-
<%
|
9
|
-
for column in columns
|
10
|
-
-%>
|
11
|
-
t.column :<%= column.column_name %>, :<%= column.column_type %>
|
12
|
-
<%
|
13
|
-
end
|
14
|
-
-%>
|
15
|
-
end
|
16
|
-
<%
|
17
|
-
end
|
18
|
-
-%>
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.down
|
22
|
-
<%
|
23
|
-
unless columns.empty?
|
24
|
-
-%>
|
25
|
-
drop_table :<%= @table_name %>
|
26
|
-
<%
|
27
|
-
end
|
28
|
-
-%>
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
module Mack
|
2
|
-
module Genosaurus
|
3
|
-
|
4
|
-
# Used to represent a 'column' from the param cols or columns for generators.
|
5
|
-
class ModelColumn
|
6
|
-
|
7
|
-
# The name of the column.
|
8
|
-
attr_accessor :column_name
|
9
|
-
# The type of the column. Ie. string, integer, datetime, etc...
|
10
|
-
attr_accessor :column_type
|
11
|
-
# The name of the model associated with the column. Ie. user, post, etc...
|
12
|
-
attr_accessor :model_name
|
13
|
-
|
14
|
-
# Takes in the model_name (user, post, etc...) and the column (username:string, body:text, etc...)
|
15
|
-
def initialize(model_name, column_unsplit)
|
16
|
-
self.model_name = model_name.singular.underscore
|
17
|
-
cols = column_unsplit.split(":")
|
18
|
-
self.column_name = cols.first.singular.underscore
|
19
|
-
self.column_type = cols.last.singular.underscore
|
20
|
-
end
|
21
|
-
|
22
|
-
# Examples:
|
23
|
-
# Mack::Generator::ColumnObject.new("user", "username:string").form_element_name # => "user[username]"
|
24
|
-
# Mack::Generator::ColumnObject.new("Post", "body:text").form_element_name # => "post[body]"
|
25
|
-
def form_element_name
|
26
|
-
"#{self.model_name}[#{self.column_name}]"
|
27
|
-
end
|
28
|
-
|
29
|
-
# Examples:
|
30
|
-
# Mack::Generator::ColumnObject.new("user", "username:string").form_element_id # => "user_username"
|
31
|
-
# Mack::Generator::ColumnObject.new("Post", "body:text").form_element_id # => "post_body"
|
32
|
-
def form_element_id
|
33
|
-
"#{self.model_name}_#{self.column_name}"
|
34
|
-
end
|
35
|
-
|
36
|
-
# Generates the appropriate HTML form field for the type of column represented.
|
37
|
-
#
|
38
|
-
# Examples:
|
39
|
-
# Mack::Generator::ColumnObject.new("user", "username:string").form_field
|
40
|
-
# => "<input type="text" name="user[username]" id="user_username" size="30" value="<%= user.username %>" />"
|
41
|
-
# Mack::Generator::ColumnObject.new("Post", "body:text").form_field
|
42
|
-
# => "<textarea name="post[body]" id="post_id"><%= post.body %></textarea>"
|
43
|
-
def form_field
|
44
|
-
case self.column_type
|
45
|
-
when "text"
|
46
|
-
%{<textarea name="#{self.form_element_name}" id="#{self.form_element_id}"><%= @#{self.model_name}.#{self.column_name} %></textarea>}
|
47
|
-
else
|
48
|
-
%{<input type="text" name="#{self.form_element_name}" id="#{self.form_element_id}" size="30" value="<%= @#{self.model_name}.#{self.column_name} %>" />}
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
end # ModelColumn
|
53
|
-
|
54
|
-
end # Generator
|
55
|
-
end # Mack
|