scorched 0.7 → 0.8

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: bbeb1df9d3b27b4e455d9c0ee30d282da0875a58
4
- data.tar.gz: bf7ee84acc65b7bd2cd355afdca30150ac8b8f6a
3
+ metadata.gz: 9e853e2cdf6c23a10cebb3ada3d26cc90a0535b7
4
+ data.tar.gz: 2cfe230e619c9ad1f0304c35699ed55cdcc9e94b
5
5
  SHA512:
6
- metadata.gz: a546b0e44c56adb26cc23d5d0fe40a60485467a50639c05fd36fadd8ce7dab591de8ff06b73c73756739ace69ab34a56402e9179d49e56b7a4920993050292d4
7
- data.tar.gz: 3f85d181a8db836196db23099b6d5b49a424bad7d2f56c9e714021127ddcb9c4cf61664ec24b251d0affbd2aa4ea7fd0ea542b87f2a5124ba3100bd202938611
6
+ metadata.gz: 236012f2a5d523733f2fe8d81389d545d9bbb01a421f2840371e31f7f4b81ccf608cd7ba06838f0291a5bb0796271bd6e1e10de6b0a61301168b4c2865c52dbf
7
+ data.tar.gz: 2e531bf2da9a00ea4efedf2eaa18d2718d6c7bebc72cf47176f48ac6f4b35c2722f5974b4d72346e5d4d8375cfc4f091fc34af46d2d1165b9c762318ce941f0c
data/Gemfile CHANGED
File without changes
data/LICENSE CHANGED
File without changes
@@ -3,19 +3,22 @@ Milestones
3
3
 
4
4
  Changelog
5
5
  ---------
6
+ ### v0.8
7
+ * Changed `controller` method signature to accept an optional URL pattern as the first argument.
8
+ * Implemented a pass mechanism to short-circuit out of the current match and invoke the next match.
9
+ * Added `:auto_pass` configuration option. When true, if none of the controller's mapping match the request, the controller will `pass` back to the outer controller without running any filters.
10
+ * Sub-controllers generated with the `controller` helper are automatically configured with `:auto_pass` set to `true`. This makes inline sub-controllers even more useful for grouping routes.
11
+
6
12
  ### v0.7
7
13
  * Logging preparations made. Now just have to decide on a logging strategy, such as what to log, how verbose the messages should be, etc.
8
- * Environment-specific defaults added. The environment variable ``RACK_ENV`` is used to determine the current environment.
9
- * Non-Development
10
- * ``config[:static_dir] = false``
11
- * Development
12
- * ``config[:show_exceptions] = true``
13
- * ``config[:logger] = Logger.new(STDOUT)``
14
- * Add developer-friendly 404 error page. This is implemented as an after filter, and won't have any effect if the response body is set.
15
- * ``absolute`` method now returns forward slash if script name is empty.
14
+ * Environment-specific defaults added. The environment variable `RACK_ENV`s used to determine the current environment.
15
+ * Non-Development
16
+ * `config[:static_dir] = false` * Development
17
+ * `config[:show_exceptions] = true` * `config[:logger] = Logger.new(STDOUT)` * Add developer-friendly 404 error page. This is implemented as an after filter, and won't have any effect if the response body is set.
18
+ * `absolute`ethod now returns forward slash if script name is empty.
16
19
 
17
20
  ### v0.6
