sinatra-admin 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -9
- data/lib/sinatra-admin/register/base.rb +1 -1
- data/lib/sinatra-admin/version.rb +1 -1
- data/spec/sinatra-admin/register/model_spec.rb +5 -0
- data/spec/sinatra-admin/version_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38b4ab16c9122b2bf6588d73a562b9b0099688d8
|
4
|
+
data.tar.gz: 62223b80352211b6c7e948b46b15d0301db04510
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eefd5b42c6f83ec5c06aaa3f796e5122553ad5d33b1eb36865c47281104fcbc5f42da03339d6df6585247f8688ee27d9ec307e84872514189001eda49cff446e
|
7
|
+
data.tar.gz: 57ae0111229b64a4ddaee2fd27f6626c81073ade1d7032b007cd128da9891a42d2904748afa0b63e3e743edea665c80f3519a1e2f984efe2dfa4e7f5ebd1b794
|
data/README.md
CHANGED
@@ -24,7 +24,16 @@ Or install it yourself as:
|
|
24
24
|
By default SinatraAdmin assumes that it's mounted over an "admin"
|
25
25
|
namespace. This is how SinatraAdmin should be configured:
|
26
26
|
|
27
|
-
1.
|
27
|
+
1. Set ENV['SINATRA_ADMIN_SECRET']. This secret key is used by
|
28
|
+
Rack::Session::Cookie to encrypt your cookies. Warden needs this
|
29
|
+
session secret key to keep the user sessions. If you do not set
|
30
|
+
this value you're going to see a security warning.
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
$ export SINATRA_ADMIN_SECRET="my_secret_key"
|
34
|
+
```
|
35
|
+
|
36
|
+
2. Define your project namespace and your Sinatra applications.
|
28
37
|
```ruby
|
29
38
|
module MyApp
|
30
39
|
class API < Sinatra::Base
|
@@ -37,14 +46,14 @@ namespace. This is how SinatraAdmin should be configured:
|
|
37
46
|
end
|
38
47
|
```
|
39
48
|
|
40
|
-
|
49
|
+
3. Add SinatraAdmin::App middleware to your admin application.
|
41
50
|
```ruby
|
42
51
|
class MyApp::Admin
|
43
52
|
use SinatraAdmin::App
|
44
53
|
end
|
45
54
|
```
|
46
55
|
|
47
|
-
|
56
|
+
4. Register model resources(let's assume that we have User and Comment
|
48
57
|
models). It creates the 7 REST actions to /create/update/remove
|
49
58
|
records.
|
50
59
|
```ruby
|
@@ -54,7 +63,7 @@ namespace. This is how SinatraAdmin should be configured:
|
|
54
63
|
end
|
55
64
|
```
|
56
65
|
|
57
|
-
|
66
|
+
5. Define your root resource(optional). This is going to be the first
|
58
67
|
page where the application is going to redirect you after the login.
|
59
68
|
SinatraAdmin defines the first registered resource as the default root.
|
60
69
|
In this case it will get 'User'(according to point number 3). If you
|
@@ -65,7 +74,7 @@ namespace. This is how SinatraAdmin should be configured:
|
|
65
74
|
end
|
66
75
|
```
|
67
76
|
|
68
|
-
|
77
|
+
6. Define your custom resources. Having model resources sometimes is not
|
69
78
|
enough and we might want to see some stats about our application. An
|
70
79
|
example could be: "As an admin I want to see how many user accounts has
|
71
80
|
been registered". Let's take a look at how to define custom resources.
|
@@ -89,7 +98,7 @@ namespace. This is how SinatraAdmin should be configured:
|
|
89
98
|
allows us to find the template that we are looking for. This takes us to
|
90
99
|
the next point.
|
91
100
|
|
92
|
-
|
101
|
+
7. Extend your views path(Only for custom resources). SinatraAdmin has
|
93
102
|
the method :extend_views_from. This method receives a value that
|
94
103
|
should either be a String instance with the path to views folder or
|
95
104
|
be a Sinatra application. SinatraAdmin expects to be mounted over an
|
@@ -102,7 +111,7 @@ namespace. This is how SinatraAdmin should be configured:
|
|
102
111
|
end
|
103
112
|
```
|
104
113
|
|
105
|
-
|
114
|
+
8. Wrapping it up.
|
106
115
|
```ruby
|
107
116
|
class MyApp::Admin < Sinatra::Base
|
108
117
|
use SinatraAmin::App
|
@@ -121,7 +130,7 @@ namespace. This is how SinatraAdmin should be configured:
|
|
121
130
|
end
|
122
131
|
```
|
123
132
|
|
124
|
-
|
133
|
+
9. Run it. We assume you're using a config.ru file to run your Sinatra
|
125
134
|
application. This is how it should look like:
|
126
135
|
```ruby
|
127
136
|
require 'path/to/my_app/api'
|
@@ -165,7 +174,7 @@ features but also writing documentation, adding issues, refactoring code
|
|
165
174
|
or just sending us either a <3 if you liked the project or a </3 if you
|
166
175
|
did not like it ;)
|
167
176
|
|
168
|
-
* Current version: 0.1.
|
177
|
+
* Current version: 0.1.1
|
169
178
|
|
170
179
|
## Contributing
|
171
180
|
|
@@ -3,7 +3,7 @@ module SinatraAdmin
|
|
3
3
|
class Base
|
4
4
|
class << self
|
5
5
|
def add(resource_constant, &block)
|
6
|
-
route = resource_constant.to_s.
|
6
|
+
route = resource_constant.to_s.split(/\s|\::/).join('_').underscore.pluralize
|
7
7
|
if SinatraAdmin.config.routes.include?(route)
|
8
8
|
raise RegistrationException, "The resource #{resource_constant.to_s} is already registered"
|
9
9
|
else
|
@@ -17,6 +17,11 @@ describe SinatraAdmin::Register::Model do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
context 'when resource has not been registered yet' do
|
20
|
+
it 'decode namespaced models correctly' do
|
21
|
+
described_class.add 'SinatraAdmin::Admin'
|
22
|
+
expect(SinatraAdmin.config.routes).to include('sinatra_admin_admins')
|
23
|
+
end
|
24
|
+
|
20
25
|
it 'adds route to config' do
|
21
26
|
described_class.add 'Tag'
|
22
27
|
expect(SinatraAdmin.config.routes).to include('tags')
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-admin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fco. Delgado
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-08-
|
13
|
+
date: 2014-08-14 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|