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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b0950b3928b9921a50ec7af0cb01869412172f09
4
- data.tar.gz: b698623e4b6e40a64cf56ac47b7d20be50df4c2f
3
+ metadata.gz: 9e4ea3f73fb031a956003067b827230358bb5f0e
4
+ data.tar.gz: e8e9ff7012cd3cfaf471b855daab89f915ce285d
5
5
  SHA512:
6
- metadata.gz: e528fe6a63bfdd08127ff405e83541a5a6032fa6db1746be18c50a0e9488de6eba591b720fb218fda4378e42b244eba4246be71fb4bc8c384921cdd9c2c2bca8
7
- data.tar.gz: 00f71b40921a073e043a985e693e8a2924c93f16a4221a2f5efcf72588d90515846c67151302cd931d1af7fe112884c17f2424c068bbd82e83170de954f1ce12
6
+ metadata.gz: 2d0da75971382d0108cf9585a55c95a13ce918d9f10ead66eac0c6cd182e710e821456a633830a16728b7d2d37ea3e81f37132dc1a9f5a6ae94ac3466a4eaaf7
7
+ data.tar.gz: d78bcf8bf3ee287f2fc880da0c6e4d956f2e1b1bb1a34f121127dfe8402eb0f2ebd66f14922e47d3cbd0f5407330fa5a5a4e33f7f4c029b2524cfff28f54d4d8
data/Gemfile CHANGED
File without changes
data/LICENSE CHANGED
File without changes
@@ -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
- Remaining
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
- * Provide a default error page somewhat similar to what Sinatra has.
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
- * Verbose logging to STDOUT
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
- The follow view configuration options can all be overriden when calling ``render``.
23
-
24
- * ``view_config[:dir] = 'views'``
25
- The directory containing all the view templates, relative to the current working directory.
26
- * ``view_config[:layout] = false``
27
- The default layout to use when rendering views.
28
- * ``view_config[:engine] = :erb``
29
- The default rendering engine. This is used when ``render`` is given a filename with no extension, or a string.
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
- _More documentation coming soon. Until then, as a tip, the whole view infrastructure of Scorched is implemented as the ``render`` method._
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.
File without changes
File without changes
@@ -1,7 +1,7 @@
1
1
  module Scorched
2
2
  class Controller
3
3
  include Scorched::Options('config')
4
- include Scorched::Options('view_config')
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
- view_config << {
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, **conditions, &block)
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: conditions, target: target} if pattern
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, **conditions, &block|
133
- conditions.merge!(methods: methods)
134
- route(*args, **conditions, &block)
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, **conditions, &block)
139
- filters[type.to_sym] << {args: args, conditions: conditions, proc: block}
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
- # Options hash is merged with the controllers _view_config_. Tilt template options are passed through.
332
- # The template engine is derived from file name, or otherwise as specified by the _:engine_ option. If String is
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 = view_config.merge(explicit_options = 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
File without changes
File without changes
File without changes
@@ -1,3 +1,3 @@
1
1
  module Scorched
2
- VERSION = '0.5.2'
2
+ VERSION = '0.6'
3
3
  end
File without changes
File without changes
@@ -585,7 +585,7 @@ module Scorched
585
585
 
586
586
  describe "rendering" do
587
587
  before(:each) do
588
- app.view_config.each { |k,v| app.view_config[k] = nil }
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.view_config[:dir] = 'views'
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.view_config[:dir] = 'views'
640
- app.view_config[:engine] = :erb
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.view_config << {:dir => 'views', :layout => :layout, :engine => :erb}
656
+ app.render_defaults << {:dir => 'views', :layout => :layout, :engine => :erb}
657
657
  app.get('/') do
658
658
  render :composer
659
659
  end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
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.5.2
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-14 00:00:00.000000000 Z
11
+ date: 2013-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack