vue-generators 0.1.1 → 0.1.2

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: 7111d3c1bf4eb4b6f78b8ddc14fd15069cd577b035e7f49faacd4ea23522783d
4
- data.tar.gz: 58248b82ab40d0ea8eb7d58b753b783adde13143dd6276979c4705d82a7c58c9
3
+ metadata.gz: 8ca22a1be57230f90cb0848c49db99329c9cb4eb3eebc90f30e797b98347dc95
4
+ data.tar.gz: 30f654be8f2d389b3f17ded84a6d5c23e90fbbe4a09fb2f4724e57041e5f4a90
5
5
  SHA512:
6
- metadata.gz: affc94a7d4ff54352a5427f7d6bb5aa775bf0c28def06b0ccafd6b46698d3ed7980da9b8155aee34844e37cf048a6674ed05cb73020df3a3aec7895bd6daf0d7
7
- data.tar.gz: 261ce989780e1abe7bd40c514cdbfd0b9a9f10e61480d4957318af7694ce1443d21bf2f4337713cf39d37a767018b70a491e92fe19dcd85e4be6ca0e2de11a19
6
+ metadata.gz: 9d4d78678668437f5694f7a383a17da40f1fbfaa2057f81a75c7d547c3ffea7ea0e6e41e23e1f9bcb952b396edc117330ef1118bca3ac0cace0bca91c390a3ea
7
+ data.tar.gz: 0bacaedd570143d4605a0bbd801eab4e0971ebe05eee83c48d7ea27a2176338a319656a3e7c23427a10947fad32ab966568ec588842f47069a1c9abd30ccbfba
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.1.2
2
+
3
+ * Add store generation
4
+
1
5
  ## 0.1.1
2
6
 
3
7
  * Fix mixin generation path
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Vue::Generators
2
- vue-generators is an opinionated library for generating Vue components and mixins
3
- for a Rails project.
2
+ vue-generators is an opinionated library for generating Vue components, mixins,
3
+ and stores for a Rails project.
4
4
 
5
5
  ## Usage
6
6
 
@@ -8,6 +8,7 @@ for a Rails project.
8
8
  ```bash
9
9
  rails g vue:component -h
10
10
  rails g vue:mixin -h
11
+ rails g vue:store -h
11
12
  ```
12
13
 
13
14
  ### Generate a component
@@ -16,7 +17,9 @@ rails g vue:mixin -h
16
17
  rails g vue:component ButtonCounter
17
18
  ```
18
19
 
19
- *This will generate `app/javascript/components/ButtonCounter.vue`*
20
+ **This will generate:**
21
+
22
+ *`app/javascript/components/ButtonCounter.vue`*
20
23
  ```JavaScript
21
24
  <template>
22
25
  <div>
