mack 0.5.0 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/CHANGELOG +19 -0
  2. data/bin/mack +3 -2
  3. data/bin/mack_ring_server +19 -1
  4. data/lib/{sea_level/controller_base.rb → controller/base.rb} +87 -128
  5. data/lib/{sea_level → controller}/cookie_jar.rb +3 -3
  6. data/lib/{sea_level → controller}/filter.rb +0 -0
  7. data/lib/{sea_level → controller}/request.rb +0 -0
  8. data/lib/{sea_level → controller}/response.rb +0 -0
  9. data/lib/{sea_level → controller}/session.rb +0 -0
  10. data/lib/{sea_level → controller}/uploaded_file.rb +0 -0
  11. data/lib/distributed/routing/urls.rb +1 -1
  12. data/lib/distributed/utils/rinda.rb +1 -1
  13. data/lib/errors/errors.rb +6 -4
  14. data/lib/generators/mack_application_generator/templates/config/initializers/mime_types.rb.template +3 -0
  15. data/lib/generators/mack_application_generator/templates/public/favicon.ico.template +0 -0
  16. data/lib/initialization/configuration.rb +2 -1
  17. data/lib/initialization/console.rb +2 -2
  18. data/lib/initialization/{initializers/logging.rb → logging.rb} +0 -0
  19. data/lib/initialization/{initializers/orm_support.rb → orm_support.rb} +0 -0
  20. data/lib/initialization/{initializers/plugins.rb → plugins.rb} +0 -0
  21. data/lib/mack.rb +107 -131
  22. data/lib/mack_tasks.rb +1 -1
  23. data/lib/rendering/engine/base.rb +26 -0
  24. data/lib/rendering/engine/builder.rb +30 -0
  25. data/lib/rendering/engine/erubis.rb +67 -0
  26. data/lib/rendering/engine/haml.rb +18 -0
  27. data/lib/rendering/engine/markaby.rb +27 -0
  28. data/lib/rendering/engine/registry.rb +48 -0
  29. data/lib/rendering/type/action.rb +37 -0
  30. data/lib/rendering/type/base.rb +59 -0
  31. data/lib/rendering/type/file_base.rb +32 -0
  32. data/lib/rendering/type/inline.rb +26 -0
  33. data/lib/rendering/type/layout.rb +26 -0
  34. data/lib/rendering/type/partial.rb +40 -0
  35. data/lib/rendering/type/public.rb +29 -0
  36. data/lib/rendering/type/template.rb +22 -0
  37. data/lib/rendering/type/text.rb +17 -0
  38. data/lib/rendering/type/url.rb +120 -0
  39. data/lib/rendering/type/xml.rb +34 -0
  40. data/lib/rendering/view_template.rb +168 -0
  41. data/lib/routing/route_map.rb +20 -11
  42. data/lib/runner.rb +137 -0
  43. data/lib/utils/mime_types.rb +56 -0
  44. data/lib/utils/mime_types.yml +449 -0
  45. data/lib/{sea_level/helpers/view_helpers → view_helpers}/html_helpers.rb +0 -0
  46. data/lib/{sea_level/helpers/view_helpers → view_helpers}/string_helpers.rb +0 -0
  47. metadata +58 -29
  48. data/lib/initialization/initializer.rb +0 -110
  49. data/lib/rendering/base.rb +0 -62
  50. data/lib/rendering/classes/action.rb +0 -26
  51. data/lib/rendering/classes/partial.rb +0 -12
  52. data/lib/rendering/classes/public.rb +0 -13
  53. data/lib/rendering/classes/text.rb +0 -12
  54. data/lib/rendering/classes/url.rb +0 -59
  55. data/lib/rendering/classes/xml.rb +0 -24
  56. data/lib/sea_level/view_binder.rb +0 -88
