sinatra_more 0.3.14 → 0.3.15

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -580,7 +580,7 @@ or perhaps we want to have a short body without the need for a template file:
580
580
 
581
581
  See the wiki article for additional information: <http://wiki.github.com/nesquena/sinatra_more/mailerplugin>
582
582
 
583
- == RoutingPlugin
583
+ === RoutingPlugin
584
584
 
585
585
  This component provides Sinatra with an enhanced url routing system which enables named route aliases to be defined
586
586
  and used throughout your application to refer to urls. The benefits of this is that instead of having to hard-code route urls
data/ROADMAP CHANGED
@@ -14,12 +14,19 @@ Use Bundler for managing dependencies:
14
14
  Framework structure:
15
15
 
16
16
  * sinatra-core (the existing sinatra framework) <= from Sinatra
17
+ * sinatra-gen (easy generation of and for sinatra apps) <= from Generator
17
18
  * sinatra-helpers (adds the markup and renderer helpers) <= from MarkupPlugin, RenderPlugin
18
19
  * sinatra-mailer (mail handling for sinatra applications) <= from MailerPlugin
19
- * sinatra-gen (easy generation of and for sinatra apps) <= from Generator
20
- * sinatra-admin (admin management dashboard for content) <= from Lipsiadmin (ported)
21
20
  * sinatra-routing (sinatra route mapping system) <= from RoutingPlugin
22
21
  * sinatra-cache (page and fragment caching support)
22
+ * sinatra-admin (admin management dashboard for content) <= from Lipsiadmin (ported)
23
+
24
+ Additional wish-list features (integrate existing plugin) (?)
25
+
26
+ * Internationalization - http://r18n.rubyforge.org/#sinatra
27
+ * Asynchronous Commands - http://github.com/deadprogrammer/spork
28
+ * Capistrano Deployment - http://github.com/nakajima/capinatra (?)
29
+ * Job Queue - http://github.com/adamcooke/resque (or http://github.com/bmizerany/sinatra-dj)
23
30
 
24
31
  'sinatra-cache' Caching concept:
25
32
 
data/TODO CHANGED
@@ -1,10 +1,7 @@
1
1
  = RESOURCES
2
2
 
3
3
  - Check out the following sinatra extensions:
4
- * http://github.com/emk/sinatra-url-for/
5
4
  * http://github.com/wbzyl/sinatra-static-assets
6
- * http://github.com/hallison/sinatra-mapping/
7
- * http://github.com/bcarlso/snap/
8
5
  * http://github.com/giraffesoft/classy_resources
9
6
  * http://github.com/nakajima/capinatra
10
7
  * http://github.com/deadprogrammer/spork
@@ -31,6 +28,8 @@
31
28
 
32
29
  = COMPLETED
33
30
 
