scorched 0.5.2 → 0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -0
- data/LICENSE +0 -0
- data/Milestones.md +13 -8
- data/README.md +1 -0
- data/docs/02_fundamentals/02_configuration.md +15 -8
- data/docs/02_fundamentals/08_views.md +11 -1
- data/lib/scorched.rb +0 -0
- data/lib/scorched/collection.rb +0 -0
- data/lib/scorched/controller.rb +13 -13
- data/lib/scorched/dynamic_delegate.rb +0 -0
- data/lib/scorched/error.rb +0 -0
- data/lib/scorched/options.rb +0 -0
- data/lib/scorched/static.rb +0 -0
- data/lib/scorched/version.rb +1 -1
- data/scorched.gemspec +0 -0
- data/spec/collection_spec.rb +0 -0
- data/spec/controller_spec.rb +5 -5
- data/spec/helper.rb +0 -0
- data/spec/options_spec.rb +0 -0
- data/spec/public/static.txt +0 -0
- data/spec/request_spec.rb +0 -0
- data/spec/views/composer.erb +0 -0
- data/spec/views/layout.erb +0 -0
- data/spec/views/main.erb +0 -0
- data/spec/views/other.str +0 -0
- data/spec/views/partial.erb +0 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e4ea3f73fb031a956003067b827230358bb5f0e
|
4
|
+
data.tar.gz: e8e9ff7012cd3cfaf471b855daab89f915ce285d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d0da75971382d0108cf9585a55c95a13ce918d9f10ead66eac0c6cd182e710e821456a633830a16728b7d2d37ea3e81f37132dc1a9f5a6ae94ac3466a4eaaf7
|
7
|
+
data.tar.gz: d78bcf8bf3ee287f2fc880da0c6e4d956f2e1b1bb1a34f121127dfe8402eb0f2ebd66f14922e47d3cbd0f5407330fa5a5a4e33f7f4c029b2524cfff28f54d4d8
|
data/Gemfile
CHANGED
File without changes
|
data/LICENSE
CHANGED
File without changes
|
data/Milestones.md
CHANGED
@@ -3,7 +3,12 @@ Milestones
|
|
3
3
|
|
4
4
|
Changelog
|
5
5
|
---------
|
6
|
+
<<<<<<< HEAD
|
7
|
+
### v0.6
|
8
|
+
* ``view_config`` options hash renamed to ``render_defaults`` which better reflects its function.
|
9
|
+
|
6
10
|
### v0.5.2
|
11
|
+
* Minor modification to routing to make it behave as a documented regarding matching at the directly before or on a path.
|
7
12
|
* Response content-type now defaults to "text/html;charset=utf-8", rather than empty.
|
8
13
|
|
9
14
|
### v0.5.1
|
@@ -44,24 +49,24 @@ Changelog
|
|
44
49
|
|
45
50
|
|
46
51
|
|
47
|
-
|
48
|
-
|
52
|
+
To Do
|
53
|
+
-----
|
49
54
|
Some of these remaining features may be broken out into a separate contributor library to keep the core lean and focused.
|
50
55
|
|
51
56
|
* Make specs for Collection and Options classes more thorough, e.g. test all non-reading modifiers such as clear, delete, etc.
|
52
57
|
* Add view helpers
|
53
58
|
* Add helper to easily read and build HTTP query strings. Takes care of "?" and "&" logic, escaping, etc. This is
|
54
59
|
intended to make link building easier.
|
55
|
-
* Form populator
|
56
|
-
*
|
57
|
-
* Add debug logging to show each routing hop and the current environment (variables, mode, etc)
|
60
|
+
* Form populator implemented with Nokogiri. This would have to be added to a contrib library.
|
61
|
+
* Add Verbose logging, including debug logging to show each routing hop and the current environment (variables, mode, etc)
|
58
62
|
* Environment optimised defaults
|
59
63
|
* Production
|
60
|
-
* Rack::Protection
|
61
|
-
* Disable static file serving
|
64
|
+
* use Rack::Protection
|
65
|
+
* Disable static file serving. Sub-controllers can obviously override this. This will just change the default.
|
62
66
|
* Development
|
63
|
-
*
|
67
|
+
* Log to STDOUT
|
64
68
|
* use Rack::ShowExceptions
|
69
|
+
* Add developer-friendly 404 error page.
|
65
70
|
|
66
71
|
Unlikely
|
67
72
|
--------
|
data/README.md
CHANGED
@@ -28,6 +28,7 @@ And light the flame...
|
|
28
28
|
|
29
29
|
rackup hello_world.ru
|
30
30
|
|
31
|
+
_**Note**: Scorched requires Ruby 2.0 as it makes use of a couple of new features. By the time Scorched hits v1.0, there should be little reason not to be running Ruby 2.0._
|
31
32
|
|
32
33
|
The Errors of Our Past
|
33
34
|
----------------------
|
@@ -19,11 +19,18 @@ Each configuration is listed below, with the default value of each included.
|
|
19
19
|
The directory Scorched should serve static files from. Should be set to false if the web server or some other middleware is serving static files.
|
20
20
|
* ``config[:logger] = Logger.new(STDOUT)`` - Currently does nothing until logging is added to Scorched.
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
22
|
+
You can also configure the default options when rendering views by setting them on the ``render_defaults`` hash. The options specified here are merged with those provided when calling the ``render`` method, with the explicit options obviously taking precedence over the defaults.
|
23
|
+
|
24
|
+
Refer to the _views_ page for more information.
|
25
|
+
|
26
|
+
Here is an example of the configuration options in action. A couple of different ways to set the options are shown. Refer to the API documentation for the ``Scorched::Options`` for more information.
|
27
|
+
|
28
|
+
# ruby
|
29
|
+
class MyApp < Scorched::Controller
|
30
|
+
config[:static_dir] = '../public'
|
31
|
+
render_defaults.merge!(
|
32
|
+
dir: 'templates',
|
33
|
+
layout: :main_layout
|
34
|
+
engine: :haml
|
35
|
+
)
|
36
|
+
end
|
@@ -1,4 +1,14 @@
|
|
1
1
|
Views
|
2
2
|
=====
|
3
3
|
|
4
|
-
|
4
|
+
Scorched uses Tilt to render templates in various supported formats. Because of this, views have been implemented as a single method, ``render``.
|
5
|
+
|
6
|
+
``render`` can take a file path or a string as the template. If a symbol is given, it assumes it's a file path, were as a string is assumed to be the template markup. ``render`` can also takes a set of options.
|
7
|
+
|
8
|
+
* ``:dir`` - The directory containing the views. This can be absolute or relative to the current working directory.
|
9
|
+
* ``:layout`` - The template to render _around_ the view. This results in a subsequent call to ``render``, where this value is sent as the first argument. Layout's inherit the settings of the main template being rendered.
|
10
|
+
* ``:engine`` - The template engine to use if it can't be derived from the file name. This is always required for string templates. Can be any string or symbol that Tilt recognises, e.g :erb, :haml, :sass, etc.
|
11
|
+
|
12
|
+
Any unrecognised options are passed through to Tilt and the corresponding rendering engine.
|
13
|
+
|
14
|
+
Finally, ``render`` takes an optional block to be _yielded_ within the view being rendered, if supported by the rendering engine.
|
data/lib/scorched.rb
CHANGED
File without changes
|
data/lib/scorched/collection.rb
CHANGED
File without changes
|
data/lib/scorched/controller.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Scorched
|
2
2
|
class Controller
|
3
3
|
include Scorched::Options('config')
|
4
|
-
include Scorched::Options('
|
4
|
+
include Scorched::Options('render_defaults')
|
5
5
|
include Scorched::Options('conditions')
|
6
6
|
include Scorched::Collection('middleware')
|
7
7
|
include Scorched::Collection('before_filters')
|
@@ -14,7 +14,7 @@ module Scorched
|
|
14
14
|
:logger => Logger.new(STDOUT)
|
15
15
|
}
|
16
16
|
|
17
|
-
|
17
|
+
render_defaults << {
|
18
18
|
:dir => 'views', # The directory containing all the view templates, relative to the current working directory.
|
19
19
|
:layout => false, # The default layout template to use, relative to the view directory. Set to false for no default layout.
|
20
20
|
:engine => :erb
|
@@ -118,25 +118,25 @@ module Scorched
|
|
118
118
|
end
|
119
119
|
|
120
120
|
# Generates and returns a new route proc from the given block, and optionally maps said proc using the given args.
|
121
|
-
def route(pattern = nil, priority = nil, **
|
121
|
+
def route(pattern = nil, priority = nil, **conds, &block)
|
122
122
|
target = lambda do |env|
|
123
123
|
env['scorched.response'].body = instance_exec(*env['scorched.request'].captures, &block)
|
124
124
|
env['scorched.response']
|
125
125
|
end
|
126
|
-
self << {pattern: compile(pattern, true), priority: priority, conditions:
|
126
|
+
self << {pattern: compile(pattern, true), priority: priority, conditions: conds, target: target} if pattern
|
127
127
|
target
|
128
128
|
end
|
129
129
|
|
130
130
|
['get', 'post', 'put', 'delete', 'head', 'options', 'patch'].each do |method|
|
131
131
|
methods = (method == 'get') ? ['GET', 'HEAD'] : [method.upcase]
|
132
|
-
define_method(method) do |*args, **
|
133
|
-
|
134
|
-
route(*args, **
|
132
|
+
define_method(method) do |*args, **conds, &block|
|
133
|
+
conds.merge!(methods: methods)
|
134
|
+
route(*args, **conds, &block)
|
135
135
|
end
|
136
136
|
end
|
137
137
|
|
138
|
-
def filter(type, *args, **
|
139
|
-
filters[type.to_sym] << {args: args, conditions:
|
138
|
+
def filter(type, *args, **conds, &block)
|
139
|
+
filters[type.to_sym] << {args: args, conditions: conds, proc: block}
|
140
140
|
end
|
141
141
|
|
142
142
|
# A bit of syntactic sugar for #filter.
|
@@ -328,13 +328,13 @@ module Scorched
|
|
328
328
|
end
|
329
329
|
|
330
330
|
# Renders the given string or file path using the Tilt templating library.
|
331
|
-
#
|
332
|
-
# The template engine is derived from file name, or otherwise as specified by the _:engine_ option. If
|
333
|
-
# given, _:engine_ option must be set.
|
331
|
+
# The options hash is merged with the controllers _render_defaults_. Unrecognised options are passed through to Tilt.
|
332
|
+
# The template engine is derived from file name, or otherwise as specified by the _:engine_ option. If a string is
|
333
|
+
# given, the _:engine_ option must be set.
|
334
334
|
#
|
335
335
|
# Refer to Tilt documentation for a list of valid template engines.
|
336
336
|
def render(string_or_file, options = {}, &block)
|
337
|
-
options =
|
337
|
+
options = render_defaults.merge(explicit_options = options)
|
338
338
|
engine = (derived_engine = Tilt[string_or_file.to_s]) || Tilt[options[:engine]]
|
339
339
|
raise Error, "Invalid or undefined template engine: #{options[:engine].inspect}" unless engine
|
340
340
|
if Symbol === string_or_file
|
File without changes
|
data/lib/scorched/error.rb
CHANGED
File without changes
|
data/lib/scorched/options.rb
CHANGED
File without changes
|
data/lib/scorched/static.rb
CHANGED
File without changes
|
data/lib/scorched/version.rb
CHANGED
data/scorched.gemspec
CHANGED
File without changes
|
data/spec/collection_spec.rb
CHANGED
File without changes
|
data/spec/controller_spec.rb
CHANGED
@@ -585,7 +585,7 @@ module Scorched
|
|
585
585
|
|
586
586
|
describe "rendering" do
|
587
587
|
before(:each) do
|
588
|
-
app.
|
588
|
+
app.render_defaults.each { |k,v| app.render_defaults[k] = nil }
|
589
589
|
end
|
590
590
|
|
591
591
|
it "can render a file, relative to the application root" do
|
@@ -630,14 +630,14 @@ module Scorched
|
|
630
630
|
app.get('/full_path') do
|
631
631
|
render(:'views/main.erb', {layout: :'views/layout.erb', dir: nil}).should == "(3 for me)"
|
632
632
|
end
|
633
|
-
app.
|
633
|
+
app.render_defaults[:dir] = 'views'
|
634
634
|
rt.get('/')
|
635
635
|
rt.get('/full_path')
|
636
636
|
end
|
637
637
|
|
638
638
|
it "derived template engine overrides specified engine" do
|
639
|
-
app.
|
640
|
-
app.
|
639
|
+
app.render_defaults[:dir] = 'views'
|
640
|
+
app.render_defaults[:engine] = :erb
|
641
641
|
app.get('/str') do
|
642
642
|
render(:'other.str').should == "hello hello"
|
643
643
|
end
|
@@ -653,7 +653,7 @@ module Scorched
|
|
653
653
|
end
|
654
654
|
|
655
655
|
it "ignores default layout when called within a view" do
|
656
|
-
app.
|
656
|
+
app.render_defaults << {:dir => 'views', :layout => :layout, :engine => :erb}
|
657
657
|
app.get('/') do
|
658
658
|
render :composer
|
659
659
|
end
|
data/spec/helper.rb
CHANGED
File without changes
|
data/spec/options_spec.rb
CHANGED
File without changes
|
data/spec/public/static.txt
CHANGED
File without changes
|
data/spec/request_spec.rb
CHANGED
File without changes
|
data/spec/views/composer.erb
CHANGED
File without changes
|
data/spec/views/layout.erb
CHANGED
File without changes
|
data/spec/views/main.erb
CHANGED
File without changes
|
data/spec/views/other.str
CHANGED
File without changes
|
data/spec/views/partial.erb
CHANGED
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scorched
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.6'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Wardrop
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-03-
|
11
|
+
date: 2013-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|