data/CHANGELOG CHANGED
@@ -1,3 +1,22 @@
1
+ ===0.5.5
2
+ * INCOMPATIBILITY NOTICE: Ripped apart the ENTIRE rendering engine and rewrote it from the ground up. This means that wherever you are using 'render' calls in your views and controllers need to be changed. The new format is render(type, value, options). Examples: render(:action, :show), render(:url, "http://www.mackframework.com"), etc...
3
+ * INCOMPATIBILITY NOTICE: Files named *.xml.erb need to be changed to *.xml.builder to use the Builder::XmlMarkup library. If you leave the .erb extension on there the file will be run through Erubis.
4
+ * INCOMPATIBILITY NOTICE: <%= @content_for_layout %> is now <%= yield_to :view %>
5
+ * Added Markaby support.
6
+ * Added Haml support.
7
+ * Added content_for and yield_to methods in views.
8
+ * Erubis compiled templates are now cached for increased performance.
9
+ * Added render(:inline) and render(:template) support.
10
+ * Refactored, and reorganized some files to clean up the gem.
11
+ * Fixed bug with cookies not merging with configured app_config parameters.
12
+ * Added mime-types. The 'Content-Type' header is now being set based on the format that is requested. Default is text/html.
13
+ * Fixed r.defaults in routes so they are always the last routes to be checked, no matter where they are placed in the routes definitions.
14
+ * render(:url) now recognizes 'local' urls and tries to run them through the app, mimicking most headers from the original request.
15
+ * Added 'options' banners to the mack and mack_ring_server binaries.
16
+ * gem: genosaurus 1.1.8
17
+ * gem: mack_ruby_core_extensions 0.1.28
18
+ * gem: markaby 0.5.0
19
+
1
20
  ===0.5.0
2
21
  * Added rake db:create and db:create:all rake tasks.
3
22
  * Refactored out constants, such as MACK_ROOT and MACK_ENV and made them into Mack::Configuration.env, Mack::Configuration.root, etc...
data/bin/mack CHANGED
@@ -13,11 +13,12 @@ raise "You must specify a name for this application!" if app.nil?
13
13
 
14
14
  options = OpenStruct.new
15
15
  options.orm = "data_mapper"
16
- options.version = "0.5.0"
16
+ options.version = "0.5.5"
17
17
 
18
18
  opts = OptionParser.new do |opts|
19
+ opts.banner = "Usage: mack <application_name> [options]"
19
20
 
20
- opts.on("-o [ORM]") do |v|
21
+ opts.on("-o [data_mapper|active_record]") do |v|
21
22
  options.orm = v
22
23
  end
23
24
 
data/bin/mack_ring_server CHANGED
@@ -3,7 +3,25 @@ require 'rubygems'
3
3
  require 'daemons'
4
4
  require 'rinda/ring'
5
5
  require 'rinda/tuplespace'
6
- require 'fileutils'
6
+ require 'fileutils'
7
+ require 'optparse'
8
+ require 'optparse/time'
9
+ require 'ostruct'
10
+
11
+ options = OpenStruct.new
12
+ opts = OptionParser.new do |opts|
13
+ opts.banner = <<-BANNER
14
+ Usage: mack_ring_server <command>
15
+ Available commands are:
16
+
17
+ - start
18
+ - stop
19
+ - restart
20
+
21
+ BANNER
22
+ end
23
+
24
+ opts.parse!(ARGV)
7
25
 
8
26
  FileUtils.mkdir_p(File.join("tmp", "pids"))
9
27
 
@@ -7,7 +7,7 @@ module Mack
7
7
  # Example:
8
8
  # class MyAwesomeController < Mack::Controller::Base
9
9
  # def index
10
- # render(:text => "Hello World!")
10
+ # render(:text, "Hello World!")
11
11
  # end
12
12
  # end
13
13
  class Base
@@ -52,18 +52,72 @@ module Mack
52
52
  # only run public methods!
53
53
  if self.public_methods.include?(self.action_name)
54
54
  # call the action and capture the results to a variable.
55
- @result_of_action_called = self.send(self.action_name)
55
+ self.send(self.action_name)
56
56
  else
57
57
  # there is no action on this controller, so call the render method
58
58
  # which will check the view directory and run action.html.erb if it exists.
59
- render(:action => self.action_name)
59
+ render(:action, self.action_name)
60
60
  end
61
61
  run_filters(:after)
62
62
  # do the work of rendering.
63
- @final_rendered_action = complete_layout_render(complete_action_render)
63
+ @final_rendered_action = do_render
64
64
  run_filters(:after_render)
65
65
  @final_rendered_action
66
66
  end
