vue_on_rails 0.9.8 → 0.9.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.md +20 -10
- data/lib/vue_on_rails/version.rb +1 -1
- data/vendor/assets/javascripts/vue_on_rails.js +13 -14
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e32e28e0ffa7888d7a1c1342b064cd13de676775e2849098b62124080c887475
|
4
|
+
data.tar.gz: 0f176aec50292a8e48c297fb8215e972318cb6d886f98955a93a922b1c3c6852
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 756e0fca42a67324ee39e028f41a0705fc24a6d68af61d794b1d4fce4682feebdbba3e33c09cdf9c3a3c4c24a20aaa7843a464bf030d272d04d1827b2d6fbe86
|
7
|
+
data.tar.gz: 70c4189628d048f61192c0a18a75fc9d5faacb697305fdf80ab0704ba1ff170729d3514313752a2b8f034f223165c9d2a5d5831f33944a3cfd43df3991ca20af
|
data/README.md
CHANGED
@@ -1,8 +1,14 @@
|
|
1
1
|
# VueOnRails
|
2
2
|
|
3
|
-
|
3
|
+
Simple and fast way to use Vue.js with Ruby on Rails and Turbolinks 5.
|
4
4
|
|
5
|
-
This gem is
|
5
|
+
This gem is fantastic to sprinkle your web page with Vue components. Lightweight script (1KB minified) that mounts and destroys Vue components on demand.
|
6
|
+
|
7
|
+
It works nicely with:
|
8
|
+
- Turbolinks rendering and caching system
|
9
|
+
- Javascript loaded asynchronously with defer or async script attribute
|
10
|
+
|
11
|
+
It's fully Google PageSpeed friendly since you can use it with defer or async, no need for render-blocking JavaScript :)
|
6
12
|
|
7
13
|
If you are building a pure SPA app with Vue and Rails without Turbolinks, you will be better off looking into:
|
8
14
|
https://github.com/adambutler/vuejs-rails
|
@@ -39,19 +45,23 @@ Require vue_on_rails in application.js
|
|
39
45
|
Mount and destroy Vue components:
|
40
46
|
```
|
41
47
|
# Mount Vue components
|
42
|
-
document.addEventListener
|
43
|
-
VueOnRails.mountComponents()
|
48
|
+
document.addEventListener('turbolinks:load', function() {
|
49
|
+
VueOnRails.mountComponents();
|
50
|
+
});
|
44
51
|
|
45
52
|
# Destroy Vue components
|
46
|
-
document.addEventListener
|
47
|
-
VueOnRails.destroyComponents()
|
53
|
+
document.addEventListener('turbolinks:before-render', function() {
|
54
|
+
VueOnRails.destroyComponents();
|
55
|
+
});
|
48
56
|
```
|
57
|
+
VueOnRails.mountComponents() will scan the page and mount components using data-vue-component and data-vue-props.
|
49
58
|
|
50
|
-
Example Vue component in my_component.
|
59
|
+
Example Vue component in my_component.js
|
51
60
|
```
|
52
|
-
|
53
|
-
props: ['myProp']
|
61
|
+
MyComponent = {
|
62
|
+
props: ['myProp'],
|
54
63
|
template: '<div>A custom component with {{myProp}}</div>'
|
64
|
+
};
|
55
65
|
```
|
56
66
|
|
57
67
|
Add component in view.html.erb
|
@@ -85,7 +95,7 @@ Props are automatically hyphen-delimited to follow vuejs and HTML5 standard.
|
|
85
95
|
|
86
96
|
### Dynamic props
|
87
97
|
```
|
88
|
-
<%= vue_component 'MessageComponent', ':
|
98
|
+
<%= vue_component 'MessageComponent', ':my_object': { title: 'Test', subtitle: 'Sweet!' } %>
|
89
99
|
```
|
90
100
|
|
91
101
|
## Contributing
|
data/lib/vue_on_rails/version.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
this.VueOnRails = (function() {
|
2
|
-
var camelCaseToHyphen, destroyComponents, mountComponent, mountComponents, newVueInstance, setElementProps;
|
3
2
|
var vueModels = [];
|
4
3
|
var namespace = null;
|
5
4
|
|
6
|
-
mountComponents = function() {
|
5
|
+
var mountComponents = function() {
|
7
6
|
vueModels = [];
|
8
7
|
namespace = VueOnRails.namespace;
|
9
8
|
var vueComponents = document.querySelectorAll('[data-vue-component]');
|
@@ -17,7 +16,7 @@ this.VueOnRails = (function() {
|
|
17
16
|
return results;
|
18
17
|
};
|
19
18
|
|
20
|
-
mountComponent = function(component) {
|
19
|
+
var mountComponent = function(component) {
|
21
20
|
var name = component.getAttribute('data-vue-component');
|
22
21
|
var props = JSON.parse(component.getAttribute('data-vue-props'));
|
23
22
|
if ((namespace && typeof window[namespace][name] === 'object') || window[name] === 'object') {
|
@@ -26,7 +25,7 @@ this.VueOnRails = (function() {
|
|
26
25
|
}
|
27
26
|
};
|
28
27
|
|
29
|
-
newVueInstance = function(name, props, component) {
|
28
|
+
var newVueInstance = function(name, props, component) {
|
30
29
|
var componentObj = {};
|
31
30
|
var nameFormatted = camelCaseToHyphen(name);
|
32
31
|
var element = document.createElement(nameFormatted);
|
@@ -41,9 +40,9 @@ this.VueOnRails = (function() {
|
|
41
40
|
});
|
42
41
|
};
|
43
42
|
|
44
|
-
setElementProps = function(element, props) {
|
45
|
-
var key,
|
46
|
-
results = [];
|
43
|
+
var setElementProps = function(element, props) {
|
44
|
+
var key, value;
|
45
|
+
var results = [];
|
47
46
|
for (key in props) {
|
48
47
|
value = props[key];
|
49
48
|
if (typeof value === 'object') {
|
@@ -55,20 +54,20 @@ this.VueOnRails = (function() {
|
|
55
54
|
return results;
|
56
55
|
};
|
57
56
|
|
58
|
-
camelCaseToHyphen = function(string) {
|
57
|
+
var camelCaseToHyphen = function(string) {
|
59
58
|
return string.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
60
59
|
};
|
61
60
|
|
62
|
-
destroyComponents = function() {
|
63
|
-
var
|
64
|
-
for (
|
65
|
-
|
66
|
-
vm.$destroy();
|
61
|
+
var destroyComponents = function() {
|
62
|
+
var i;
|
63
|
+
for (i = 0; i < vueModels.length; i++) {
|
64
|
+
vueModels[i].$destroy();
|
67
65
|
}
|
68
|
-
|
66
|
+
vueModels = [];
|
69
67
|
};
|
70
68
|
|
71
69
|
return {
|
70
|
+
mountComponent: mountComponent,
|
72
71
|
mountComponents: mountComponents,
|
73
72
|
destroyComponents: destroyComponents
|
74
73
|
};
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vue_on_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benoit Zeler
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -47,7 +47,7 @@ dependencies:
|
|
47
47
|
version: '4.0'
|
48
48
|
- - "<"
|
49
49
|
- !ruby/object:Gem::Version
|
50
|
-
version: '
|
50
|
+
version: '7'
|
51
51
|
type: :development
|
52
52
|
prerelease: false
|
53
53
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -57,7 +57,7 @@ dependencies:
|
|
57
57
|
version: '4.0'
|
58
58
|
- - "<"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: '
|
60
|
+
version: '7'
|
61
61
|
description: Ideal to sprinkle your app with Vue components
|
62
62
|
email: benoit@kimkim.com
|
63
63
|
executables: []
|
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
93
|
version: '0'
|
94
94
|
requirements: []
|
95
95
|
rubyforge_project:
|
96
|
-
rubygems_version: 2.6
|
96
|
+
rubygems_version: 2.7.6
|
97
97
|
signing_key:
|
98
98
|
specification_version: 4
|
99
99
|
summary: Easy and simple way to mount/destroy Vue.js components with Ruby on Rails
|