18
- * ``view_config`` options hash renamed to ``render_defaults`` which better reflects its function.
21
+ * `view_config`ptions hash renamed to ` `render_defaults`ch better reflects its function.
19
22
 
20
23
  ### v0.5.2
21
24
  * Minor modification to routing to make it behave as a documented regarding matching at the directly before or on a path.
@@ -30,12 +33,10 @@ Changelog
30
33
  * Added session method for convenience, and implemented helper for flash session data.
31
34
  * Added cookie helper for conveniently setting, retrieving and deleting cookies.
32
35
  * Static file serving actually works now
33
- * Custom middleware Scorched::Static serves as a thin layer on top of Rack::File.
36
+ * Custom middleware Scorched::Static serves as a thin layer on top of Rack::File.
34
37
  * Added specs for each configuration option.
35
38
  * Using Ruby 2.0 features where applicable. No excuse not to be able to deploy on 2.0 by the time Scorched is ready for production.
36
- * Keyword arguments instead of ``*args`` combined with ``Hash === args.last``.
37
- * Replaced instances of __FILE__ with __dir__.
38
- * Added expected Rack middleware, Rack::MethodOverride and Rack::Head.
39
+ * Keyword arguments instead of `*args`ombined with ` `Hash === args.last` * Replaced instances of `__FILE__`ith ` `__dir__`Added expected Rack middleware, Rack::MethodOverride and Rack::Head.
39
40
 
40
41
  ### v0.4
41
42
  * Make filters behave like middleware. Inheritable, but are only executed once.
@@ -45,7 +46,7 @@ Changelog
45
46
  * Basic request handling and routing
46
47
  * String and Regex URL matching, with capture support
47
48
  * Implemented route conditions
48
- * Added HTTP method condition which the route helpers depend on.
49
+ * Added HTTP method condition which the route helpers depend on.
49
50
  * Added route helpers
50
51
  * Implemented support for sub-controllers
51
52
  * Implement before and after filters with proper execution order.
@@ -53,7 +54,7 @@ Changelog
53
54
  * Mechanism for including Rack middleware.
54
55
  * Added more route conditions e.g. content-type, language, user-agent, etc.
55
56
  * Provide means to `halt` request.
56
- * Added redirect helping for halting and redirecting request
57
+ * Added redirect helping for halting and redirecting request
57
58
  * Mechanism for handling exceptions in routes and before/after filters.
58
59
  * Added static resource serving. E.g. public folder.
59
60
 
@@ -61,27 +62,23 @@ Changelog
61
62
 
62
63
  To Do
63
64
  -----
64
- Some of these remaining features may be broken out into a separate contributor library to keep the core lean and focused.
65
+ Some of these remaining features may be reconsidered and either left out, or put into some kind of contrib library.
65
66
 
66
67
  * Make specs for Collection and Options classes more thorough, e.g. test all non-reading modifiers such as clear, delete, etc.
67
- * Add view helpers
68
+ * Implement template caching with option to disable/enable (disabled by default in development)
69
+ * Add more view helpers, maybe?
68
70
  * Add helper to easily read and build HTTP query strings. Takes care of "?" and "&" logic, escaping, etc. This is
69
71
  intended to make link building easier.
70
72
  * Form populator implemented with Nokogiri. This would have to be added to a contrib library.
71
73
  * Add Verbose logging, including debug logging to show each routing hop and the current environment (variables, mode, etc)
72
- * Environment optimised defaults
73
- * Production
74
- * use Rack::Protection
75
- * Disable static file serving. Sub-controllers can obviously override this. This will just change the default.
76
- * Development
77
- * Log to STDOUT
78
- * use Rack::ShowExceptions
79
- * Add developer-friendly 404 error page.
80
-
74
+
75
+
81
76
  Unlikely
82
77
  --------
78
+ These features are unlikely to be implemented unless someone provides a good reason.
79
+
83
80
  * Mutex locking option - I'm of the opinion that the web server should be configured for the concurrency model of the application, rather than the framework.
84
81
  * Using Rack::Protection by default - The problem here is that a good portion of Rack::Protection involves sessions, and given that Scorched doesn't itself load any session middleware, these components of Rack::Protection would have to be excluded. I wouldn't want to invoke a false sense of security
85
82
 
86
83
 
87
- More things will be added to these lists as they're thought of and considered.
84
+ More things will be added as they're thought of and considered.
data/README.md CHANGED
@@ -3,32 +3,39 @@
3
3
 
4
4
  Scorched is a generic, unopinionated, DRY, light-weight web framework for Ruby. It provides a generic yet powerful set of constructs for processing HTTP requests, with which websites and applications of almost any scale can be built.
5
5
 
6
- If you've used a light-weight DSL-based Ruby web framework before, such as a Sinatra, it should look familiar. Scorched is a true evolutionary enhancement of Sinatra, with more power, focus, and less clutter.
6
+ If you've used a light-weight DSL-based Ruby web framework before, such as Sinatra, it should look familiar. Scorched is a true evolutionary enhancement of Sinatra, with more power, focus, and less clutter.
7
7
 
8
8
  Getting Started
9
9
  ---------------
10
10
 
11
11
  Install the canister...
12
12
 
13
- gem install scorched
13
+ ```console
14
+ $ gem install scorched
15
+ ```
14
16
 
15
17
  Open the valve...
16
18
 
17
- # ruby
18
- # hello_world.ru
19
- require 'scorched'
20
- class App < Scorched::Controller
21
- get '/' do
22
- 'hello world'
23
- end
24
- end
25
- run App
19
+ ```ruby
20
+ # hello_world.ru
21
+ require 'scorched'
22
+ class App < Scorched::Controller
23
+ get '/' do
24
+ 'hello world'
25
+ end
26
+ end
27
+ run App
28
+ ```
26
29
 
27
30
  And light the flame...
28
31
 
29
- rackup hello_world.ru
32
+ ```console
33
+ $ rackup hello_world.ru
34
+ ```
35
+
36
+ #### A Note on Requirements
30
37
 
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._
38
+ Scorched requires Ruby 2.0 as it makes use of a few new features. It is however, important to ensure your version of Ruby 2.0 includes [changeset 39919](http://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/39919) in order to avoid suffering from [random segmentation faults](http://bugs.ruby-lang.org/issues/8100). The first official patch release of 2.0.0 should include the fix, otherwise you can patch it during installation with RVM.
32
39
 
33
40
  The Errors of Our Past
34
41
  ----------------------
@@ -54,42 +61,43 @@ Part of what keeps Scorched lightweight, is that unlike other lightweight web fr
54
61
  First Impressions
55
62
  -----------------
56
63
 
57
- # ruby
58
- class MyApp < Scorched::Controller
59
-
60
- # From the most simple route possible...
61
- get '/' do
62
- "Hello World"
63
- end
64
-
65
- # To something that gets the muscle's flexing
66
- route '/articles/:title/::opts', 2, methods: ['GET', 'POST'], content_type: :json do
67
- # Do what you want in here. Note, the second argument is the optional route priority.
68
- end
69
-
70
- # Anonymous controllers allow for convenient route grouping to which filters and conditions can be applied
71
- controller conditions: {media_type: 'application/json'} do
72
- get '/articles/*' do |page|
73
- {title: 'Scorched Rocks', body: '...', created_at: '27/08/2012', created_by: 'Bob'}
74
- end
75
-
76
- after do
77
- response.body = response.body.to_json
78
- end
79
- end
80
-
81
- # The things you get for free by using Classes for Controllers (...that's directed at you Padrino)
82
- def my_little_helper
83
- # Do some crazy awesome stuff that no route can resist using.
84
- end
85
-
86
- # You can always avoid the routing helpers and add mappings manually. Anything that responds to #call is a valid
87
- # target, with the only minor exception being that proc's are instance_exec'd, not call'd.
88
- self << {pattern: '/admin', priority: 10, target: My3rdPartyAdminApp}
89
- self << {pattern: '**', conditions: {maintenance_mode: true}, target: proc { |env|
90
- @request.body << 'Maintenance underway, please be patient.'
91
- }}
64
+ ```ruby
65
+ class MyApp < Scorched::Controller
66
+
67
+ # From the most simple route possible...
68
+ get '/' do
69
+ "Hello World"
70
+ end
71
+
72
+ # To something that gets the muscle's flexing
73
+ route '/articles/:title/::opts', 2, methods: ['GET', 'POST'], content_type: :json do
74
+ # Do what you want in here. Note, the second argument is the optional route priority.
75
+ end
76
+
77
+ # Anonymous controllers allow for convenient route grouping to which filters and conditions can be applied
78
+ controller conditions: {media_type: 'application/json'} do
79
+ get '/articles/*' do |page|
80
+ {title: 'Scorched Rocks', body: '...', created_at: '27/08/2012', created_by: 'Bob'}
81
+ end
82
+
83
+ after do
84
+ response.body = response.body.to_json
92
85
  end