67
+
68
+ # This will redirect the request to the specified url. A default status of
69
+ # 302, Moved Temporarily, is set if no status is specified. A simple HTML
70
+ # page is rendered in case the redirect does not occur. A server side
71
+ # redirect is also possible by using the option :server_side => true.
72
+ # When a server side redirect occurs the url must be a 'local' url, not an
73
+ # external url. The 'original' url of the request will NOT change.
74
+ def redirect_to(url, options = {})
75
+ options = {:status => 302}.merge(options)
76
+ raise Rack::ForwardRequest.new(url) if options[:server_side]
77
+ response.status = options[:status]
78
+ response[:location] = url
79
+ render(:text, redirect_html(request.path_info, url, options[:status]))
80
+ end
81
+
82
+ # In an action wants will run blocks of code based on the content type that has
83
+ # been requested.
84
+ #
85
+ # Examples:
86
+ # class MyAwesomeController < Mack::Controller::Base
87
+ # def hello
88
+ # wants(:html) do
89
+ # render(:text, "<html>Hello World</html>")
90
+ # end
91
+ # wants(:xml) do
92
+ # render(:text, "<xml><greeting>Hello World</greeting></xml>")
93
+ # end
94
+ # end
95
+ # end
96
+ #
97
+ # If you were to go to: /my_awesome/hello you would get:
98
+ # "<html>Hello World</html>"
99
+ #
100
+ # If you were to go to: /my_awesome/hello.html you would get:
101
+ # "<html>Hello World</html>"
102
+ #
103
+ # If you were to go to: /my_awesome/hello.xml you would get:
104
+ # "<xml><greeting>Hello World</greeting></xml>"
105
+ def wants(header_type, &block)
106
+ header_type = header_type.to_sym
107
+ if header_type == params(:format).to_sym
108
+ yield
109
+ end
110
+ end
111
+
112
+ # Returns true/false depending on whether the render action has been called yet.
113
+ def render_performed?
114
+ @render_performed
115
+ end
116
+
117
+ # Gives access to the MACK_DEFAULT_LOGGER.
118
+ def logger
119
+ MACK_DEFAULT_LOGGER
120
+ end
67
121
 
68
122
  # This method can be called from within an action. This 'registers' the render that you
69
123
  # would like to happen once the action is completed.
@@ -84,18 +138,18 @@ module Mack
84
138
  # class MyAwesomeController < Mack::Controller::Base
85
139
  # # This will render the text 'Hello World!' to the screen.
86
140
  # def index
87
- # render(:text => "Hello World!")
141
+ # render(:text, "Hello World!")
88
142
  # end
89
143
  #
90
144
  # # This will render Mack::Configuration.root/views/my_awesome_controller/foo.html.erb
91
145
  # def show
92
- # render(:action => :foo)
146
+ # render(:action, :foo)
93
147
  # end
94
148
  #
95
149
  # # This will raise a Mack::Errors::DoubleRender error.
96
150
  # def edit
97
- # render(:text => "Hello World!")
98
- # render(:action => :foo)
151
+ # render(:text, "Hello World!")
152
+ # render(:action, :foo)
99
153
  # end
100
154
  #
101
155
  # # This will render Mack::Configuration.root/views/my_awesome_controller/delete.html.erb
@@ -119,7 +173,7 @@ module Mack
119
173
  # # This will raise a Errno::ENOENT error. Assuming that
120
174
  # # there is no file: Mack::Configuration.root/views/my_awesome_controller/bar.html.erb
121
175
  # def bar
122
- # render(:action => "bar")
176
+ # render(:action, "bar")
123
177
  # end
124
178
  #
125
179
  # # This will render a file from the public directory. Files served from the
@@ -127,7 +181,7 @@ module Mack
127
181
  # # served from the public directory is .html. This can be overridden with the
128
182
  # # :ext => ".<ext>" option.
129
183
  # def show_public_file
130
- # render(:public => "my/files/foo")
184
+ # render(:public, "my/files/foo")
131
185
  # end
132
186
  #
133
187
  # # This will render a file from the public directory. Files served from the
@@ -135,39 +189,39 @@ module Mack
135
189
  # # served from the public directory is .html. This can be overridden with the
136
190
  # # :ext => ".<ext>" option.
137
191
  # def show_public_xml_file
138
- # render(:public => "my/files/foo", :ext => ".xml")
192
+ # render(:public, "my/files/foo", :ext => ".xml")
139
193
  # end
140
194
  #
141
195
  # # This will render a partial. In this case it will look for:
142
196
  # # Mack::Configuration.root/views/my_awesome_controller/_latest_news.html.erb
143
197
  # # Partials do NOT get wrapped in layouts.
144
198
  # def latest_news
145
- # render(:partial => :latest_news)
199
+ # render(:partial, :latest_news)
146
200
  # end
147
201
  #
148
202
  # # This will render a partial. In this case it will look for:
149
203
  # # Mack::Configuration.root/views/some_other/_old_news.html.erb
150
204
  # # Partials do NOT get wrapped in layouts.
