mack 0.6.1.2 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. data/CHANGELOG +49 -3
  2. data/README +4 -4
  3. data/bin/mack +1 -2
  4. data/lib/mack/controller/controller.rb +1 -1
  5. data/lib/mack/controller/cookie_jar.rb +4 -0
  6. data/lib/mack/controller/request.rb +55 -3
  7. data/lib/mack/controller/session.rb +9 -0
  8. data/lib/mack/controller/tell.rb +13 -0
  9. data/lib/mack/core_extensions/kernel.rb +39 -11
  10. data/lib/mack/core_extensions/symbol.rb +107 -0
  11. data/lib/mack/generators/controller_generator/controller_generator.rb +64 -0
  12. data/lib/mack/generators/controller_generator/manifest.yml +18 -0
  13. data/lib/mack/generators/controller_generator/templates/app/controllers/controller.rb.template +7 -0
  14. data/lib/mack/generators/controller_generator/templates/test/controllers/rspec.rb.template +15 -0
  15. data/lib/mack/generators/controller_generator/templates/test/controllers/test_case.rb.template +15 -0
  16. data/lib/mack/generators/controller_helper_generator/controller_helper_generator.rb +16 -0
  17. data/lib/mack/generators/controller_helper_generator/manifest.yml +15 -0
  18. data/lib/mack/generators/controller_helper_generator/templates/app/helpers/controllers/helper.rb.template +7 -0
  19. data/lib/mack/generators/controller_helper_generator/templates/test/helpers/controllers/rspec.rb.template +6 -0
  20. data/lib/mack/generators/controller_helper_generator/templates/test/helpers/controllers/test_case.rb.template +10 -0
  21. data/lib/mack/generators/mack_application_generator/mack_application_generator.rb +1 -0
  22. data/lib/mack/generators/mack_application_generator/manifest.yml +26 -10
  23. data/lib/mack/generators/mack_application_generator/templates/Rakefile.template +1 -1
  24. data/lib/mack/generators/mack_application_generator/templates/app/controllers/default_controller.rb.template +7 -1
  25. data/lib/mack/generators/mack_application_generator/templates/app/helpers/controllers/default_controller_helper.rb.template +1 -1
  26. data/lib/mack/generators/mack_application_generator/templates/app/helpers/views/application_helper.rb.template +3 -0
  27. data/lib/mack/generators/mack_application_generator/templates/app/views/default/index.html.erb.template +60 -2
  28. data/lib/mack/generators/mack_application_generator/templates/app/views/layouts/application.html.erb.template +10 -2
  29. data/lib/mack/generators/mack_application_generator/templates/config/app_config/default.yml.template +21 -0
  30. data/lib/mack/generators/mack_application_generator/templates/config/app_config/development.yml.template +1 -0
  31. data/lib/mack/generators/mack_application_generator/templates/config/app_config/production.yml.template +1 -0
  32. data/lib/mack/generators/mack_application_generator/templates/config/app_config/test.yml.template +1 -0
  33. data/lib/mack/generators/mack_application_generator/templates/config/database.yml.template +24 -0
  34. data/lib/mack/generators/mack_application_generator/templates/config/initializers/inflections.rb.template +13 -0
  35. data/lib/mack/generators/mack_application_generator/templates/config/initializers/mime_types.rb.template +1 -0
  36. data/lib/mack/generators/mack_application_generator/templates/public/stylesheets/scaffold.css.template +125 -29
  37. data/lib/mack/generators/mack_application_generator/templates/test/{functional → controllers}/default_controller_spec.rb.template +2 -0
  38. data/lib/mack/generators/mack_application_generator/templates/test/{functional → controllers}/default_controller_test.rb.template +2 -0
  39. data/lib/mack/generators/mack_application_generator/templates/test/helpers/controllers/default_controller_helper_spec.rb.template +6 -0
  40. data/lib/mack/generators/mack_application_generator/templates/test/helpers/controllers/default_controller_helper_test.rb.template +10 -0
  41. data/lib/mack/generators/mack_application_generator/templates/test/helpers/views/application_helper_spec.rb.template +6 -0
  42. data/lib/mack/generators/mack_application_generator/templates/test/helpers/views/application_helper_test.rb.template +10 -0
  43. data/lib/mack/generators/view_helper_generator/manifest.yml +15 -0
  44. data/lib/mack/generators/view_helper_generator/templates/app/helpers/views/helper.rb.template +7 -0
  45. data/lib/mack/generators/view_helper_generator/templates/test/helpers/views/rspec.rb.template +6 -0
  46. data/lib/mack/generators/view_helper_generator/templates/test/helpers/views/test_case.rb.template +10 -0
  47. data/lib/mack/generators/view_helper_generator/view_helper_generator.rb +16 -0
  48. data/lib/mack/initialization/application.rb +6 -6
  49. data/lib/mack/initialization/configuration.rb +17 -9
  50. data/lib/mack/initialization/helpers.rb +3 -3
  51. data/lib/mack/initialization/logging.rb +30 -20
  52. data/lib/mack/rendering/view_template.rb +1 -0
  53. data/lib/mack/routing/route_map.rb +10 -12
  54. data/lib/mack/routing/urls.rb +0 -40
  55. data/lib/mack/runner.rb +7 -2
  56. data/lib/mack/runner_helpers/request_logger.rb +1 -1
  57. data/lib/mack/runner_helpers/session.rb +13 -6
  58. data/lib/mack/tasks/mack_dump_tasks.rake +1 -8
  59. data/lib/mack/tasks/mack_tasks.rake +1 -1
  60. data/lib/mack/tasks/test_tasks.rake +2 -2
  61. data/lib/mack/testing/file.rb +28 -0
  62. data/lib/mack/testing/helpers.rb +59 -4
  63. data/lib/mack/testing/rspec.rb +19 -7
  64. data/lib/mack/utils/mime_types.yml +1 -0
  65. data/lib/mack/utils/server.rb +1 -1
  66. data/lib/mack/version.rb +3 -0
  67. data/lib/mack/view_helpers/date_time_helpers.rb +106 -0
  68. data/lib/mack/view_helpers/form_helpers.rb +282 -0
  69. data/lib/mack/view_helpers/html_helpers.rb +4 -88
  70. data/lib/mack/view_helpers/link_helpers.rb +171 -0
  71. data/lib/mack/view_helpers/object_helpers.rb +14 -0
  72. data/lib/mack/view_helpers/string_helpers.rb +41 -0
  73. data/lib/mack_app.rb +1 -0
  74. data/lib/mack_core.rb +3 -7
  75. data/lib/mack_tasks.rb +8 -16
  76. metadata +36 -27
  77. data/bin/mack_ring_server +0 -33
  78. data/lib/mack/core_extensions/string.rb +0 -21
  79. data/lib/mack/distributed/errors/errors.rb +0 -27
  80. data/lib/mack/distributed/routing/urls.rb +0 -44
  81. data/lib/mack/distributed/utils/rinda.rb +0 -45
  82. data/lib/mack/initialization/orm_support.rb +0 -20
  83. data/lib/mack/tasks/mack_ring_server_tasks.rake +0 -33
  84. data/lib/mack/utils/crypt/default_worker.rb +0 -28
  85. data/lib/mack/utils/crypt/keeper.rb +0 -46
