merb 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. data/README +22 -4
  2. data/Rakefile +15 -3
  3. data/TODO +2 -3
  4. data/bin/merb +61 -36
  5. data/examples/sample_app/dist/app/controllers/files.rb +31 -0
  6. data/examples/sample_app/dist/app/controllers/posts.rb +26 -2
  7. data/examples/sample_app/dist/app/controllers/test.rb +7 -1
  8. data/examples/sample_app/dist/app/views/files/progress.jerb +3 -0
  9. data/examples/sample_app/dist/app/views/files/start.herb +62 -0
  10. data/examples/sample_app/dist/app/views/files/upload.herb +6 -0
  11. data/examples/sample_app/dist/app/views/layout/{application.rhtml → application.herb} +2 -3
  12. data/examples/sample_app/dist/app/views/layout/{foo.rhtml → foo.herb} +0 -0
  13. data/examples/sample_app/dist/app/views/posts/{_comments.rhtml → _comments.herb} +0 -0
  14. data/examples/sample_app/dist/app/views/posts/comment.jerb +1 -0
  15. data/examples/sample_app/dist/app/views/posts/{list.rhtml → list.herb} +0 -0
  16. data/examples/sample_app/dist/app/views/posts/{new.rhtml → new.herb} +0 -0
  17. data/examples/sample_app/dist/app/views/posts/{show.rhtml → show.herb} +0 -0
  18. data/examples/sample_app/dist/app/views/posts/xml_test.xerb +3 -0
  19. data/examples/sample_app/dist/app/views/test/{foo.rhtml → foo.herb} +0 -0
  20. data/examples/sample_app/dist/app/views/test/{hello.rhtml → hello.herb} +0 -0
  21. data/examples/sample_app/dist/app/views/test/json.jerb +1 -0
  22. data/examples/sample_app/dist/conf/merb.yml +11 -0
  23. data/examples/sample_app/dist/conf/merb_init.rb +1 -1
  24. data/examples/sample_app/dist/conf/mup.conf +11 -0
  25. data/examples/sample_app/dist/public/javascripts/mup.js +113 -0
  26. data/examples/sample_app/script/merb_stop +7 -3
  27. data/examples/sample_app/script/startdrb +8 -0
  28. data/lib/merb.rb +37 -2
  29. data/lib/merb/merb_class_extensions.rb +21 -22
  30. data/lib/merb/merb_controller.rb +101 -33
  31. data/lib/merb/merb_handler.rb +26 -25
  32. data/lib/merb/merb_router.rb +1 -1
  33. data/lib/merb/merb_utils.rb +35 -37
  34. data/lib/merb/mixins/basic_authentication_mixin.rb +39 -0
  35. data/lib/merb/mixins/controller_mixin.rb +119 -115
  36. data/lib/merb/mixins/javascript_mixin.rb +63 -0
  37. data/lib/merb/mixins/render_mixin.rb +85 -69
  38. data/lib/merb/mixins/responder_mixin.rb +38 -0
  39. data/lib/merb/session/merb_drb_server.rb +107 -0
  40. data/lib/merb/session/merb_drb_session.rb +71 -0
  41. data/lib/merb/session/merb_session.rb +1 -0
  42. data/lib/merb/vendor/paginator/README.txt +84 -0
  43. data/lib/merb/vendor/paginator/paginator.rb +121 -0
  44. data/lib/mutex_hotfix.rb +34 -0
  45. metadata +41 -63
  46. data/doc/rdoc/classes/ControllerMixin.html +0 -676
  47. data/doc/rdoc/classes/Hash.html +0 -148
  48. data/doc/rdoc/classes/Merb.html +0 -140
  49. data/doc/rdoc/classes/Merb/Controller.html +0 -338
  50. data/doc/rdoc/classes/Merb/RouteMatcher.html +0 -388
  51. data/doc/rdoc/classes/Merb/Server.html +0 -148
  52. data/doc/rdoc/classes/Merb/Session.html +0 -201
  53. data/doc/rdoc/classes/Merb/SessionMixin.html +0 -199
  54. data/doc/rdoc/classes/MerbControllerError.html +0 -111
  55. data/doc/rdoc/classes/MerbHandler.html +0 -430
  56. data/doc/rdoc/classes/MerbHash.html +0 -469
  57. data/doc/rdoc/classes/MerbHash/Mutex.html +0 -198
  58. data/doc/rdoc/classes/Noroutefound.html +0 -153
  59. data/doc/rdoc/classes/Object.html +0 -149
  60. data/doc/rdoc/classes/RenderMixin.html +0 -362
  61. data/doc/rdoc/classes/String.html +0 -212
  62. data/doc/rdoc/classes/Symbol.html +0 -179
  63. data/doc/rdoc/created.rid +0 -1
  64. data/doc/rdoc/files/LICENSE.html +0 -129
  65. data/doc/rdoc/files/README.html +0 -417
  66. data/doc/rdoc/files/TODO.html +0 -151
  67. data/doc/rdoc/files/lib/merb/merb_class_extensions_rb.html +0 -101
  68. data/doc/rdoc/files/lib/merb/merb_controller_rb.html +0 -101
  69. data/doc/rdoc/files/lib/merb/merb_handler_rb.html +0 -101
  70. data/doc/rdoc/files/lib/merb/merb_router_rb.html +0 -101
  71. data/doc/rdoc/files/lib/merb/merb_utils_rb.html +0 -108
  72. data/doc/rdoc/files/lib/merb/mixins/controller_mixin_rb.html +0 -101
  73. data/doc/rdoc/files/lib/merb/mixins/render_mixin_rb.html +0 -101
  74. data/doc/rdoc/files/lib/merb/session/merb_session_rb.html +0 -101
  75. data/doc/rdoc/files/lib/merb_rb.html +0 -140
  76. data/doc/rdoc/files/lib/merb_tasks_rb.html +0 -101
  77. data/doc/rdoc/fr_class_index.html +0 -43
  78. data/doc/rdoc/fr_file_index.html +0 -40
  79. data/doc/rdoc/fr_method_index.html +0 -104
  80. data/doc/rdoc/index.html +0 -24
  81. data/doc/rdoc/rdoc-style.css +0 -208
  82. data/examples/sample_app/dist/app/controllers/upload.rb +0 -29
  83. data/examples/sample_app/dist/app/views/posts/comment.merbjs +0 -1
  84. data/examples/sample_app/dist/app/views/upload/start.rhtml +0 -15
  85. data/examples/sample_app/dist/app/views/upload/upload.rhtml +0 -4
  86. data/examples/sample_app/dist/public/files/README +0 -35
  87. data/examples/sample_app/dist/public/files/setup.rb +0 -1346
  88. data/examples/sample_app/log/merb.log +0 -778
