vails 0.0.3

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.
Files changed (32) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +28 -0
  4. data/Rakefile +27 -0
  5. data/lib/generators/USAGE +8 -0
  6. data/lib/generators/vails_generator.rb +12 -0
  7. data/lib/generators/vue/api_file_generator.rb +41 -0
  8. data/lib/generators/vue/install_generator.rb +48 -0
  9. data/lib/generators/vue/templates/application.html.erb +11 -0
  10. data/lib/generators/vue/templates/index.html.erb +1 -0
  11. data/lib/generators/vue/templates/javascript/SideBar.vue +14 -0
  12. data/lib/generators/vue/templates/javascript/api.js.tt +34 -0
  13. data/lib/generators/vue/templates/javascript/app.vue +23 -0
  14. data/lib/generators/vue/templates/javascript/main.js +17 -0
  15. data/lib/generators/vue/templates/javascript/methods.js +17 -0
  16. data/lib/generators/vue/templates/javascript/resolve.js +8 -0
  17. data/lib/generators/vue/templates/javascript/router.js +15 -0
  18. data/lib/generators/vue/templates/javascript/scaffold.scss +46 -0
  19. data/lib/generators/vue/templates/javascript/store.js +11 -0
  20. data/lib/generators/vue/templates/welcome_controller.rb +4 -0
  21. data/lib/generators/vue/views_generator.rb +39 -0
  22. data/lib/generators/vue/vue_router_generator.rb +33 -0
  23. data/lib/tasks/vails_tasks.rake +5 -0
  24. data/lib/templates/vue/scaffold/_form.vue.tt +57 -0
  25. data/lib/templates/vue/scaffold/edit.vue.tt +50 -0
  26. data/lib/templates/vue/scaffold/index.vue.tt +96 -0
  27. data/lib/templates/vue/scaffold/new.vue.tt +50 -0
  28. data/lib/templates/vue/scaffold/show.vue.tt +52 -0
  29. data/lib/vails.rb +5 -0
  30. data/lib/vails/railtie.rb +4 -0
  31. data/lib/vails/version.rb +3 -0
  32. metadata +93 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2d919c383b064b7035a4eb92ddc54c0d2d881bccdac9c91f8ddd7672e729fae7
