rails_vue_melt 0.1.0
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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +131 -0
- data/Rakefile +28 -0
- data/lib/generators/vue_melt/source/application.js +33 -0
- data/lib/generators/vue_melt/source/components/Hello.vue +20 -0
- data/lib/generators/vue_melt/source/options/users.js +9 -0
- data/lib/generators/vue_melt/source/store/actions.js +1 -0
- data/lib/generators/vue_melt/source/store/getters.js +0 -0
- data/lib/generators/vue_melt/source/store/index.js +17 -0
- data/lib/generators/vue_melt/source/store/mutation-types.js +0 -0
- data/lib/generators/vue_melt/source/store/mutations.js +1 -0
- data/lib/generators/vue_melt/vue_melt_generator.rb +21 -0
- data/lib/rails_vue_melt/version.rb +3 -0
- data/lib/rails_vue_melt.rb +2 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1d1d0c588ea63fa010025d75154666f382469e6a
|
4
|
+
data.tar.gz: 27395b5d4d5f7287160ce3922deb00876a39a117
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b7daa9fd6e8dbd9233f37d63bcea7d132f2685c25a7e14245902bcdf2c9b08b238e90a7944a22f90cd4c36c278c21093030cace6aa67f3060642ba3341cf9e3c
|
7
|
+
data.tar.gz: 1766a400402fb44ec0d4b779569971f1166e3910125aa334b8e4d20a8dc4f9c5daf04bdd8e7c79c9e0b29a7ef71430a81f260fa8ac89e778a8f82e9c3c3dccf2
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2017 midnightSuyama
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
# RailsVueMelt
|
2
|
+
|
3
|
+
[](http://badge.fury.io/rb/rails_vue_melt)
|
4
|
+
[](https://circleci.com/gh/midnightSuyama/rails_vue_melt)
|
5
|
+
|
6
|
+
Rails view with webpack=vue optimizer
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'rails_vue_melt'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install rails_vue_melt
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
$ rails new APP_PATH --webpack=vue
|
27
|
+
...
|
28
|
+
$ rails generate vue_melt
|
29
|
+
|
30
|
+
### Generate
|
31
|
+
|
32
|
+
#### create `app/javascript/packs/vue_melt`
|
33
|
+
|
34
|
+
* application.js
|
35
|
+
* options/
|
36
|
+
* users.js
|
37
|
+
* components/
|
38
|
+
* Hello.vue
|
39
|
+
* store/
|
40
|
+
* index.js
|
41
|
+
* getters.js
|
42
|
+
* actions.js
|
43
|
+
* mutations.js
|
44
|
+
* mutation-types.js
|
45
|
+
|
46
|
+
#### insert `app/views/layouts/application.html.erb`
|
47
|
+
|
48
|
+
```html
|
49
|
+
<%= javascript_pack_tag 'vue_melt/application' %>
|
50
|
+
<meta name="turbolinks-cache-control" content="no-cache">
|
51
|
+
```
|
52
|
+
|
53
|
+
#### gsub `config/webpack/loaders/vue.js`
|
54
|
+
|
55
|
+
```javascript
|
56
|
+
extractCSS: false,
|
57
|
+
```
|
58
|
+
|
59
|
+
#### install packages
|
60
|
+
|
61
|
+
* [vuex](https://www.npmjs.com/package/vuex)
|
62
|
+
* [vue-assign-model](https://www.npmjs.com/package/vue-assign-model)
|
63
|
+
* [lodash.clonedeep](https://www.npmjs.com/package/lodash.clonedeep)
|
64
|
+
|
65
|
+
### Example
|
66
|
+
|
67
|
+
```erb
|
68
|
+
<!-- app/views/**/*.html.erb -->
|
69
|
+
|
70
|
+
<div data-vue="users">
|
71
|
+
<input value="Example" v-model="user.name">
|
72
|
+
<p>User Name: {{ user.name }}</p>
|
73
|
+
|
74
|
+
<hello></hello>
|
75
|
+
</div>
|
76
|
+
```
|
77
|
+
|
78
|
+
Add `data-vue` attribute, the value is file name in `app/javascript/packs/vue_melt/options`. Vue instance is mounted at `turbolinks:load` event and unmounted at `turbolinks:visit` event.
|
79
|
+
|
80
|
+
Before Vue rendering, `value`, `checked` or `selected` attributes of elements with `v-model` is automatically assigned to Vue model. Therefore, `form_with` and so on using Active Model can use data binding easily.
|
81
|
+
|
82
|
+
#### accepts_nested_attributes_for
|
83
|
+
|
84
|
+
JSON of `data-vue-model` is assigned to Vue model. Also, `v-model` with prefix `_` is not assigned for `v-for` scope.
|
85
|
+
|
86
|
+
```erb
|
87
|
+
<!-- app/views/**/*.html.erb -->
|
88
|
+
|
89
|
+
<div data-vue="users">
|
90
|
+
<%= content_tag :div, 'data-vue-model': "{ \"items\": #{user.items.to_json} }" do %>
|
91
|
+
<div v-for="(_item, i) in items">
|
92
|
+
<input type="text" :name="'user[items_attributes][' + i + '][name]'" v-model="_item.name">
|
93
|
+
<input type="hidden" :name="'user[items_attributes][' + i + '][id]'" :value="_item.id" v-if="_item.id">
|
94
|
+
</div>
|
95
|
+
<% end %>
|
96
|
+
</div>
|
97
|
+
```
|
98
|
+
|
99
|
+
With Add and Remove function:
|
100
|
+
|
101
|
+
```erb
|
102
|
+
<!-- app/views/**/*.html.erb -->
|
103
|
+
|
104
|
+
<div data-vue="users">
|
105
|
+
<%= content_tag :div, 'data-vue-model': "{ \"items\": #{user.items.to_json}, \"items_destroy_ids\": [] }" do %>
|
106
|
+
<div v-for="(_item, i) in items">
|
107
|
+
<input type="text" :name="'user[items_attributes][' + i + '][name]'" v-model="_item.name">
|
108
|
+
<input type="hidden" :name="'user[items_attributes][' + i + '][id]'" :value="_item.id" v-if="_item.id">
|
109
|
+
<button type="button" @click="_item.hasOwnProperty('id') ? items_destroy_ids.push(items.splice(i, 1)[0].id) : items.splice(i, 1)">Remove</button>
|
110
|
+
</div>
|
111
|
+
|
112
|
+
<template v-for="(id, i) in items_destroy_ids">
|
113
|
+
<input type="hidden" :name="'user[items_attributes][' + (items.length+i) + '][id]'" :value="id">
|
114
|
+
<input type="hidden" :name="'user[items_attributes][' + (items.length+i) + '][_destroy]'" value="1">
|
115
|
+
</template>
|
116
|
+
|
117
|
+
<button type="button" @click="items.push({ name: '' })">Add</button>
|
118
|
+
<% end %>
|
119
|
+
</div>
|
120
|
+
```
|
121
|
+
|
122
|
+
## Development
|
123
|
+
|
124
|
+
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).
|
125
|
+
|
126
|
+
## Contributing
|
127
|
+
|
128
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/midnightSuyama/rails_vue_melt.
|
129
|
+
|
130
|
+
## License
|
131
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'RailsVueMelt'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
require 'bundler/gem_tasks'
|
23
|
+
|
24
|
+
require 'rspec/core/rake_task'
|
25
|
+
|
26
|
+
RSpec::Core::RakeTask.new(:spec)
|
27
|
+
|
28
|
+
task default: :spec
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import Vue from 'vue/dist/vue.esm'
|
2
|
+
import store from './store'
|
3
|
+
import cloneDeep from 'lodash.clonedeep'
|
4
|
+
|
5
|
+
import VueAssignModel from 'vue-assign-model'
|
6
|
+
Vue.use(VueAssignModel)
|
7
|
+
|
8
|
+
const storeState = cloneDeep(store.state)
|
9
|
+
var vms = []
|
10
|
+
var options = {}
|
11
|
+
var requireContext = require.context("./options", false, /\.js$/)
|
12
|
+
requireContext.keys().forEach(key => {
|
13
|
+
let name = key.split('/').pop().split('.').shift()
|
14
|
+
options[name] = requireContext(key).default
|
15
|
+
})
|
16
|
+
|
17
|
+
document.addEventListener('turbolinks:load', () => {
|
18
|
+
let templates = document.querySelectorAll('[data-vue]')
|
19
|
+
for (let el of templates) {
|
20
|
+
let vm = new Vue(
|
21
|
+
Object.assign(options[el.dataset.vue], { el, store })
|
22
|
+
)
|
23
|
+
vms.push(vm)
|
24
|
+
}
|
25
|
+
})
|
26
|
+
|
27
|
+
document.addEventListener('turbolinks:visit', () => {
|
28
|
+
for (let vm of vms) {
|
29
|
+
vm.$destroy()
|
30
|
+
}
|
31
|
+
vms = []
|
32
|
+
store.replaceState(cloneDeep(storeState))
|
33
|
+
})
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<template>
|
2
|
+
<div>
|
3
|
+
<p>{{ message }}</p>
|
4
|
+
</div>
|
5
|
+
</template>
|
6
|
+
|
7
|
+
<script>
|
8
|
+
export default {
|
9
|
+
data: () => ({
|
10
|
+
message: 'Hello Vue!'
|
11
|
+
})
|
12
|
+
}
|
13
|
+
</script>
|
14
|
+
|
15
|
+
<style scoped>
|
16
|
+
p {
|
17
|
+
font-size: 2em;
|
18
|
+
text-align: center;
|
19
|
+
}
|
20
|
+
</style>
|
@@ -0,0 +1 @@
|
|
1
|
+
import * as types from './mutation-types'
|
File without changes
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import Vue from 'vue/dist/vue.esm'
|
2
|
+
import Vuex from 'vuex'
|
3
|
+
import * as getters from './getters'
|
4
|
+
import * as actions from './actions'
|
5
|
+
import * as mutations from './mutations'
|
6
|
+
|
7
|
+
Vue.use(Vuex)
|
8
|
+
|
9
|
+
const state = {
|
10
|
+
}
|
11
|
+
|
12
|
+
export default new Vuex.Store({
|
13
|
+
state,
|
14
|
+
getters,
|
15
|
+
actions,
|
16
|
+
mutations
|
17
|
+
})
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
import * as types from './mutation-types'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class VueMeltGenerator < Rails::Generators::Base
|
2
|
+
source_root File.expand_path('../source', __FILE__)
|
3
|
+
|
4
|
+
def create
|
5
|
+
directory '.', 'app/javascript/packs/vue_melt'
|
6
|
+
end
|
7
|
+
|
8
|
+
def edit
|
9
|
+
inject_into_file 'app/views/layouts/application.html.erb', before: /^\s*<\/head>/ do
|
10
|
+
<<-EOS
|
11
|
+
<%= javascript_pack_tag 'vue_melt/application' %>
|
12
|
+
<meta name="turbolinks-cache-control" content="no-cache">
|
13
|
+
EOS
|
14
|
+
end
|
15
|
+
gsub_file 'config/webpack/loaders/vue.js', 'extractCSS: true,', 'extractCSS: false,'
|
16
|
+
end
|
17
|
+
|
18
|
+
def yarn
|
19
|
+
run 'yarn add vuex vue-assign-model lodash.clonedeep'
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_vue_melt
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- midnightSuyama
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-08-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.1.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.1.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: generator_spec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Rails view with webpack=vue optimizer
|
56
|
+
email:
|
57
|
+
- midnightSuyama@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- MIT-LICENSE
|
63
|
+
- README.md
|
64
|
+
- Rakefile
|
65
|
+
- lib/generators/vue_melt/source/application.js
|
66
|
+
- lib/generators/vue_melt/source/components/Hello.vue
|
67
|
+
- lib/generators/vue_melt/source/options/users.js
|
68
|
+
- lib/generators/vue_melt/source/store/actions.js
|
69
|
+
- lib/generators/vue_melt/source/store/getters.js
|
70
|
+
- lib/generators/vue_melt/source/store/index.js
|
71
|
+
- lib/generators/vue_melt/source/store/mutation-types.js
|
72
|
+
- lib/generators/vue_melt/source/store/mutations.js
|
73
|
+
- lib/generators/vue_melt/vue_melt_generator.rb
|
74
|
+
- lib/rails_vue_melt.rb
|
75
|
+
- lib/rails_vue_melt/version.rb
|
76
|
+
homepage: https://github.com/midnightSuyama/rails_vue_melt
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.5.2
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Rails view with webpack=vue optimizer
|
100
|
+
test_files: []
|