merb 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +105 -95
- data/Rakefile +4 -5
- data/examples/skeleton.tar +0 -0
- data/examples/skeleton/dist/conf/router.rb +5 -2
- data/examples/skeleton/dist/schema/migrations/001_add_sessions_table.rb +0 -1
- data/lib/merb.rb +10 -3
- data/lib/merb/core_ext.rb +3 -1
- data/lib/merb/core_ext/merb_class.rb +85 -51
- data/lib/merb/core_ext/merb_inflections.rb +112 -0
- data/lib/merb/core_ext/merb_inflector.rb +275 -0
- data/lib/merb/core_ext/merb_object.rb +0 -55
- data/lib/merb/core_ext/merb_string.rb +1 -13
- data/lib/merb/merb_controller.rb +26 -20
- data/lib/merb/merb_dispatcher.rb +10 -3
- data/lib/merb/merb_exceptions.rb +6 -1
- data/lib/merb/merb_handler.rb +1 -1
- data/lib/merb/merb_mailer.rb +3 -2
- data/lib/merb/merb_request.rb +56 -0
- data/lib/merb/merb_router.rb +24 -38
- data/lib/merb/mixins/controller_mixin.rb +34 -5
- data/lib/merb/mixins/render_mixin.rb +7 -7
- data/lib/merb/mixins/responder_mixin.rb +17 -10
- data/lib/merb/mixins/view_context_mixin.rb +13 -2
- data/lib/merb/session/merb_ar_session.rb +4 -4
- data/lib/merb/session/merb_memory_session.rb +4 -4
- data/lib/merb/template/erubis.rb +1 -1
- data/lib/merb/template/haml.rb +20 -14
- data/lib/tasks/merb.rake +11 -2
- metadata +4 -2
@@ -49,7 +49,7 @@ module Merb
|
|
49
49
|
#
|
50
50
|
def render(opts={}, &blk)
|
51
51
|
action = opts[:action] || params[:action]
|
52
|
-
opts[:layout] ||=
|
52
|
+
opts[:layout] ||= _layout
|
53
53
|
|
54
54
|
case
|
55
55
|
when status = opts[:nothing]
|
@@ -161,12 +161,12 @@ module Merb
|
|
161
161
|
if action = opts[:action]
|
162
162
|
path =
|
163
163
|
File.expand_path(MERB_ROOT / "dist/app/views" / self.class.name.snake_case / action)
|
164
|
-
elsif
|
165
|
-
path =
|
164
|
+
elsif _layout = opts[:layout]
|
165
|
+
path = _layout_root / _layout
|
166
166
|
else
|
167
167
|
raise "called find_template without an :action or :layout"
|
168
168
|
end
|
169
|
-
extensions = [
|
169
|
+
extensions = [_template_extensions.keys].flatten.uniq
|
170
170
|
glob = "#{path}.{#{opts[:ext] || extensions.join(',')}}"
|
171
171
|
Dir[glob].first
|
172
172
|
end
|
@@ -175,11 +175,11 @@ module Merb
|
|
175
175
|
if template =~ /\//
|
176
176
|
t = template.split('/')
|
177
177
|
template = t.pop
|
178
|
-
path =
|
178
|
+
path = _template_root / t.join('/') / "_#{template}"
|
179
179
|
else
|
180
|
-
path =
|
180
|
+
path = _template_root / self.class.name.snake_case / "_#{template}"
|
181
181
|
end
|
182
|
-
extensions = [
|
182
|
+
extensions = [_template_extensions.keys].flatten.uniq
|
183
183
|
glob = "#{path}.{#{opts[:ext] || extensions.join(',')}}"
|
184
184
|
Dir[glob].first
|
185
185
|
end
|
@@ -1,5 +1,6 @@
|
|
1
|
+
require 'enumerator'
|
2
|
+
|
1
3
|
module Merb
|
2
|
-
# Thanks to Chris Wanstrath
|
3
4
|
# use this in your controllers to switch output based on
|
4
5
|
# the HTTP_ACCEPT header. like so:
|
5
6
|
# respond_to do |type|
|
@@ -8,15 +9,13 @@ module Merb
|
|
8
9
|
# type.xml { @foo.to_xml }
|
9
10
|
# type.yaml { @foo.to_yaml }
|
10
11
|
# end
|
11
|
-
|
12
|
-
# TODO : revisit this whole patern. Can we improve on this?
|
13
12
|
module ResponderMixin
|
14
13
|
|
15
14
|
def respond_to(&block)
|
16
15
|
responder = Rest::Responder.new(@env['HTTP_ACCEPT'], params)
|
17
16
|
block.call(responder)
|
18
17
|
responder.respond(headers)
|
19
|
-
@status = responder.status
|
18
|
+
@status = responder.status if responder.status
|
20
19
|
responder.body
|
21
20
|
end
|
22
21
|
|
@@ -56,7 +55,6 @@ module Merb
|
|
56
55
|
mime_type = negotiate_content
|
57
56
|
if mime_type
|
58
57
|
headers['Content-Type'] = mime_type.super_range
|
59
|
-
@status = 200
|
60
58
|
@body = @stack[mime_type.to_sym].call
|
61
59
|
else
|
62
60
|
headers['Content-Type'] = nil
|
@@ -68,10 +66,19 @@ module Merb
|
|
68
66
|
protected
|
69
67
|
|
70
68
|
def self.parse(accept_header)
|
71
|
-
|
72
|
-
|
69
|
+
# parse the raw accept header into a unique, sorted array of AcceptType objects
|
70
|
+
returning( accept_header.split(/,/).enum_for(:each_with_index).map do |entry,index|
|
73
71
|
AcceptType.new(entry,index += 1)
|
74
|
-
end.sort
|
72
|
+
end.sort.uniq ) do |list|
|
73
|
+
# firefox (and possibly other browsers) send broken default accept headers.
|
74
|
+
# fix them up by sorting alternate xml forms (namely application/xhtml+xml)
|
75
|
+
# ahead of pure xml types (application/xml,text/xml).
|
76
|
+
if app_xml = list.detect{|e| e.super_range == 'application/xml'}
|
77
|
+
list.select{|e| e.to_s =~ /\+xml/}.each { |acc_type|
|
78
|
+
list[list.index(acc_type)],list[list.index(app_xml)] =
|
79
|
+
list[list.index(app_xml)],list[list.index(acc_type)] }
|
80
|
+
end
|
81
|
+
end
|
75
82
|
end
|
76
83
|
|
77
84
|
private
|
@@ -88,7 +95,7 @@ module Merb
|
|
88
95
|
format = @params['format'].to_sym
|
89
96
|
if @stack[format]
|
90
97
|
if @accepts.map(&:to_sym).include?(format)
|
91
|
-
@accepts.
|
98
|
+
@accepts.detect{|a| a.to_sym == format }
|
92
99
|
else
|
93
100
|
AcceptType.new(TYPES[format].first,0)
|
94
101
|
end
|
@@ -116,7 +123,7 @@ module Merb
|
|
116
123
|
end
|
117
124
|
|
118
125
|
def <=>(entry)
|
119
|
-
returning
|
126
|
+
returning((entry.quality <=> quality).to_s) do |c|
|
120
127
|
c.replace((index <=> entry.index).to_s) if c == '0'
|
121
128
|
end.to_i
|
122
129
|
end
|
@@ -17,8 +17,19 @@ module Merb
|
|
17
17
|
%{<a href="#" onclick="#{function}; return false;">#{name}</a>}
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
# creates an <img> tag
|
21
|
+
# defaults to a src path prefix of /images/
|
22
|
+
#
|
23
|
+
# image_tag('foo.gif') => <img src='/images/foo.gif' />
|
24
|
+
# image_tag('foo.gif', :class => 'bar') => <img src='/images/foo.gif' class='bar' />
|
25
|
+
#
|
26
|
+
# you can override the default path by sending a :path parameter in the opts
|
27
|
+
#
|
28
|
+
# image_tag('foo.gif', :path => '/files/') => <img src='/files/foo.gif' />
|
29
|
+
#
|
30
|
+
def image_tag(img, opts={})
|
31
|
+
opts[:path] ||= '/images/'
|
32
|
+
%{<img src="#{opts.delete(:path) + img}" #{opts.map{|k,v| "#{k}=\"#{v}\""}.join(' ')} />}
|
22
33
|
end
|
23
34
|
|
24
35
|
# calls .to_json on data. This will use fjson if installed
|
@@ -6,10 +6,10 @@ module Merb
|
|
6
6
|
|
7
7
|
def setup_session
|
8
8
|
MERB_LOGGER.info("Setting up session")
|
9
|
-
before = @cookies[
|
10
|
-
@session, @cookies[
|
9
|
+
before = @cookies[_session_id_key]
|
10
|
+
@session, @cookies[_session_id_key] = Merb::Session.persist(@cookies[_session_id_key])
|
11
11
|
@_fingerprint_before = Marshal.dump(@session).hash
|
12
|
-
@_new_cookie = @cookies[
|
12
|
+
@_new_cookie = @cookies[_session_id_key] != before
|
13
13
|
end
|
14
14
|
|
15
15
|
def finalize_session
|
@@ -17,7 +17,7 @@ module Merb
|
|
17
17
|
unless Marshal.dump(@session).hash == @_fingerprint_before
|
18
18
|
@session.save
|
19
19
|
end
|
20
|
-
set_cookie(
|
20
|
+
set_cookie(_session_id_key, @cookies[_session_id_key], Time.now+Merb::Const::WEEK*2) if @_new_cookie
|
21
21
|
end
|
22
22
|
|
23
23
|
end
|
@@ -4,14 +4,14 @@ module Merb
|
|
4
4
|
|
5
5
|
def setup_session
|
6
6
|
MERB_LOGGER.info("Setting up session")
|
7
|
-
before = @cookies[
|
8
|
-
@session , @cookies[
|
9
|
-
@_new_cookie = @cookies[
|
7
|
+
before = @cookies[_session_id_key]
|
8
|
+
@session , @cookies[_session_id_key] = Merb::MemorySession.persist(@cookies[_session_id_key])
|
9
|
+
@_new_cookie = @cookies[_session_id_key] != before
|
10
10
|
end
|
11
11
|
|
12
12
|
def finalize_session
|
13
13
|
MERB_LOGGER.info("Finalize session")
|
14
|
-
set_cookie(
|
14
|
+
set_cookie(_session_id_key, @cookies[_session_id_key], Time.now+Merb::Const::WEEK*2) if @_new_cookie
|
15
15
|
end
|
16
16
|
|
17
17
|
end
|
data/lib/merb/template/erubis.rb
CHANGED
data/lib/merb/template/haml.rb
CHANGED
@@ -23,15 +23,13 @@ module Merb
|
|
23
23
|
module Template
|
24
24
|
module Haml
|
25
25
|
|
26
|
-
# Custom HAML-options to be merged.
|
27
|
-
|
28
|
-
trait :haml_options => {
|
29
|
-
:locals => {}
|
30
|
-
}
|
31
|
-
|
32
26
|
::Merb::Controller.register_engine self, %w[ haml ]
|
33
27
|
|
34
28
|
class << self
|
29
|
+
|
30
|
+
class_inheritable_accessor :haml_options
|
31
|
+
self.haml_options = { :locals => {} }
|
32
|
+
|
35
33
|
@@hamls ||= {}
|
36
34
|
@@mtimes ||= {}
|
37
35
|
def exempt_from_layout?
|
@@ -40,15 +38,23 @@ module Merb
|
|
40
38
|
|
41
39
|
def transform(options = {})
|
42
40
|
opts, file, view_context = options.values_at(:opts, :file, :view_context)
|
43
|
-
opts =
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
41
|
+
opts = haml_options.merge(opts)
|
42
|
+
begin
|
43
|
+
if precompiled = get_precompiled(file)
|
44
|
+
opts[:precompiled] ||= precompiled
|
45
|
+
haml = ::Haml::Engine.new("", opts)
|
46
|
+
else
|
47
|
+
haml = ::Haml::Engine.new(IO.read(file), opts)
|
48
|
+
set_precompiled(file, haml.precompiled)
|
49
|
+
end
|
50
|
+
|
51
|
+
haml.to_html(view_context)
|
52
|
+
rescue
|
53
|
+
# ::Haml::Engine often inserts a bogus "(haml):#{line_number}" entry in the backtrace.
|
54
|
+
# Let's replace it with the path of the actual template
|
55
|
+
$@[0].sub! /\(haml\)/, file
|
56
|
+
raise # Raise the exception again
|
50
57
|
end
|
51
|
-
haml.to_html(view_context)
|
52
58
|
end
|
53
59
|
|
54
60
|
private
|
data/lib/tasks/merb.rake
CHANGED
@@ -9,7 +9,16 @@ namespace :merb do
|
|
9
9
|
f.chmod(0744)
|
10
10
|
}
|
11
11
|
|
12
|
-
puts "Freezing Merb Framework into dist/framework"
|
13
|
-
puts "Use script/merb to start instead of plain merb"
|
12
|
+
puts " Freezing Merb Framework into dist/framework"
|
13
|
+
puts " Use script/merb to start instead of plain merb"
|
14
|
+
end
|
15
|
+
desc "unfreeze this app from the framework and use system gem."
|
16
|
+
task :unfreeze do
|
17
|
+
FileUtils.rm_rf MERB_ROOT / 'dist/framework'
|
18
|
+
FileUtils.rm MERB_ROOT / 'script/merb'
|
19
|
+
|
20
|
+
puts " Removed: "
|
21
|
+
puts " - #{MERB_ROOT / 'dist/framework'} (recursive) "
|
22
|
+
puts " - #{MERB_ROOT / 'script/merb'}"
|
14
23
|
end
|
15
24
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
|
|
3
3
|
specification_version: 1
|
4
4
|
name: merb
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2007-
|
6
|
+
version: 0.3.0
|
7
|
+
date: 2007-04-28 00:00:00 -07:00
|
8
8
|
summary: Merb == Mongrel + Erb. Pocket rocket web framework.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -70,6 +70,8 @@ files:
|
|
70
70
|
- lib/merb/core_ext/merb_class.rb
|
71
71
|
- lib/merb/core_ext/merb_enumerable.rb
|
72
72
|
- lib/merb/core_ext/merb_hash.rb
|
73
|
+
- lib/merb/core_ext/merb_inflections.rb
|
74
|
+
- lib/merb/core_ext/merb_inflector.rb
|
73
75
|
- lib/merb/core_ext/merb_kernel.rb
|
74
76
|
- lib/merb/core_ext/merb_module.rb
|
75
77
|
- lib/merb/core_ext/merb_numeric.rb
|