vue_on_rails 0.9.5 → 0.9.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 101e6dafb8b7e2ac7a5f4170b913ee26ff523453
4
- data.tar.gz: a451623e1205737a8d71283ea5ab153cb7c3c538
3
+ metadata.gz: 44cba178d9fcdee4a09bcb8e6969b510590fa589
4
+ data.tar.gz: d155a02addcf11b43bf9e540695b0d3bbdf7483d
5
5
  SHA512:
6
- metadata.gz: 4ec1d7709cfb2be51a5c3183b85ddb0cabb2e942440dafe8d3406db263b309a5135c0472748080233c51f0e1198e34027cde8e4e78673dc2793e02949e2263b9
7
- data.tar.gz: f66ecb179f33378e6526f89c7d5d30d3de1843b81c487c45e0a786e5d9c2284667303e2f021328a53c3df136b943f53c01b7d9d928b22c6295fc5f2493720243
6
+ metadata.gz: 5a0099fc74fb0918e829317f94c65abc04d7c7aac797d2f7d73b70a535fed81576e2862ba01e7a4bd8d7c3ebdab287eafbeea13856d48332fe68b54294b1017e
7
+ data.tar.gz: 1df3b0d77feb32ff16cbec3b32ae920ebf35c87c425acc1160c6bf5f0bb18535a69f78407f07b7395ca1a26d86845fa2f87d3c1c60b4d7630bcdf42ff46a7874
data/README.md CHANGED
@@ -1,8 +1,17 @@
1
1
  # VueOnRails
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/vue/on/rails`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Easy and simple way to use Vue.js with Ruby on Rails and Turbolinks 5.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ This gem is intended to sprinkle your Rails app with Vue components.
6
+ It's compatible with Turbolinks caching system.
7
+
8
+ If you are building a pure SPA app with Vue and Rails without Turbolinks, please look into:
9
+ https://github.com/adambutler/vuejs-rails
10
+
11
+ ## Requirements
12
+
13
+ - [Vue.js](https://vuejs.org/v2/guide/installation.html) >= 2.0
14
+ - [Turbolinks](https://github.com/turbolinks/turbolinks) >= 5.0
6
15
 
7
16
  ## Installation
8
17
 
@@ -20,19 +29,69 @@ Or install it yourself as:
20
29
 
21
30
  $ gem install vue_on_rails
22
31
 
32
+
23
33
  ## Usage
24
34
 
25
- TODO: Write usage instructions here
35
+ Require vue_on_rails in application.js
36
+ ```
37
+ //= require vue_on_rails
38
+ ```
39
+
40
+ Init and destroy Vue components:
41
+ ```
42
+ # Mount Vue components
43
+ document.addEventListener 'turbolinks:load', ->
44
+ VueOnRails.init()
45
+
46
+ # Destroy Vue components
47
+ document.addEventListener 'turbolinks:before-render', ->
48
+ VueOnRails.destroy()
49
+ ```
50
+
51
+ Example Vue component in my_component.coffee
52
+ ```
53
+ @MyComponent =
54
+ props: ['myProp']
55
+ template: '<div>A custom component with {{myProp}}</div>'
56
+ ```
57
+
58
+ Add component in view.html.erb
59
+ ```
60
+ <%= vue_component 'MyComponent', my_prop: 'awesome prop!' %>
61
+ <!-- This will output -->
62
+ <div data-vue-component="MyComponent" data-vue-props="{&quot;my-prop&quot;:&quot;awesome prop!&quot;}">
63
+ <div>A custom component with awesome prop!</div>
64
+ </div>
65
+ ```
66
+
67
+ ## View Helper
68
+ A view helper generate a div with component and props:
69
+ ```
70
+ def vue_component(component_name, props = {}, html_options = {})
71
+ ```
72
+ Example with html tag:
73
+ ```
74
+ <%= vue_component 'UserComponent', { user_id: 1 }, { class: 'd-inline-block align-middle' } %>
75
+ <!-- Becomes: -->
76
+ <div data-vue-component="UserComponent" data-vue-props="{'user-id': 1}" class="d-inline-block align-middle">
77
+ ...
78
+ </div>
79
+ ```
80
+
81
+ ## Props
26
82
 
27
- ## Development
83
+ ### Kebab-case (hyphen-delimited)
28
84
 
29
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
85
+ Props are automatically hyphen-delimited to follow vuejs and HTML5 standard.
30
86
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
87
+ ### Dynamic props
88
+ ```
89
+ <%= vue_component 'MessageComponent', ':my_message': 'hello world' %>
90
+ ```
32
91
 
33
92
  ## Contributing
34
93
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/vue-on-rails.
94
+ Bug reports and pull requests are welcome on GitHub at https://github.com/benoitontgit/vue-on-rails.
36
95
 
37
96
 
38
97
  ## License
@@ -1,3 +1,3 @@
1
1
  module VueOnRails
2
- VERSION = "0.9.5".freeze
2
+ VERSION = '0.9.6'
3
3
  end
@@ -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
+ })();
metadata CHANGED
@@ -1,63 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vue_on_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5
4
+ version: 0.9.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benoit Zeler
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-17 00:00:00.000000000 Z
11
+ date: 2017-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: coffee-rails
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '4.0'
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: '5.0'
23
- type: :runtime
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- version: '4.0'
30
- - - "<"
31
- - !ruby/object:Gem::Version
32
- version: '5.0'
33
13
  - !ruby/object:Gem::Dependency
34
14
  name: bundler
35
15
  requirement: !ruby/object:Gem::Requirement
36
16
  requirements:
37
- - - "~>"
17
+ - - "<"
38
18
  - !ruby/object:Gem::Version
39
- version: '1.13'
19
+ version: '2.0'
40
20
  type: :development
41
21
  prerelease: false
42
22
  version_requirements: !ruby/object:Gem::Requirement
43
23
  requirements:
44
- - - "~>"
24
+ - - "<"
45
25
  - !ruby/object:Gem::Version
46
- version: '1.13'
26
+ version: '2.0'
47
27
  - !ruby/object:Gem::Dependency
48
28
  name: rake
49
29
  requirement: !ruby/object:Gem::Requirement
50
30
  requirements:
51
- - - "~>"
31
+ - - "<="
52
32
  - !ruby/object:Gem::Version
53
- version: '10.0'
33
+ version: '13.0'
54
34
  type: :development
55
35
  prerelease: false
56
36
  version_requirements: !ruby/object:Gem::Requirement
57
37
  requirements:
58
- - - "~>"
38
+ - - "<="
59
39
  - !ruby/object:Gem::Version
60
- version: '10.0'
40
+ version: '13.0'
61
41
  - !ruby/object:Gem::Dependency
62
42
  name: rails
63
43
  requirement: !ruby/object:Gem::Requirement
@@ -65,9 +45,9 @@ dependencies:
65
45
  - - ">="
66
46
  - !ruby/object:Gem::Version
67
47
  version: '4.0'
68
- - - "<="
48
+ - - "<"
69
49
  - !ruby/object:Gem::Version
70
- version: '5.2'
50
+ version: '6'
71
51
  type: :development
72
52
  prerelease: false
73
53
  version_requirements: !ruby/object:Gem::Requirement
@@ -75,9 +55,9 @@ dependencies:
75
55
  - - ">="
76
56
  - !ruby/object:Gem::Version
77
57
  version: '4.0'
78
- - - "<="
58
+ - - "<"
79
59
  - !ruby/object:Gem::Version
80
- version: '5.2'
60
+ version: '6'
81
61
  description: Ideal to sprinkle your app with Vue components
82
62
  email: benoit@kimkim.com
83
63
  executables: []
@@ -91,8 +71,8 @@ files:
91
71
  - lib/vue_on_rails/railtie.rb
92
72
  - lib/vue_on_rails/version.rb
93
73
  - lib/vue_on_rails/view_helper.rb
94
- - vendor/assets/javascripts/vue_on_rails.js.coffee
95
- homepage: https://github.com/benoitongit
74
+ - vendor/assets/javascripts/vue_on_rails.js
75
+ homepage: https://github.com/benoitongit/vue-on-rails
96
76
  licenses:
97
77
  - MIT
98
78
  metadata:
@@ -116,5 +96,5 @@ rubyforge_project:
116
96
  rubygems_version: 2.6.11
117
97
  signing_key:
118
98
  specification_version: 4
119
- summary: Easy way to use Vue.js with Ruby on Rails and Turbolinks 5.
99
+ summary: Easy and simple way to use Vue.js with Ruby on Rails and Turbolinks 5.
120
100
  test_files: []
@@ -1,49 +0,0 @@
1
- @VueOnRails = do ->
2
- vueModels = []
3
- namespace = null
4
-
5
- init = ->
6
- vueModels = []
7
- namespace = VueOnRails.namespace
8
- vueComponents = document.querySelectorAll('[data-vue-component]')
9
- return if vueComponents.length <= 0
10
- for i in [0...vueComponents.length]
11
- mountComponent(vueComponents[i])
12
-
13
- mountComponent = (component) ->
14
- name = component.getAttribute('data-vue-component')
15
- props = JSON.parse(component.getAttribute('data-vue-props'))
16
- if (namespace && typeof window[namespace][name] == 'object') || window[name] == 'object'
17
- el = document.createElement('element-to-be-mounted')
18
- component.innerHTML = ''
19
- component.appendChild(el)
20
- vm = newVueInstance(name, props, el)
21
- vueModels.push(vm)
22
-
23
- newVueInstance = (name, props, el) ->
24
- nameFormatted = camelCaseToHyphen(name)
25
- element = document.createElement(nameFormatted)
26
- setElementProps(element, props)
27
- component = if namespace then window[namespace][name] else window[name]
28
- new Vue({
29
- el: el
30
- template: element.outerHTML
31
- components: { "#{nameFormatted}": component }
32
- })
33
-
34
- setElementProps = (element, props) ->
35
- for key, value of props
36
- if typeof value == 'object'
37
- element.setAttribute(key, JSON.stringify(value))
38
- else
39
- element.setAttribute(key, value)
40
-
41
- camelCaseToHyphen = (string) ->
42
- string.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase()
43
-
44
- destroy = ->
45
- for vm in vueModels
46
- vm.$destroy()
47
- vueModels = []
48
-
49
- { init, destroy }