151
205
  # def latest_news
152
- # render(:partial => "some_other/old_news")
206
+ # render(:partial, "some_other/old_news")
153
207
  # end
154
208
  #
155
209
  # # This will render a url. If the url does not return a status code of '200',
156
210
  # # an empty string will be returned by default. The default method for rendering
157
211
  # # urls is a get.
158
212
  # def yahoo
159
- # render(:url => "http://www.yahoo.com")
213
+ # render(:url, "http://www.yahoo.com")
160
214
  # end
161
215
  #
162
216
  # # This will render a url. If the url does not return a status code of '200',
163
217
  # # a Mack::Errors::UnsuccessfulRenderUrl exception will be raised.
164
218
  # def idontexist
165
- # render(:url => "http://www.idontexist.com", :raise_exception => true)
219
+ # render(:url, "http://www.idontexist.com", :raise_exception => true)
166
220
  # end
167
221
  #
168
222
  # # This will render a url with a post.
169
223
  # def post_to_somewhere
170
- # render(:url => "http://www.mackframework.com/post_to_me", :method => :post,
224
+ # render(:url, "http://www.mackframework.com/post_to_me", :method => :post,
171
225
  # :parameters => {:id => 1, :user => "markbates"})
172
226
  # end
173
227
  #
@@ -175,81 +229,36 @@ module Mack
175
229
  # # reach out for the config parameter "mack::site_domain" and prepend that
176
230
  # # to the url. This can be overridden locally with the :domain option.
177
231
  # def get_index
178
- # render(:url => "/")
232
+ # render(:url, "/")
179
233
  # end
180
234
  #
181
235
  # # This will render 'application/404' and set the response status code to 404
182
236
  # def to_the_unknown
183
- # return render(:action => '/application/404', :status => 404)
237
+ # return render(:action, '/application/404', :status => 404)
184
238
  # end
185
239
  #
186
240
  # end
187
- def render(options = {:action => self.action_name})
241
+ def render(render_type = :action, render_value = self.action_name, options = {})
188
242
  raise Mack::Errors::DoubleRender.new if render_performed?
189
243
  response.status = options[:status] unless options[:status].nil?
190
- unless options[:action] || options[:text]
191
- options = {:layout => false}.merge(options)
192
- end
193
- @render_options = options
244
+ options = {:content_type => Mack::Utils::MimeTypes[params(:format)], :layout => layout}.merge(options)
245
+ response["Content-Type"] = options[:content_type]
246
+ options.delete(:content_type)
247
+ @view_template = Mack::Rendering::ViewTemplate.new(render_type, render_value,
248
+ {:format => params(:format).to_sym, :controller => self}.merge(options))
194
249
  @render_performed = true
195
250
  end
196
251
 
197
- # This will redirect the request to the specified url. A default status of
198
- # 302, Moved Temporarily, is set if no status is specified. A simple HTML
199
- # page is rendered in case the redirect does not occur. A server side
200
- # redirect is also possible by using the option :server_side => true.
201
- # When a server side redirect occurs the url must be a 'local' url, not an
202
- # external url. The 'original' url of the request will NOT change.
203
- def redirect_to(url, options = {})
204
- options = {:status => 302}.merge(options)
205
- raise Rack::ForwardRequest.new(url) if options[:server_side]
206
- response.status = options[:status]
207
- response[:location] = url
208
- render(:text => redirect_html(request.path_info, url, options[:status]))
209
- end
210
-
211
- # In an action wants will run blocks of code based on the content type that has
212
- # been requested.
213
- #
214
- # Examples:
215
- # class MyAwesomeController < Mack::Controller::Base
216
- # def hello
217
- # wants(:html) do
218
- # render(:text => "<html>Hello World</html>")
219
- # end
220
- # wants(:xml) do
221
- # render(:text => "<xml><greeting>Hello World</greeting></xml>")
222
- # end
223
- # end
224
- # end
225
- #
226
- # If you were to go to: /my_awesome/hello you would get:
227
- # "<html>Hello World</html>"
228
- #
229
- # If you were to go to: /my_awesome/hello.html you would get:
230
- # "<html>Hello World</html>"
231
- #
232
- # If you were to go to: /my_awesome/hello.xml you would get:
233
- # "<xml><greeting>Hello World</greeting></xml>"
234
- def wants(header_type, &block)
235
- header_type = header_type.to_sym
236
- if header_type == params(:format).to_sym
237
- yield
238
- end
239
- end
240
-
241
- # Returns true/false depending on whether the render action has been called yet.
242
- def render_performed?
243
- @render_performed
252
+ private
253
+ def do_render
254
+ render unless @view_template
255
+ @rendered_action = @view_template.compile_and_render
244
256
  end
245
-
246
- # Gives access to the MACK_DEFAULT_LOGGER.
247
- def logger
248
- MACK_DEFAULT_LOGGER
257
+
258
+ def layout
259
+ :application
249
260
  end
250
261
 
251
- private
252
-
253
262
  def run_filters(type)
254
263
  filters = self.class.controller_filters[type]
255
264
  return true if filters.empty?
@@ -261,56 +270,6 @@ module Mack
261
270
  end
262
271
  end
263
272
 
264
- def complete_layout_render(action_content)
265
- @content_for_layout = action_content
266
- # if @render_options[:action] || @render_options[:text]
267
- # only action and text should get a layout.
268
- # if a layout is specified, use that:
269
- # i use has_key? here because we want people
270
- # to be able to override layout with nil/false.
271
- if @render_options.has_key?(:layout)
272
- if @render_options[:layout]
273
- return Mack::ViewBinder.new(self).render(@render_options.merge({:action => "layouts/#{@render_options[:layout]}"}))
274
- else
275
- # someone has specified NO layout via nil/false
276
- return @content_for_layout
277
- end
278
- else layout
279
- # use the layout specified by the layout method
280
- begin
281
- return Mack::ViewBinder.new(self).render(@render_options.merge({:action => "layouts/#{layout}"}))
282
- rescue Errno::ENOENT => e
283
- # if the layout doesn't exist, we don't care.
284
- rescue Exception => e
285
- raise e
286
- end
287
- end
288
- # end
289
- @content_for_layout
290
- end
291
-
292
- def complete_action_render
293
- if render_performed?
294
- return Mack::ViewBinder.new(self, @render_options).render(@render_options)
295
- else
296
- begin
297
- # try action.html.erb
298
- return Mack::ViewBinder.new(self).render({:action => self.action_name})
299
- rescue Errno::ENOENT => e
300
- if @result_of_action_called.is_a?(String)
301
- @render_options[:text] = @result_of_action_called
302
- return Mack::ViewBinder.new(self).render(@render_options)
303
- else
304
- raise e
305
- end
306
- end
307
- end
308
- end # complete_action_render
309
-
310
- def layout
311
- :application
312
- end
313
-
314
273
  public
315
274
  class << self
316
275
 
@@ -359,12 +318,12 @@ module Mack
359
318
  #
360
319
  # def index
361
320
  # # Sets this action to use: "#{Mack::Configuration.root}/app/views/layouts/bright.html.erb" as it's layout.
362
- # render(:text => "Welcome...", :layout => :bright)
321
+ # render(:text, "Welcome...", :layout => :bright)
363
322
  # end
364
323
  #
365
324
  # def index
366
325
  # # This will no use a layout.
367
- # render(:text => "Welcome...", :layout => false)
326
+ # render(:text, "Welcome...", :layout => false)
368
327
  # end
369
328
  # end
370
329
  #
@@ -4,11 +4,11 @@ module Mack
4
4
  # class MyAwesomeController < Mack::Controller::Base
5
5
  # def index
6
6
  # cookies[:id] = 1
7
- # render(:text => "Hello!")
7
+ # render(:text, "Hello!")
8
8
  # end
9
9
  #
10
10
  # def show
11
- # render(:text => "The id in the cookie is: #{cookies[:id]}")
11
+ # render(:text, "The id in the cookie is: #{cookies[:id]}")
12
12
  # end
13
13
  # end
14
14
  class CookieJar
@@ -42,7 +42,7 @@ module Mack
42
42
  unless value.is_a?(Hash)
43
43
  value = {:value => value}
44
44
  end
45
- value = app_config.mack.cookie_values.merge(value)
45
+ value = app_config.mack.cookie_values.symbolize_keys.merge(value)
46
46
  self.all_cookies[key] = value
47
47
  self.response.set_cookie(key, value)
48
48
  end
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -13,7 +13,7 @@ module Mack
13
13
  def put
14
14
  Mack::Distributed::Utils::Rinda.register_or_renew(:space => app_config.mack.distributed_app_name.to_sym,
15
15
  :klass_def => :distributed_routes,
16
- :object => self)
16
+ :object => self, :timeout => 0)
17
17
  end
18
18
 
19
19
  def run(meth, options)