86
+ end
87
+
88
+ # The things you get for free by using Classes for Controllers (...that's directed at you Padrino)
89
+ def my_little_helper
90
+ # Do some crazy awesome stuff that no route can resist using.
91
+ end
92
+
93
+ # You can always avoid the routing helpers and add mappings manually. Anything that responds to #call is a valid
94
+ # target, with the only minor exception being that proc's are instance_exec'd, not call'd.
95
+ self << {pattern: '/admin', priority: 10, target: My3rdPartyAdminApp}
96
+ self << {pattern: '**', conditions: {maintenance_mode: true}, target: proc { |env|
97
+ @request.body << 'Maintenance underway, please be patient.'
98
+ }}
99
+ end
100
+ ```
93
101
 
94
102
  This API shouldn't look too foreign to anyone familiar with frameworks like Sinatra, and the potential power at hand should be obvious. The `route` method demonstrates a few minor features of Scorched:
95
103
 
@@ -1,6 +1,16 @@
1
1
  Preface
2
2
  =======
3
3
 
4
- _This is where I share with you all my infinite wisdom. It will come. In the mean time, know that the documentation is currently incomplete, and likely the victim of quite a few typos._
4
+ This collection of documentation serves as a practical technical reference for using Scorched. It explains and demonstrates the use of all constructs, but not necessarily every method. For the story behind Scorched, refer to: http://scorchedrb.com/about
5
5
 
6
- _As an early adopter, feel free to use the Github issue tracker to ask questions and request assistance. Such questions will be used to further refine the documentation._
6
+
7
+ Getting Started
8
+ ---------------
9
+ If you haven't already done so, please refer to the [README](../README.md) for a generic introduction to Scorched, including how to get started.
10
+
11
+
12
+ Who Should Use Scorched?
13
+ ------------------------
14
+ Whilst Scorched is suitable for any Ruby developer, the documentation does assume you're comfortable programming in Ruby, and that you're familiar with Rack. It also assumes some prior experience with web development and HTTP. Scorched itself, as a very unopinionated and open-ended framework, doesn't necessarily serve the inexperienced developer. To get the most out of Scorched, you need to implement your ideas on top of it, using your preferred tools and techniques, which only a developer with the aforementioned experience will be able to do effectively.
15
+
16
+ Those who will enjoy using Scorched the most, are creative developers who like to apply their own values, ideas, and toolset to solving web development problems. Anyone who doesn't like Rails should love Scorched.
@@ -1,19 +1,140 @@
1
1
  The Controller
2
2
  ==============
3
3
 
4
- Scorched consists almost entirely of the ``Scorched::Controller``. The Controller is the class from which your application class inherits. All the code examples provided in the documentation are assumed to be wrapped within a controller class.
4
+ Scorched consists almost entirely of the `Scorched::Controller`. The Controller is the class from which your application class inherits. All the code examples provided in the documentation are assumed to be wrapped within a controller class.
5
5
 
6
- # ruby
7
- class MyApp < Scorched::Controller
8
- # We are now within the controller class.
9
- # Most examples are assumed to be within this context.
6
+ ```ruby
7
+ class MyApp < Scorched::Controller
8
+ # We are now within the controller class.
9
+ # Most examples are assumed to be within this context.
10
+ end
11
+ ```
12
+
13
+ Your application's root controller (named `MyApp` in the example above), should be configured as the _run_ target in your rackup file:
14
+
15
+ ```ruby
16
+ # config.ru
17
+ require './myapp.rb'
18
+ run MyApp
19
+ ```
20
+
21
+ Sub-Controllers
22
+ ---------------
23
+ One of the core features of Scorched is the fact that Controller's are intended to be inheritable and nestable as sub-controllers. This is perhaps the main advantage of Scorched over the likes of Sinatra and Padrino, and is one of the key innovations of the framework.
24
+
25
+ For the most part, you will find yourself breaking up your application into many discrete controllers. This will allow you to scope your configuration, filters, error handlers, and conditions, to logical groups of routes. This can save a lot of code repetition, keeping your code DRY, hence the name _Scorched_.
26
+
27
+ A sub-controller is any controller that's mapped by another controller. `ControllerB` in the following example, is one example of a sub-controller.
28
+
29
+ ``` ruby
30
+ class ControllerA < Scorched::Controller
31
+ get '/' do
32
+ "Hello there"
33
+ end
34
+
35
+ after do
36
+ response.body[0] << '.' # Always forgetting to add my periods
37
+ end
38
+ end
39
+
40
+ class ControllerB < Scorched::Controller
41
+ get '/' do
42
+ "I'm apparently a sub-controller"
43
+ end
44
+ end
45
+
46
+ ControllerA << {pattern: '/sub', target: ControllerB}
47
+ ```
48
+
49
+ The previous example is awfully crude, but it hopefully demonstrates that there's absolutely no magic happening here. In that previous example, a request for `/sub` will pass through `ControllerA` and onto `ControllerB`, before heading back out the way it came. Hence, a request for `/sub` will yield `I'm apparently a sub-controller.`; note the period added by ControllerA's _after_ filter (more on _after_ filters later).
50
+
51
+ While in the previous example, `ControllerB` counts as a sub-controller in that it's nested within ControllerA, at least from a routing perspective, `ControllerA` and `ControllerB` are completely unrelated; they share nothing.
52
+
53
+ A lot can be gained by not only nesting `ControllerB` within `ControllerA`, but by also inheriting from it.
54
+
55
+ ``` ruby
56
+ class ControllerA < Scorched::Controller
57
+ render_defaults[:dir] = 'views'
58
+ render_defaults[:layout] = :main
59
+
60
+ conditions[:user] = proc { |usernames|
61
+ [*usernames].include? session['username']
62
+ }
63
+
64
+
65
+ get '/' do
66
+ bold "Hello there"
67
+ end
68
+
69
+ def bold(str)
70
+ "<strong>#{str}</strong>"
71
+ end
72
+ end
73
+
74
+ class ControllerB < Scorched::Controller
75
+ render_defaults[:layout] = :controller_b
76
+
77
+ get '/', user: 'bob' do
78
+ bold "I'm apparently a sub-controller"
79
+ end
80
+ end
81
+
82
+ ControllerA << {pattern: '/sub', target: ControllerB}
83
+ ```
84
+
85
+ Now that `ControllerB` is inheriting from `ControllerA`, it not only gets access to all its methods, such as the very helpful `bold`, but it also inherits anything configured on `ControllerA`, such as rendering defaults, filters, middleware, conditions, etc. Very handy.
86
+
87
+ You can use nesting and inheritance exclusively, or together, depending on your needs.
88
+
89
+ Controller Helper
90
+ -----------------
91
+ There is a more succinct way of defining sub-controllers, and that's with the `controller` helper. Here's the previous example re-written using the `controller` helper.
92
+
93
+ ``` ruby
94
+ class MyApp < Scorched::Controller
95
+ render_defaults[:dir] = 'views'
96
+ render_defaults[:layout] = :main
97
+
98
+ conditions[:user] = proc { |usernames|
99
+ [*usernames].include? 'bob'
100
+ }
101
+
102
+ get '/' do
103
+ bold "Hello there"
104
+ end
105
+
106
+ controller '/sub' do
107
+ render_defaults[:layout] = :controller_b
108
+
109
+ get '/', user: ['bob', 'jeff'] do
110
+ bold "I'm apparently a sub-controller"
10
111
  end
112
+ end
113
+
114
+ def bold(str)
115
+ "<strong>#{str}</strong>"
116
+ end
117
+ end
118
+ ```
119
+
120
+ The controller helper takes an optional URL pattern as it's first argument, an optional parent class as it's second, and finally a mapping hash as its third optional argument, where you can define a priority, conditions, or override the URL pattern. Of course, the `controller` helper takes a block as well, which defines the body of the new controller class.
121
+
122
+ The optional URL pattern defaults to `'/'` which can be handy for grouping a set of routes.
11
123
 
