vue_on_rails 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 101e6dafb8b7e2ac7a5f4170b913ee26ff523453
4
+ data.tar.gz: a451623e1205737a8d71283ea5ab153cb7c3c538
5
+ SHA512:
6
+ metadata.gz: 4ec1d7709cfb2be51a5c3183b85ddb0cabb2e942440dafe8d3406db263b309a5135c0472748080233c51f0e1198e34027cde8e4e78673dc2793e02949e2263b9
7
+ data.tar.gz: f66ecb179f33378e6526f89c7d5d30d3de1843b81c487c45e0a786e5d9c2284667303e2f021328a53c3df136b943f53c01b7d9d928b22c6295fc5f2493720243
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Benoit Zeler
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # VueOnRails
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.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'vue_on_rails'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install vue_on_rails
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
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.
30
+
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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/vue-on-rails.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
@@ -0,0 +1,10 @@
1
+ require "rails"
2
+ require "vue_on_rails/version"
3
+
4
+ module VueOnRails
5
+ if defined?(::Rails) and Gem::Requirement.new('>= 4.0').satisfied_by?(Gem::Version.new ::Rails.version)
6
+ require 'vue_on_rails/engine'
7
+ require 'vue_on_rails/view_helper'
8
+ require 'vue_on_rails/railtie'
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module VueOnRails
2
+ class Engine < ::Rails::Engine; end
3
+ end
@@ -0,0 +1,7 @@
1
+ module VueOnRails
2
+ class Railtie < Rails::Railtie
3
+ ActiveSupport.on_load(:action_view) do
4
+ include ::VueOnRails::ViewHelper
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module VueOnRails
2
+ VERSION = "0.9.5".freeze
3
+ end
@@ -0,0 +1,39 @@
1
+ module VueOnRails
2
+ module ViewHelper
3
+ def vue_component(component_name, props = {}, html_options = {})
4
+ html_options = html_options.reverse_merge(data: {})
5
+ props = VueOnRails::ViewHelper.format_props(props)
6
+ html_options[:data].tap do |data|
7
+ data[:vue_component] = component_name
8
+ data[:vue_props] = props.to_json
9
+ end
10
+ html_tag = html_options[:tag] || :div
11
+ html_options.except!(:tag)
12
+ content_tag(html_tag, '', html_options)
13
+ end
14
+
15
+ def self.format_props(props)
16
+ case props
17
+ when Hash
18
+ props.each_with_object({}) do |(key, value), new_props|
19
+ new_key = key.to_s.dasherize
20
+ new_props[new_key] = VueOnRails::ViewHelper.camelize_props(value)
21
+ end
22
+ else
23
+ props
24
+ end
25
+ end
26
+
27
+ def self.camelize_props(props)
28
+ case props
29
+ when Hash
30
+ props.each_with_object({}) do |(key, value), new_props|
31
+ new_key = key.to_s.camelize(:lower)
32
+ new_props[new_key] = VueOnRails::ViewHelper.camelize_props(value)
33
+ end
34
+ else
35
+ props
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,49 @@
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 }
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vue_on_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.5
5
+ platform: ruby
6
+ authors:
7
+ - Benoit Zeler
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-04-17 00:00:00.000000000 Z
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
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.13'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.13'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '10.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '10.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rails
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '4.0'
68
+ - - "<="
69
+ - !ruby/object:Gem::Version
70
+ version: '5.2'
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '4.0'
78
+ - - "<="
79
+ - !ruby/object:Gem::Version
80
+ version: '5.2'
81
+ description: Ideal to sprinkle your app with Vue components
82
+ email: benoit@kimkim.com
83
+ executables: []
84
+ extensions: []
85
+ extra_rdoc_files: []
86
+ files:
87
+ - LICENSE.txt
88
+ - README.md
89
+ - lib/vue_on_rails.rb
90
+ - lib/vue_on_rails/engine.rb
91
+ - lib/vue_on_rails/railtie.rb
92
+ - lib/vue_on_rails/version.rb
93
+ - lib/vue_on_rails/view_helper.rb
94
+ - vendor/assets/javascripts/vue_on_rails.js.coffee
95
+ homepage: https://github.com/benoitongit
96
+ licenses:
97
+ - MIT
98
+ metadata:
99
+ allowed_push_host: https://rubygems.org
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.6.11
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Easy way to use Vue.js with Ruby on Rails and Turbolinks 5.
120
+ test_files: []