sinatra-mapping 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +4 -4
- data/lib/sinatra/mapping.rb +25 -0
- data/test/test_mapping.rb +4 -5
- metadata +2 -2
data/VERSION
CHANGED
data/lib/sinatra/mapping.rb
CHANGED
@@ -34,6 +34,31 @@ module Sinatra
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
+
# Auto mapping from a hash. This method is very useful.
|
38
|
+
# Example:
|
39
|
+
#
|
40
|
+
# # In Web application.
|
41
|
+
# class WebApp << Sinatra::Base
|
42
|
+
# mapping :root => "tasks", # /tasks
|
43
|
+
# :status => "changes" # /tasks/changes
|
44
|
+
# end
|
45
|
+
#
|
46
|
+
# Or, it's possible use from configuration file.
|
47
|
+
#
|
48
|
+
# # YAML file "settings.yml".
|
49
|
+
# mapping:
|
50
|
+
# root: tasks
|
51
|
+
# status: changes
|
52
|
+
# # In Web application.
|
53
|
+
# class WebApp << Sinatra::Base
|
54
|
+
# mapping YAML.load_file("settings.yml")[:mapping]
|
55
|
+
# end
|
56
|
+
def mapping(hash)
|
57
|
+
hash.each do |name, path|
|
58
|
+
map name, path
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
37
62
|
# Returns URL path with query instructions.
|
38
63
|
def query_path_to(*args)
|
39
64
|
args.compact!
|
data/test/test_mapping.rb
CHANGED
@@ -12,12 +12,11 @@ class AppForTest < Sinatra::Base
|
|
12
12
|
register Sinatra::Mapping
|
13
13
|
helpers Sinatra::MappingHelpers
|
14
14
|
|
15
|
-
map :root
|
16
|
-
map :
|
17
|
-
map :archive, "archive/articles" # archive_path => /archive/articles
|
18
|
-
map :about # about_path => /about
|
15
|
+
map :root # root_path => /
|
16
|
+
map :about # about_path => /about
|
19
17
|
|
20
|
-
|
18
|
+
mapping :posts => "articles", # posts_path => /articles
|
19
|
+
:archive => "archive/articles" # archive_path => /archive/articles
|
21
20
|
|
22
21
|
before do
|
23
22
|
@date = Date.today
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-mapping
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hallison Batista
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-07-
|
12
|
+
date: 2009-07-18 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|