locomotive_plugins 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +60 -8
- data/lib/locomotive/plugin.rb +1 -0
- data/lib/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YWQ1NjFhMTAyN2JmZjUyZjZmYzgzM2UxMzkwMzQxYjI1ZmQ2NDNlNw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YzhhYzllOTQzMWZjYWVhNDVmZmU2ZGU4YTAxNTQ4ZjFkY2UxNDRhZg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ODM5ZTI0MGYzODEwZTgyYjVmMTU1YTFiOTIxN2UxMGFhYTgzNmJkMGY2ZWJm
|
10
|
+
NDE0ODU4ZDQ1ZmNmMDczNjY1MDAyMGE3ZjVhMDE1ZDMwNmI4Yzg4NjA0NDM1
|
11
|
+
NmNmZmM0Y2MzM2UzNjNmODk3YmE1MzYxOWVhZTYxMTMwNmIyMDE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZTBkNWNmOWJiZTBmMzEyMGZhMWRmZGUyZGMwODBmYmViZWNmNTM4NDczMWQ1
|
14
|
+
NzBhZmUwN2QzMzMwODZlN2EyYTIzYzY1NzY5YTc2MjYzOWM5ZDEzNDI4NTM0
|
15
|
+
ODk0ZGJlYWFmYjVkODA3MGYwZjIwMjczODEwYzExYTJkMmJiMzU=
|
data/README.md
CHANGED
@@ -272,10 +272,11 @@ checked, the config hash will be as follows:
|
|
272
272
|
|
273
273
|
Plugins can persist data in Locomotive's database through the use of Database
|
274
274
|
Models. A Database Model is simply a Mongoid document which is managed by
|
275
|
-
Locomotive CMS.
|
275
|
+
Locomotive CMS. To allow your model to be managed by Locomotive CMS you must
|
276
|
+
use Locomotive::Plugins::Document instead of Mongoid::Document. For example:
|
276
277
|
|
277
278
|
class VisitCount
|
278
|
-
include
|
279
|
+
include Locomotive::Plugins::Document
|
279
280
|
field :count, default: 0
|
280
281
|
end
|
281
282
|
|
@@ -296,12 +297,63 @@ Locomotive CMS. For example:
|
|
296
297
|
end
|
297
298
|
end
|
298
299
|
|
299
|
-
Note that the plugin databases
|
300
|
-
In other words, if a plugin is
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
300
|
+
Note that the plugin databases that use the Locomtive::Plugins::Document are
|
301
|
+
isolated between Locomotive site instances. In other words, if a plugin is
|
302
|
+
enabled on two sites, A and B, and a request comes in to site A which causes
|
303
|
+
a Mongoid Document to be saved to the database, this document will not be
|
304
|
+
accessible to the plugin when a request comes in to site B. Thus plugin
|
305
|
+
database models should be developed in the context of a single site, since
|
306
|
+
each site will have its own database. If you require a database model the is
|
307
|
+
avaiable to all sites then you can do so by using a regualar Mongoid::Document.
|
308
|
+
|
309
|
+
### JS3 (JavaScript on the Server Side)
|
310
|
+
|
311
|
+
JS3 was developed to provide a secure way to allow inter-plugin communication.
|
312
|
+
It allows a plugin developer to provide methods and variables to any other
|
313
|
+
plugin contained in a sandbox. For instance if you have a plugin A that
|
314
|
+
provides user accounts and a plugin B the restricts access to a configured path
|
315
|
+
then you may want to be able to access the accounts on plugin A from plugin B.
|
316
|
+
To do this you would have to do the following.
|
317
|
+
|
318
|
+
Plugin A: allow plugins to access users.
|
319
|
+
|
320
|
+
In the plugin definition add the following:
|
321
|
+
|
322
|
+
def self.javascript_context
|
323
|
+
{
|
324
|
+
users: Locomotive::Plugins::Variable.new { Users.all }
|
325
|
+
}
|
326
|
+
end
|
327
|
+
|
328
|
+
Plugin B:
|
329
|
+
|
330
|
+
You have a few options here. You can access the users from ruby by doing the
|
331
|
+
following:
|
332
|
+
|
333
|
+
plugin_object.js3_context['plugin_a_users']
|
334
|
+
|
335
|
+
This will return a mongoid criteria the you can do what you want with. If you
|
336
|
+
want the restrictions to be variable by site the you could add a javascript
|
337
|
+
block to the config and then run that javascript code on the js3 context.
|
338
|
+
|
339
|
+
plugin_object.js3_context.eval(config['javascript_block'])
|
340
|
+
|
341
|
+
You can also add other methods or variable to the context that you want only
|
342
|
+
your plugin to have access to, each time you call js3_context you will get a
|
343
|
+
new object. To find out more take a look at the gem
|
344
|
+
['therubyracer'](https://github.com/cowboyd/therubyracer).
|
345
|
+
|
346
|
+
Locomotive CMS also adds two helper methods to the context to help with doing
|
347
|
+
simple database queries. The two methods are as follows:
|
348
|
+
|
349
|
+
* mongoid_where(criteria, key, value) - criteria is a mongoid criteria, key
|
350
|
+
the the field name, and value is the query value. This method will run a
|
351
|
+
where query on the given field with the given value and return a mongoid
|
352
|
+
criteria.
|
353
|
+
* mongoid_in(criteria, key, value) - criteria is a mongoid criteria, key
|
354
|
+
the the field name, and value is the query value. This method will run a
|
355
|
+
in query on the given field with the given value and return a mongoid
|
356
|
+
criteria.
|
305
357
|
|
306
358
|
### Rack App
|
307
359
|
|
data/lib/locomotive/plugin.rb
CHANGED
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: locomotive_plugins
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Colibri Software
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: locomotive_liquid
|