12
- Your application's root controller (named ``MyApp`` in the example above), should be configured as the _run_ target in your rackup file:
124
+ ``` ruby
125
+ class MyApp < Scorched::Controller
126
+ get '/' do
127
+ bold "Hello there"
128
+ end
129
+
130
+ controller conditions: {media_type: 'application/json'} do
131
+
132
+ end
133
+ end
134
+ ```
13
135
 
14
- # ruby
15
- # config.ru
16
- require './myapp.rb'
17
- run MyApp
136
+ The Root Controller
137
+ -------------------
138
+ Although you will likely have a main controller to serve as the target for Rack, Scorched does not have the concept of a root controller. It mades no differentiation between a sub-controller and any other controller. All Controllers are made equal.
18
139
 
19
- The rest of the documentation will detail the Controller more thoroughly.
140
+ You can arrange and nest your controllers in any way, shape or form. Scorched has been designed to not make any assumptions about how you structure your controllers, which can accommodate very creative solutions.
@@ -3,34 +3,36 @@ Configuration
3
3
 
4
4
  Scorched includes a few configurable options out of the box. These all have common defaults, or are otherwise left intentionally blank to ensure the developer opts-in to any potentially undesirable or surprising behaviour.
5
5
 
6
- There are two sets of configurables. Those which apply to views, and everything else. Each set of configuration options is a ``Scorched::Options`` instance. This allows configuration options to be inherited and subsequently overriden by child classes. This is handy in many instances, but a common requirement might be to change the view directory or default layout of some sub-controller.
6
+ There are two sets of configurables. Those which apply to views, and everything else. Each set of configuration options is a `Scorched::Options` instance. This allows configuration options to be inherited and subsequently overridden by child classes. This is handy in many instances, but a common requirement might be to change the view directory or default layout of some sub-controller.
7
7
 