4
+ data.tar.gz: 92fe7c744380da62084b539cd9515a8fc3410cf07b5013bf0b2ba9d41179ade2
5
+ SHA512:
6
+ metadata.gz: 6fd5b0f39e8dcff5f06c1bbcbf303821152f1508fddbba897cb976adc762a7e9089d2b3d0ded57332b5d115ed5e52fba57472179b04b36d998153c4ea76f36db
7
+ data.tar.gz: 9758509d0e94e86a73f1a3ec6d12f996a96ae5c66955e3bbac97b2519b8f1024ac1ff697db5f2ea3c138577746b25301958c584a8f2b20886558f2b14cb895ee
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2020 NeeKin
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,28 @@
1
+ # Vails
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'vails'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install vails
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,27 @@
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 = 'Vails'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ require 'bundler/gem_tasks'
18
+
19
+ require 'rake/testtask'
20
+
21
+ Rake::TestTask.new(:test) do |t|
22
+ t.libs << 'test'
23
+ t.pattern = 'test/**/*_test.rb'
24
+ t.verbose = false
25
+ end
26
+
27
+ task default: :test
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate vails Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,12 @@
1
+ class VailsGenerator < Rails::Generators::NamedBase
2
+ def vue
3
+ log :invoke, "views"
4
+ invoke "vue:views"
5
+ log :invoke, "vue_router"
6
+ invoke "vue:vue_router"
7
+ log :invoke, "api_file"
8
+ invoke "vue:api_file"
9
+ invoke :model
10
+ invoke :scaffold_controller
11
+ end
12
+ end
@@ -0,0 +1,41 @@
1
+ require "rails/generators/resource_helpers"
2
+ module Vue
3
+ module Generators
4
+ class ApiFileGenerator < Rails::Generators::NamedBase
5
+ include Rails::Generators::ResourceHelpers
6
+ source_root File.expand_path("../templates", __FILE__)
7
+ # def the_api_init
8
+ # unless File.exist?(Rails.root.join("app/javascript/packs/api", "index.js"))
9
+ # create_file "app/javascript/packs/api/index.js", 'export default {}'
10
+ # end
11
+ # unless File.exist?(Rails.root.join("app/javascript/packs/api", "methods.js"))
12
+ # copy_file 'methods.js', "app/javascript/packs/api/methods.js"
13
+ # end
14
+ # end
15
+
16
+ def copy_api_file
17
+ log :copy_api, controller_file_path
18
+ template "javascript/api.js", "app/javascript/packs/api/res/#{controller_file_path}.js"
19
+ end
20
+
21
+ def write_import_api_form_index
22
+ sentinel = /export default\s*{\s*/m
23
+ content = "import #{controller_file_path} from './res/#{controller_file_path}' \n"
24
+ log :import_api, content
25
+ inject_into_file "app/javascript/packs/api/index.js", content, before: sentinel, verbose: false, force: false
26
+ end
27
+ def write_export_api
28
+ sentinel = /export default\s*{\n*/m
29
+ content = "#{controller_file_path},\n"
30
+ log :export_api, controller_file_path
31
+ inject_into_file "app/javascript/packs/api/index.js", content, after: sentinel, verbose: false, force: false
32
+ end
33
+ def write_components
34
+ sentinel = /<template>\s*\n*<ul>\s*\n*/m
35
+ content = "<li><router-link to='/#{controller_file_path}'>#{controller_file_path.capitalize}</router-link></li>\n"
36
+ log :add_components, controller_file_path
37
+ inject_into_file "app/javascript/packs/components/SideBar.vue", content, after: sentinel, verbose: false, force: false
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,48 @@
1
+ module Vue
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path("../templates", __FILE__)
5
+ def remove_default_file
6
+ remove_file 'app/javascript/app.vue'
7
+ remove_file 'app/javascript/packs/application.js'
8
+ remove_file 'app/javascript/packs/hello_vue.js'
9
+ end
10
+ def the_api_init
11
+ unless File.exist?(Rails.root.join("app/javascript/packs/api", "index.js"))
12
+ create_file "app/javascript/packs/api/index.js", 'export default {}'
13
+ end
14
+ unless File.exist?(Rails.root.join("app/javascript/packs/api", "methods.js"))
15
+ copy_file 'javascript/methods.js', "app/javascript/packs/api/methods.js"
16
+ copy_file 'javascript/main.js', "app/javascript/packs/main.js"
17
+ copy_file 'javascript/router.js', "app/javascript/packs/router/index.js"
18
+ copy_file 'javascript/store.js', "app/javascript/packs/store/index.js"
19
+ copy_file 'javascript/app.vue', "app/javascript/packs/app.vue"
20
+ copy_file 'javascript/SideBar.vue', "app/javascript/packs/components/SideBar.vue"
21
+ copy_file 'javascript/scaffold.scss', "app/javascript/packs/assets/scss/scaffold.scss"
22
+ end
23
+ unless File.exist?(Rails.root.join("app/views/layouts", "application.html.erb"))
24
+ copy_file 'application.html.erb', "app/views/layouts/application.html.erb"
25
+ copy_file 'index.html.erb', "app/views/welcome/index.html.erb"
26
+ copy_file 'welcome_controller.rb', "app/controllers/welcome_controller.rb"
27
+ end
28
+ end
29
+
30
+
31
+ def change_wepacker_config
32
+ copy_file 'javascript/resolve.js', "config/webpack/resolve.js"
33
+ end
34
+ def change_webpack_config_env
35
+ inject_into_file "config/webpack/environment.js", "\nconst resolvePath = require('./resolve')", after: "const vue = require('./loaders/vue')", verbose: false, force: false
36
+ inject_into_file "config/webpack/environment.js", "environment.config.merge(resolvePath)\n", before: "environment.plugins.prepend('VueLoaderPlugin', new VueLoaderPlugin())", verbose: false, force: false
37
+ end
38
+ def change_config_routus
39
+ content = %Q{ scope '/api' do
40
+ end
41
+ root 'welcome#index'
42
+ get '/*path', to: 'welcome#index' , format: false
43
+ }
44
+ inject_into_file "config/routes.rb", content, after: "# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html\n", verbose: false, force: false
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,11 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>vails</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+ </head>
8
+ <body>
9
+ <%= yield %>
10
+ </body>
11
+ </html>
@@ -0,0 +1 @@
1
+ <%= javascript_pack_tag 'main' %>
@@ -0,0 +1,14 @@
1
+ <template>
2
+ <ul>
3
+ </ul>
4
+ </template>
5
+
6
+ <script>
7
+ export default {
8
+
9
+ }
10
+ </script>
11
+
12
+ <style>
13
+
14
+ </style>
@@ -0,0 +1,34 @@
1
+ import {get,destory,post,put} from '../methods'
2
+
3
+
4
+ export default{
5
+ list(){
6
+ return get({url:'/api/<%= plural_table_name %>'})
7
+ },
8
+ get(id){
9
+ return get({
10
+ url:`/api/<%= plural_table_name %>/${id}`
11
+ })
12
+ },
13
+ destory(id){
14
+ return destory({
15
+ url:`/api/<%= plural_table_name %>/${id}`
16
+ })
17
+ },
18
+ create(data){
19
+ return post({
20
+ url:'/api/<%= plural_table_name %>',
21
+ data:{
22
+ <%= singular_table_name %>:data
23
+ }
24
+ })
25
+ },
26
+ update(id,data){
27
+ return put({
28
+ url:`/api/<%= plural_table_name %>/${id}`,
29
+ data:{
30
+ <%= singular_table_name %>:data
31
+ }
32
+ })
33
+ }
34
+ }
@@ -0,0 +1,23 @@
1
+ <template>
2
+ <div id="app">
3
+ <side-bar/>
4
+ <router-view />
5
+ </div>
6
+ </template>
7
+
8
+ <script>
9
+ import SideBar from '@/components/SideBar'
10
+
11
+ export default {
12
+ components:{
13
+ SideBar
14
+ },
15
+ data: function () {
16
+ return {
17
+ }
18
+ }
19
+ }
20
+ </script>
21
+
22
+ <style scoped>
23
+ </style>
@@ -0,0 +1,17 @@
1
+ import Vue from 'vue'
2
+ import App from './app.vue'
3
+ import router from "./router";
4
+ import store from "./store";
5
+ import api from './api'
6
+
7
+ Vue.prototype.$api = api
8
+ document.addEventListener('DOMContentLoaded', () => {
9
+ const app = new Vue({
10
+ router,
11
+ store,
12
+ render: h => h(App)
13
+ }).$mount()
14
+ document.body.appendChild(app.$el)
15
+
16
+ console.log(app)
17
+ })
@@ -0,0 +1,17 @@
1
+ import axios from 'axios'
2
+
3
+
4
+
5
+ export function get(request){
6
+ return axios.get(request.url,request.config)
7
+ }
8
+ export function post(request){
9
+ return axios.post(request.url,request.data,request.config)
10
+ }
11
+
12
+ export function destory(request){
13
+ return axios.delete(request.url,request.config)
14
+ }
15
+ export function put(request){
16
+ return axios.put(request.url,request.data,request.config)
17
+ }
@@ -0,0 +1,8 @@
1
+ const { resolve } = require('path');
2
+ module.exports = {
3
+ resolve:{
4
+ alias: {
5
+ '@': resolve('app/javascript/packs')
6
+ }
7
+ }
8
+ }
@@ -0,0 +1,15 @@
1
+ import Vue from "vue";
2
+ import VueRouter from "vue-router";
3
+ Vue.use(VueRouter);
4
+
5
+ const routes = [
6
+
7
+ ];
8
+
9
+ const router = new VueRouter({
10
+ mode: "history",
11
+ base: process.env.BASE_URL,
12
+ routes
13
+ });
14
+
15
+ export default router;
@@ -0,0 +1,46 @@
1
+ .modal{
2
+ position: fixed;
3
+ width: 100%;
4
+ height:100%;
5
+ background-color: rgba(0,0,0,.3);
6
+ top:0;
7
+ left:0;
8
+ /deep/.form{
9
+ width: 600px;
10
+ height:auto;
11
+ background-color: #fff;
12
+ position: absolute;
13
+ left:50%;
14
+ transform: translateX(-50%);
15
+ top:20%;
16
+ padding: 30px;
17
+ .content{
18
+ p{
19
+ display: flex;
20
+ align-items: center;
21
+ padding-left: 10px;
22
+ box-sizing: border-box;
23
+ }
24
+ .field{
25
+ display: flex;
26
+ align-items: center;
27
+ }
28
+ }
29
+ .header{
30
+ height:60px;
31
+ border-bottom: 1px solid #ccc;
32
+ position: relative;
33
+ display: flex;
34
+ align-items: center;
35
+ }
36
+ .close{
37
+ position: absolute;
38
+ right:0;
39
+ }
40
+ .footer{
41
+ height:60px;
42
+ display: flex;
43
+ align-items: center;
44
+ }
45
+ }
46
+ }
@@ -0,0 +1,11 @@
1
+ import Vue from "vue";
2
+ import Vuex from "vuex";
3
+
4
+ Vue.use(Vuex);
5
+
6
+ export default new Vuex.Store({
7
+ state: {},
8
+ mutations: {},
9
+ actions: {},
10
+ modules: {}
11
+ });
@@ -0,0 +1,4 @@
1
+ class WelcomeController < ActionController::Base
2
+ def index
3
+ end
4
+ end
@@ -0,0 +1,39 @@
1
+ require "rails/generators/resource_helpers"
2
+
3
+ module Vue # :nodoc:
4
+ module Generators # :nodoc:
5
+ class ViewsGenerator < Rails::Generators::NamedBase
6
+ source_root File.expand_path("../../../templates/vue/scaffold", __FILE__)
7
+ include Rails::Generators::ResourceHelpers
8
+ argument :attributes, type: :array, default: [], banner: "field:type field:type"
9
+ def create_root_folder
10
+ empty_directory File.join("app/javascript/packs/views", controller_file_path)
11
+ end
12
+ def copy_view_files
13
+ available_views.each do |view|
14
+ formats.each do |format|
15
+ filename = filename_with_extensions(view, format)
16
+ template filename, File.join("app/javascript/packs/views", controller_file_path, filename)
17
+ end
18
+ end
19
+ end
20
+
21
+ private
22
+ def available_views
23
+ %w(index edit show new _form)
24
+ end
25
+
26
+ def formats
27
+ [format]
28
+ end
29
+
30
+ def format
31
+ :vue
32
+ end
33
+
34
+ def filename_with_extensions(name, file_format = format)
35
+ [name, file_format].compact.join(".")
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,33 @@
1
+ require "rails/generators/resource_helpers"
2
+ module Vue
3
+ module Generators
4
+ class VueRouterGenerator < Rails::Generators::NamedBase
5
+ include Rails::Generators::ResourceHelpers
6
+ source_root File.expand_path("../templates", __FILE__)
7
+ def the_api_init
8
+ unless File.exist?(Rails.root.join("app/javascript/packs/router", "index.js"))
9
+ template "router.js", "app/javascript/packs/router/index.js"
10
+ end
11
+ end
12
+
13
+ def import_page_for_router
14
+ sentinel = /const routes\s*=\s*\[\s*/m
15
+ content = %Q{{
16
+ path: '/#{controller_file_path}',
17
+ name: '#{ class_name }',
18
+ component: () =>
19
+ import(/* webpackChunkName: "about" */ '../views/#{ controller_file_path }/index.vue')
20
+ },}
21
+ log :import_router_page, controller_file_path
22
+ inject_into_file "app/javascript/packs/router/index.js", content, after: sentinel, verbose: false, force: false
23
+ end
24
+
25
+ def rails_route
26
+ sentinel = /scope '\/api'\s* do\n*/m
27
+ content = " resources :#{controller_file_path}\n"
28
+ log :route, content
29
+ inject_into_file "config/routes.rb", content, after: sentinel, verbose: false, force: false
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,5 @@
1
+ desc "Explaining what the task does"
2
+ task :vue:install do
3
+ # Task goes here
4
+ puts('hello WOrld')
5
+ end
@@ -0,0 +1,57 @@
1
+ <template>
2
+ <div>
3
+
4
+ <% attributes.each do |attribute| -%>
5
+ <div class="field">
6
+ <% if attribute.password_digest? -%>
7
+ <label>password</label>
8
+ <input type='password' v-model='<%= singular_table_name %>.password'/>
9
+ </div>
10
+ <div class="field">
11
+ <label>password_confirmation</label>
12
+ <input type='password' v-model='<%= singular_table_name %>.password_confirmation'/>
13
+ <% elsif attribute.attachments? -%>
14
+ <%%= form.label :<%= attribute.column_name %> %>
15
+ <%%= form.<%= attribute.field_type %> :<%= attribute.column_name %>, multiple: true %>
16
+ <% else -%>
17
+ <label><%= attribute.column_name %></label>
18
+ <% if attribute.field_type == :text_field -%>
19
+ <input type='text' v-model='<%= singular_table_name %>.<%= attribute.column_name %>'/>
20
+ <% end %>
21
+ <% if attribute.field_type == :check_box -%>
22
+ <input type='checkbox' v-model='<%= singular_table_name %>.<%= attribute.column_name %>'/>
23
+ <% end %>
24
+ <% if attribute.field_type == :text_area -%>
25
+ <textarea v-model='<%= singular_table_name %>.<%= attribute.column_name %>'></textarea>
26
+ <% end %>
27
+ <% if attribute.field_type == :date_select -%>
28
+ <input type='date' v-model='<%= singular_table_name %>.<%= attribute.column_name %>'/>
29
+ <% end %>
30
+ <% end -%>
31
+ </div>
32
+ <% end -%>
33
+ </div>
34
+ </template>
35
+
36
+ <script>
37
+ export default {
38
+ props:{
39
+ <%= singular_table_name %>:{
40
+ default:null
41
+ }
42
+ },
43
+ model:{
44
+ prop:"<%= singular_table_name %>",
45
+ event:"close"
46
+ },
47
+ methods:{
48
+ close(){
49
+ this.$emit('close',null)
50
+ }
51
+ }
52
+ }
53
+ </script>
54
+
55
+ <style scoped lang='scss'>
56
+
57
+ </style>
@@ -0,0 +1,50 @@
1
+ <template>
2
+ <div class='modal' v-if='<%= singular_table_name %>'>
3
+ <div class="form">
4
+ <div class="header">
5
+ Editing <%= singular_table_name.titleize %>
6
+ <div class="close" @click="close">X</div>
7
+ </div>
8
+ <div class="content">
9
+ <<%= singular_table_name %>-form v-model='<%= singular_table_name %>'/>
10
+ </div>
11
+
12
+ <div class="footer">
13
+ <button @click='update'>保存</button>
14
+ <button @click='close'>取消</button>
15
+ </div>
16
+ </div>
17
+ </div>
18
+
19
+ </template>
20
+
21
+ <script>
22
+ import <%= singular_table_name %>Form from './_form'
23
+ export default {
24
+ components:{
25
+ <%= singular_table_name %>Form
26
+ },
27
+ props:{
28
+ <%= singular_table_name %>:{
29
+ default:null
30
+ }
31
+ },
32
+ model:{
33
+ prop:"<%= singular_table_name %>",
34
+ event:"close"
35
+ },
36
+ methods:{
37
+ close(){
38
+ this.$emit('close',null)
39
+ },
40
+ update(){
41
+ this.$emit('update')
42
+ this.close()
43
+ }
44
+ }
45
+ }
46
+ </script>
47
+
48
+ <style scoped lang='scss'>
49
+
50
+ </style>
@@ -0,0 +1,96 @@
1
+ <template>
2
+ <div>
3
+ <h1><%= plural_table_name.titleize %></h1>
4
+ <table>
5
+ <thead>
6
+ <tr>
7
+ <% attributes.reject(&:password_digest?).each do |attribute| -%>
8
+ <th><%= attribute.human_name %></th>
9
+ <% end -%>
10
+ <th colspan="3"></th>
11
+ </tr>
12
+ </thead>
13
+ <tbody>
14
+ <tr v-for='<%= singular_table_name %> in list' :key='<%= singular_table_name %>.id'>
15
+ <% attributes.reject(&:password_digest?).each do |attribute| -%>
16
+ <td>{{<%= singular_table_name %>.<%= attribute.column_name %>}} </td>
17
+ <% end -%>
18
+
19
+
20
+ <td>
21
+ <button @click='get(<%= singular_table_name %>.id,"show<%= model_resource_name.capitalize %>")'>详情</button>
22
+ </td>
23
+ <td>
24
+ <button @click='get(<%= singular_table_name %>.id,"edit<%= model_resource_name.capitalize %>")'>编辑</button>
25
+ </td>
26
+ <td>
27
+ <button @click='destory(<%= singular_table_name %>.id)'>删除</button>
28
+ </td>
29
+ </tr>
30
+ </tbody>
31
+ </table>
32
+ <button @click='add'>新增</button>
33
+ <show v-model='show<%= model_resource_name.capitalize %>' />
34
+ <edit v-model='edit<%= model_resource_name.capitalize %>' @update='update'/>
35
+ <new v-model='new<%= model_resource_name.capitalize %>' @create='create'/>
36
+ </div>
37
+ </template>
38
+
39
+ <script>
40
+ import Show from './show'
41
+ import Edit from './edit'
42
+ import New from './new'
43
+ export default {
44
+ components:{
45
+ Show,
46
+ Edit,
47
+ New
48
+ },
49
+ data(){
50
+ return {
51
+ list:[],
52
+ show<%= model_resource_name.capitalize %>:null,
53
+ edit<%= model_resource_name.capitalize %>:null,
54
+ new<%= model_resource_name.capitalize %>:null
55
+ }
56
+ },
57
+ created(){
58
+ this.getList()
59
+ },
60
+ methods:{
61
+ add(){
62
+ this.new<%= model_resource_name.capitalize %> = {
63
+ <% attributes.each do |attribute| -%>
64
+ <%= attribute.column_name %>:"",
65
+ <% end -%>
66
+ }
67
+ },
68
+ async get(id,type){
69
+ let { data } = await this.$api.<%= plural_table_name %>.get(id)
70
+ this[type] = data
71
+ },
72
+ async getList(){
73
+ let { data } = await this.$api.<%= plural_table_name %>.list();
74
+ this.list = data
75
+ },
76
+ async update(){
77
+ await this.$api.<%= plural_table_name %>.update(this.edit<%= model_resource_name.capitalize %>.id,this.edit<%= model_resource_name.capitalize %>)
78
+ this.getList()
79
+ },
80
+ async destory(id){
81
+ if(confirm('确认删除资源吗?')) {
82
+ await this.$api.<%= plural_table_name %>.destory(id)
83
+ this.getList()
84
+ }
85
+ },
86
+ async create(){
87
+ await this.$api.<%= plural_table_name %>.create(this.new<%= model_resource_name.capitalize %>)
88
+ this.getList()
89
+ }
90
+ }
91
+ }
92
+ </script>
93
+
94
+ <style lang='scss' scoped>
95
+ @import '../../assets/scss/scaffold.scss';
96
+ </style>
@@ -0,0 +1,50 @@
1
+ <template>
2
+ <div class='modal' v-if='<%= singular_table_name %>'>
3
+ <div class="form">
4
+ <div class="header">
5
+ <h1>New <%= singular_table_name.titleize %></h1>
6
+ <div class="close" @click="close">X</div>
7
+ </div>
8
+ <div class="content">
9
+ <<%= singular_table_name %>-form v-model='<%= singular_table_name %>'/>
10
+ </div>
11
+
12
+ <div class="footer">
13
+ <button @click='create'>创建</button>
14
+ <button @click='close'>取消</button>
15
+ </div>
16
+ </div>
17
+ </div>
18
+
19
+ </template>
20
+
21
+ <script>
22
+ import <%= singular_table_name %>Form from './_form'
23
+ export default {
24
+ components:{
25
+ <%= singular_table_name %>Form
26
+ },
27
+ props:{
28
+ <%= singular_table_name %>:{
29
+ default:null
30
+ }
31
+ },
32
+ model:{
33
+ prop:"<%= singular_table_name %>",
34
+ event:"close"
35
+ },
36
+ methods:{
37
+ close(){
38
+ this.$emit('close',null)
39
+ },
40
+ create(){
41
+ this.$emit('create')
42
+ this.close()
43
+ }
44
+ }
45
+ }
46
+ </script>
47
+
48
+ <style scoped lang='scss'>
49
+
50
+ </style>
@@ -0,0 +1,52 @@
1
+ <template>
2
+ <div class='modal' v-if='<%= singular_table_name %>'>
3
+ <div class="form">
4
+ <div class="header">
5
+ <div class="close" @click="close">X</div>
6
+ </div>
7
+ <div class="content">
8
+ <% attributes.reject(&:password_digest?).each do |attribute| -%>
9
+ <p>
10
+ <strong><%= attribute.human_name %>:</strong>
11
+ <% if attribute.attachment? -%>
12
+ <%%= link_to @<%= singular_table_name %>.<%= attribute.column_name %>.filename, @<%= singular_table_name %>.<%= attribute.column_name %> if @<%= singular_table_name %>.<%= attribute.column_name %>.attached? %>
13
+ <% elsif attribute.attachments? -%>
14
+ <%% @<%= singular_table_name %>.<%= attribute.column_name %>.each do |<%= attribute.singular_name %>| %>
15
+ <div><%%= link_to <%= attribute.singular_name %>.filename, <%= attribute.singular_name %> %></div>
16
+ <%% end %>
17
+ <% else -%>
18
+ {{<%= singular_table_name %>.<%= attribute.column_name %>}}
19
+ <% end -%>
20
+ </p>
21
+
22
+ <% end -%>
23
+ </div>
24
+ <div class="footer">
25
+ <button @click='close'>关闭</button>
26
+ </div>
27
+ </div>
28
+ </div>
29
+ </template>
30
+
31
+ <script>
32
+ export default {
33
+ props:{
34
+ <%= singular_table_name %>:{
35
+ default:null
36
+ }
37
+ },
38
+ model:{
39
+ prop:"<%= singular_table_name %>",
40
+ event:"close"
41
+ },
42
+ methods:{
43
+ close(){
44
+ this.$emit('close',null)
45
+ }
46
+ }
47
+ }
48
+ </script>
49
+
50
+ <style scoped lang='scss'>
51
+
52
+ </style>
data/lib/vails.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "vails/railtie"
2
+
3
+ module Vails
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,4 @@
1
+ module Vails
2
+ class Railtie < ::Rails::Railtie
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module Vails
2
+ VERSION = '0.0.3'
3
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - NeeKin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-08-03 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: 6.0.1
20
+ - - "~>"
21
+ - !ruby/object:Gem::Version
22
+ version: 6.0.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 6.0.1
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: 6.0.1
33
+ description: a simple vue scaffold on rails.
34
+ email:
35
+ - njgzs360@gmail.com
36
+ executables: []
37
+ extensions: []
38
+ extra_rdoc_files: []
39
+ files:
40
+ - MIT-LICENSE
41
+ - README.md
42
+ - Rakefile
43
+ - lib/generators/USAGE
44
+ - lib/generators/vails_generator.rb
45
+ - lib/generators/vue/api_file_generator.rb
46
+ - lib/generators/vue/install_generator.rb
47
+ - lib/generators/vue/templates/application.html.erb
48
+ - lib/generators/vue/templates/index.html.erb
49
+ - lib/generators/vue/templates/javascript/SideBar.vue
50
+ - lib/generators/vue/templates/javascript/api.js.tt
51
+ - lib/generators/vue/templates/javascript/app.vue
52
+ - lib/generators/vue/templates/javascript/main.js
53
+ - lib/generators/vue/templates/javascript/methods.js
54
+ - lib/generators/vue/templates/javascript/resolve.js
55
+ - lib/generators/vue/templates/javascript/router.js
56
+ - lib/generators/vue/templates/javascript/scaffold.scss
57
+ - lib/generators/vue/templates/javascript/store.js
58
+ - lib/generators/vue/templates/welcome_controller.rb
59
+ - lib/generators/vue/views_generator.rb
60
+ - lib/generators/vue/vue_router_generator.rb
61
+ - lib/tasks/vails_tasks.rake
62
+ - lib/templates/vue/scaffold/_form.vue.tt
63
+ - lib/templates/vue/scaffold/edit.vue.tt
64
+ - lib/templates/vue/scaffold/index.vue.tt
65
+ - lib/templates/vue/scaffold/new.vue.tt
66
+ - lib/templates/vue/scaffold/show.vue.tt
67
+ - lib/vails.rb
68
+ - lib/vails/railtie.rb
69
+ - lib/vails/version.rb
70
+ homepage: https://github.com/neekin/vails
71
+ licenses:
72
+ - MIT
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubygems_version: 3.0.3
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: a simple vue scaffold on rails.
93
+ test_files: []