rails_vue_generator 0.2.0 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 845ede3c6dc62f3710389fc8e9ec87d70849388a18102ae4c0a676dcb84a6a32
4
- data.tar.gz: 29dd83376ecd343ea0a24df9f247955400ef66dd503815e6ccc5098e6d1f5767
3
+ metadata.gz: 21772ef2496ba484d808199ab642ec609a8acfeae4696a8a33885ab6e69aa35a
4
+ data.tar.gz: 6cbabc654baad819476449aaa4e2411afc6d3ae88243506cfa962a1bd55d491d
5
5
  SHA512:
6
- metadata.gz: a7c2f93ee0151486fa17c00f72c9f00ba248a6c478fb03700ea653a2ec26e30070a398e9c74812a6b0428feb6214bb2627aa82118eb4c63fd7fcfcce0304d9b6
7
- data.tar.gz: 00c2cb6ef9e8ca3f9e2b9a2b94ebd74850f73062994255b56d2751ba37bfcad12d1ecbc713c9bc43aca5667a5acd0e51b143e968876be8fa470db7398edabc15
6
+ metadata.gz: 5629a5fb314c75681f78a751cb4a1f22ffc9960c0ab490959284833b727aa62414f931c65e4ec88631545d3565c7b3e219042cbfde57a8c65b151b1eedfd725e
7
+ data.tar.gz: f26fb251f444a9c398e20c457e227ec5395212d419e6f628663069d57f8c5f98ad15a80268ade4dd5459e77ad397bcbce50691d0d34a55750caa73df5f8db5bb
@@ -4,7 +4,7 @@ module RailsVueGenerator
4
4
  class Generator
5
5
  ROOT_PATH = File.join(Dir.getwd, "vue_example")
6
6
 
7
- def generate
7
+ def self.generate
8
8
  ModelGenerator.new.generate
9
9
 
10
10
  RouterGenerator.new.generate
@@ -5,16 +5,16 @@ module RailsVueGenerator
5
5
 
6
6
  def generate
7
7
  lines = []
8
- lines << "import axios from 'axios';"
8
+ lines << "import axios from 'axios'"
9
9
  lines << ""
10
- lines << "export const HTTP = axios.create({"
10
+ lines << "export const HTTP = axios.create({"
11
11
  lines << " baseURL: process.env.VUE_APP_API_ENDPOINT || 'http://localhost:3000'"
12
12
  lines << "})"
13
13
  lines << ""
14
14
  lines << "export default {"
15
15
 
16
16
  lines << " async getAll() {"
17
- lines << " const response = await HTTP.get(`/#{model_name.pluralize}`)"
17
+ lines << " const response = await HTTP.get('/#{model_name.pluralize}')"
18
18
  lines << " return response"
19
19
  lines << " },"
20
20
 
@@ -24,7 +24,7 @@ module RailsVueGenerator
24
24
  lines << " },"
25
25
 
26
26
  lines << " async create(data) {"
27
- lines << " const response = await HTTP.post(`/#{model_name.pluralize}`, {#{model_name}: data})"
27
+ lines << " const response = await HTTP.post('/#{model_name.pluralize}`, {#{model_name}: data})"
28
28
  lines << " return response"
29
29
  lines << " },"
30
30
 
@@ -39,6 +39,7 @@ module RailsVueGenerator
39
39
  lines << " }"
40
40
 
41
41
  lines << "}"
42
+ lines << ""
42
43
 
43
44
  lines.join("\n")
44
45
  end
@@ -16,7 +16,7 @@ module RailsVueGenerator
16
16
  lines << template
17
17
  lines << script
18
18
  lines << style
19
- lines.join("\n\n")
19
+ lines.join("\n\n") + "\n"
20
20
  end
21
21
  end
22
22
  end
@@ -44,7 +44,7 @@ module RailsVueGenerator
44
44
  edit_form_lines << '</div>'
45
45
  end
46
46
  edit_form_lines << "<div>"
47
- edit_form_lines << "<a href='#' class='btn btn-primary' @click=\"save\">Save Changes</a> "
47
+ edit_form_lines << "<a href='#' class='btn btn-primary' @click=\"save\">Save Changes</a>"
48
48
  edit_form_lines << "<router-link :to=\"{name: '#{model_name.pluralize}'}\">Back</router-link>"
