locomotive_plugins 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NGY3MDQyNWJhN2VkZGM3ZjU5MGNjNzhhMmYxZGQzMzRlNTIyMjdhNA==
4
+ MWY0YzE2YWNmMjMzMGQxOTZmNjQzMWY5MWI1ZDhiNzAxNWY5OTczZQ==
5
5
  data.tar.gz: !binary |-
6
- MmJmMGYzMmNhNWM5ZDlhZDg0MzJiYzE0OWE4OTdhYzYyZDNlYTY0Mw==
6
+ YmE3OGQ3NjliNTVkN2JmYzU1OTc2MGNhZmUxM2UyNGM5NDIxZDljZg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MDAxZDdlODc5ZjEwZmQxYTdjZWZkYTg2ZWEzZTcwZGUzODRkZGFiNTI2MGNm
10
- ZDFmM2UyZDAxNzkxZjczNDY5ZDQzNTk0ZDkzZGUwZmIxYWU5ZTQ2ZGQ5NDIw
11
- OGM4OGM3MDQ5NGQwMDkwMzA1MDE1ZjI3Nzk4ZDcyOWRjYzM2NmE=
9
+ NDdmNjhmZTljM2VkODExMDkzZTllNWFmNTZkZmM2YTQyNjkyYjg2ZTQxNGFl
10
+ NTFlZjE2MzJmZjc3NTk0ZjQ1ZDk4YzNhNTA0NDFiMWFmODU1NDZlMjJiZjk5
11
+ MDViNTgyNDE1ZjIzNjE2YjVmMWFkNjYyNGVmMjdmYzY2YTMwOWI=
12
12
  data.tar.gz: !binary |-
13
- YzNiZjdkM2MwYWZmNzllN2FjZjZkNzkxN2E2NTQ3OTcxY2RjYzNmNzFiOTAx
14
- MDU4MmMwMTdiMDk3YmY1YWY3ZjQ3NWI2N2NmMzAyZDU1NzZiMDhlMjc0MjZk
15
- M2ZmODdkZDhlYTg5MDRkMzYzYzg4OGY2Y2ExZGQ5ZTI5NjY3MWQ=
13
+ MWE3MzlmNTg5MWU4NDY5Mzk3ZjI5M2ZiYTg1OWIwY2QzZWU5NDU1OTk1ZWU4
14
+ ZDk2OWIyNTJhMWI3OGFjZjNhYTg2OWRkYjY4ZjgyYjEwYTUyZmY3OWZmYTMw
15
+ ZjYzZTIzMGVkMjAwOWY4OTIxY2YzODE1YWQzMGM1Y2U3ZTY4ZDU=
@@ -15,6 +15,7 @@ module Locomotive
15
15
  include LoadInitialization
16
16
  include Liquid
17
17
  include RackAppHelpers
18
+ include JS3
18
19
 
19
20
  # @private
20
21
  #
@@ -95,7 +96,29 @@ module Locomotive
95
96
  nil
96
97
  end
97
98
 
98
- end
99
+ # Override this method to specify ruby objects accessable via the global
100
+ # javascript context. The return value must be a hash whoes keys are the
101
+ # variable names and the values are the objects. The objects will be
102
+ # included in the global context after being prefixed with the plugin_id.
103
+ #
104
+ # Note:
105
+ # therubyracer is not able to execute class methods so please ensure
106
+ # that the objects you pass in are not classes.
107
+ #
108
+ # @exaple
109
+ # class MyPlugin
110
+ # def self.javascript_context
111
+ # {
112
+ # :things => ::Locomotive::Plugins::Variable.new {Thing.all},
113
+ # :say => lambda{|this,word,times| word * times}
114
+ # }
115
+ # end
116
+ # end
117
+ def javascript_context
118
+ {}
119
+ end
120
+
121
+ end ## class
99
122
 
100
123
  # This variable is set by LocomotiveCMS. It contains the controller which
101
124
  # is handling the current request.
@@ -0,0 +1,15 @@
1
+ module Locomotive
2
+ module Plugin
3
+ # This module add helpers for using js3 (JavaScript on the Server Side)
4
+ module JS3
5
+
6
+ # The js3 context
7
+ #
8
+ # @return a V8 context object
9
+ def js3_context
10
+ Locomotive::Plugins.js3_context
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module LocomotivePlugins
2
- VERSION = '1.0.1'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -42,5 +42,13 @@ module Locomotive
42
42
  PluginWithRackApp.rack_app.should_not be_nil
43
43
  end
44
44
 
45
+ it 'should optionally supply a js3 context' do
46
+ MyPlugin.javascript_context.keys.should == [:variable, :method]
47
+ UselessPlugin.javascript_context.should == {}
48
+ end
49
+
50
+ it 'should be able to get a js3 context' do
51
+ @plugin.respond_to?(:js3_context).should be true
52
+ end
45
53
  end
46
54
  end
@@ -48,6 +48,13 @@ module Locomotive
48
48
  { 'my_tag' => MyTag }
49
49
  end
50
50
 
51
+ def self.javascript_context
52
+ {
53
+ variable: self.custom_attribute,
54
+ method: lambda{|this,word,times| word * times }
55
+ }
56
+ end
57
+
51
58
  def my_method1
52
59
  'This is my before filter!'
53
60
  end
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.0.1
4
+ version: 1.1.0
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-07-23 00:00:00.000000000 Z
11
+ date: 2014-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: locomotive_liquid
@@ -108,6 +108,7 @@ files:
108
108
  - lib/locomotive/plugin/class_tracker.rb
109
109
  - lib/locomotive/plugin/config_ui.rb
110
110
  - lib/locomotive/plugin/exceptions.rb
111
+ - lib/locomotive/plugin/js3.rb
111
112
  - lib/locomotive/plugin/liquid.rb
112
113
  - lib/locomotive/plugin/liquid/context_helpers.rb
113
114
  - lib/locomotive/plugin/liquid/drop_extension.rb