camping 2.1.467 → 2.1.523

Sign up to get free protection for your applications and to get access to all the features.
@@ -44,7 +44,7 @@ module Camping
44
44
  options = {}
45
45
 
46
46
  opt_parser = OptionParser.new("", 24, ' ') do |opts|
47
- opts.banner = "Usage: camping app1.rb app2.rb..."
47
+ opts.banner = "Usage: camping my-camping-app.rb"
48
48
  opts.define_head "#{File.basename($0)}, the microframework ON-button for ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
49
49
  opts.separator ""
50
50
  opts.separator "Specific options:"
@@ -62,7 +62,7 @@ module Camping
62
62
  opts.on("-C", "--console",
63
63
  "Run in console mode with IRB") { options[:server] = "console" }
64
64
 
65
- server_list = ["mongrel", "webrick", "console"]
65
+ server_list = ["thin", "webrick", "console"]
66
66
  opts.on("-s", "--server NAME",
67
67
  "Server to force (#{server_list.join(', ')})") { |v| options[:server] = v }
68
68
 
@@ -90,15 +90,14 @@ module Camping
90
90
  exit
91
91
  end
92
92
 
93
- options[:scripts] = args
93
+ options[:script] = args.shift
94
94
  options
95
95
  end
96
96
  end
97
97
 
98
98
  def initialize(*)
99
99
  super
100
- @reloader = Camping::Reloader.new
101
- @reloader.on_reload do |app|
100
+ @reloader = Camping::Reloader.new(options[:script]) do |app|
102
101
  if !app.options.has_key?(:dynamic_templates)
103
102
  app.options[:dynamic_templates] = true
104
103
  end
@@ -125,16 +124,16 @@ module Camping
125
124
 
126
125
  def middleware
127
126
  h = super
128
- h["development"].unshift [XSendfile]
127
+ h["development"] << [XSendfile]
129
128
  h
130
129
  end
131
130
 
132
131
  def start
133
132
  if options[:server] == "console"
134
133
  puts "** Starting console"
135
- reload!
136
- this = self
137
- eval("self", TOPLEVEL_BINDING).meta_def(:reload!) { this.reload!; nil }
134
+ @reloader.reload!
135
+ r = @reloader
136
+ eval("self", TOPLEVEL_BINDING).meta_def(:reload!) { r.reload!; nil }
138
137
  ARGV.clear
139
138
  IRB.start
140
139
  exit
@@ -144,95 +143,29 @@ module Camping
144
143
  super
145
144
  end
146
145
  end
147
-
148
- def find_scripts
149
- scripts = options[:scripts].map do |path|
150
- if File.file?(path)
151
- path
152
- elsif File.directory?(path)
153
- Dir[File.join(path, '*.rb')]
154
- end
155
- end.flatten.compact
156
-
157
- @reloader.update(*scripts)
158
- end
159
-
160
- def reload!
161
- find_scripts
146
+
147
+ def public_dir
148
+ File.expand_path('../public', @reloader.file)
162
149
  end
163
150
 
164
151
  def app
165
- self
152
+ Rack::Cascade.new([Rack::File.new(public_dir), self], [405, 404, 403])
166
153
  end
167
154
 
168
- def call(env)
169
- reload!
155
+ def current_app
156
+ @reloader.reload
170
157
  apps = @reloader.apps
