bcarlso-snap 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Brandon Carlson (bcarlso)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,7 @@
1
+ = Sinatra NAmed Paths (snap)
2
+
3
+ Enables named paths in Sinatra apps. For documentation, see the wiki.
4
+
5
+ == Copyright
6
+
7
+ Copyright (c) 2009 Brandon Carlson (bcarlso). See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,48 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "snap"
8
+ gem.summary = "Sinatra NAmed Path support"
9
+ gem.email = "bcarlso@gmail.com"
10
+ gem.homepage = "http://github.com/bcarlso/snap"
11
+ gem.authors = ["bcarlso"]
12
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
13
+ end
14
+
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
17
+ end
18
+
19
+ require 'spec/rake/spectask'
20
+ Spec::Rake::SpecTask.new(:spec) do |spec|
21
+ spec.libs << 'lib' << 'spec'
22
+ spec.spec_files = FileList['spec/**/*_spec.rb']
23
+ end
24
+
25
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
26
+ spec.libs << 'lib' << 'spec'
27
+ spec.pattern = 'spec/**/*_spec.rb'
28
+ spec.rcov = true
29
+ end
30
+
31
+
32
+ task :default => :spec
33
+
34
+ require 'rake/rdoctask'
35
+ Rake::RDocTask.new do |rdoc|
36
+ if File.exist?('VERSION.yml')
37
+ config = YAML.load(File.read('VERSION.yml'))
38
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
39
+ else
40
+ version = ""
41
+ end
42
+
43
+ rdoc.rdoc_dir = 'rdoc'
44
+ rdoc.title = "snap #{version}"
45
+ rdoc.rdoc_files.include('README*')
46
+ rdoc.rdoc_files.include('lib/**/*.rb')
47
+ end
48
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,19 @@
1
+ require 'rubygems'
2
+ require 'sinatra'
3
+ require '../lib/sinatra/named_path_support'
4
+
5
+ path :home, '/index'
6
+ path :add, '/add/:augend/:addend'
7
+ path :result, '/sum/:augend/:addend'
8
+
9
+ get :home do
10
+ "Hello World!"
11
+ end
12
+
13
+ get :add do
14
+ redirect(path_to(:result).with(params[:augend], params[:addend]))
15
+ end
16
+
17
+ get :result do
18
+ "#{params[:augend]} + #{params[:addend]} = #{params[:augend].to_i + params[:addend].to_i}"
19
+ end
@@ -0,0 +1,37 @@
1
+ require 'sinatra/base'
2
+
3
+ module Sinatra
4
+ module PathDefinitionSupport
5
+ def path name, pattern
6
+ named_paths[name] = pattern
7
+ end
8
+
9
+ def route(verb, path, options={}, &block)
10
+ path = named_paths[path] if path.kind_of? Symbol
11
+ super verb, path, options, &block
12
+ end
13
+
14
+ def self.registered(app)
15
+ app.set :named_paths, {}
16
+ end
17
+ end
18
+
19
+ module PathBuilderSupport
20
+ def path_to path_name
21
+ pattern = self.class.named_paths[path_name]
22
+ def pattern.with(*values)
23
+ url = String.new(self)
24
+ index = 0;
25
+ scan(%r{/?(:\S+?)(?:/|$)}).each do | placeholder |
26
+ url.gsub!(Regexp.new(placeholder[0]), values[index].to_s)
27
+ index += 1
28
+ end
29
+ url
30
+ end
31
+ pattern
32
+ end
33
+ end
34
+
35
+ register PathDefinitionSupport
36
+ helpers PathBuilderSupport
37
+ end
data/lib/snap.rb ADDED
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + '/sinatra/named_path_support'
data/spec/snap_spec.rb ADDED
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Snap" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec'
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ require 'snap'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bcarlso-snap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - bcarlso
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-24 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: bcarlso@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - .document
27
+ - .gitignore
28
+ - LICENSE
29
+ - README.rdoc
30
+ - Rakefile
31
+ - VERSION
32
+ - lib/snap.rb
33
+ - lib/sinatra/named_path_support.rb
34
+ - spec/snap_spec.rb
35
+ - spec/spec_helper.rb
36
+ has_rdoc: false
37
+ homepage: http://github.com/bcarlso/snap
38
+ post_install_message:
39
+ rdoc_options:
40
+ - --charset=UTF-8
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ requirements: []
56
+
57
+ rubyforge_project:
58
+ rubygems_version: 1.2.0
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: Sinatra NAmed Path support
62
+ test_files:
63
+ - spec/snap_spec.rb
64
+ - spec/spec_helper.rb
65
+ - examples/named_route_example.rb