roda 3.32.0 → 3.33.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2a342192f0ab697bea9c4e5b55669644f06fe16e161539b1efc3d10f3c6b9947
4
- data.tar.gz: cf01944fe14494efd606cd892cbbbae5b5128f5a1d83c5e411bd4c64cc6e4321
3
+ metadata.gz: 0f9ede53406b16bff69c2115f7d35e808835e300ca866a5caadde9b9fad9d206
4
+ data.tar.gz: f78eb239a3d15e83879b8a7272f07959a00b6d94e93595f6871841144d3d718b
5
5
  SHA512:
6
- metadata.gz: e5de72f1385942855bd2c8e1c0f6be5187430d7d83112d7400bc573f045456a445166edfdbb6a7f70779c7b008745e8063bd44274b0111dec95643f87cfe12fe
7
- data.tar.gz: b69e2fb41045d19c1f9e79dd2d1a87ca691fcd8de975bd34e37456cd6c5183cd2a6ad6bb59a07594527588d2903ef1bceea5f356a809aef03c01e5f64415246b
6
+ metadata.gz: 45e3020a3509bacc5f39107659fca5e64ba25c322c18af6a62b976308f5bac2ac44a18d54bc82d9b1d4260e260883208ce8210ac2fb660e09b63b65401abfed6
7
+ data.tar.gz: 5a00af14f4d6e01c472a23b59f5a51eec66fc55c2d8d34069de869d7ff487913ff6ab1d21023b8207f5fdf18ad6354f30520b3cf89d2491de4b330c1ae30f10a
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ = 3.33.0 (2020-06-16)
2
+
3
+ * Add :brotli option to public plugin to supplement it to serve brotli-compressed files like :gzip does for gzipped files (hmdne) (#194)
4
+
5
+ * Add url method to path plugin, similar to path but returning the entire URL (jeremyevans)
6
+
1
7
  = 3.32.0 (2020-05-15)
2
8
 
3
9
  * Make :dependencies option in assets plugin work correctly with render plugin template caching (jeremyevans) (#191)
@@ -15,6 +15,8 @@ For a small application, the following directory layout is recommended:
15
15
  Rakefile
16
16
  app_name.rb
17
17
  assets/
18
+ config.ru
19
+ db.rb
18
20
  migrate/
19
21
  models.rb
20
22
  models/
@@ -25,6 +27,8 @@ For a small application, the following directory layout is recommended:
25
27
  +app_name.rb+ should contain the Roda application, and should reflect the name of your application.
26
28
  So, if your application is named +FooBar+, you should use +foo_bar.rb+.
27
29
 
30
+ +config.ru+ should contain the code the webserver uses to determine which application to run.
31
+
28
32
  +views/+ should contain your template files. This assumes you are using the +render+ plugin
29
33
  and server-side rendering. If you are creating a single page application and just serving
30
34
  JSON, then you won't need a +views+ directory. For small applications, all view files should be
@@ -36,7 +40,11 @@ Again, for pure JSON applications, you won't need a +public+ directory.
36
40
  +assets/+ should contain the source files for your CSS and javascript assets. If you are
37
41
  not using the +assets+ plugin, you won't need an +assets+ directory.
38
42
 
39
- +models.rb+ should contain all code related to your database/ORM. This file should be required
43
+ +db.rb+ should contain the minimum code to setup a database connection, without loading any of
44
+ the applications models. This can be required in cases where you don't want the models loaded,
45
+ such as when running migrations. This file should be required by +models.rb+.
46
+
47
+ +models.rb+ should contain all code related to your ORM. This file should be required
40
48
  by +app_name.rb+. This keeps your model code separate from your web code, making it easier
41
49
  to use outside of your web code. It allows you to get an IRB shell for accessing your models
42
50
  via <tt>irb -r ./models</tt>, without loading the Roda application.
@@ -46,7 +54,7 @@ via irb -r ./models, without loading the Roda application.
46
54
  +migrate/+ should create your database migration files, if you are using an ORM that uses
47
55
  migrations.
48
56
 
49
- +spec/+ should contain your specifications/tests. For a small application, it's recommended
57
+ +spec/+ (or +test/+ should contain your specifications/tests. For a small application, it's recommended
50
58
  to a have a single file for your model tests, and a single file for your web/integration tests.
51
59
 
52
60
  +Rakefile+ should contain the rake tasks for the application. The convention is that the
@@ -83,7 +91,8 @@ The routes used by the +hash_routes+ or +multi_run+ should be stored in routing
83
91
  directory, with one file per prefix.
84
92
 
85
93
  For specs/tests, you should have +spec/models/+ and +spec/web/+, with one file per model in +spec/models/+
86
- and one file per prefix in +spec/web/+.
94
+ and one file per prefix in +spec/web/+. Substitute +spec+ with +test+ if that is what you are using as the
95
+ name of the directory.
87
96
 
88
97
  You should have a separate view subdirectory per prefix. If you are using +hash_routes+ and +view_options+ plugins,
89
98
  use +set_view_subdir+ in your routing files to specify the subdirectory to use, so it doesn't need to be
@@ -105,7 +114,7 @@ subdirectories in the +routes/+ directory, and nested subdirectories in the +vie
105
114
  For a small application, the convention in Roda is to layout your Roda application file (+app_name.rb+) like this:
106
115
 
107
116
  require 'roda'
108
- require './models'
117
+ require_relative 'models'
109
118
 
110
119
  class AppName < Roda
111
120
  SOME_CONSTANT = 1
@@ -138,24 +147,24 @@ used in your route block or views.
138
147
  For larger applications, there are some slight changes to the Roda application file layout:
139
148
 
140
149
  require 'roda'
141
- require './models'
150
+ require_relative 'models'
142
151
 
143
152
  class AppName < Roda
144
153
  SOME_CONSTANT = 1
145
154
 
146
155
  use SomeMiddleware
147
156
 
148
- plugin :render, escape: true
157
+ plugin :render, escape: true, layout: './layout'
149
158
  plugin :assets
150
159
  plugin :view_options
151
160
  plugin :hash_routes
152
- Dir['./routes/*.rb'].each{|f| require f}
161
+ Dir['routes/*.rb'].each{|f| require_relative f}
153
162
 
154
163
  route do |r|
155
164
  r.hash_routes
156
165
  end
157
166
 
158
- Dir['./helpers/*.rb'].each{|f| require f}
167
+ Dir['helpers/*.rb'].each{|f| require_relative f}
159
168
  end
160
169
 
161
170
  After loading the +view_options+ and +hash_routes+ plugin, you require all of your
@@ -0,0 +1,8 @@
1
+ = New Features
2
+
3
+ * The path plugin now supports a url method, allowing for returning
4
+ the entire URL instead of just the path for class-based paths.
5
+
6
+ * The public plugin now supports a :brotli option that will directly
7
+ serve brotli-compressed files (with .br extension) similar to how the
8
+ :gzip option directly serves gzipped files (with the .gz extension).
@@ -10,7 +10,8 @@ class Roda
10
10
  #
11
11
  # Additionally, you can call the +path+ class method with a class and a block, and it will register
12
12
  # the class. You can then call the +path+ instance method with an instance of that class, and it will
13
- # execute the block in the context of the route block scope with the arguments provided to path.
13
+ # execute the block in the context of the route block scope with the arguments provided to path. You
14
+ # can call the +url+ instance method with the same arguments as the +path+ method to get the full URL.
14
15
  #
15
16
  # Example:
16
17
  #
@@ -46,11 +47,11 @@ class Roda
46
47
  #
47
48
  # r.post 'quux' do
48
49
  # bar = Quux[1]
49
- # r.redirect path(quux, '/bar') # /quux/1/bar
50
+ # r.redirect url(quux, '/bar') # http://example.com/quux/1/bar
50
51
  # end
51
52
  # end
52
53
  #
53
- # The path method accepts the following options when not called with a class:
54
+ # The path class method accepts the following options when not called with a class:
54
55
  #
55
56
  # :add_script_name :: Prefix the path generated with SCRIPT_NAME. This defaults to the app's
56
57
  # :add_script_name option.
@@ -62,7 +63,7 @@ class Roda
62
63
  # method. If a Symbol or String, uses the value as the url method name.
63
64
  # :url_only :: Do not create a path method, just a url method.
64
65
  #
65
- # Note that if :add_script_name, :url, or :url_only is used, the path method will also create a
66
+ # Note that if :add_script_name, :relative, :url, or :url_only is used, the path method will also create a
66
67
  # <tt>_*_path</tt> private method.
67
68
  module Path
68
69
  DEFAULT_PORTS = {'http' => 80, 'https' => 443}.freeze
@@ -165,14 +166,8 @@ class Roda
165
166
  end
166
167
 
167
168
  url_block = lambda do |*a, &blk|
168
- r = request
169
- scheme = r.scheme
170
- port = r.port
171
- uri = ["#{scheme}://#{r.host}#{":#{port}" unless DEFAULT_PORTS[scheme] == port}"]
172
- uri << request.script_name.to_s if add_script_name
173
169
  # Allow calling private _method to get path
174
- uri << send(_meth, *a, &blk)
175
- File.join(uri)
170
+ "#{_base_url}#{request.script_name if add_script_name}#{send(_meth, *a, &blk)}"
176
171
  end
177
172
 
178
173
  define_method(url_meth, &url_block)
@@ -207,6 +202,21 @@ class Roda
207
202
  path = request.script_name.to_s + path if opts[:add_script_name]
208
203
  path
209
204
  end
205
+
206
+ # Similar to #path, but returns a complete URL.
207
+ def url(*args, &block)
208
+ "#{_base_url}#{path(*args, &block)}"
209
+ end
210
+
211
+ private
212
+
213
+ # The string to prepend to the path to make the path a URL.
214
+ def _base_url
215
+ r = @_request
216
+ scheme = r.scheme
217
+ port = r.port
218
+ "#{scheme}://#{r.host}#{":#{port}" unless DEFAULT_PORTS[scheme] == port}"
219
+ end
210
220
  end
211
221
  end
212
222
 
@@ -42,6 +42,8 @@ class Roda
42
42
  # :default_mime :: The default mime type to use if the mime type is not recognized.
43
43
  # :gzip :: Whether to serve already gzipped files with a .gz extension for clients
44
44
  # supporting gzipped transfer encoding.
45
+ # :brotli :: Whether to serve already brotli-compressed files with a .br extension
46
+ # for clients supporting brotli transfer encoding.
45
47
  # :headers :: A hash of headers to use for statically served files
46
48
  # :root :: Use this option for the root of the public directory (default: "public")
47
49
  def self.configure(app, opts={})
@@ -52,6 +54,7 @@ class Roda
52
54
  end
53
55
  app.opts[:public_server] = ::Rack::File.new(app.opts[:public_root], opts[:headers]||{}, opts[:default_mime] || 'text/plain')
54
56
  app.opts[:public_gzip] = opts[:gzip]
57
+ app.opts[:public_brotli] = opts[:brotli]
55
58
  end
56
59
 
57
60
  module RequestMethods
@@ -65,23 +68,8 @@ class Roda
65
68
  server = roda_opts[:public_server]
66
69
  path = ::File.join(server.root, *public_path_segments(path))
67
70
 
68
- if roda_opts[:public_gzip] && env['HTTP_ACCEPT_ENCODING'] =~ /\bgzip\b/
69
- gzip_path = path + '.gz'
70
-
71
- if public_file_readable?(gzip_path)
72
- res = public_serve(server, gzip_path)
73
- headers = res[1]
74
-
75
- unless res[0] == 304
76
- if mime_type = ::Rack::Mime.mime_type(::File.extname(path), 'text/plain')
77
- headers['Content-Type'] = mime_type
78
- end
79
- headers['Content-Encoding'] = 'gzip'
80
- end
81
-
82
- halt res
83
- end
84
- end
71
+ public_serve_compressed(server, path, '.br', 'br') if roda_opts[:public_brotli]
72
+ public_serve_compressed(server, path, '.gz', 'gzip') if roda_opts[:public_gzip]
85
73
 
86
74
  if public_file_readable?(path)
87
75
  halt public_serve(server, path)
@@ -113,6 +101,26 @@ class Roda
113
101
  # :nocov:
114
102
  end
115
103
 
104
+ def public_serve_compressed(server, path, suffix, encoding)
105
+ if env['HTTP_ACCEPT_ENCODING'] =~ /\b#{encoding}\b/
106
+ compressed_path = path + suffix
107
+
108
+ if public_file_readable?(compressed_path)
109
+ res = public_serve(server, compressed_path)
110
+ headers = res[1]
111
+
112
+ unless res[0] == 304
113
+ if mime_type = ::Rack::Mime.mime_type(::File.extname(path), 'text/plain')
114
+ headers['Content-Type'] = mime_type
115
+ end
116
+ headers['Content-Encoding'] = encoding
117
+ end
118
+
119
+ halt res
120
+ end
121
+ end
122
+ end
123
+
116
124
  if ::Rack.release > '2'
117
125
  # Serve the given path using the given Rack::File server.
118
126
  def public_serve(server, path)
@@ -4,7 +4,7 @@ class Roda
4
4
  RodaMajorVersion = 3
5
5
 
6
6
  # The minor version of Roda, updated for new feature releases of Roda.
7
- RodaMinorVersion = 32
7
+ RodaMinorVersion = 33
8
8
 
9
9
  # The patch version of Roda, updated only for bug fixes from the last
10
10
  # feature release.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roda
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.32.0
4
+ version: 3.33.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-15 00:00:00.000000000 Z
11
+ date: 2020-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -208,6 +208,7 @@ extra_rdoc_files:
208
208
  - doc/release_notes/3.30.0.txt
209
209
  - doc/release_notes/3.31.0.txt
210
210
  - doc/release_notes/3.32.0.txt
211
+ - doc/release_notes/3.33.0.txt
211
212
  files:
212
213
  - CHANGELOG
213
214
  - MIT-LICENSE
@@ -241,6 +242,7 @@ files:
241
242
  - doc/release_notes/3.30.0.txt
242
243
  - doc/release_notes/3.31.0.txt
243
244
  - doc/release_notes/3.32.0.txt
245
+ - doc/release_notes/3.33.0.txt
244
246
  - doc/release_notes/3.4.0.txt
245
247
  - doc/release_notes/3.5.0.txt
246
248
  - doc/release_notes/3.6.0.txt