@@ -80,8 +83,9 @@ export default {
80
83
  ```bash
81
84
  rails g vue:mixin MyMixin
82
85
  ```
86
+ **This will generate:**
83
87
 
84
- *This will generate `app/javascript/mixins/MyMixin.js`*
88
+ *`app/javascript/mixins/MyMixin.js`*
85
89
 
86
90
  ```JavaScript
87
91
  export default {
@@ -120,6 +124,59 @@ export default {
120
124
  },
121
125
  }
122
126
  ```
127
+ ### Generate a store
128
+
129
+ ```bash
130
+ rails g vue:store Application
131
+ ```
132
+
133
+ **This will generate:**
134
+
135
+ *`app/javascript/application/store/Store.js`*
136
+ ```JavaScript
137
+ import { actions } from "./actions"
138
+ import { getters } from "./getters"
139
+ import { mutations } from "./mutations"
140
+ import { state } from "./state"
141
+
142
+ export default {
143
+ namespaced: true,
144
+
145
+ actions: actions,
146
+ getters: getters,
147
+ mutations: mutations,
148
+ state: state
149
+ }
150
+ ```
151
+
152
+ *`app/javascript/application/store/actions.js`*
153
+ ```JavaScript
154
+ export const actions = {
155
+
156
+ }
157
+ ```
158
+
159
+ *`app/javascript/application/store/getters.js`*
160
+ ```JavaScript
161
+ export const getters = {
162
+
163
+ }
164
+ ```
165
+
166
+ *`app/javascript/application/store/mutations.js`*
167
+ ```JavaScript
168
+ export const mutations = {
169
+ }
170
+
171
+ ```
172
+
173
+ *`app/javascript/application/store/state.js`*
174
+ ```JavaScript
175
+ export const state = {
176
+
177
+ }
178
+ ```
179
+
123
180
 
124
181
  ## Installation
125
182
  Add this line to your application's Gemfile:
@@ -1,5 +1,5 @@
1
1
  module Vue
2
2
  module Generators
3
- VERSION = '0.1.1'
3
+ VERSION = '0.1.2'
4
4
  end
5
5
  end
@@ -0,0 +1,23 @@
1
+ Description:
2
+ Generates a namespaced, blank Vuex store split into multiple files
3
+
4
+ Example:
5
+ rails generate vue:store Application
6
+
7
+ This will create:
8
+ app/javascript/application/store/Store.js
9
+ app/javascript/application/store/actions.js
10
+ app/javascript/application/store/getters.js
11
+ app/javascript/application/store/mutations.js
12
+ app/javascript/application/store/state.js
13
+
14
+ Example:
15
+ rails generate vue:store pets/Kittens
16
+
17
+ This will create:
18
+ app/javascript/pets/kittens/store/Store.js
19
+ app/javascript/pets/kittens/store/actions.js
20
+ app/javascript/pets/kittens/store/getters.js
21
+ app/javascript/pets/kittens/store/mutations.js
22
+ app/javascript/pets/kittens/store/state.js
23
+
@@ -0,0 +1,24 @@
1
+ module Vue
2
+ class StoreGenerator < Rails::Generators::NamedBase
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def generate_store
6
+ [
7
+ 'Store', 'actions', 'getters', 'mutations', 'state'
8
+ ].each do |template|
9
+ template "#{template}.template", Rails.root.join("app", "javascript", *path, "#{template}.js")
10
+ end
11
+ end
12
+
13
+ private
14
+ def store_name
15
+ # name is from Rails::Generators::NamedBase which expects a single argument to the generator
16
+ store = name.split("/").last
17
+ store.camelize(:lower) # makesTheFirstLetterLowerCase
18
+ end
19
+
20
+ def path
21
+ name.split("/").map {|part| part.underscore.tr('_', '-') } + ['store']
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,27 @@
1
+ import { actions } from "./actions"
2
+ import { getters } from "./getters"
3
+ import { mutations } from "./mutations"
4
+ import { state } from "./state"
5
+
6
+ // https://vuex.vuejs.org/guide/
7
+ //
8
+ // At the center of every Vuex application is the store. A "store" is basically a
9
+ // container that holds your application state. There are two things that make a
10
+ // Vuex store different from a plain global object:
11
+ //
12
+ // Vuex stores are reactive. When Vue components retrieve state from it, they will
13
+ // reactively and efficiently update if the store's state changes.
14
+ //
15
+ // You cannot directly mutate the store's state. The only way to change a store's
16
+ // state is by explicitly committing mutations. This ensures every state change
17
+ // leaves a track-able record, and enables tooling that helps us better understand
18
+ // our applications
19
+ //
20
+ export default {
21
+ namespaced: true,
22
+
23
+ actions: actions,
24
+ getters: getters,
25
+ mutations: mutations,
26
+ state: state
27
+ }
@@ -0,0 +1,18 @@
1
+ // https://vuex.vuejs.org/guide/actions.html
2
+ //
3
+ // Actions are similar to mutations, the differences being that:
4
+ // - Instead of mutating the state, actions commit mutations.
5
+ // - Actions can contain arbitrary asynchronous operations.
6
+ //
7
+ // Action handlers receive a context object which exposes the same set of
8
+ // methods/properties on the store instance, so you can call context.commit to
9
+ // commit a mutation, or access the state and getters via context.state and
10
+ // context.getters. We can even call other actions with context.dispatch
11
+ //
12
+ // Mutations have to be synchronous. Actions don't
13
+ export const actions = {
14
+ // // this.$store.dispatch('<%= store_name %>/createPost', { .. } )
15
+ // createPost(context, payload) {
16
+ // ...
17
+ // },
18
+ }
@@ -0,0 +1,15 @@
1
+ // https://vuex.vuejs.org/guide/getters.html
2
+ //
3
+ // Getters provide a way to re-use a computation of derived state. Getters
4
+ // are like computed properties for stores. A getter's result is cached based
5
+ // on its dependencies, and will only re-evaluate when some of its dependencies
6
+ // have changed.
7
+ //
8
+ export const getters = {
9
+ // /**
10
+ // * getters['<%= store_name %>/counter']
11
+ // */
12
+ // counter: (state) => () => {
13
+ // return state.counter
14
+ // },
15
+ }
@@ -0,0 +1,16 @@
1
+ // https://vuex.vuejs.org/guide/mutations.html
2
+ //
3
+ // The only way to actually change state in a Vuex store is by committing a
4
+ // mutation. Vuex mutations are very similar to events: each mutation has a
5
+ // string type and a handler. The handler function is where we perform actual
6
+ // state modifications, and it will receive the state as the first argument
7
+ //
8
+ // One important rule to remember is that mutation handler functions must be
9
+ // synchronous
10
+ //
11
+ export const mutations = {
12
+ // // this.$store.commit('<%= store_name %>/incrementCounter', 42 )
13
+ // setCounter(state, payload) {
14
+ // state.counter = payload
15
+ // },
16
+ }
@@ -0,0 +1,12 @@
1
+ // https://vuex.vuejs.org/guide/state.html
2
+ //
3
+ // Vuex uses a single state tree - that is, this single object contains all your
4
+ // application level state and serves as the "single source of truth.
5
+ //
6
+ export const state = {
7
+ // // this.$store.state.<%= store_name %>.posts
8
+ // posts: [],
9
+
10
+ // // this.$store.state.<%= store_name %>.counter
11
+ // counter: 0
12
+ }
@@ -1,2 +1,3 @@
1
1
  require "vue/generators/vue/component/component_generator.rb"
2
2
  require "vue/generators/vue/mixin/mixin_generator.rb"
3
+ require "vue/generators/vue/store/store_generator.rb"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vue-generators
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Naegle
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-01 00:00:00.000000000 Z
11
+ date: 2019-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -59,6 +59,13 @@ files:
59
59
  - lib/vue/generators/vue/mixin/USAGE
60
60
  - lib/vue/generators/vue/mixin/mixin_generator.rb
61
61
  - lib/vue/generators/vue/mixin/templates/Mixin.template
62
+ - lib/vue/generators/vue/store/USAGE
63
+ - lib/vue/generators/vue/store/store_generator.rb
64
+ - lib/vue/generators/vue/store/templates/Store.template
65
+ - lib/vue/generators/vue/store/templates/actions.template
66
+ - lib/vue/generators/vue/store/templates/getters.template
67
+ - lib/vue/generators/vue/store/templates/mutations.template
68
+ - lib/vue/generators/vue/store/templates/state.template
62
69
  homepage: https://github.com/GoodMeasuresLLC/vue-generators
63
70
  licenses:
64
71
  - MIT