Skip to content

Commit d3178dc

Browse files
committed
Remove dependency on coffee-rails
1 parent dbf2bdb commit d3178dc

File tree

5 files changed

+87
-57
lines changed

5 files changed

+87
-57
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Easy and simple way to use Vue.js with Ruby on Rails and Turbolinks 5.
44

5-
This gem was made to sprinkle your Rails app with Vue components.
5+
This gem is intended to sprinkle your Rails app with Vue components.
66
It's compatible with Turbolinks caching system.
77

88
If you are building a pure SPA app with Vue and Rails without Turbolinks, please look into:

lib/vue_on_rails/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module VueOnRails
2-
VERSION = "0.9.5".freeze
2+
VERSION = '0.9.6'
33
end
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
this.VueOnRails = (function() {
2+
var camelCaseToHyphen, destroyComponents, mountComponent, mountComponents, newVueInstance, setElementProps;
3+
var vueModels = [];
4+
var namespace = null;
5+
6+
mountComponents = function() {
7+
vueModels = [];
8+
namespace = VueOnRails.namespace;
9+
var vueComponents = document.querySelectorAll('[data-vue-component]');
10+
if (vueComponents.length <= 0) {
11+
return;
12+
}
13+
var results = [];
14+
for (var i = 0; i < vueComponents.length; i++) {
15+
results.push(mountComponent(vueComponents[i]));
16+
}
17+
return results;
18+
};
19+
20+
mountComponent = function(component) {
21+
var el, name, props, vm;
22+
name = component.getAttribute('data-vue-component');
23+
props = JSON.parse(component.getAttribute('data-vue-props'));
24+
if ((namespace && typeof window[namespace][name] === 'object') || window[name] === 'object') {
25+
el = document.createElement('element-to-be-mounted');
26+
component.innerHTML = '';
27+
component.appendChild(el);
28+
vm = newVueInstance(name, props, el);
29+
return vueModels.push(vm);
30+
}
31+
};
32+
33+
newVueInstance = function(name, props, el) {
34+
var component, element, nameFormatted, obj;
35+
nameFormatted = camelCaseToHyphen(name);
36+
element = document.createElement(nameFormatted);
37+
setElementProps(element, props);
38+
component = namespace ? window[namespace][name] : window[name];
39+
return new Vue({
40+
el: el,
41+
template: element.outerHTML,
42+
components: (
43+
obj = {},
44+
obj["" + nameFormatted] = component,
45+
obj
46+
)
47+
});
48+
};
49+
50+
setElementProps = function(element, props) {
51+
var key, results, value;
52+
results = [];
53+
for (key in props) {
54+
value = props[key];
55+
if (typeof value === 'object') {
56+
results.push(element.setAttribute(key, JSON.stringify(value)));
57+
} else {
58+
results.push(element.setAttribute(key, value));
59+
}
60+
}
61+
return results;
62+
};
63+
64+
camelCaseToHyphen = function(string) {
65+
return string.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
66+
};
67+
68+
destroyComponents = function() {
69+
var j, len, vm;
70+
for (j = 0, len = vueModels.length; j < len; j++) {
71+
vm = vueModels[j];
72+
vm.$destroy();
73+
}
74+
return vueModels = [];
75+
};
76+
77+
return {
78+
mountComponents: mountComponents,
79+
destroyComponents: destroyComponents
80+
};
81+
})();

vendor/assets/javascripts/vue_on_rails.js.coffee

Lines changed: 0 additions & 49 deletions
This file was deleted.

vue_on_rails.gemspec

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
99
spec.authors = ["Benoit Zeler"]
1010
spec.email = "[email protected]"
1111

12-
spec.summary = %q{Easy and simple way to use Vue.js with Ruby on Rails and Turbolinks 5.}
12+
spec.summary = %q{Easy and simple way to mount/destroy Vue.js components with Ruby on Rails and Turbolinks 5.}
1313
spec.description = %q{Ideal to sprinkle your app with Vue components}
1414
spec.homepage = "https://github.com/benoitongit/vue-on-rails"
1515
spec.license = "MIT"
@@ -27,9 +27,7 @@ Gem::Specification.new do |spec|
2727
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
2828
spec.require_paths = ["lib"]
2929

30-
spec.add_dependency "coffee-rails", ">= 4.0", "< 5.0"
31-
32-
spec.add_development_dependency "bundler", "~> 1.13"
33-
spec.add_development_dependency "rake", "~> 10.0"
34-
spec.add_development_dependency "rails", ">= 4.0", "<= 5.2"
30+
spec.add_development_dependency "bundler", "< 2.0"
31+
spec.add_development_dependency "rake", "<= 13.0"
32+
spec.add_development_dependency "rails", ">= 4.0", "< 6"
3533
end

0 commit comments

Comments
 (0)