@@ -0,0 +1,84 @@
1
+ paginator
2
+ by Bruce Williams
3
+ http://codefluency.com
4
+
5
+ == DESCRIPTION:
6
+
7
+ Paginator is a simple pagination class that provides a generic interface suitable
8
+ for use in any Ruby program.
9
+
10
+ == FEATURES/PROBLEMS:
11
+
12
+ Paginator doesn't make any assumptions as to how data is retrieved; you just
13
+ have to provide it with the total number of objects and a way to pull a specific
14
+ set of objects based on the offset and number of objects per page.
15
+
16
+ == SYNOPSIS:
17
+
18
+ In both of these examples I'm using a PER_PAGE constant (the number of items per page), but it's merely for labeling purposes.
19
+
20
+ You could, of course, just pass in the number of items per page directly to the initializer without assigning it somewhere beforehand.
21
+
22
+ === In a Rails Application
23
+
24
+ def index
25
+ @pager = ::Paginator.new(Foo.count, PER_PAGE) do |offset, per_page|
26
+ Foo.find(:all, :limit => per_page, :offset => offset)
27
+ end
28
+ @page = @pager.page(params[:page])
29
+ # respond_to here if you want it
30
+ end
31
+
32
+ # In your view
33
+ <% @page.items.each do |foo| %>
34
+ <%# Show something for each item %>
35
+ <% end %>
36
+ <%= @page.number %>
37
+ <%= link_to("Prev", foos_url(:page => @page.prev.number)) if @page.prev? %>
38
+ <%= link_to("Next", foos_url(:page => @page.next.number)) if @page.next? %>
39
+
40
+ === Anything else
41
+
42
+ bunch_o_data = (1..60).to_a
43
+ pager = Paginator.new(bunch_o_data.size, PER_PAGE) do |offset, per_page|
44
+ bunch_o_data[offset,per_page]
45
+ end
46
+ pager.each do |page|
47
+ puts "Page ##{page.number}"
48
+ page.each do |item|
49
+ puts item
50
+ end
51
+ end
52
+
53
+ == REQUIREMENTS:
54
+
55
+ None.
56
+
57
+ == INSTALL:
58
+
59
+ No special instructions.
60
+
61
+ == LICENSE:
62
+
63
+ (The MIT License)
64
+
65
+ Copyright (c) 2006 Bruce Williams (http://codefluency.com)
66
+
67
+ Permission is hereby granted, free of charge, to any person obtaining
68
+ a copy of this software and associated documentation files (the
69
+ 'Software'), to deal in the Software without restriction, including
70
+ without limitation the rights to use, copy, modify, merge, publish,
71
+ distribute, sublicense, and/or sell copies of the Software, and to
72
+ permit persons to whom the Software is furnished to do so, subject to
73
+ the following conditions:
74
+
75
+ The above copyright notice and this permission notice shall be
76
+ included in all copies or substantial portions of the Software.
77
+
78
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
79
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
80
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
81
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
82
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
83
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
84
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,121 @@
1
+ require 'forwardable'
2
+
3
+ class Paginator
4
+
5
+ VERSION = '1.0.6'
6
+
7
+ class ArgumentError < ::ArgumentError; end
8
+ class MissingCountError < ArgumentError; end
9
+ class MissingSelectError < ArgumentError; end
10
+
11
+ attr_reader :per_page
12
+
13
+ # Instantiate a new Paginator object
14
+ #
15
+ # Provide:
16
+ # * A total count of the number of objects to paginate
17
+ # * The number of objects in each page
18
+ # * A block that returns the array of items
19
+ # * The block is passed the item offset
20
+ # (and the number of items to show per page, for
21
+ # convenience, if the arity is 2)
22
+ def initialize(count, per_page, &select)
23
+ @count, @per_page = count, per_page
24
+ unless select
25
+ raise MissingSelectError, "Must provide block to select data for each page"
26
+ end
27
+ @select = select
28
+ end
29
+
30
+ # Total number of pages
31
+ def number_of_pages
32
+ (@count / @per_page) + (@count % @per_page > 0 ? 1 : 0)
33
+ end
34
+
35
+ # First page object
36
+ def first
37
+ page 1
38
+ end
39
+
40
+ # Last page object
41
+ def last
42
+ page number_of_pages
43
+ end
44
+
45
+ # Iterate through pages
46
+ def each
47
+ each_with_index do |item, index|
48
+ yield item
49
+ end
50
+ end
51
+
52
+ # Iterate through pages with indices
53
+ def each_with_index
54
+ 1.upto(number_of_pages) do |number|
55
+ yield(page(number), number - 1)
56
+ end
57
+ end
58
+
59
+ # Retrieve page object by number
60
+ def page(number)
61
+ number = (n = number.to_i) > 0 ? n : 1
62
+ Page.new(self, number, lambda {
63
+ offset = (number - 1) * @per_page
64
+ args = [offset]
65
+ args << @per_page if @select.arity == 2
66
+ @select.call(*args)
67
+ })
68
+ end
69
+
70
+ # Page object
71
+ #
72
+ # Retrieves items for a page and provides metadata about the position
73
+ # of the page in the paginator
74
+ class Page
75
+
76
+ extend Forwardable
77
+ def_delegator :@pager, :first, :first
78
+ def_delegator :@pager, :last, :last
79
+ def_delegator :items, :each
80
+ def_delegator :items, :each_with_index
81
+
82
+ attr_reader :number, :pager
83
+
84
+ def initialize(pager, number, select) #:nodoc:
85
+ @pager, @number = pager, number
86
+ @select = select
87
+ end
88
+
89
+ # Retrieve the items for this page
90
+ # * Caches
91
+ def items
92
+ @items ||= @select.call
93
+ end
94
+
95
+ # Checks to see if there's a page before this one
96
+ def prev?
97
+ @number > 1
98
+ end
99
+
100
+ # Get previous page (if possible)
101
+ def prev
102
+ @pager.page(@number - 1) if prev?
103
+ end
104
+
105
+ # Checks to see if there's a page after this one
106
+ def next?
107
+ @number < @pager.number_of_pages
108
+ end
109
+
110
+ # Get next page (if possible)
111
+ def next
112
+ @pager.page(@number + 1) if next?
113
+ end
114
+
115
+ def ==(other) #:nodoc:
116
+ @pager == other.pager && self.number == other.number
117
+ end
118
+
119
+ end
120
+
121
+ end
@@ -0,0 +1,34 @@
1
+ require 'thread'
2
+
3
+ # monkey patch Mutex so it does not leak memory.
4
+ class Mutex
5
+
6
+ def lock
7
+ while (Thread.critical = true; @locked)
8
+ @waiting.unshift Thread.current
9
+ Thread.stop
10
+ end
11
+ @locked = true
12
+ Thread.critical = false
13
+ self
14
+ end
15
+
16
+ def unlock
17
+ return unless @locked
18
+ Thread.critical = true
19
+ @locked = false
20
+ begin
21
+ t = @waiting.pop
22
+ t.wakeup if t
23
+ rescue ThreadError
24
+ retry
25
+ end
26
+ Thread.critical = false
27
+ begin
28
+ t.run if t
29
+ rescue ThreadError
30
+ end
31
+ self
32
+ end
33
+
34
+ end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: merb
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.6
7
- date: 2006-11-09 00:00:00 -08:00
6
+ version: 0.0.7
7
+ date: 2006-11-29 00:00:00 -08:00
8
8
  summary: Merb == Mongrel + Erb. Pocket rocket web framework.
9
9
  require_paths:
10
10
  - lib
@@ -34,57 +34,13 @@ files:
34
34
  - Rakefile
35
35
  - TODO
36
36
  - bin/merb
37
- - doc/rdoc
38
- - doc/rdoc/classes
39
- - doc/rdoc/created.rid
40
- - doc/rdoc/files
41
- - doc/rdoc/fr_class_index.html
42
- - doc/rdoc/fr_file_index.html
43
- - doc/rdoc/fr_method_index.html
44
- - doc/rdoc/index.html
45
- - doc/rdoc/rdoc-style.css
46
- - doc/rdoc/classes/ControllerMixin.html
47
- - doc/rdoc/classes/Hash.html
48
- - doc/rdoc/classes/Merb
49
- - doc/rdoc/classes/Merb.html
50
- - doc/rdoc/classes/MerbControllerError.html
51
- - doc/rdoc/classes/MerbHandler.html
52
- - doc/rdoc/classes/MerbHash
53
- - doc/rdoc/classes/MerbHash.html
54
- - doc/rdoc/classes/Noroutefound.html
55
- - doc/rdoc/classes/Object.html
56
- - doc/rdoc/classes/RenderMixin.html
57
- - doc/rdoc/classes/String.html
58
- - doc/rdoc/classes/Symbol.html
59
- - doc/rdoc/classes/Merb/Controller.html
60
- - doc/rdoc/classes/Merb/RouteMatcher.html
61
- - doc/rdoc/classes/Merb/Server.html
62
- - doc/rdoc/classes/Merb/Session.html
63
- - doc/rdoc/classes/Merb/SessionMixin.html
64
- - doc/rdoc/classes/MerbHash/Mutex.html
65
- - doc/rdoc/files/lib
66
- - doc/rdoc/files/LICENSE.html
67
- - doc/rdoc/files/README.html
68
- - doc/rdoc/files/TODO.html
69
- - doc/rdoc/files/lib/merb
70
- - doc/rdoc/files/lib/merb_rb.html
71
- - doc/rdoc/files/lib/merb_tasks_rb.html
72
- - doc/rdoc/files/lib/merb/merb_class_extensions_rb.html
73
- - doc/rdoc/files/lib/merb/merb_controller_rb.html
74
- - doc/rdoc/files/lib/merb/merb_handler_rb.html
75
- - doc/rdoc/files/lib/merb/merb_router_rb.html
76
- - doc/rdoc/files/lib/merb/merb_utils_rb.html
77
- - doc/rdoc/files/lib/merb/mixins
78
- - doc/rdoc/files/lib/merb/session
79
- - doc/rdoc/files/lib/merb/mixins/controller_mixin_rb.html
80
- - doc/rdoc/files/lib/merb/mixins/render_mixin_rb.html
81
- - doc/rdoc/files/lib/merb/session/merb_session_rb.html
82
37
  - test/test_helper.rb
83
38
  - test/unit
84
39
  - test/unit/route_matcher_test.rb
85
40
  - lib/merb
86
41
  - lib/merb.rb
87
42
  - lib/merb_tasks.rb
43
+ - lib/mutex_hotfix.rb
88
44
  - lib/tasks
89
45
  - lib/merb/merb_class_extensions.rb
90
46
  - lib/merb/merb_controller.rb
@@ -93,9 +49,18 @@ files:
93
49
  - lib/merb/merb_utils.rb
94
50
  - lib/merb/mixins
95
51
  - lib/merb/session
52
+ - lib/merb/vendor
53
+ - lib/merb/mixins/basic_authentication_mixin.rb
96
54
  - lib/merb/mixins/controller_mixin.rb
55
+ - lib/merb/mixins/javascript_mixin.rb
97
56
  - lib/merb/mixins/render_mixin.rb
57
+ - lib/merb/mixins/responder_mixin.rb
58
+ - lib/merb/session/merb_drb_server.rb
59
+ - lib/merb/session/merb_drb_session.rb
98
60
  - lib/merb/session/merb_session.rb
61
+ - lib/merb/vendor/paginator
62
+ - lib/merb/vendor/paginator/paginator.rb
63
+ - lib/merb/vendor/paginator/README.txt
99
64
  - lib/tasks/db.rake
100
65
  - examples/app_skeleton
101
66
  - examples/sample_app
@@ -144,34 +109,37 @@ files:
144
109
  - examples/sample_app/dist/app/controllers
145
110
  - examples/sample_app/dist/app/models
146
111
  - examples/sample_app/dist/app/views
112
+ - examples/sample_app/dist/app/controllers/files.rb
147
113
  - examples/sample_app/dist/app/controllers/posts.rb
148
114
  - examples/sample_app/dist/app/controllers/test.rb
149
- - examples/sample_app/dist/app/controllers/upload.rb
150
115
  - examples/sample_app/dist/app/models/comment.rb
151
116
  - examples/sample_app/dist/app/models/post.rb
117
+ - examples/sample_app/dist/app/views/files
152
118
  - examples/sample_app/dist/app/views/layout
153
119
  - examples/sample_app/dist/app/views/posts
154
120
  - examples/sample_app/dist/app/views/test
155
- - examples/sample_app/dist/app/views/upload
156
- - examples/sample_app/dist/app/views/layout/application.rhtml
157
- - examples/sample_app/dist/app/views/layout/foo.rhtml
158
- - examples/sample_app/dist/app/views/posts/_comments.rhtml
159
- - examples/sample_app/dist/app/views/posts/comment.merbjs
160
- - examples/sample_app/dist/app/views/posts/list.rhtml
161
- - examples/sample_app/dist/app/views/posts/new.rhtml
162
- - examples/sample_app/dist/app/views/posts/show.rhtml
163
- - examples/sample_app/dist/app/views/test/foo.rhtml
164
- - examples/sample_app/dist/app/views/test/hello.rhtml
165
- - examples/sample_app/dist/app/views/upload/start.rhtml
166
- - examples/sample_app/dist/app/views/upload/upload.rhtml
121
+ - examples/sample_app/dist/app/views/files/progress.jerb
122
+ - examples/sample_app/dist/app/views/files/start.herb
123
+ - examples/sample_app/dist/app/views/files/upload.herb
124
+ - examples/sample_app/dist/app/views/layout/application.herb
125
+ - examples/sample_app/dist/app/views/layout/foo.herb
126
+ - examples/sample_app/dist/app/views/posts/_comments.herb
127
+ - examples/sample_app/dist/app/views/posts/comment.jerb
128
+ - examples/sample_app/dist/app/views/posts/list.herb
129
+ - examples/sample_app/dist/app/views/posts/new.herb
130
+ - examples/sample_app/dist/app/views/posts/show.herb
131
+ - examples/sample_app/dist/app/views/posts/xml_test.xerb
132
+ - examples/sample_app/dist/app/views/test/foo.herb
133
+ - examples/sample_app/dist/app/views/test/hello.herb
134
+ - examples/sample_app/dist/app/views/test/json.jerb
135
+ - examples/sample_app/dist/conf/merb.yml
167
136
  - examples/sample_app/dist/conf/merb_init.rb
137
+ - examples/sample_app/dist/conf/mup.conf
168
138
  - examples/sample_app/dist/conf/router.rb
169
139
  - examples/sample_app/dist/public/files
170
140
  - examples/sample_app/dist/public/images
171
141
  - examples/sample_app/dist/public/javascripts
172
142
  - examples/sample_app/dist/public/stylesheets
173
- - examples/sample_app/dist/public/files/README
174
- - examples/sample_app/dist/public/files/setup.rb
175
143
  - examples/sample_app/dist/public/images/bg.jpg
176
144
  - examples/sample_app/dist/public/images/book.gif
177
145
  - examples/sample_app/dist/public/images/booksmall.gif
@@ -185,15 +153,16 @@ files:
185
153
  - examples/sample_app/dist/public/images/nautica.jpg
186
154
  - examples/sample_app/dist/public/javascripts/application.js
187
155
  - examples/sample_app/dist/public/javascripts/effects.js
156
+ - examples/sample_app/dist/public/javascripts/mup.js
188
157
  - examples/sample_app/dist/public/javascripts/prototype.js
189
158
  - examples/sample_app/dist/public/stylesheets/merb.css
190
159
  - examples/sample_app/dist/schema/migrations
191
160
  - examples/sample_app/dist/schema/schema.rb
192
161
  - examples/sample_app/dist/schema/migrations/001_add_comments_to_posts.rb
193
162
  - examples/sample_app/dist/schema/migrations/002_add_sessions_table.rb
194
- - examples/sample_app/log/merb.log
195
163
  - examples/sample_app/script/merb_stop
196
164
  - examples/sample_app/script/new_migration
165
+ - examples/sample_app/script/startdrb
197
166
  - examples/sample_app/test/fixtures
198
167
  - examples/sample_app/test/spec
199
168
  - examples/sample_app/test/test_helper.rb
@@ -242,3 +211,12 @@ dependencies:
242
211
  - !ruby/object:Gem::Version
243
212
  version: 0.0.0
244
213
  version:
214
+ - !ruby/object:Gem::Dependency
215
+ name: json
216
+ version_requirement:
217
+ version_requirements: !ruby/object:Gem::Version::Requirement
218
+ requirements:
219
+ - - ">"
220
+ - !ruby/object:Gem::Version
221
+ version: 0.0.0
222
+ version:
@@ -1,676 +0,0 @@
1
- <?xml version="1.0" encoding="iso-8859-1"?>
2
- <!DOCTYPE html
3
- PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
-
6
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
- <head>
8
- <title>Module: ControllerMixin</title>
9
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
- <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
- <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
- <script type="text/javascript">
13
- // <![CDATA[
14
-
15
- function popupCode( url ) {
16
- window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
- }
18
-
19
- function toggleCode( id ) {
20
- if ( document.getElementById )
21
- elem = document.getElementById( id );
22
- else if ( document.all )
23
- elem = eval( "document.all." + id );
24
- else
25
- return false;
26
-
27
- elemStyle = elem.style;
28
-
29
- if ( elemStyle.display != "block" ) {
30
- elemStyle.display = "block"
31
- } else {
32
- elemStyle.display = "none"
33
- }
34
-
35
- return true;
36
- }
37
-
38
- // Make codeblocks hidden by default
39
- document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
-
41
- // ]]>
42
- </script>
43
-
44
- </head>
45
- <body>
46
-
47
-
48
-
49
- <div id="classHeader">
50
- <table class="header-table">
51
- <tr class="top-aligned-row">
52
- <td><strong>Module</strong></td>
53
- <td class="class-name-in-header">ControllerMixin</td>
54
- </tr>
55
- <tr class="top-aligned-row">
56
- <td><strong>In:</strong></td>
57
- <td>
58
- <a href="../files/lib/merb/mixins/controller_mixin_rb.html">
59
- lib/merb/mixins/controller_mixin.rb
60
- </a>
61
- <br />
62
- </td>
63
- </tr>
64
-
65
- </table>
66
- </div>
67
- <!-- banner header -->
68
-
69
- <div id="bodyContent">
70
-
71
-
72
-
73
- <div id="contextContent">
74
-
75
-
76
-
77
- </div>
78
-
79
- <div id="method-list">
80
- <h3 class="section-bar">Methods</h3>
81
-
82
- <div class="name-list">
83
- <a href="#M000048">ajax?</a>&nbsp;&nbsp;
84
- <a href="#M000058">domain</a>&nbsp;&nbsp;
85
- <a href="#M000042">escape</a>&nbsp;&nbsp;
86
- <a href="#M000044">escape_js</a>&nbsp;&nbsp;
87
- <a href="#M000056">host</a>&nbsp;&nbsp;
88
- <a href="#M000045">js</a>&nbsp;&nbsp;
89
- <a href="#M000059">method</a>&nbsp;&nbsp;
90
- <a href="#M000040">nginx_send_file</a>&nbsp;&nbsp;
91
- <a href="#M000053">path</a>&nbsp;&nbsp;
92
- <a href="#M000054">path_info</a>&nbsp;&nbsp;
93
- <a href="#M000055">port</a>&nbsp;&nbsp;
94
- <a href="#M000050">protocol</a>&nbsp;&nbsp;
95
- <a href="#M000041">query_parse</a>&nbsp;&nbsp;
96
- <a href="#M000038">redirect</a>&nbsp;&nbsp;
97
- <a href="#M000049">remote_ip</a>&nbsp;&nbsp;
98
- <a href="#M000039">send_file</a>&nbsp;&nbsp;
99
- <a href="#M000051">ssl?</a>&nbsp;&nbsp;
100
- <a href="#M000057">subdomains</a>&nbsp;&nbsp;
101
- <a href="#M000043">unescape</a>&nbsp;&nbsp;
102
- <a href="#M000052">uri</a>&nbsp;&nbsp;
103
- <a href="#M000047">xhr?</a>&nbsp;&nbsp;
104
- <a href="#M000046">xml_http_request?</a>&nbsp;&nbsp;
105
- </div>
106
- </div>
107
-
108
- </div>
109
-
110
-
111
- <!-- if includes -->
112
-
113
- <div id="section">
114
-
115
-
116
-
117
-
118
-
119
-
120
-
121
-
122
- <!-- if method_list -->
123
- <div id="methods">
124
- <h3 class="section-bar">Public Instance methods</h3>
125
-
126
- <div id="method-M000048" class="method-detail">
127
- <a name="M000048"></a>
128
-
129
- <div class="method-heading">
130
- <span class="method-name">ajax?</span><span class="method-args">()</span>
131
- </div>
132
-
133
- <div class="method-description">
134
- <p>
135
- Alias for xml_http_request?
136
- </p>
137
- </div>
138
- </div>
139
-
140
- <div id="method-M000058" class="method-detail">
141
- <a name="M000058"></a>
142
-
143
- <div class="method-heading">
144
- <a href="#M000058" class="method-signature">
145
- <span class="method-name">domain</span><span class="method-args">(tld_length = 1)</span>
146
- </a>
147
- </div>
148
-
149
- <div class="method-description">
150
- <p><a class="source-toggle" href="#"
151
- onclick="toggleCode('M000058-source');return false;">[Source]</a></p>
152
- <div class="method-source-code" id="M000058-source">
153
- <pre>
154
- <span class="ruby-comment cmt"># File lib/merb/mixins/controller_mixin.rb, line 116</span>
155
- 116: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">domain</span>(<span class="ruby-identifier">tld_length</span> = <span class="ruby-value">1</span>)
156
- 117: <span class="ruby-identifier">host</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">'.'</span>).<span class="ruby-identifier">last</span>(<span class="ruby-value">1</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">tld_length</span>).<span class="ruby-identifier">join</span>(<span class="ruby-value str">'.'</span>)
157
- 118: <span class="ruby-keyword kw">end</span>
158
- </pre>
159
- </div>
160
- </div>
161
- </div>
162
-
163
- <div id="method-M000042" class="method-detail">
164
- <a name="M000042"></a>
165
-
166
- <div class="method-heading">
167
- <a href="#M000042" class="method-signature">
168
- <span class="method-name">escape</span><span class="method-args">(s)</span>
169
- </a>
170
- </div>
171
-
172
- <div class="method-description">
173
- <p>
174
- does url escaping
175
- </p>
176
- <p><a class="source-toggle" href="#"
177
- onclick="toggleCode('M000042-source');return false;">[Source]</a></p>
178
- <div class="method-source-code" id="M000042-source">
179
- <pre>
180
- <span class="ruby-comment cmt"># File lib/merb/mixins/controller_mixin.rb, line 44</span>
181
- 44: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">escape</span>(<span class="ruby-identifier">s</span>)
182
- 45: <span class="ruby-constant">Mongrel</span><span class="ruby-operator">::</span><span class="ruby-constant">HttpRequest</span>.<span class="ruby-identifier">escape</span>(<span class="ruby-identifier">s</span>)
183
- 46: <span class="ruby-keyword kw">end</span>
184
- </pre>
185
- </div>
186
- </div>
187
- </div>
188
-
189
- <div id="method-M000044" class="method-detail">
190
- <a name="M000044"></a>
191
-
192
- <div class="method-heading">
193
- <a href="#M000044" class="method-signature">
194
- <span class="method-name">escape_js</span><span class="method-args">(javascript)</span>
195
- </a>
196
- </div>
197
-
198
- <div class="method-description">
199
- <p>
200
- <a href="ControllerMixin.html#M000042">escape</a> text for javascript.
201
- </p>
202
- <p><a class="source-toggle" href="#"
203
- onclick="toggleCode('M000044-source');return false;">[Source]</a></p>
204
- <div class="method-source-code" id="M000044-source">
205
- <pre>
206
- <span class="ruby-comment cmt"># File lib/merb/mixins/controller_mixin.rb, line 54</span>
207
- 54: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">escape_js</span>(<span class="ruby-identifier">javascript</span>)
208
- 55: (<span class="ruby-identifier">javascript</span> <span class="ruby-operator">||</span> <span class="ruby-value str">''</span>).<span class="ruby-identifier">gsub</span>(<span class="ruby-value str">'\\'</span>,<span class="ruby-value str">'\0\0'</span>).<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/\r\n|\n|\r/</span>, <span class="ruby-value str">&quot;\\n&quot;</span>).<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/[&quot;']/</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">m</span><span class="ruby-operator">|</span> <span class="ruby-node">&quot;\\#{m}&quot;</span> }
209
- 56: <span class="ruby-keyword kw">end</span>
210
- </pre>
211
- </div>
212
- </div>
213
- </div>
214
-
215
- <div id="method-M000056" class="method-detail">
216
- <a name="M000056"></a>
217
-
218
- <div class="method-heading">
219
- <a href="#M000056" class="method-signature">
220
- <span class="method-name">host</span><span class="method-args">()</span>
221
- </a>
222
- </div>
223
-
224
- <div class="method-description">
225
- <p><a class="source-toggle" href="#"
226
- onclick="toggleCode('M000056-source');return false;">[Source]</a></p>
227
- <div class="method-source-code" id="M000056-source">
228
- <pre>
229
- <span class="ruby-comment cmt"># File lib/merb/mixins/controller_mixin.rb, line 107</span>
230
- 107: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">host</span>
231
- 108: <span class="ruby-ivar">@headers</span>[<span class="ruby-value str">'HTTP_X_FORWARDED_HOST'</span>] <span class="ruby-operator">||</span> <span class="ruby-ivar">@headers</span>[<span class="ruby-value str">'HTTP_HOST'</span>]
232
- 109: <span class="ruby-keyword kw">end</span>
233
- </pre>
234
- </div>
235
- </div>
236
- </div>
237
-
238
- <div id="method-M000045" class="method-detail">
239
- <a name="M000045"></a>
240
-
241
- <div class="method-heading">
242
- <span class="method-name">js</span><span class="method-args">(javascript)</span>
243
- </div>
244
-
245
- <div class="method-description">
246
- <p>
247
- Alias for <a href="ControllerMixin.html#M000044">escape_js</a>
248
- </p>
249
- </div>
250
- </div>
251
-
252
- <div id="method-M000059" class="method-detail">
253
- <a name="M000059"></a>
254
-
255
- <div class="method-heading">
256
- <a href="#M000059" class="method-signature">
257
- <span class="method-name">method</span><span class="method-args">()</span>
258
- </a>
259
- </div>
260
-
261
- <div class="method-description">
262
- <p><a class="source-toggle" href="#"
263
- onclick="toggleCode('M000059-source');return false;">[Source]</a></p>
264
- <div class="method-source-code" id="M000059-source">
265
- <pre>
266
- <span class="ruby-comment cmt"># File lib/merb/mixins/controller_mixin.rb, line 120</span>
267
- 120: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">method</span>
268
- 121: <span class="ruby-ivar">@headers</span>[<span class="ruby-value str">'REQUEST_METHOD'</span>].<span class="ruby-identifier">downcase</span>.<span class="ruby-identifier">to_sym</span>
269
- 122: <span class="ruby-keyword kw">end</span>
270
- </pre>
271
- </div>
272
- </div>
273
- </div>
274
-
275
- <div id="method-M000040" class="method-detail">
276
- <a name="M000040"></a>
277
-
278
- <div class="method-heading">
279
- <a href="#M000040" class="method-signature">
280
- <span class="method-name">nginx_send_file</span><span class="method-args">(file)</span>
281
- </a>
282
- </div>
283
-
284
- <div class="method-description">
285
- <p>
286
- This uses nginx X-Accel-Redirect header to send a file directly from nginx.
287
- See the nginx wiki: <a
288
- href="http://wiki.codemongers.com/NginxXSendfile">wiki.codemongers.com/NginxXSendfile</a>
289
- </p>
290
- <p><a class="source-toggle" href="#"
291
- onclick="toggleCode('M000040-source');return false;">[Source]</a></p>
292
- <div class="method-source-code" id="M000040-source">
293
- <pre>
294
- <span class="ruby-comment cmt"># File lib/merb/mixins/controller_mixin.rb, line 24</span>
295
- 24: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">nginx_send_file</span>(<span class="ruby-identifier">file</span>)
296
- 25: <span class="ruby-identifier">headers</span>[<span class="ruby-value str">'X-Accel-Redirect'</span>] = <span class="ruby-identifier">file</span>
297
- 26: <span class="ruby-keyword kw">return</span>
298
- 27: <span class="ruby-keyword kw">end</span>
299
- </pre>
300
- </div>
301
- </div>
302
- </div>
303
-
304
- <div id="method-M000053" class="method-detail">
305
- <a name="M000053"></a>
306
-
307
- <div class="method-heading">
308
- <a href="#M000053" class="method-signature">
309
- <span class="method-name">path</span><span class="method-args">()</span>
310
- </a>
311
- </div>
312
-
313
- <div class="method-description">
314
- <p>
315
- The <a href="ControllerMixin.html#M000053">path</a> is the <a
316
- href="ControllerMixin.html#M000052">uri</a> without the query string.
317
- </p>
318
- <p><a class="source-toggle" href="#"
319
- onclick="toggleCode('M000053-source');return false;">[Source]</a></p>
320
- <div class="method-source-code" id="M000053-source">
321
- <pre>
322
- <span class="ruby-comment cmt"># File lib/merb/mixins/controller_mixin.rb, line 95</span>
323
- 95: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">path</span>
324
- 96: <span class="ruby-identifier">uri</span> <span class="ruby-value">? </span><span class="ruby-identifier">uri</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">'?'</span>).<span class="ruby-identifier">first</span> <span class="ruby-operator">:</span> <span class="ruby-value str">''</span>
325
- 97: <span class="ruby-keyword kw">end</span>
326
- </pre>
327
- </div>
328
- </div>
329
- </div>
330
-
331
- <div id="method-M000054" class="method-detail">
332
- <a name="M000054"></a>
333
-
334
- <div class="method-heading">
335
- <a href="#M000054" class="method-signature">
336
- <span class="method-name">path_info</span><span class="method-args">()</span>
337
- </a>
338
- </div>
339
-
340
- <div class="method-description">
341
- <p><a class="source-toggle" href="#"
342
- onclick="toggleCode('M000054-source');return false;">[Source]</a></p>
343
- <div class="method-source-code" id="M000054-source">
344
- <pre>
345
- <span class="ruby-comment cmt"># File lib/merb/mixins/controller_mixin.rb, line 99</span>
346
- 99: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">path_info</span>
347
- 100: <span class="ruby-ivar">@headers</span>[<span class="ruby-value str">'PATH_INFO'</span>]
348
- 101: <span class="ruby-keyword kw">end</span>
349
- </pre>
350
- </div>
351
- </div>
352
- </div>
353
-
354
- <div id="method-M000055" class="method-detail">
355
- <a name="M000055"></a>
356
-
357
- <div class="method-heading">
358
- <a href="#M000055" class="method-signature">
359
- <span class="method-name">port</span><span class="method-args">()</span>
360
- </a>
361
- </div>
362
-
363
- <div class="method-description">
364
- <p><a class="source-toggle" href="#"
365
- onclick="toggleCode('M000055-source');return false;">[Source]</a></p>
366
- <div class="method-source-code" id="M000055-source">
367
- <pre>
368
- <span class="ruby-comment cmt"># File lib/merb/mixins/controller_mixin.rb, line 103</span>
369
- 103: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">port</span>
370
- 104: <span class="ruby-ivar">@headers</span>[<span class="ruby-value str">'SERVER_PORT'</span>].<span class="ruby-identifier">to_i</span>
371
- 105: <span class="ruby-keyword kw">end</span>
372
- </pre>
373
- </div>
374
- </div>
375
- </div>
376
-
377
- <div id="method-M000050" class="method-detail">
378
- <a name="M000050"></a>
379
-
380
- <div class="method-heading">
381
- <a href="#M000050" class="method-signature">
382
- <span class="method-name">protocol</span><span class="method-args">()</span>
383
- </a>
384
- </div>
385
-
386
- <div class="method-description">
387
- <p><a class="source-toggle" href="#"
388
- onclick="toggleCode('M000050-source');return false;">[Source]</a></p>
389
- <div class="method-source-code" id="M000050-source">
390
- <pre>
391
- <span class="ruby-comment cmt"># File lib/merb/mixins/controller_mixin.rb, line 79</span>
392
- 79: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">protocol</span>
393
- 80: <span class="ruby-ivar">@headers</span>[<span class="ruby-value str">'HTTPS'</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">'on'</span> <span class="ruby-operator">?</span> <span class="ruby-value str">'https://'</span> <span class="ruby-operator">:</span> <span class="ruby-value str">'http://'</span>
394
- 81: <span class="ruby-keyword kw">end</span>
395
- </pre>
396
- </div>
397
- </div>
398
- </div>
399
-
400
- <div id="method-M000041" class="method-detail">
401
- <a name="M000041"></a>
402
-
403
- <div class="method-heading">
404
- <a href="#M000041" class="method-signature">
405
- <span class="method-name">query_parse</span><span class="method-args">(qs, d = '&amp;;')</span>
406
- </a>
407
- </div>
408
-
409
- <div class="method-description">
410
- <p>
411
- parses a query string or the payload of a POST request into the params
412
- hash. So for example:
413
- /foo?bar=nik&amp;post[title]=heya&amp;post[body]=whatever parses into:
414
- {:bar =&gt; &#8216;nik&#8217;, :post =&gt; {:title =&gt;
415
- &#8216;heya&#8217;, :body =&gt; &#8216;whatever}}
416
- </p>
417
- <p><a class="source-toggle" href="#"
418
- onclick="toggleCode('M000041-source');return false;">[Source]</a></p>
419
- <div class="method-source-code" id="M000041-source">
420
- <pre>
421
- <span class="ruby-comment cmt"># File lib/merb/mixins/controller_mixin.rb, line 34</span>
422
- 34: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">query_parse</span>(<span class="ruby-identifier">qs</span>, <span class="ruby-identifier">d</span> = <span class="ruby-value str">'&amp;;'</span>)
423
- 35: <span class="ruby-identifier">m</span> = <span class="ruby-identifier">proc</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">_</span>,<span class="ruby-identifier">o</span>,<span class="ruby-identifier">n</span><span class="ruby-operator">|</span><span class="ruby-identifier">o</span>.<span class="ruby-identifier">u</span>(<span class="ruby-identifier">n</span>,<span class="ruby-operator">&amp;</span><span class="ruby-identifier">m</span>)<span class="ruby-keyword kw">rescue</span>([<span class="ruby-operator">*</span><span class="ruby-identifier">o</span>]<span class="ruby-operator">&lt;&lt;</span><span class="ruby-identifier">n</span>)}
424
- 36: (<span class="ruby-identifier">qs</span><span class="ruby-operator">||</span><span class="ruby-value str">''</span>).<span class="ruby-identifier">split</span>(<span class="ruby-node">/[#{d}] */n</span>).<span class="ruby-identifier">inject</span>(<span class="ruby-constant">MerbHash</span>[]) { <span class="ruby-operator">|</span><span class="ruby-identifier">h</span>,<span class="ruby-identifier">p</span><span class="ruby-operator">|</span>
425
- 37: <span class="ruby-identifier">k</span>, <span class="ruby-identifier">v</span>=<span class="ruby-identifier">unescape</span>(<span class="ruby-identifier">p</span>).<span class="ruby-identifier">split</span>(<span class="ruby-value str">'='</span>,<span class="ruby-value">2</span>)
426
- 38: <span class="ruby-identifier">h</span>.<span class="ruby-identifier">u</span>(<span class="ruby-identifier">k</span>.<span class="ruby-identifier">split</span>(<span class="ruby-regexp re">/[\]\[]+/</span>).<span class="ruby-identifier">reverse</span>.
427
- 39: <span class="ruby-identifier">inject</span>(<span class="ruby-identifier">v</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">x</span>,<span class="ruby-identifier">i</span><span class="ruby-operator">|</span> <span class="ruby-constant">MerbHash</span>[<span class="ruby-identifier">i</span>,<span class="ruby-identifier">x</span>] },<span class="ruby-operator">&amp;</span><span class="ruby-identifier">m</span>)
428
- 40: }
429
- 41: <span class="ruby-keyword kw">end</span>
430
- </pre>
431
- </div>
432
- </div>
433
- </div>
434
-
435
- <div id="method-M000038" class="method-detail">
436
- <a name="M000038"></a>
437
-
438
- <div class="method-heading">
439
- <a href="#M000038" class="method-signature">
440
- <span class="method-name">redirect</span><span class="method-args">(url)</span>
441
- </a>
442
- </div>
443
-
444
- <div class="method-description">
445
- <p>
446
- <a href="ControllerMixin.html#M000038">redirect</a> to another url It can
447
- be like /foo/bar for redirecting within your same app. Or it can be a fully
448
- qualified url to another site.
449
- </p>
450
- <p><a class="source-toggle" href="#"
451
- onclick="toggleCode('M000038-source');return false;">[Source]</a></p>
452
- <div class="method-source-code" id="M000038-source">
453
- <pre>
454
- <span class="ruby-comment cmt"># File lib/merb/mixins/controller_mixin.rb, line 6</span>
455
- 6: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">redirect</span>(<span class="ruby-identifier">url</span>)
456
- 7: <span class="ruby-constant">MERB_LOGGER</span>.<span class="ruby-identifier">info</span>(<span class="ruby-node">&quot;Redirecting to: #{url}&quot;</span>)
457
- 8: <span class="ruby-ivar">@status</span> = <span class="ruby-value">302</span>
458
- 9: <span class="ruby-ivar">@headers</span>.<span class="ruby-identifier">merge!</span>({<span class="ruby-value str">'Location'</span>=<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">url</span>})
459
- 10: <span class="ruby-keyword kw">return</span> <span class="ruby-value str">''</span>
460
- 11: <span class="ruby-keyword kw">end</span>
461
- </pre>
462
- </div>
463
- </div>
464
- </div>
465
-
466
- <div id="method-M000049" class="method-detail">
467
- <a name="M000049"></a>
468
-
469
- <div class="method-heading">
470
- <a href="#M000049" class="method-signature">
471
- <span class="method-name">remote_ip</span><span class="method-args">()</span>
472
- </a>
473
- </div>
474
-
475
- <div class="method-description">
476
- <p><a class="source-toggle" href="#"
477
- onclick="toggleCode('M000049-source');return false;">[Source]</a></p>
478
- <div class="method-source-code" id="M000049-source">
479
- <pre>
480
- <span class="ruby-comment cmt"># File lib/merb/mixins/controller_mixin.rb, line 65</span>
481
- 65: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">remote_ip</span>
482
- 66: <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@headers</span>[<span class="ruby-value str">'HTTP_CLIENT_IP'</span>] <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@headers</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-value str">'HTTP_CLIENT_IP'</span>)
483
- 67:
484
- 68: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@headers</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-value str">'HTTP_X_FORWARDED_FOR'</span>) <span class="ruby-keyword kw">then</span>
485
- 69: <span class="ruby-identifier">remote_ips</span> = <span class="ruby-ivar">@headers</span>[<span class="ruby-value str">'HTTP_X_FORWARDED_FOR'</span>].<span class="ruby-identifier">split</span>(<span class="ruby-value str">','</span>).<span class="ruby-identifier">reject</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">ip</span><span class="ruby-operator">|</span>
486
- 70: <span class="ruby-identifier">ip</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^unknown$|^(127|10|172\.16|192\.168)\./i</span>
487
- 71: <span class="ruby-keyword kw">end</span>
488
- 72:
489
- 73: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">remote_ips</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">strip</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">remote_ips</span>.<span class="ruby-identifier">empty?</span>
490
- 74: <span class="ruby-keyword kw">end</span>
491
- 75:
492
- 76: <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@headers</span>[<span class="ruby-value str">'REMOTE_ADDR'</span>]
493
- 77: <span class="ruby-keyword kw">end</span>
494
- </pre>
495
- </div>
496
- </div>
497
- </div>
498
-
499
- <div id="method-M000039" class="method-detail">
500
- <a name="M000039"></a>
501
-
502
- <div class="method-heading">
503
- <a href="#M000039" class="method-signature">
504
- <span class="method-name">send_file</span><span class="method-args">(file)</span>
505
- </a>
506
- </div>
507
-
508
- <div class="method-description">
509
- <p>
510
- pass in a <a href="ControllerMixin.html#M000053">path</a> to a file and
511
- this will set the right headers and let mongrel do its thang and serve the
512
- static file directly.
513
- </p>
514
- <p><a class="source-toggle" href="#"
515
- onclick="toggleCode('M000039-source');return false;">[Source]</a></p>
516
- <div class="method-source-code" id="M000039-source">
517
- <pre>
518
- <span class="ruby-comment cmt"># File lib/merb/mixins/controller_mixin.rb, line 16</span>
519
- 16: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">send_file</span>(<span class="ruby-identifier">file</span>)
520
- 17: <span class="ruby-identifier">headers</span>[<span class="ruby-value str">'X-SENDFILE'</span>] = <span class="ruby-identifier">file</span>
521
- 18: <span class="ruby-keyword kw">return</span>
522
- 19: <span class="ruby-keyword kw">end</span>
523
- </pre>
524
- </div>
525
- </div>
526
- </div>
527
-
528
- <div id="method-M000051" class="method-detail">
529
- <a name="M000051"></a>
530
-
531
- <div class="method-heading">
532
- <a href="#M000051" class="method-signature">
533
- <span class="method-name">ssl?</span><span class="method-args">()</span>
534
- </a>
535
- </div>
536
-
537
- <div class="method-description">
538
- <p><a class="source-toggle" href="#"
539
- onclick="toggleCode('M000051-source');return false;">[Source]</a></p>
540
- <div class="method-source-code" id="M000051-source">
541
- <pre>
542
- <span class="ruby-comment cmt"># File lib/merb/mixins/controller_mixin.rb, line 83</span>
543
- 83: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">ssl?</span>
544
- 84: <span class="ruby-ivar">@headers</span>[<span class="ruby-value str">'HTTPS'</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">'on'</span>
545
- 85: <span class="ruby-keyword kw">end</span>
546
- </pre>
547
- </div>
548
- </div>
549
- </div>
550
-
551
- <div id="method-M000057" class="method-detail">
552
- <a name="M000057"></a>
553
-
554
- <div class="method-heading">
555
- <a href="#M000057" class="method-signature">
556
- <span class="method-name">subdomains</span><span class="method-args">(tld_length = 1)</span>
557
- </a>
558
- </div>
559
-
560
- <div class="method-description">
561
- <p><a class="source-toggle" href="#"
562
- onclick="toggleCode('M000057-source');return false;">[Source]</a></p>
563
- <div class="method-source-code" id="M000057-source">
564
- <pre>
565
- <span class="ruby-comment cmt"># File lib/merb/mixins/controller_mixin.rb, line 111</span>
566
- 111: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">subdomains</span>(<span class="ruby-identifier">tld_length</span> = <span class="ruby-value">1</span>)
567
- 112: <span class="ruby-identifier">parts</span> = <span class="ruby-identifier">host</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">'.'</span>)
568
- 113: <span class="ruby-identifier">parts</span>[<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-operator">-</span>(<span class="ruby-identifier">tld_length</span><span class="ruby-operator">+</span><span class="ruby-value">2</span>)]
569
- 114: <span class="ruby-keyword kw">end</span>
570
- </pre>
571
- </div>
572
- </div>
573
- </div>
574
-
575
- <div id="method-M000043" class="method-detail">
576
- <a name="M000043"></a>
577
-
578
- <div class="method-heading">
579
- <a href="#M000043" class="method-signature">
580
- <span class="method-name">unescape</span><span class="method-args">(s)</span>
581
- </a>
582
- </div>
583
-
584
- <div class="method-description">
585
- <p>
586
- does url unescaping
587
- </p>
588
- <p><a class="source-toggle" href="#"
589
- onclick="toggleCode('M000043-source');return false;">[Source]</a></p>
590
- <div class="method-source-code" id="M000043-source">
591
- <pre>
592
- <span class="ruby-comment cmt"># File lib/merb/mixins/controller_mixin.rb, line 49</span>
593
- 49: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">unescape</span>(<span class="ruby-identifier">s</span>)
594
- 50: <span class="ruby-constant">Mongrel</span><span class="ruby-operator">::</span><span class="ruby-constant">HttpRequest</span>.<span class="ruby-identifier">unescape</span>(<span class="ruby-identifier">s</span>)
595
- 51: <span class="ruby-keyword kw">end</span>
596
- </pre>
597
- </div>
598
- </div>
599
- </div>
600
-
601
- <div id="method-M000052" class="method-detail">
602
- <a name="M000052"></a>
603
-
604
- <div class="method-heading">
605
- <a href="#M000052" class="method-signature">
606
- <span class="method-name">uri</span><span class="method-args">()</span>
607
- </a>
608
- </div>
609
-
610
- <div class="method-description">
611
- <p>
612
- The request <a href="ControllerMixin.html#M000052">uri</a>.
613
- </p>
614
- <p><a class="source-toggle" href="#"
615
- onclick="toggleCode('M000052-source');return false;">[Source]</a></p>
616
- <div class="method-source-code" id="M000052-source">
617
- <pre>
618
- <span class="ruby-comment cmt"># File lib/merb/mixins/controller_mixin.rb, line 89</span>
619
- 89: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">uri</span>
620
- 90: <span class="ruby-ivar">@headers</span>[<span class="ruby-value str">'REQUEST_URI'</span>]
621
- 91: <span class="ruby-keyword kw">end</span>
622
- </pre>
623
- </div>
624
- </div>
625
- </div>
626
-
627
- <div id="method-M000047" class="method-detail">
628
- <a name="M000047"></a>
629
-
630
- <div class="method-heading">
631
- <span class="method-name">xhr?</span><span class="method-args">()</span>
632
- </div>
633
-
634
- <div class="method-description">
635
- <p>
636
- Alias for xml_http_request?
637
- </p>
638
- </div>
639
- </div>
640
-
641
- <div id="method-M000046" class="method-detail">
642
- <a name="M000046"></a>
643
-
644
- <div class="method-heading">
645
- <a href="#M000046" class="method-signature">
646
- <span class="method-name">xml_http_request?</span><span class="method-args">()</span>
647
- </a>
648
- </div>
649
-
650
- <div class="method-description">
651
- <p><a class="source-toggle" href="#"
652
- onclick="toggleCode('M000046-source');return false;">[Source]</a></p>
653
- <div class="method-source-code" id="M000046-source">
654
- <pre>
655
- <span class="ruby-comment cmt"># File lib/merb/mixins/controller_mixin.rb, line 59</span>
656
- 59: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">xml_http_request?</span>
657
- 60: <span class="ruby-keyword kw">not</span> <span class="ruby-regexp re">/XMLHttpRequest/i</span>.<span class="ruby-identifier">match</span>(<span class="ruby-ivar">@headers</span>[<span class="ruby-value str">'HTTP_X_REQUESTED_WITH'</span>]).<span class="ruby-identifier">nil?</span>
658
- 61: <span class="ruby-keyword kw">end</span>
659
- </pre>
660
- </div>
661
- </div>
662
- </div>
663
-
664
-
665
- </div>
666
-
667
-
668
- </div>
669
-
670
-
671
- <div id="validator-badges">
672
- <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
673
- </div>
674
-
675
- </body>
676
- </html>