49
49
  edit_form_lines << '</div>'
50
50
  edit_form_lines << '</div>'
@@ -57,24 +57,26 @@ module RailsVueGenerator
57
57
  lines = []
58
58
 
59
59
  lines << '<script>'
60
- lines << " import {mapState} from 'vuex'"
61
- lines << ' export default {'
62
- lines << " name: '#{model_name}-edit',"
63
- lines << ' computed:{'
60
+ lines << "import {mapState} from 'vuex'"
61
+ lines << 'export default {'
62
+ lines << " name: '#{model_name}-edit',"
63
+ lines << ' computed: {'
64
64
  lines << ' ...mapState({'
65
65
  lines << " #{model_name}: state => state.#{model_name}.current,"
66
66
  lines << " loading: state => state.#{model_name}.loading.current"
67
- lines << ' }),'
67
+ lines << ' })'
68
68
  lines << ' },'
69
69
  lines << ' methods: {'
70
- lines << ' save(){'
70
+ lines << ' save() {'
71
71
  lines << " const data = this.#{model_name}"
72
72
  lines << " if (this.#{model_name}.id !== undefined) {"
73
73
  lines << " const id = this.#{model_name}.id"
74
- lines << " console.log(\"updating \", this.#{model_name})"
75
- lines << " this.$store.dispatch('#{model_name}/update', {id, data}).then(function(response) {this.$router.push({name: '#{model_name}', params: {id: response.id}})}.bind(this))"
74
+ lines << " this.$store.dispatch('#{model_name}/update', {id, data}).then("
75
+ lines << " function(response) {"
76
+ lines << " this.$router.push({name: '#{model_name}', params: {id: response.id}})"
77
+ lines << " }.bind(this)"
78
+ lines << " )"
76
79
  lines << ' } else {'
77
- lines << " console.log(\"updating \", this.#{model_name})"
78
80
  lines << " this.$store.dispatch('#{model_name}/create', this.#{model_name}).then(function(response) {this.$router.push({name: '#{model_name}', params: {id: response.id}})}.bind(this))"
79
81
  lines << ' }'
80
82
  lines << ' }'
@@ -86,7 +88,7 @@ module RailsVueGenerator
86
88
  lines << " this.$store.dispatch('#{model_name}/clearCurrent', this.$route.params.id)"
87
89
  lines << " }"
88
90
  lines << ' }'
89
- lines << '};'
91
+ lines << '}'
90
92
  lines << '</script>'
91
93
  lines.join("\n")
92
94
  end
@@ -3,29 +3,32 @@ module RailsVueGenerator
3
3
  class IndexHandler < BaseHandler
4
4
  def template
5
5
  index_page_lines = []
6
- index_page_lines << "<template><div><h1>#{model_name.titleize}</h1>"
7
- index_page_lines << "<div class=\"spinner\" v-if='loading'>Loading #{model_name.pluralize.titleize}</div>"
8
- index_page_lines << "<div v-else>"
9
- index_page_lines << "<table>"
10
- index_page_lines << "<tr>"
6
+ index_page_lines << "<template>"
7
+ index_page_lines << " <div>"
8
+ index_page_lines << " <h1>#{model_name.titleize}</h1>"
9
+ index_page_lines << " <div class=\"spinner\" v-if='loading'>Loading #{model_name.pluralize.titleize}</div>"
10
+ index_page_lines << " <div v-else>"
11
+ index_page_lines << " <table>"
12
+ index_page_lines << " <tr>"
11
13
  @model.columns.reject { |column| IGNORED_COLUMNS.include?(column.name.to_sym) }.each do |column|
12
- index_page_lines << "<th>#{column.name.titleize}</th>"
14
+ index_page_lines << " <th>#{column.name.titleize}</th>"
13
15
  end
14
- index_page_lines << "<th></th>"
15
- index_page_lines << "</tr>"
16
+ index_page_lines << " <th></th>"
17
+ index_page_lines << " </tr>"
16
18
 
