cuba-contrib 3.0.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cuba-contrib"
3
- s.version = "3.0.0"
3
+ s.version = "3.0.1"
4
4
  s.summary = "Cuba plugins and utilities."
5
5
  s.description = "Includes various helper tools for Cuba."
6
6
  s.authors = ["Cyril David"]
@@ -1,8 +1,9 @@
1
1
  class Cuba
2
2
  CONTRIB_ROOT = File.expand_path("../../", File.dirname(__FILE__))
3
3
 
4
- autoload :Prelude, "cuba/contrib/prelude"
5
- autoload :Mote, "cuba/contrib/mote"
6
- autoload :TextHelpers, "cuba/contrib/text_helpers"
7
- autoload :FormHelpers, "cuba/contrib/form_helpers"
4
+ require "cuba/contrib/prelude"
5
+ require "cuba/contrib/mote"
6
+ require "cuba/contrib/text_helpers"
7
+ require "cuba/contrib/form_helpers"
8
+ require "cuba/contrib/with"
8
9
  end
@@ -0,0 +1,14 @@
1
+ class Cuba
2
+ module With
3
+ def with(dict = {})
4
+ old, env["cuba.vars"] = vars, dict
5
+ yield
6
+ ensure
7
+ env["cuba.vars"] = old
8
+ end
9
+
10
+ def vars
11
+ env["cuba.vars"] ||= {}
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,32 @@
1
+ require_relative "helper"
2
+
3
+ Cuba.plugin Cuba::With
4
+
5
+ class UserPhotos < Cuba
6
+ define do
7
+ on root do
8
+ res.write "uid: %d" % vars[:user_id]
9
+ end
10
+ end
11
+ end
12
+
13
+ test do
14
+ Cuba.define do
15
+ on "users/:id/photos" do |id|
16
+ with user_id: id do
17
+ _, _, body = UserPhotos.call(req.env)
18
+
19
+ body.each do |line|
20
+ res.write line
21
+ end
22
+ end
23
+
24
+ res.write vars.inspect
25
+ end
26
+ end
27
+
28
+ _, _, body = Cuba.call({ "PATH_INFO" => "/users/1001/photos",
29
+ "SCRIPT_NAME" => "" })
30
+
31
+ assert_response body, ["uid: 1001", "{}"]
32
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cuba-contrib
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-22 00:00:00.000000000 Z
12
+ date: 2012-04-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cuba
16
- requirement: &70184945975400 !ruby/object:Gem::Requirement
16
+ requirement: &70149650848280 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70184945975400
24
+ version_requirements: *70149650848280
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: cutest
27
- requirement: &70184945974540 !ruby/object:Gem::Requirement
27
+ requirement: &70149650847560 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70184945974540
35
+ version_requirements: *70149650847560
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: capybara
38
- requirement: &70184945973580 !ruby/object:Gem::Requirement
38
+ requirement: &70149650846740 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70184945973580
46
+ version_requirements: *70149650846740
47
47
  description: Includes various helper tools for Cuba.
48
48
  email:
49
49
  - me@cyrildavid.com
@@ -58,11 +58,13 @@ files:
58
58
  - lib/cuba/contrib/mote.rb
59
59
  - lib/cuba/contrib/prelude.rb
60
60
  - lib/cuba/contrib/text_helpers.rb
61
+ - lib/cuba/contrib/with.rb
61
62
  - lib/cuba/contrib.rb
62
63
  - cuba-contrib.gemspec
63
64
  - test/helper.rb
64
65
  - test/mote.rb
65
66
  - test/text_helper.rb
67
+ - test/vars.rb
66
68
  - views/field.mote
67
69
  - views/file.mote
68
70
  - views/option.mote