styxie 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/app/assets/javascripts/styxie.js.coffee +0 -19
- data/lib/styxie/initializer.rb +13 -9
- data/lib/styxie/version.rb +1 -1
- data/spec/lib/styxie_initializer_spec.rb +1 -0
- 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: d6544120d5ab6bae640de6ea3daa9c084aca872d
|
4
|
+
data.tar.gz: b2dc50ecec73907c0b77e01dcb5c1e40ac69da4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef3ce1b35d08cc70bca59dba9a89147bcf1ce53c8b24073b4f5a832a552de55c3c24ef04a988d6117ee969240737cb074061367a190ad141e2444a6a210a7e5f
|
7
|
+
data.tar.gz: cc17cab622ae5ccd74ff07853770f5e639d9880895a7ccad7d586fdbfa5717706996b9a3ce20fa8b5a8ef67ba981ba81b4291b57f8cc21155b7f435908a93b2c
|
data/README.md
CHANGED
@@ -21,6 +21,7 @@ In your assets application.js include appropriate libs:
|
|
21
21
|
# app/controllers/foos_controller.rb
|
22
22
|
class FoosController < ApplicationController
|
23
23
|
include Styxie::Initializer
|
24
|
+
helper_method :styxie_initialize # in case of Rails
|
24
25
|
end
|
25
26
|
```
|
26
27
|
|
@@ -33,7 +34,7 @@ In common each controller in Rails comes with *app/assets/javascripts/controller
|
|
33
34
|
**Styxie.Initializer** allows you to define bootstrap logic for each Rails action separately and
|
34
35
|
pass some data from server right into it.
|
35
36
|
|
36
|
-
To enable initializers bootstrap, add *
|
37
|
+
To enable initializers bootstrap, add *styxie_initialize* call into your layout:
|
37
38
|
|
38
39
|
```erb
|
39
40
|
<head>
|
@@ -1,22 +1,3 @@
|
|
1
1
|
@Styxie = {
|
2
2
|
Initializers: {}
|
3
3
|
}
|
4
|
-
|
5
|
-
@Styxie.URL =
|
6
|
-
go: (url, force=false) ->
|
7
|
-
# 'Force' required if you want to reload same page with another anchor
|
8
|
-
url = this.build(url, "reloadthispagepls=#{Math.random()}") if force
|
9
|
-
window.location.href = url
|
10
|
-
|
11
|
-
build: (url, params) ->
|
12
|
-
hash = url.match(/\#.*$/)
|
13
|
-
hash = if hash then hash[0] else false
|
14
|
-
|
15
|
-
url = url.replace(hash, '') if hash
|
16
|
-
url = url + "?" if url.indexOf("?") == -1
|
17
|
-
|
18
|
-
url = "#{url}&#{params}"
|
19
|
-
|
20
|
-
url = url + hash if hash
|
21
|
-
|
22
|
-
return url
|
data/lib/styxie/initializer.rb
CHANGED
@@ -5,19 +5,23 @@ module Styxie
|
|
5
5
|
cfg.merge! data
|
6
6
|
end
|
7
7
|
|
8
|
-
def styxie_initialize(klass: styxie_class, method: action_name, data: styxie_configuration)
|
8
|
+
def styxie_initialize(klass: styxie_class, method: action_name, data: styxie_configuration, autorun: true)
|
9
9
|
json = data.to_json
|
10
|
+
init_call = autorun ? 'initStyxie();' : ''
|
10
11
|
result = <<-CODE
|
11
12
|
<script type="text/javascript">
|
12
13
|
//<![CDATA[
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
14
|
+
function initStyxie() {
|
15
|
+
if (Styxie.Initializers.#{klass} && Styxie.Initializers.#{klass}.initialize)
|
16
|
+
{
|
17
|
+
Styxie.Initializers.#{klass}.initialize(#{json});
|
18
|
+
}
|
19
|
+
if (Styxie.Initializers.#{klass} && Styxie.Initializers.#{klass}['#{method}'])
|
20
|
+
{
|
21
|
+
Styxie.Initializers.#{klass}['#{method}'](#{json});
|
22
|
+
}
|
23
|
+
};
|
24
|
+
#{init_call}
|
21
25
|
//]]>
|
22
26
|
</script>
|
23
27
|
CODE
|
data/lib/styxie/version.rb
CHANGED
@@ -22,6 +22,7 @@ describe Styxie::Initializer do
|
|
22
22
|
controller.stub(action_name: 'index')
|
23
23
|
result = controller.styxie_initialize
|
24
24
|
expect(result).to include "Styxie.Initializers.ModuleTests['index']({});"
|
25
|
+
expect(result).to include "initStyxie();"
|
25
26
|
expect(result.html_safe?).to be_truthy
|
26
27
|
end
|
27
28
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: styxie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yury Kotov
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-10-20 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Set of helpers to maintain bridge between Server side and Client (JS)
|
15
15
|
side
|