17
- index_page_lines << "<tr v-for='#{model_name.downcase} in #{model_name.downcase.pluralize}' :key='#{model_name.downcase}.id'>"
19
+ index_page_lines << " <tr v-for='#{model_name.downcase} in #{model_name.downcase.pluralize}' :key='#{model_name.downcase}.id'>"
18
20
  @model.columns.reject { |column| IGNORED_COLUMNS.include?(column.name.to_sym) }.each do |column|
19
- index_page_lines << "<td>{{#{model_name.downcase}.#{column.name}}}</td>"
21
+ index_page_lines << " <td>{{#{model_name.downcase}.#{column.name}}}</td>"
20
22
  end
21
- index_page_lines << "<td><router-link :to=\"{name: '#{model_name}', params: {id: #{model_name.downcase}.id}}\">Show</router-link> | "
22
- index_page_lines << "<router-link :to=\"{name: 'edit-#{model_name}', params: {id: #{model_name.downcase}.id}}\">Edit</router-link></td>"
23
-
24
- index_page_lines << "</tr>"
25
- index_page_lines << "</table>"
26
- index_page_lines << "<router-link :to=\"{name: 'new-#{model_name}'}\">Create a new #{model_name.titleize}</router-link>"
27
- index_page_lines << "</div>"
28
- index_page_lines << "</div>"
23
+ index_page_lines << " <td>"
24
+ index_page_lines << " <router-link :to=\"{name: '#{model_name}', params: {id: #{model_name.downcase}.id}}\">Show</router-link>&nbsp;|&nbsp;"
25
+ index_page_lines << " <router-link :to=\"{name: 'edit-#{model_name}', params: {id: #{model_name.downcase}.id}}\">Edit</router-link>"
26
+ index_page_lines << " </td>"
27
+ index_page_lines << " </tr>"
28
+ index_page_lines << " </table>"
29
+ index_page_lines << " <router-link :to=\"{name: 'new-#{model_name}'}\">Create a new #{model_name.titleize}</router-link>"
30
+ index_page_lines << " </div>"
31
+ index_page_lines << " </div>"
29
32
  index_page_lines << "</template>"
30
33
  index_page_lines.join("\n")
31
34
  end
@@ -36,17 +39,17 @@ module RailsVueGenerator
36
39
  lines << "<script>"
37
40
  lines << "import {mapState} from 'vuex'"
38
41
  lines << "export default {"
39
- lines << "name: '#{model_name}-edit',"
40
- lines << "computed:{"
41
- lines << "...mapState({"
42
- lines << "#{model_name.pluralize}: state => state.#{model_name}.all,"
43
- lines << "loading: state => state.#{model_name}.loading.all"
44
- lines << "}),"
45
- lines << "},"
46
- lines << "created() {"
47
- lines << "this.$store.dispatch('#{model_name}/getAll')"
42
+ lines << " name: '#{model_name}-edit',"
43
+ lines << " computed: {"
44
+ lines << " ...mapState({"
45
+ lines << " #{model_name.pluralize}: state => state.#{model_name}.all,"
46
+ lines << " loading: state => state.#{model_name}.loading.all"
47
+ lines << " })"
48
+ lines << " },"
49
+ lines << " created() {"
50
+ lines << " this.$store.dispatch('#{model_name}/getAll')"
51
+ lines << " }"
48
52
  lines << "}"
49
- lines << "};"
50
53
  lines << "</script>"
51
54
  lines.join("\n")
52
55
  end
@@ -1,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RailsVueGenerator
2
4
  module Handlers
3
5
  class RouterHandler < BaseHandler
4
6
  def generate
5
7
  routes = []
