cuba-sugar 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +42 -0
- data/lib/cuba/sugar.rb +16 -0
- metadata +27 -5
data/README.md
CHANGED
@@ -61,6 +61,48 @@ Cuba.define do
|
|
61
61
|
end
|
62
62
|
```
|
63
63
|
|
64
|
+
### csrf_tag && csrf_token
|
65
|
+
|
66
|
+
In the forms:
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
<%= csrf_tag %>
|
70
|
+
```
|
71
|
+
|
72
|
+
In the code:
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
require "cuba"
|
76
|
+
require "cuba/sugar"
|
77
|
+
|
78
|
+
Cuba.use Rack::Csrf
|
79
|
+
|
80
|
+
Cuba.define do
|
81
|
+
# Automatic csrf validation
|
82
|
+
on post
|
83
|
+
end
|
84
|
+
end
|
85
|
+
```
|
86
|
+
|
87
|
+
### helpers
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
require "cuba"
|
91
|
+
require "cuba/sugar"
|
92
|
+
|
93
|
+
Cuba.define do
|
94
|
+
helpers do
|
95
|
+
def now
|
96
|
+
Time.now
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
on "time" do
|
101
|
+
as { "The current time is: #{now}" }
|
102
|
+
end
|
103
|
+
end
|
104
|
+
```
|
105
|
+
|
64
106
|
Contributors
|
65
107
|
------------
|
66
108
|
|
data/lib/cuba/sugar.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'json'
|
2
|
+
require "rack/csrf"
|
2
3
|
|
3
4
|
class Cuba
|
4
5
|
# Sugar to do some common response tasks
|
@@ -21,4 +22,19 @@ class Cuba
|
|
21
22
|
(yield).to_json if block_given?
|
22
23
|
end
|
23
24
|
end
|
25
|
+
|
26
|
+
# From sinatra/base
|
27
|
+
def helpers(*extensions, &block)
|
28
|
+
instance_eval(&block) if block_given?
|
29
|
+
include(*extensions) if extensions.any?
|
30
|
+
end
|
31
|
+
|
32
|
+
def csrf_tag
|
33
|
+
Rack::Csrf.tag(env)
|
34
|
+
end
|
35
|
+
|
36
|
+
def csrf_token
|
37
|
+
Rack::Csrf.token(env)
|
38
|
+
end
|
39
|
+
|
24
40
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cuba-sugar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,7 +14,7 @@ default_executable:
|
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: cuba
|
17
|
-
requirement: &
|
17
|
+
requirement: &70196371413660 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70196371413660
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: json
|
28
|
-
requirement: &
|
28
|
+
requirement: &70196371413100 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,7 +33,29 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70196371413100
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rack_csrf
|
39
|
+
requirement: &70196371412560 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
type: :runtime
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *70196371412560
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: cutest
|
50
|
+
requirement: &70196371412020 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *70196371412020
|
37
59
|
description: Bundled contrib utils to use with cuba
|
38
60
|
email:
|
39
61
|
- yo@brunoaguirre.com
|