31
+ * Add support for multiple applications being mounted into routing system
32
+ * Add support for RoutingPlugin for easy to use named alias routes for urls
34
33
  * Add support for bundler (http://github.com/wycats/bundler) to make setting up a generated app easy
35
34
  * Add support for button tag method, mail_to helper
36
35
  * Add support for simple fields_for tag helper
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.14
1
+ 0.3.15
@@ -11,7 +11,7 @@ module SinatraMore
11
11
  # Used to define the url mapping to the supplied alias
12
12
  # NamedRoute.new(@app, :account).to('/account/path')
13
13
  def to(path)
14
- @app.named_paths[@names] = path
14
+ @app.named_paths[@names.unshift(@app.app_name)] = path
15
15
  end
16
16
 
17
17
  # Used to define the url mappings for child aliases within a namespace
@@ -5,9 +5,10 @@ module SinatraMore
5
5
  # url_for(:accounts) => '/accounts'
6
6
  # url_for(:account, :id => 5) => '/account/5'
7
7
  # url_for(:admin, show, :id => 5, :name => "demo") => '/admin/path/5/demo'
8
- def url_for(*names)
9
- values = names.extract_options!
10
- mapped_url = self.class.named_paths[names]
8
+ def url_for(*route_name)
9
+ values = route_name.extract_options!
10
+ mapped_url = self.class.named_paths[route_name] || self.class.named_paths[route_name.dup.unshift(self.class.app_name)]
11
+ raise SinatraMore::RouteNotFound.new("Route alias #{route_name.inspect} is not mapped to a url") unless mapped_url
11
12
  result_url = String.new(mapped_url)
12
13
  result_url.scan(%r{/?(:\S+?)(?:/|$)}).each do |placeholder|
13
14
  value_key = placeholder[0][1..-1].to_sym
@@ -2,11 +2,14 @@ require File.dirname(__FILE__) + '/support_lite'
2
2
  Dir[File.dirname(__FILE__) + '/routing_plugin/**/*.rb'].each {|file| load file }
3
3
 
4
4
  module SinatraMore
5
+ class RouteNotFound < RuntimeError; end
6
+
5
7
  module RoutingPlugin
6
8
  def self.registered(app)
7
9
  # Named paths stores the named route aliases mapping to the url
8
10
  # i.e { [:account] => '/account/path', [:admin, :show] => '/admin/show/:id' }
9
11
  app.set :named_paths, {}
12
+ app.set :app_name, app.name.underscore.to_sym
10
13
  app.helpers SinatraMore::RoutingHelpers
11
14
 
12
15
  # map constructs a mapping between a named route and a specified alias
@@ -32,8 +35,11 @@ module SinatraMore
32
35
  # Supports namespaces by accessing the instance variable and appending this to the route alias name
33
36
  # If the path is not a symbol, nothing is changed and the original route method is invoked
34
37
  def route(verb, path, options={}, &block)
35
- route_name = [@_namespace, path].flatten.compact
36
- path = named_paths[route_name] if path.kind_of? Symbol
38
+ if path.kind_of? Symbol
39
+ route_name = [self.app_name, @_namespace, path].flatten.compact
40
+ path = named_paths[route_name]
41
+ raise RouteNotFound.new("Route alias #{route_name.inspect} is not mapped to a url") unless path
42
+ end
37
43
  super verb, path, options, &block
38
44
  end
39
45
  end
data/sinatra_more.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sinatra_more}
8
- s.version = "0.3.14"
8
+ s.version = "0.3.15"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Nathan Esquenazi"]
@@ -41,4 +41,8 @@ class RoutingDemo < Sinatra::Base
41
41
  get '/links' do
42
42
  haml :index
43
43
  end
44
+
45
+ get '/failed_route' do
46
+ url_for(:some, :not_real, :id => 5)
47
+ end
44
48
  end
@@ -1,5 +1,7 @@
1
1
  %p.admin_url= url_for(:admin, :show, :id => 25)
2
+ %p.app_admin_url= url_for(:routing_demo, :admin, :show, :id => 25)
2
3
  %p.admin_url2= url_for(:admin, :update, :id => 10, :name => "test")
3
4
  %p.admin_url3= url_for(:admin, :destroy, :id => 12)
4
5
  %p.account_url= url_for(:account, :name => 'foobar', :id => 10)
5
6
  %p.accounts_index=url_for(:accounts)
7
+ %p.app_accounts_index=url_for(:routing_demo, :accounts)
@@ -17,6 +17,27 @@ class TestRoutingPlugin < Test::Unit::TestCase
17
17
  assert_have_selector :p, :class => 'admin_url2', :content => '/admin/10/update/test'
18
18
  assert_have_selector :p, :class => 'admin_url3', :content => '/admin/12/destroy'
19
19
  end
20
+ should "support app namespaces" do
21
+ assert_have_selector :p, :class => 'app_accounts_index', :content => '/the/accounts/index'
22
+ assert_have_selector :p, :class => 'app_admin_url', :content => '/admin/25/show'
23
+ end
24
+ end
25
+
26
+ context 'for failed or missing routes' do
27
+ should "properly not raise when found" do
28
+ assert_nothing_raised { app.new.url_for(:accounts) }
29
+ assert_nothing_raised { app.new.url_for(:routing_demo, :admin, :show, :id => 5) }
30
+ end
31
+ should "properly raise not found exception" do
32
+ assert_raises(SinatraMore::RouteNotFound) { visit '/failed_route' }
33
+ assert_raises(SinatraMore::RouteNotFound) { app.new.url_for(:admin, :fake) }
34
+ end
35
+ should "properly raise about an invalid alias for route definition" do
36
+ assert_raises(SinatraMore::RouteNotFound) { app.get(:fake) }
37
+ end
38
+ should "properly work when alias is used in proper route definition" do
39
+ assert_nothing_raised { app.get(:accounts) do; end }
40
+ end
20
41
  end
21
42
 
22
43
  context 'for no namespaced account route' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra_more
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.14
4
+ version: 0.3.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Esquenazi