6
- routes << " {\n path: '/#{model_name.pluralize}',\n name: '#{model_name.pluralize}',\n component: () => import( /* webpackChunkName: \"#{model_name.pluralize}\" */ '@/views/#{model_name}/index.vue')\n },\n"
7
- routes << " {\n path: '/#{model_name}/new',\n name: 'new-#{model_name}',\n component: () => import( /* webpackChunkName: \"#{model_name.pluralize}\" */ '@/views/#{model_name}/edit.vue')\n },\n"
8
- routes << " {\n path: '/#{model_name}/:id',\n name: '#{model_name}',\n component: () => import( /* webpackChunkName: \"#{model_name.pluralize}\" */ '@/views/#{model_name}/show.vue')\n },\n"
9
- routes << " {\n path: '/#{model_name}/:id/edit',\n name: 'edit-#{model_name}',\n component: () => import( /* webpackChunkName: \"#{model_name.pluralize}\" */ '@/views/#{model_name}/edit.vue')\n },\n"
8
+ routes << " {\n path: '/#{model_name.pluralize}',\n name: '#{model_name.pluralize}',\n component: () => import( /* webpackChunkName: \"#{model_name.pluralize}\" */ '@/views/#{model_name}/index.vue')\n },\n"
9
+ routes << " {\n path: '/#{model_name}/new',\n name: 'new-#{model_name}',\n component: () => import( /* webpackChunkName: \"#{model_name.pluralize}\" */ '@/views/#{model_name}/edit.vue')\n },\n"
10
+ routes << " {\n path: '/#{model_name}/:id',\n name: '#{model_name}',\n component: () => import( /* webpackChunkName: \"#{model_name.pluralize}\" */ '@/views/#{model_name}/show.vue')\n ,\n"
11
+ routes << " {\n path: '/#{model_name}/:id/edit',\n name: 'edit-#{model_name}',\n component: () => import( /* webpackChunkName: \"#{model_name.pluralize}\" */ '@/views/#{model_name}/edit.vue')\n },\n"
10
12
  routes
11
13
  end
12
14
  end
@@ -3,23 +3,25 @@ module RailsVueGenerator
3
3
  class ShowHandler < BaseHandler
4
4
  def template
5
5
  show_page_lines = []
6
- show_page_lines << "<template><div>"
6
+ show_page_lines << "<template>"
7
+ show_page_lines << " <div>"
7
8
  ignored_columns = [:id]
8
- show_page_lines << "<div v-if='loading' class=\"spinner\">Loading #{model_name.titleize}</div>"
9
- show_page_lines << "<div v-else>"
10
- show_page_lines << "<table>"
9
+ show_page_lines << " <div v-if='loading' class=\"spinner\">Loading #{model_name.titleize}</div>"
10
+ show_page_lines << " <div v-else>"
11
+ show_page_lines << " <table>"
11
12
  @model.columns.reject { |column| IGNORED_COLUMNS.include?(column.name.to_sym) }.each do |column|
12
- show_page_lines << "<tr>"
13
- show_page_lines << "<th>#{column.name.titleize}</th><td>{{#{model_name}.#{column.name}}}</td>"
14
- show_page_lines << "</tr>"
13
+ show_page_lines << " <tr>"
14
+ show_page_lines << " <th>#{column.name.titleize}</th><td>{{#{model_name}.#{column.name}}}</td>"
15
+ show_page_lines << " </tr>"
15
16
  end
16
- show_page_lines << "</table>"
17
- show_page_lines << "<div>"
18
- show_page_lines << "<router-link :to=\"{name: 'edit-#{model_name}', params: {id: #{model_name}.id}}\">Edit</router-link>"
19
- show_page_lines << "<a href='#' @click='deleteRecord'>Delete</a>"
20
- show_page_lines << "</div>"
21
- show_page_lines << "</div>"
22
- show_page_lines << "</div></template>"
17
+ show_page_lines << " </table>"
18
+ show_page_lines << " <div>"
19
+ show_page_lines << " <router-link :to=\"{name: 'edit-#{model_name}', params: {id: #{model_name}.id}}\">Edit</router-link>"
20
+ show_page_lines << " <a href='#' @click='deleteRecord'>Delete</a>"
21
+ show_page_lines << " </div>"
22
+ show_page_lines << " </div>"
23
+ show_page_lines << " </div>"
24
+ show_page_lines << "</template>"
23
25
  show_page_lines.join("\n")
24
26
  end
25
27
 
@@ -30,11 +32,11 @@ module RailsVueGenerator
30
32
  lines << "import {mapState} from 'vuex'"
31
33
  lines << "export default {"
32
34
  lines << " name: '#{model_name}-show',"