8
8
  Options
9
9
  -------
10
10
 
11
- Each configuration is listed below, with the default value of each included.
11
+ Each configuration is listed below, with the default value of each included. Note, environment specific defaults may override the default values below.
12
12
 
13
- * ``config[:strip_trailing_slash] = :redirect``
13
+ * `config[:strip_trailing_slash] = :redirect`
14
14
  Controls how trailing forward slashes in requests are handled.
15
- * ``:redirect`` - Strips and redirects URL's ending in a forward slash
16
- * ``:ignore`` - Internally ignores trailing slash
17
- * ``false`` - Does nothing. Respects the presence of a trailing forward flash.
18
- * ``config[:static_dir] = 'public'``
15
+ * `:redirect` - Strips and redirects URL's ending in a forward slash
16
+ * `:ignore` - Internally ignores trailing slash
17
+ * `false` - Does nothing. Respects the presence of a trailing forward flash.
18
+ * `config[:static_dir] = 'public'`
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
- * ``config[:logger] = Logger.new(STDOUT)`` - Currently does nothing until logging is added to Scorched.
20
+ * `config[:logger] = Logger.new(STDOUT)` - Currently does nothing until logging is added to Scorched.
21
+ * `config[:auto_pass] = false` - If no routes within the current controller match, automatically _pass_ the request back to the outer controller without running any filters. This makes sub-controllers behave more like a kind-of route group.
21
22
 
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
+ 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
 
24
25
  Refer to the _views_ page for more information.
25
26
 
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
27
+ 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.
28
+
29
+ ```ruby
30
+ class MyApp < Scorched::Controller
31
+ config[:static_dir] = '../public'
32
+ render_defaults.merge!(
33
+ dir: 'templates',
34
+ layout: :main_layout
35
+ engine: :haml
36
+ )
37
+ end
38
+ ```