data/CHANGELOG CHANGED
@@ -1,6 +1,52 @@
1
- ===0.6.1.2
2
- * gem: application_configuration 1.5.3
3
- * gem: cachetastic 1.7.4
1
+ === 0.7.0
2
+ * [#114] Javascript link_helper
3
+ * [#112] Error generating mack application
4
+ * [#109] DataMapper 0.9.4
5
+ * [#103] Log colors for the console are now configurable per log level.
6
+ * [#102] New association method in data_factory
7
+ * [#101] Update to file upload testing (build_file -> file_for_upload, and multipart support in put)
8
+ * [#100] Inline routing parameters are being mutated
9
+ * [#99] Upgraded to facets 2.4.3
10
+ * [#98] Fixed mack-facets not being loaded before app_config files.
11
+ * [#97] Fixed sessions only working with 'local_memory' mode
12
+ * [#96] Distributed Views module now uses file cache
13
+ * [#92] Removed deprecated app_config.orm code.
14
+ * [#91] Fixed Mack blowing up if there is no config/initializers/gems.rb file.
15
+ * [#90] Added deprecation system.
16
+ * [#89] rake gems:* will now only display warning if any gem required is not installed (and not break)
17
+ * [#88] Implemented pending SQLite3 tests in mack-activerecord
18
+ * [#87] Refactored out common ORM code from mack-active_record and mack-data_mapper into mack-orm
19
+ * [#86] stylesheet link helper
20
+ * [#85] Refactored out Mack::ViewHelpers::HtmlHelpers into Mack::ViewHelpers::HtmlHelpers, Mack::ViewHelpers::FormHelpers and
21
+ Mack::ViewHelpers::linkHelpers
22
+ * [#84] Added Mack::Distributed.lookup(url) to retrieve specific distributed services.
23
+ * [#83] Added mail_to HTML helper.
24
+ * [#82] Added ACL support to mack-distributed
25
+ * [#81] Fixed sessions working with redirects in testing
26
+ * [#80] Distributed objects present both the DRb::DRbObject inspect and the original object's inspect when asked.
27
+ * [#79] Renamed app_config.mack.use_distributed_routes to app_config.mack.share_routes
28
+ * [#76] Move mack_ring_server to mack-distributed
29
+ * [#75] Left over mack-distributed rake tasks
30
+ * [#74] Added optional feature to disable initialization logging.
31
+ * [#73] Tests no longer use the functional/unit directories
32
+ * [#69] Added ViewHelperGenerator and ControllerHelperGenerator
33
+ * [#68] Transactional support in mack-AR
34
+ * [#67] Added test:setup tasks for active_record and data_mapper
35
+ * [#62] Removed const redefined warnings if mack-l10n is used along with mack-activerecord
36
+ * [#39] HAML 2.0.2 support
37
+ * [#28] Refactored out encryption into the mack-encryption gem.
38
+ * [#25] Added ControllerGenerator
39
+ * [#19] Added HTML form helpers
40
+ * [#15] File upload testing support (ability to do multipart form post in testing)
41
+ * [#11] Distributed Layout/Views
42
+ * [#10] Added distributed objects to mack-distributed.
43
+ * [#8] Move distributed code from mack-core to mack-more
44
+ * [#5] Added tell messaging
45
+ * gem: genosaurus 1.2.2
46
+ * gem: haml 2.0.2
47
+ * gem: addressable 1.0.4
48
+ * gem: facets 2.4.3
49
+ * gem: data_mapper 0.9.4
4
50
 
5
51
  ===0.6.1.1
6
52
  * [#72] Fixed serial data type in DataMapper doesn't work with SQLite3
data/README CHANGED
@@ -12,7 +12,7 @@ First things first, let's generate your application:
12
12
  $ mack <app_name>
13
13
 
14
14
  To run a Mack application:
15
- $ rake script:server
15
+ $ rake mack:server:start
16
16
 
17
17
  It will try and run the app using the following servers in this order:
18
18
  * Thin
@@ -20,15 +20,15 @@ It will try and run the app using the following servers in this order:
20
20
  * WEBrick
21
21
 
22
22
  rake script:server takes the following options:
23
- $ rake script:server PORT=<port> Mack.env=<environment> HANDLER=<rack_handler>
23
+ $ rake server PORT=<port> Mack.env=<environment> HANDLER=<rack_handler>
24
24
 
25
25
  The port and rack_handler flags don't apply if you're using Thin[http://code.macournoyer.com/thin] to run the app, which is the default if it is installed. Use the thin.yml file in your application's config directory to configure Thin. The rack_handler one will allow you to switch which server is used to run the app. See Rack for more Rack::Handlers.
26
26
 
27
27
  The environment can also be changed like this:
28
- $ rake script:server#<environment>
28
+ $ rake mack:server:start#<environment>
29
29
 
30
30
  You can also run:
31
- $ rake console
31
+ $ rake mack:console
32
32
  This will give you console level access to your application.
33
33
 
34
34
 
data/bin/mack CHANGED
@@ -15,7 +15,6 @@ options = OpenStruct.new
15
15
  options.orm = "data_mapper"
16
16
  options.testing_framework = "rspec"
17
17
  options.js_framework = "jquery"
18
- options.version = "0.6.1.2"
19
18
 
20
19
  opts = OptionParser.new do |opts|
21
20
  opts.banner = "Usage: mack <application_name> [options]"
@@ -36,4 +35,4 @@ end
36
35
 
37
36
  opts.parse!(ARGV)
38
37
 
39
- MackApplicationGenerator.run({"version" => options.version, "app" => app, "orm" => options.orm, "testing_framework" => options.testing_framework, "js_framework" => options.js_framework})
38
+ MackApplicationGenerator.run({"app" => app, "orm" => options.orm, "testing_framework" => options.testing_framework, "js_framework" => options.js_framework})
@@ -38,7 +38,7 @@ module Mack
38
38
 
39
39
  # Gives access to all the parameters for this request.
40
40
  def params
41
- self.request
41
+ self.request.all_params
42
42
  end
43
43
 
44
44
  # Gives access to the session. See Mack::Session for more information.
@@ -63,6 +63,10 @@ module Mack
63
63
  self.all_cookies
64
64
  end
65
65
 
66
+ def inspect
67
+ self.all_cookies.inspect
68
+ end
69
+
66
70
  end # CookieJar
67
71
 
68
72
  end # Mack
@@ -82,7 +82,28 @@ module Mack
82
82
 
83
83
  private
84
84
  def parse_params(ps)
85
- ps.each_pair do |k, v|
85
+
86
+ # look for date time selects:
87
+ dts = ps.select {|k,v| k.to_s.match(/\(.+\)/)}
88
+ unless dts.empty?
89
+ dtsh = {}
90
+ dts.each do |k,v|
91
+ # convert dilbert[created_at(year)] # => dilbert[created_at]
92
+ p_name = k.gsub(/\(.+\)/, '')
93
+ # get 'year'
94
+ sub_p_name = k.match(/\((.+)\)/).captures.first.to_s
95
+ # create a new DateTimeParameter if one doesn't exist for this parameter yet
96
+ dtsh[p_name] = DateTimeParameter.new if dtsh[p_name].nil?
97
+ # set the accessor for this part of the select
98
+ dtsh[p_name].add(sub_p_name, v)
99
+ end
100
+ # Add the final DateTimeParameter's back onto the request stack.
101
+ dtsh.each do |k,v|
102
+ ps[k] = v.to_time
103
+ end
104
+ end
105
+
106
+ ps.reject {|k,v| k.to_s.match(/\(.+\)/)}.each do |k,v|
86
107
  if k.to_s.match(/.+\[.+\]/)
87
108
  nv = k.to_s.match(/.+\[(.+)\]/).captures.first
88
109
  nk = k.to_s.match(/(.+)\[.+\]/).captures.first
@@ -96,5 +117,36 @@ module Mack
96
117
  end
97
118
  end
98
119
 
99
- end
100
- end
120
+ class DateTimeParameter # :nodoc:
121
+ attr_accessor :year
122
+ attr_accessor :month
123
+ attr_accessor :day
124
+ attr_accessor :hour
125
+ attr_accessor :minute
126
+ attr_accessor :second
127
+
128
+ def initialize
129
+ self.year = Time.now.year
130
+ self.month = 1
131
+ self.day = 1
132
+ self.hour = 0
133
+ self.minute = 0
134
+ self.second = 0
135
+ end
136
+
137
+ def add(key, value)
138
+ self.send("#{key}=", value)
139
+ end
140
+
141
+ def to_s
142
+ "#{year}-#{month}-#{day} #{hour}:#{minute}:#{second}"
143
+ end
144
+
145
+ def to_time
146
+ Time.parse(self.to_s)
147
+ end
148
+
149
+ end
150
+
151
+ end # Request
152
+ end # Mack
@@ -30,6 +30,15 @@ module Mack
30
30
  @sess_hash = {}
31
31
  end
32
32
 
33
+ # Deletes a value from the session
34
+ def delete(key)
35
+ @sess_hash.delete(key.to_sym)
36
+ end
37
+
38
+ def inspect
39
+ "#{self.id}: #{@sess_hash.inspect}"
40
+ end
41
+
33
42
  private
34
43
  attr_reader :sess_hash # :nodoc:
35
44
 
@@ -0,0 +1,13 @@
1
+ module Mack
2
+ module Controller
3
+ module Tell
4
+
5
+ def tell
6
+ (session[:tell] ||= {})
7
+ end
8
+
9
+ include_safely_into(Mack::Controller, Mack::Rendering::ViewTemplate)
10
+
11
+ end # Tell
12
+ end # Controller
13
+ end # Mack
@@ -1,20 +1,48 @@
1
1
  module Kernel
2
2
 
3
- # A helper method that calls Mack::Utils::Crypt::Keeper with the specified worker
4
- # and calls the encrypt method on that worker.
5
- def _encrypt(value, worker = :default)
6
- Mack::Utils::Crypt::Keeper.instance.worker(worker).encrypt(value)
3
+ # Returns Mack::Utils::GemManager
4
+ def require_gems
5
+ yield Mack::Utils::GemManager.instance
7
6
  end
8
7
 
9
- # A helper method that calls Mack::Utils::Crypt::Keeper with the specified worker
10
- # and calls the decrypt method on that worker.
11
- def _decrypt(value, worker = :default)
12
- Mack::Utils::Crypt::Keeper.instance.worker(worker).decrypt(value)
8
+ # Returns an Array of gems required by the Mack::Utils::GemManager
9
+ def required_gem_list
10
+ Mack::Utils::GemManager.instance.required_gem_list
13
11
  end
14
12
 
15
- # Returns Mack::Utils::GemManager
16
- def require_gems
17
- yield Mack::Utils::GemManager.instance
13
+ # Aliases the deprecated method to the new method and logs a warning.
14
+ def alias_deprecated_method(deprecated_method, new_method, version_deprecrated = nil, version_to_be_removed = nil)
15
+ eval %{
16
+ def #{deprecated_method}(*args)
17
+ deprecate_method(:#{deprecated_method}, :#{new_method}, "#{version_deprecrated}", "#{version_to_be_removed}")
18
+ #{new_method}(*args)
19
+ end
20
+ }
21
+ end
22
+
23
+ # Logs a warning that a method has been deprecated. Warnings will only get logged once.
24
+ def deprecate_method(deprecated_method, new_method = nil, version_deprecrated = nil, version_to_be_removed = nil)
25
+ message = "DEPRECATED: '#{deprecated_method}'."
26
+ if new_method
27
+ message << " Please use '#{new_method}' instead."
28
+ end
29
+ if version_deprecrated
30
+ message << " Deprecated in version: '#{version_deprecrated}'."
31
+ if version_to_be_removed.nil?
32
+ version_to_be_removed = ">=#{version_deprecrated.succ}"
33
+ end
34
+ end
35
+ if version_to_be_removed
36
+ message << " To be removed in version: '#{version_to_be_removed}'."
37
+ end
38
+ unless Kernel::DeprecatedRegistryList.registered_items.include?(message)
39
+ Mack.logger.warn(message)
40
+ Kernel::DeprecatedRegistryList.add(message)
41
+ end
42
+ end
43
+
44
+ private
45
+ class DeprecatedRegistryList < Mack::Utils::RegistryList # :nodoc:
18
46
  end
19
47
 
20
48
  end
@@ -0,0 +1,107 @@
1
+ class Symbol
2
+
3
+ # See Mack::ViewHelpers::FormHelpers date_time_select for more information
4
+ def date_time_select(*args)
5
+ Thread.current[:view_template].date_time_select(self, *args)
6
+ end
7
+
8
+ # See Mack::ViewHelpers::FormHelpers date_select for more information
9
+ def date_select(*args)
10
+ Thread.current[:view_template].date_select(self, *args)
11
+ end
12
+
13
+ # See Mack::ViewHelpers::FormHelpers check_box for more information
14
+ #
15
+ # Examples:
16
+ # @user = User.new(:accepted_tos => true)
17
+ # <%= :user.check_box :accepted_tos %> # => <input checked="checked" id="user_accepted_tos" name="user[accepted_tos]" type="checkbox" />
18
+ # <%= :i_dont_exist.check_box %> # => <input id="i_dont_exist" name="i_dont_exist" type="checkbox" />
19
+ def check_box(*args)
20
+ Thread.current[:view_template].check_box(self, *args)
21
+ end
22
+
23
+ # See Mack::ViewHelpers::FormHelpers file_field for more information
24
+ #
25
+ # Examples:
26
+ # @user = User.new(:bio_file => "~/bio.doc")
27
+ # <%= :user.file_field :bio_file %> # => <input id="user_bio_field" name="user[bio_field]" type="file" value="~/bio.doc" />
28
+ # <%= :i_dont_exist.file_field %> # => <input id="i_dont_exist" name="i_dont_exist" type="file" value="" />
29
+ def file_field(*args)
30
+ Thread.current[:view_template].file_field(self, *args)
31
+ end
32
+
33
+ # See Mack::ViewHelpers::FormHelpers hidden_field for more information
34
+ #
35
+ # Examples:
36
+ # @user = User.new(:email => "mark@mackframework.com")
37
+ # <%= :user.hidden_field :email %> # => <input id="user_email" name="user[email]" type="hidden" value="mark@mackframework.com" />
38
+ # <%= :i_dont_exist.hidden_field %> # => <input id="i_dont_exist" name="i_dont_exist" type="hidden" />
39
+ def hidden_field(*args)
40
+ Thread.current[:view_template].hidden_field(self, *args)
41
+ end
42
+
43
+ # See Mack::ViewHelpers::FormHelpers label_tag for more information
44
+ #
45
+ # Examples:
46
+ # @user = User.new
47
+ # <%= :user.label_tag :email %> # => <label for="user_email">Email</label>
48
+ # <%= :i_dont_exist.label_tag %> # => <label for="i_dont_exist">I don't exist</label>
49
+ # <%= :i_dont_exist.label_tag :value => "Hello" %> # => <label for="i_dont_exist">Hello</label>
50
+ def label_tag(*args)
51
+ Thread.current[:view_template].label_tag(self, *args)
52
+ end
53
+
54
+ # See Mack::ViewHelpers::FormHelpers password_field for more information
55
+ #
56
+ # Examples:
57
+ # @user = User.new(:email => "mark@mackframework.com")
58
+ # <%= :user.password_field :email %> # => <input id="user_email" name="user[email]" type="password" value="mark@mackframework.com" />
59
+ # <%= :i_dont_exist.password_field %> # => <input id="i_dont_exist" name="i_dont_exist" type="password" />
60
+ def password_field(*args)
61
+ Thread.current[:view_template].password_field(self, *args)
62
+ end
63
+
64
+ # See Mack::ViewHelpers::FormHelpers radio_button for more information
65
+ #
66
+ # Examples:
67
+ # @user = User.new(:level => 1)
68
+ # <%= :user.radio_button :level %> # => <input checked="checked" id="user_level" name="user[level]" type="radio" value="1" />
69
+ # <%= :user.radio_button :level, :value => 2 %> # => <input id="user_level" name="user[level]" type="radio" value="2" />
70
+ # <%= :i_dont_exist.radio_button %> # => <input id="i_dont_exist" name="i_dont_exist" type="radio" value="" />
71
+ def radio_button(*args)
72
+ Thread.current[:view_template].radio_button(self, *args)
73
+ end
74
+
75
+ # See Mack::ViewHelpers::FormHelpers select_tag for more information
76
+ #
77
+ # Examples:
78
+ # @user = User.new(:level => 1)
79
+ # <%= :user.select_tag :level, :options => [["one", 1], ["two", 2]] %> # => <select id="user_level" name="user[level]"><option value="1" selected>one</option><option value="2" >two</option></select>
80
+ # <%= :user.select_tag :level, :options => {:one => 1, :two => 2} %> # => <select id="user_level" name="user[level]"><option value="1" selected>one</option><option value="2" >two</option></select>
81
+ # <%= :i_dont_exist.select_tag :options => [["one", 1], ["two", 2]], :selected => 1 %> # => <select id="i_dont_exist" name="i_dont_exist"><option value="1" selected>one</option><option value="2" >two</option></select>
82
+ def select_tag(*args)
83
+ Thread.current[:view_template].select_tag(self, *args)
84
+ end
85
+
86
+ # See Mack::ViewHelpers::FormHelpers text_area for more information
87
+ #
88
+ # Examples:
89
+ # @user = User.new(:bio => "my bio here")
90
+ # <%= :user.text_area :bio %> # => <textarea id="user_bio" name="user[bio]">my bio here</textarea>
91
+ # <%= :i_dont_exist.text_area %> # => <textarea id="i_dont_exist" name="i_dont_exist"></textarea>
92
+ # <%= :i_dont_exist.text_area :value => "hi there" %> # => <textarea id="i_dont_exist" name="i_dont_exist">hi there</textarea>
93
+ def text_area(*args)
94
+ Thread.current[:view_template].text_area(self, *args)
95
+ end
96
+
97
+ # See Mack::ViewHelpers::FormHelpers text_field for more information
98
+ #
99
+ # Examples:
100
+ # @user = User.new(:email => "mark@mackframework.com")
101
+ # <%= :user.text_field :email %> # => <input id="user_email" name="user[email]" type="text" value="mark@mackframework.com" />
102
+ # <%= :i_dont_exist.text_field %> # => <input id="i_dont_exist" name="i_dont_exist" type="text" />
103
+ def text_field(*args)
104
+ Thread.current[:view_template].text_field(self, *args)
105
+ end
106
+
107
+ end
@@ -0,0 +1,64 @@
1
+ # Generates a controller for Mack applications.
2
+ #
3
+ # Example:
4
+ # rake generate:controller name=post
5
+ class ControllerGenerator < Genosaurus
6
+
7
+ require_param :name
8
+
9
+ def setup # :nodoc:
10
+ @name_singular = param(:name).singular.underscore
11
+ @name_plural = param(:name).plural.underscore
12
+ @name_singular_camel = @name_singular.camelcase
13
+ @name_plural_camel = @name_plural.camelcase
14
+ @actions = []
15
+ @actions = param(:actions).split(",") unless param(:actions).blank?
16
+ end
17
+
18
+ def after_generate # :nodoc:
19
+ add_actions
20
+ update_routes_file
21
+ ControllerHelperGenerator.run(@options)
22
+ end
23
+
24
+ private
25
+ def update_routes_file # :nodoc:
26
+ unless @actions.empty?
27
+ routes = File.join(Mack.root, "config", "routes.rb")
28
+ rf = File.open(routes).read
29
+ unless rf.match(".resource :#{@name_plural}")
30
+ puts "Updating routes.rb"
31
+ nrf = ""
32
+ rf.each do |line|
33
+ if line.match("Mack::Routes.build")
34
+ x = line.match(/\|(.+)\|/).captures
35
+ line << "\n # Added by rake generate:controller name=#{param(:name)} actions=#{param(:actions)}"
36
+ line << "\n r.with_options(:controller => :#{@name_plural}) do |map|"
37
+ @actions.each do |action|
38
+ line << "\n map.#{@name_plural}_#{action} \"/#{@name_plural}#{action == "index" ? "" : "/#{action}"}\", :action => :#{action}"
39
+ end
40
+ line << "\n end # #{@name_plural}\n"
41
+ end
42
+ nrf << line
43
+ end
44
+ File.open(routes, "w") do |f|
45
+ f.puts nrf
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ def add_actions
52
+ @actions.each do |action|
53
+ template(action_template(action), File.join("app", "views", @name_plural, "#{action}.html.erb"))
54
+ end
55
+ end
56
+
57
+ def action_template(action) # :nodoc:
58
+ %{
59
+ <h1>#{@name_plural_camel}Controller##{action}</h1>
60
+ <p>You can find me in app/views/#{@name_plural}/#{action}.html.erb</p>
61
+ }.strip
62
+ end
63
+
64
+ end