33
- lines << " computed:{"
35
+ lines << " computed: {"
34
36
  lines << " ...mapState({"
35
37
  lines << " #{model_name}: state => state.#{model_name}.current,"
36
38
  lines << " loading: state => state.#{model_name}.loading.current"
37
- lines << " }),"
39
+ lines << " })"
38
40
  lines << " },"
39
41
  lines << " created() {"
40
42
  lines << " this.$store.dispatch('#{model_name}/get', this.$route.params.id)"
@@ -44,7 +46,7 @@ module RailsVueGenerator
44
46
  lines << " this.$store.dispatch('#{model_name}/delete', this.#{model_name}.id).then(function(response) {this.$router.push({name: '#{model_name.pluralize}'})}.bind(this))"
45
47
  lines << " }"
46
48
  lines << " }"
47
- lines << "};"
49
+ lines << "}"
48
50
  lines << "</script>"
49
51
  lines.join("\n")
50
52
  end
@@ -6,7 +6,6 @@ module RailsVueGenerator
6
6
  def generate
7
7
  lines = []
8
8
  lines << "import api from '@/api'"
9
- lines << "import router from '@/router'"
10
9
  lines << ''
11
10
  lines << 'const state = {'
12
11
  lines << ' current: {},'
@@ -59,7 +58,7 @@ module RailsVueGenerator
59
58
  lines << ' return responseData'
60
59
  lines << ' },'
61
60
  lines << ' clearCurrent({commit}) {'
62
- lines << ' commit("clearCurrent")'
61
+ lines << " commit('clearCurrent')"
63
62
  lines << ' }'
64
63
  lines << ''
65
64
  lines << '}'
@@ -8,7 +8,15 @@ module RailsVueGenerator
8
8
 
9
9
  def generate
10
10
  FileUtils.mkdir_p(@options[:path])
11
- File.write(File.join(@options[:path], @options[:filename]), "<template><div>" + models.map { |model| Handlers::NavigationHandler.new(model).generate }.join("\n") + "</div></template>")
11
+
12
+ nav_text = []
13
+ nav_text << "<template>"
14
+ nav_text << " <div>"
15
+ nav_text << models.map { |model| " #{Handlers::NavigationHandler.new(model).generate}" }.join("\n")
16
+ nav_text << " </div>"
17
+ nav_text << "</template>"
18
+
19
+ File.write(File.join(@options[:path], @options[:filename]), nav_text.join)
12
20
  end
13
21
  end
14
22
  end
@@ -12,7 +12,7 @@ module RailsVueGenerator
12
12
  models.each do |model|
13
13
  routes += Handlers::RouterHandler.new(model).generate
14
14
  end
15
- File.write(File.join(@options[:path], @options[:filename]), "import Vue from 'vue'\nimport VueRouter from 'vue-router'\nVue.use(VueRouter)\nconst routes = [" + routes.join + "]\nconst router = new VueRouter({\nmode: 'history',\nbase: process.env.BASE_URL,\nroutes\n})\nexport default router\n")
15
+ File.write(File.join(@options[:path], @options[:filename]), "import Vue from 'vue'\nimport VueRouter from 'vue-router'\nVue.use(VueRouter)\nconst routes = [\n" + routes.join + "\n]\nconst router = new VueRouter({\nmode: 'history',\nbase: process.env.BASE_URL,\nroutes\n})\nexport default router\n")
16
16
  end
17
17
  end
18
18
  end
@@ -1,3 +1,3 @@
1
1
  module RailsVueGenerator
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_vue_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stewart McKee
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-20 00:00:00.000000000 Z
11
+ date: 2021-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -77,7 +77,7 @@ homepage: ''
77
77
  licenses:
78
78
  - MIT
79
79
  metadata: {}
80
- post_install_message:
80
+ post_install_message:
81
81
  rdoc_options: []
82
82
  require_paths:
83
83
  - lib
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  version: '0'
94
94
  requirements: []
95
95
  rubygems_version: 3.1.2
96
- signing_key:
96
+ signing_key:
97
97
  specification_version: 4
98
98
  summary: Generates VueJS code based no models in rails
99
99
  test_files: []