sinatra-backstage 0.2.3.2 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sinatra/backstage/rest/rest_routes.rb +15 -7
- data/lib/sinatra/backstage/user/user_helper.rb +16 -8
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b83633623dbf543d85186a19488832fcd7ec46bc
|
4
|
+
data.tar.gz: 282236a8b6055e173583e34a4803df1855e51587
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa5d87d94f1c11f8af4aac892bfa9b0191fbe494cd1aa9a32b50019baff5a45ddb92d007f91d46e289b3cddf6016db2b5b0ee9732a6e45320088cce39e78f07f
|
7
|
+
data.tar.gz: 83cdbaea1046c545090f9f62b4c3ea70543266ba7f942c9928c02f1a14c82f2057d84dc763134bf1524ceb4d3b6bc7d871a0aec9356c3bc4f5c9e6e932fd0ba7
|
@@ -1,3 +1,7 @@
|
|
1
|
+
## gorilla-patch
|
2
|
+
require 'gorilla-patch'
|
3
|
+
|
4
|
+
## datamapper
|
1
5
|
require 'dm-serializer'
|
2
6
|
|
3
7
|
module Sinatra
|
@@ -5,6 +9,10 @@ module Sinatra
|
|
5
9
|
module REST
|
6
10
|
module Routing
|
7
11
|
|
12
|
+
using GorillaPatch::ArrayExt
|
13
|
+
using GorillaPatch::HashExt
|
14
|
+
using GorillaPatch::ModuleExt
|
15
|
+
|
8
16
|
def self.included(controller)
|
9
17
|
controller.extend self
|
10
18
|
end
|
@@ -18,7 +26,7 @@ module Sinatra
|
|
18
26
|
# puts "-- REST.Routing get namespace ( params = #{params})"
|
19
27
|
format = params.delete('format') || 'html'
|
20
28
|
# puts "-- REST.Routing get namespace after format ( params = #{params})"
|
21
|
-
format = 'json' if request.accept.
|
29
|
+
format = 'json' if request.accept.include_any?('text/json', 'application/json')
|
22
30
|
## get json options
|
23
31
|
json_method = params.delete('json_method')
|
24
32
|
json_opts = {:methods => ([json_method] || [])}
|
@@ -31,7 +39,7 @@ module Sinatra
|
|
31
39
|
## return
|
32
40
|
case format
|
33
41
|
when 'html'
|
34
|
-
halt eval "#{settings.render_engine} '#{
|
42
|
+
halt eval "#{settings.render_engine} '#{klass.demodulize.downcase}/list'"
|
35
43
|
when 'json'
|
36
44
|
halt @objects.to_json(json_opts)
|
37
45
|
end
|
@@ -40,10 +48,10 @@ module Sinatra
|
|
40
48
|
|
41
49
|
### get add-form
|
42
50
|
get "#{namespace}/new" do
|
43
|
-
template = ["#{
|
51
|
+
template = ["#{klass.demodulize.downcase}/new"]
|
44
52
|
if display_list
|
45
53
|
@objects = rest_get_all(klass)
|
46
|
-
template.unshift "#{
|
54
|
+
template.unshift "#{klass.demodulize.downcase}/list"
|
47
55
|
end
|
48
56
|
eval "#{settings.render_engine} ['#{template.join('\',\'')}']"
|
49
57
|
end
|
@@ -70,10 +78,10 @@ module Sinatra
|
|
70
78
|
|
71
79
|
get "#{namespace}/:id" do |id|
|
72
80
|
@object = klass.get!(id)
|
73
|
-
template = ["#{
|
81
|
+
template = ["#{klass.demodulize.downcase}/edit"]
|
74
82
|
if display_list
|
75
83
|
@objects = rest_get_all(klass)
|
76
|
-
template.unshift "#{
|
84
|
+
template.unshift "#{klass.demodulize.downcase}/list"
|
77
85
|
end
|
78
86
|
eval "#{settings.render_engine} ['#{template.join('\',\'')}']"
|
79
87
|
end
|
@@ -93,7 +101,7 @@ module Sinatra
|
|
93
101
|
end
|
94
102
|
|
95
103
|
def rest_get_all(klass, params = {})
|
96
|
-
klass.all params.
|
104
|
+
klass.all params.to_sym_keys
|
97
105
|
end
|
98
106
|
|
99
107
|
end
|
@@ -1,3 +1,6 @@
|
|
1
|
+
## gorilla-patch
|
2
|
+
require 'gorilla-patch'
|
3
|
+
|
1
4
|
## sinatra gems
|
2
5
|
require 'sinatra'
|
3
6
|
|
@@ -8,25 +11,30 @@ module Sinatra
|
|
8
11
|
module User
|
9
12
|
module Helper
|
10
13
|
|
14
|
+
using GorillaPatch::ArrayExt
|
15
|
+
|
11
16
|
def self.included(app)
|
12
17
|
if app.ancestors.include? Sinatra::Base
|
13
|
-
app.set(:
|
18
|
+
app.set(:user_access) do |roles|
|
14
19
|
condition do
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
20
|
+
settings.site_routes.each do |controller, hash|
|
21
|
+
if request.path =~ /^(#{hash['href']}$|#{hash['href']}\/.*$)/
|
22
|
+
# puts "-- Backstage::UserHelper :user_access ( controller = #{controller} )"
|
23
|
+
# puts "-- Backstage::UserHelper :user_access ( hash = #{hash} )"
|
24
|
+
return hash['access'].compare(roles)
|
25
|
+
end
|
26
|
+
end
|
19
27
|
end
|
20
28
|
end
|
21
29
|
|
22
30
|
## Hooks
|
23
|
-
app.before :
|
24
|
-
# puts "-- Backstage::User
|
31
|
+
app.before :user_access => [:anon] do
|
32
|
+
# puts "-- Backstage::User before authorized? = #{authorized?}"
|
25
33
|
redirect '/' if authorized?
|
26
34
|
# settings.site_routes[request.path]['active'] = true if settings.site_routes[request.path]
|
27
35
|
end
|
28
36
|
|
29
|
-
# app.after :
|
37
|
+
# app.after :user_access => [:anon] do
|
30
38
|
# settings.site_routes[request.path]['active'] = false if settings.site_routes[request.path]
|
31
39
|
# end
|
32
40
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-backstage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Popov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
12
|
-
dependencies:
|
11
|
+
date: 2015-05-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: gorilla-patch
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
description: Sinatra-Backstage simplifies the use of the basic routes and models for
|
14
28
|
Sinatra and DataMapper. Currently it includes REST and User.
|
15
29
|
email: alex.wayfer@gmail.com
|