171
-
172
- case apps.length
173
- when 0
174
- index_page(apps)
175
- when 1
176
- apps.values.first.call(env)
177
- else
178
- apps.each do |name, app|
179
- mount = name.to_s.downcase
180
- case env["PATH_INFO"]
181
- when %r{^/#{mount}}
182
- env["SCRIPT_NAME"] = env["SCRIPT_NAME"] + $&
183
- env["PATH_INFO"] = $'
184
- return app.call(env)
185
- when %r{^/code/#{mount}}
186
- return [200, {'Content-Type' => 'text/plain', 'X-Sendfile' => @reloader.script(app).file}, []]
187
- end
188
- end
189
-
190
- index_page(apps)
158
+ return apps.values.first if apps.size == 1
159
+ if key = apps.keys.grep(/^#{@reloader.name}$/i)[0]
160
+ apps[key]
191
161
  end
192
162
  end
193
-
194
- def index_page(apps)
195
- [200, {'Content-Type' => 'text/html'}, [TEMPLATE.result(binding)]]
163
+
164
+ def call(env)
165
+ app = current_app || raise("Could not find an app called `#{@reloader.name}`")
166
+ app.call(env)
196
167
  end
197
168
 
198
- SOURCE = <<-HTML
199
- <html>
200
- <head>
201
- <title>You are Camping</title>
202
- <style type="text/css">
203
- body {
204
- font-family: verdana, arial, sans-serif;
205
- padding: 10px 40px;
206
- margin: 0;
207
- }
208
- h1, h2, h3, h4, h5, h6 {
209
- font-family: utopia, georgia, serif;
210
- }
211
- h3 { display: inline; }
212
- </style>
213
- </head>
214
- <body>
215
- <% if apps.empty? %>
216
- <p>Good day. I'm sorry, but I could not find any Camping apps.
217
- You might want to take a look at the console to see if any errors
218
- have been raised.</p>
219
- <% else %>
220
- <p>Good day. These are the Camping apps you've mounted.</p>
221
- <ul>
222
- <% apps.each do |name, app| %>
223
- <li>
224
- <h3><a href="/<%= name.to_s.downcase %>"><%= app %></a></h3>
225
- <small> / <a href="/code/<%= name.to_s.downcase %>">View source</a></small>
226
- </li>
227
- <% end %>
228
- </ul>
229
- <% end %>
230
- </body>
231
- </html>
232
- HTML
233
-
234
- TEMPLATE = ERB.new(SOURCE)
235
-
236
169
  class XSendfile
237
170
  def initialize(app)
238
171
  @app = app
@@ -262,4 +195,4 @@ module Camping
262
195
  end
263
196
  end
264
197
  end
265
- end
198
+ end
@@ -23,6 +23,12 @@ end
23
23
 
24
24
  module Helpers::Controllers
25
25
  class Index
26
+ def get
27
+ URL('/').to_s
28
+ end
29
+ end
30
+
31
+ class Model
26
32
  def get
27
33
  current_user.name
28
34
  end
@@ -37,7 +43,7 @@ end
37
43
 
38
44
  class Helpers::Test < TestCase
39
45
  def test_models
40
- get '/'
46
+ get '/model'
41
47
  assert_body "Bob"
42
48
  end
43
49
 
@@ -45,5 +51,10 @@ class Helpers::Test < TestCase
45
51
  get '/users'
46
52
  assert_body "/"
47
53
  end
54
+
55
+ def test_url
56
+ get '/', {}, 'PATH_INFO' => ''
57
+ assert_body "http://example.org/"
58
+ end
48
59
  end
49
60
 
@@ -15,6 +15,32 @@ module Markup::Controllers
15
15
  render :index, :layout => false
16
16
  end
17
17
  end
18
+
19
+ class AutoPrepend
20
+ def get
21
+ mab do
22
+ img :src => '/hello.png'
23
+ end
24
+ end
25
+ end
26
+
27
+ class Compat < R '/compat/(.*?)'
28
+ def get(type)
29
+ mab do
30
+ send(type) do
31
+ body { h1 'Nice' }
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ class CompatHelpers
38
+ def get
39
+ mab do
40
+ helpers.R CompatHelpers
41
+ end
42
+ end
43
+ end
18
44
  end
19
45
 
20
46
  module Markup::Views
@@ -23,6 +49,7 @@ module Markup::Views
23
49
  end
24
50
 
25
51
  def layout
52
+ self << '<!DOCTYPE html>'
26
53
  html do
27
54
  head do
28
55
  title "Web Page"
@@ -36,6 +63,7 @@ end
36
63
  class Markup::Test < TestCase
37
64
  def test_render
38
65
  get '/'
66
+ assert_body %r{\A<!DOCTYPE html>}
39
67
  assert_body %r{<h1>Welcome!</h1>}
40
68
  assert_body %r{<title>Web Page</title>}
41
69
  end
@@ -48,4 +76,30 @@ class Markup::Test < TestCase
48
76
  assert_body %r{<title>Web Page</title>}
49
77
  end
50
78
  end
79
+
80
+ def test_auto_prepend
81
+ get '/auto/prepend', {}, 'SCRIPT_NAME' => '/mount'
82
+ assert_body '<img src="/mount/hello.png">'
83
+ end
84
+
85
+ def test_compat
86
+ warning = "xhtml_strict is no longer supported (or an active standard); using HTML5 instead\n"
87
+
88
+ assert_output '', warning * 3 do
89
+ get '/compat/xhtml_strict'
90
+ assert_body '<!DOCTYPE html><html><body><h1>Nice</h1></body></html>'
91
+
92
+ get '/compat/xhtml_transitional'
93
+ assert_body '<!DOCTYPE html><html><body><h1>Nice</h1></body></html>'
94
+
95
+ get '/compat/xhtml_frameset'
96
+ assert_body '<!DOCTYPE html><html><body><h1>Nice</h1></body></html>'
97
+ end
98
+ end
99
+
100
+ def test_compat_helpers
101
+ get '/compat/helpers'
102
+ assert_body '/compat/helpers'
103
+ end
51
104
  end
105
+
@@ -0,0 +1,70 @@
1
+ require 'test_helper'
2
+ require 'fileutils'
3
+ require 'camping/reloader'
4
+
5
+ $counter = 0
6
+
7
+ module TestCaseReloader
8
+ def reloader
9
+ @reloader ||= Camping::Reloader.new(file)
10
+ end
11
+
12
+ def setup
13
+ super
14
+ reloader.reload!
15
+ assert Object.const_defined?(:Reloader), "Reloader didn't load app"
16
+ end
17
+
18
+ def teardown
19
+ super
20
+ assert Object.const_defined?(:Reloader), "Test removed app"
21
+ reloader.remove_apps
22
+ assert !Object.const_defined?(:Reloader), "Reloader didn't remove app"
23
+ end
24
+ end
25
+
26
+ class TestReloader < TestCase
27
+ include TestCaseReloader
28
+ BASE = File.expand_path('../apps/reloader', __FILE__)
29
+
30
+ def file; BASE + '.rb' end
31
+
32
+ def setup
33
+ $counter = 0
34
+ super
35
+ end
36
+
37
+ def test_counter
38
+ assert_equal 1, $counter
39
+ end
40
+
41
+ def test_forced_reload
42
+ reloader.reload!
43
+ assert_equal 2, $counter
44
+ end
45
+
46
+ def test_mtime_reload
47
+ reloader.reload
48
+ assert_equal 1, $counter
49
+
50
+ FileUtils.touch(BASE + '.rb')
51
+ sleep 1
52
+ reloader.reload
53
+ assert_equal 2, $counter
54
+
55
+ FileUtils.touch(BASE + '/reload_me.rb')
56
+ sleep 1
57
+ reloader.reload
58
+ assert_equal 3, $counter
59
+ end
60
+ end
61
+
62
+ class TestConfigRu < TestReloader
63
+ BASE = File.expand_path('../apps/reloader', __FILE__)
64
+ def file; BASE + '/config.ru' end
65
+
66
+ def test_name
67
+ assert_equal Reloader, reloader.apps[:reloader]
68
+ end
69
+ end
70
+
@@ -47,6 +47,12 @@ module Simple::Controllers
47
47
  "Optional: #{value}"
48
48
  end
49
49
  end
50
+
51
+ class Weird
52
+ def get
53
+ redirect MultipleComplexX, 'hello%#/world'
54
+ end
55
+ end
50
56
  end
51
57
 
52
58
  class Simple::Test < TestCase
@@ -94,4 +100,10 @@ class Simple::Test < TestCase
94
100
  get '/optional/override'
95
101
  assert_body "Optional: override"
96
102
  end
103
+
104
+ def test_weird
105
+ get '/weird'
106
+ follow_redirect!
107
+ assert_body 'Complex: hello%#/world'
108
+ end
97
109
  end
@@ -0,0 +1,7 @@
1
+ require 'camping'
2
+
3
+ Camping.goes :Reloader
4
+
5
+ $LOAD_PATH << File.dirname(__FILE__)
6
+ require 'reloader/reload_me'
7
+
@@ -0,0 +1,5 @@
1
+ $LOAD_PATH << File.dirname(__FILE__) + '/../'
2
+
3
+ require 'reloader'
4
+ run Reloader
5
+
@@ -0,0 +1,2 @@
1
+ $counter += 1
2
+
@@ -0,0 +1,3 @@
1
+ $LOAD_PATH << File.dirname(__FILE__)
2
+ require 'reloader'
3
+
@@ -11,10 +11,10 @@ else
11
11
  require 'camping-unabridged'
12
12
  end
13
13
 
14
- require 'test/unit'
14
+ require 'minitest/autorun'
15
15
  require 'rack/test'
16
16
 
17
- class TestCase < Test::Unit::TestCase
17
+ class TestCase < MiniTest::Unit::TestCase
18
18
  include Rack::Test::Methods
19
19
 
20
20
  def self.inherited(mod)
@@ -50,7 +50,6 @@ class TestCase < Test::Unit::TestCase
50
50
  def assert_status(code)
51
51
  assert_equal(code, last_response.status)
52
52
  end
53
-
54
- def test_noop
55
- end
53
+
54
+ def test_silly; end
56
55
  end
metadata CHANGED
@@ -1,66 +1,75 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: camping
3
- version: !ruby/object:Gem::Version
4
- version: 2.1.467
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.1.523
5
5
  prerelease:
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - why the lucky stiff
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-10-05 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2012-09-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: rack
17
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70274142153900 !ruby/object:Gem::Requirement
18
17
  none: false
19
- requirements:
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: "1.0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
23
22
  type: :runtime
24
23
  prerelease: false
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
24
+ version_requirements: *70274142153900
25
+ - !ruby/object:Gem::Dependency
26
+ name: mab
27
+ requirement: &70274142153120 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70274142153120
36
+ - !ruby/object:Gem::Dependency
27
37
  name: rake
28
- requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirement: &70274142152460 !ruby/object:Gem::Requirement
29
39
  none: false
30
- requirements:
31
- - - "="
32
- - !ruby/object:Gem::Version
33
- version: 0.8.7
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
34
44
  type: :development
35
45
  prerelease: false
36
- version_requirements: *id002
37
- - !ruby/object:Gem::Dependency
46
+ version_requirements: *70274142152460
47
+ - !ruby/object:Gem::Dependency
38
48
  name: rack-test
39
- requirement: &id003 !ruby/object:Gem::Requirement
49
+ requirement: &70274150145520 !ruby/object:Gem::Requirement
40
50
  none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- version: "0"
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
45
55
  type: :development
46
56
  prerelease: false
47
- version_requirements: *id003
57
+ version_requirements: *70274150145520
48
58
  description:
49
59
  email: why@ruby-lang.org
50
- executables:
60
+ executables:
51
61
  - camping
52
62
  extensions: []
53
-
54
- extra_rdoc_files:
55
- - README
63
+ extra_rdoc_files:
64
+ - README.md
56
65
  - CHANGELOG
57
66
  - COPYING
58
- - book/01_introduction
59
- - book/02_getting_started
60
- - book/51_upgrading
61
- files:
67
+ - book/01_introduction.md
68
+ - book/02_getting_started.md
69
+ - book/51_upgrading.md
70
+ files:
62
71
  - COPYING
63
- - README
72
+ - README.md
64
73
  - Rakefile
65
74
  - bin/camping
66
75
  - test/app_cookies.rb
@@ -69,6 +78,7 @@ files:
69
78
  - test/app_inline_templates.rb
70
79
  - test/app_markup.rb
71
80
  - test/app_partials.rb
81
+ - test/app_reloader.rb
72
82
  - test/app_route_generating.rb
73
83
  - test/app_sessions.rb
74
84
  - test/app_simple.rb
@@ -77,6 +87,10 @@ files:
77
87
  - test/apps/forward_to_other_controller.rb
78
88
  - test/apps/migrations.rb
79
89
  - test/apps/misc.rb
90
+ - test/apps/reloader/config.ru
91
+ - test/apps/reloader/reload_me.rb
92
+ - test/apps/reloader.rb
93
+ - test/apps/reloader_indirect.rb
80
94
  - test/apps/sessions.rb
81
95
  - test/test_helper.rb
82
96
  - lib/camping/ar.rb
@@ -109,16 +123,15 @@ files:
109
123
  - extras/rdoc/generator/template/flipbook/readme.rhtml
110
124
  - extras/rdoc/generator/template/flipbook/reference.rhtml
111
125
  - extras/rdoc/generator/template/flipbook/toc.rhtml
112
- - book/01_introduction
113
- - book/02_getting_started
114
- - book/51_upgrading
126
+ - book/01_introduction.md
127
+ - book/02_getting_started.md
128
+ - book/51_upgrading.md
115
129
  - examples/blog.rb
116
130
  - CHANGELOG
117
131
  homepage: http://camping.rubyforge.org/
118
132
  licenses: []
119
-
120
133
  post_install_message:
121
- rdoc_options:
134
+ rdoc_options:
122
135
  - --line-numbers
123
136
  - --quiet
124
137
  - --main
@@ -127,26 +140,25 @@ rdoc_options:
127
140
  - ^(examples|extras)\/
128
141
  - --exclude
129
142
  - lib/camping.rb
130
- require_paths:
143
+ require_paths:
131
144
  - lib
132
- required_ruby_version: !ruby/object:Gem::Requirement
145
+ required_ruby_version: !ruby/object:Gem::Requirement
133
146
  none: false
134
- requirements:
135
- - - ">="
136
- - !ruby/object:Gem::Version
147
+ requirements:
148
+ - - ! '>='
149
+ - !ruby/object:Gem::Version
137
150
  version: 1.8.2
138
- required_rubygems_version: !ruby/object:Gem::Requirement
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
152
  none: false
140
- requirements:
141
- - - ">="
142
- - !ruby/object:Gem::Version
143
- version: "0"
153
+ requirements:
154
+ - - ! '>='
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
144
157
  requirements: []
145
-
146
158
  rubyforge_project: camping
147
- rubygems_version: 1.8.11
159
+ rubygems_version: 1.8.10
148
160
  signing_key:
149
161
  specification_version: 3
150
162
  summary: minature rails for stay-at-home moms
151
163
  test_files: []
152
-
164
+ has_rdoc: true