Skip to content

Commit 9682925

Browse files
authored
Merge pull request #65 from ElMassimo/vue-template
feat: Implement generator for Vue apps
2 parents 93ab3a7 + 1c891cd commit 9682925

File tree

5 files changed

+50
-3
lines changed

5 files changed

+50
-3
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<template>
2+
<h1 :style="{ 'text-align': 'center' }">Hello {{name}}!</h1>
3+
</template>
4+
5+
<script>
6+
export default {
7+
props: {
8+
name: { type: String, required: true },
9+
},
10+
}
11+
</script>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import axios from 'axios'
2+
import Vue from 'vue'
3+
4+
import { app, plugin } from '@inertiajs/inertia-vue'
5+
import { InertiaProgress } from '@inertiajs/progress'
6+
7+
document.addEventListener('DOMContentLoaded', () => {
8+
const csrfToken = document.querySelector('meta[name=csrf-token]').content
9+
axios.defaults.headers.common['X-CSRF-Token'] = csrfToken
10+
11+
InertiaProgress.init();
12+
const el = document.getElementById('app')
13+
14+
Vue.use(plugin)
15+
16+
new Vue({
17+
render: h => h(app, {
18+
props: {
19+
initialPage: JSON.parse(el.dataset.page),
20+
resolveComponent: name => require(`../Pages/${name}`).default,
21+
},
22+
}),
23+
}).$mount(el)
24+
})

lib/generators/inertia_rails/install_generator.rb

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class InstallGenerator < Rails::Generators::Base
55

66
FRONT_END_INSTALLERS = [
77
'react',
8+
'vue',
89
]
910

1011
def install
@@ -32,6 +33,8 @@ def installable?
3233

3334
return false
3435
end
36+
37+
true
3538
end
3639

3740
def install_base!
@@ -53,10 +56,19 @@ def install_base!
5356
def install_react!
5457
say "Creating a React page component...", :blue
5558
run 'yarn add @inertiajs/inertia-react'
56-
template "react.jsx", Rails.root.join("app/javascript/Pages/InertiaExample.js").to_s
59+
template "react/InertiaExample.jsx", Rails.root.join("app/javascript/Pages/InertiaExample.js").to_s
5760
say "Copying inertia.jsx into webpacker's packs folder...", :blue
58-
template "inertia.jsx", Rails.root.join("app/javascript/packs/inertia.jsx").to_s
61+
template "react/inertia.jsx", Rails.root.join("app/javascript/packs/inertia.jsx").to_s
62+
say "done!", :green
63+
end
64+
65+
def install_vue!
66+
say "Creating a Vue page component...", :blue
67+
run 'yarn add @inertiajs/inertia-vue'
68+
template "vue/InertiaExample.vue", Rails.root.join("app/javascript/Pages/InertiaExample.vue").to_s
69+
say "Copying inertia.js into webpacker's packs folder...", :blue
70+
template "vue/inertia.js", Rails.root.join("app/javascript/packs/inertia.js").to_s
5971
say "done!", :green
6072
end
6173
end
62-
end
74+
end

0 commit comments

Comments
 (0)