vue-helpers 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e3c19734771df336832f89bb1e02190086739b74
4
+ data.tar.gz: b7a9caaf7c527f55158bc847704980aaf7139dc1
5
+ SHA512:
6
+ metadata.gz: e39b54b722615ffeb26b4b8fcf97156d1ec7201816809283f96f64e7e0a2f868b4a048f7ab18664de6b2d64cd14cda65f2abc61f7d749046e9c3324d1643416b
7
+ data.tar.gz: b95e227d7091417dda0769553e5a69ee3769c49803935512fd57b06253f595b4cfb37db7015fb02cc9383537016c8ffa3b6a4b035fdeaae3afc569ba33d4e6a1
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /Gemfile.lock
10
+
11
+ .DS_Store
12
+ /vendor/
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 1.16.6
@@ -0,0 +1,19 @@
1
+ ## v0.1.0 (2019-01-04) Initial Release!
2
+
3
+ * Parse single-file-component.vue files.
4
+
5
+ * Automate Vue component and root boilerplate code.
6
+
7
+ * Package and send Vue-related code to the client.
8
+
9
+ * Compose Vue components with your favorite Ruby templating system.
10
+
11
+ * Use multiple Vue roots.
12
+
13
+ * Manage global-vs-local component registration.
14
+
15
+ * Customize the boilerplate code with your own templates.
16
+
17
+ * Pass variables and data to Vue root and component JS objects.
18
+
19
+ * Inline the rendered HTML/JS or serve it as an external script resource.
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in vue-helpers.gemspec
6
+ gemspec
7
+
8
+
9
+ # Include these in your project Gemfile (not this Gemfile), IF:
10
+ #
11
+ # You use option :external_resource => true.
12
+ # gem 'rack'
13
+ #
14
+ # You use option :minify => true.
15
+ # gem 'uglifier'
16
+ # Plus make sure your system has a javascript runtime installed (like nodejs).
17
+ #
18
+ # You want to use ruby template engines other that ERB.
19
+ # gem '<haml-or-whatever>'
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 William Richardson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,357 @@
1
+ # Vue::Helpers
2
+
3
+ Vue-helpers is a Ruby gem that provides helper methods for adding [VueJS](https://vuejs.org) functionality to your Ruby applications. Vue-helpers makes it easy to build Vue components and applications without getting mired in the technicalities of how to package and deploy. Vue-helpers does not depend on server-side Javascript processing, just Ruby.
4
+
5
+ #### Features at a glance:
6
+
7
+ * Parse single-file-component.vue files.
8
+ * Automate Vue component and root boilerplate code.
9
+ * Package and send Vue-related code to the client.
10
+ * Compose Vue components with your favorite Ruby templating system.
11
+ * Use multiple Vue roots.
12
+ * Manage global-vs-local component registration.
13
+ * Customize the boilerplate code with your own templates.
14
+ * Pass variables and data to Vue root and component JS objects.
15
+ * Inline the rendered HTML/JS or serve it as an external script resource.
16
+
17
+
18
+ #### Goals
19
+
20
+ The goal of vue-helpers is to get the primary features of VueJS in your front-end code with minimal setup and maintenance on the server side. Vue-helpers is not trying to replace backend JS tools like Webpack and Vue Loader. Rather, it aims to provide an easier path to get up and running.
21
+
22
+
23
+ #### Intended Audience
24
+
25
+ * You want to use VueJS components to build a responsive front-end experience, but you're not yet ready to dive into the full Javascript backend setup.
26
+
27
+ * Your main web application is coded in Ruby, but maybe not Rails, and you want to take advantage of VueJS on the front-end.
28
+
29
+ * You have an existing monolithic VueJS front-end (just a Vue root with no components), and you want to split your code into manageable components that can easily be reused and rearranged.
30
+
31
+ * You want your VueJS code to be processed through ERB, Haml, Slim, or any other templating engine supported by Tilt.
32
+
33
+
34
+ #### Simple Example
35
+
36
+ my\_view.html.erb:
37
+ ```erb
38
+ <%= vue_root do %>
39
+ <p>Everything in this block is part of the Vue app.</p>
40
+ <%= vue_component 'my-component', attributes: {color:'green', '@click':'doSomething'} do %>
41
+ <p>This block is passed to the component slot.</p>
42
+ <% end %>
43
+ <% end %>
44
+ ```
45
+ my-component.vue.erb *(a single-file-component)*
46
+ ```html
47
+ <template>
48
+ <div>
49
+ This will read green: {{ color }}.
50
+ <slot>This will be replaced with the component-call block text.</slot>
51
+ </div>
52
+ </template>
53
+ <script>
54
+ export default {
55
+ props: ['color'],
56
+ methods: {
57
+ doSomething: function () {alert('Yay!')}
58
+ }
59
+ }
60
+ </script>
61
+ ```
62
+
63
+ The rendered html contains the Vue app, the 'my-component' template & JS object (rendered from my-component.vue.erb) and the root Vue app, all packaged with the appropriate html tags for the browser. See below for more examples.
64
+
65
+
66
+ ## Requirements
67
+
68
+ * Ruby 2.3 or greater. Earlier versions of Ruby may work but are not tested.
69
+
70
+ * VueJS 2.0 or greater. Earlier versions of VueJS may work but are not tested.
71
+
72
+ The Vue-helpers gem officially supports Rails, Sinatra, and Rack applications using Erb, Haml, and Slim templating. In most cases, support for additional frameworks and templating libraries is easily integrated.
73
+
74
+
75
+ ## Installation
76
+
77
+ Add this line to your application's Gemfile:
78
+
79
+ ```ruby
80
+ gem 'vue-helpers', require: 'vue/helpers'
81
+ ```
82
+
83
+ And then execute:
84
+
85
+ $ bundle
86
+
87
+ Or install it yourself as:
88
+
89
+ $ gem install vue-helpers
90
+
91
+ Then make sure VueJS is loaded into your browser:
92
+
93
+ <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
94
+
95
+
96
+ #### Optional Requirements
97
+
98
+ If you want to serve VueJS javascript to your clients using external script resources,
99
+ Make sure ```rack``` is part of your gem set. You only need to consider this if you are not
100
+ using a Rack-based framework.
101
+
102
+ If you want to use the ```:minify``` option for compressing javascript output,
103
+ add the ```uglifier``` gem to your Gemfile.
104
+ Uglifier requires a Javascript runtime, so nodejs or equivalent will need to be installed on your server OS.
105
+
106
+
107
+ ## Setup
108
+ Setup for vue-helpers is relatively simple but differs slightly from framework to framework.
109
+
110
+ ### Rails
111
+ application\_helper.rb
112
+ ```ruby
113
+ require 'vue/helpers'
114
+
115
+ module ApplicationHelper
116
+ include Vue::Helpers
117
+ end
118
+ ```
119
+
120
+ config/initializers/middleware.rb (optional - if you want to serve the rendered JS as an external script)
121
+ ```ruby
122
+ require 'vue/helpers'
123
+
124
+ Rails::Application.configure do
125
+ config.middleware.use Vue::Helpers::Server
126
+ end
127
+ ```
128
+
129
+ ### Sinatra
130
+ app.rb
131
+ ```ruby
132
+ require 'vue/helpers'
133
+
134
+ class App << Sinatra::Base
135
+ helper Vue::Helpers
136
+
137
+ use Vue::Helpers::Server (optional)
138
+ end
139
+ ```
140
+
141
+ ### Rack
142
+ my\_rack\_app.rb
143
+ ```ruby
144
+ require 'vue/helpers'
145
+
146
+ class MyRackApp
147
+ include Vue::Helpers
148
+
149
+ def call(env)
150
+ ...
151
+ end
152
+ end
153
+ ```
154
+
155
+ config.ru
156
+ ```ruby
157
+ require 'vue/helpers'
158
+ require_relative 'my_rack_app'
159
+ require 'rack'
160
+
161
+ use Vue::Helpers::Server (optional)
162
+ run MyRackApp.new
163
+ ```
164
+
165
+
166
+ ## Generic Example
167
+
168
+ This generic example assumes you are using a rack-based framework and ERB templates.
169
+ Note that neither Rack nor ERB are required to use the vue-helpers gem.
170
+
171
+ your-app-helpers.rb
172
+ ```ruby
173
+ include Vue::Helpers
174
+ ```
175
+
176
+ views/foo.erb
177
+ ```erb
178
+ <h2>My Page of Interesting Info</h2>
179
+ <% vue_component 'my-component', attributes:{message:'Hello World!'} %>
180
+ <p>This block is sent to a Vue slot</p>
181
+ <% end %>
182
+ ```
183
+
184
+ views/my-component.vue.erb
185
+ ```erb
186
+ <template>
187
+ <div>
188
+ <p>This is a VueJS single-file-component {{ message }}</p>
189
+ <slot></slot>
190
+ </div>
191
+ </template>
192
+
193
+ <script>
194
+ export default {
195
+ props: ['message']
196
+ }
197
+ </script>
198
+
199
+ <!-- Scoped styles are a feature of the Vue Loader and are not supported (yet?) in the vue-helpers gem. -->
200
+ ```
201
+
202
+ views/layout.erb
203
+ ```erb
204
+ <html>
205
+ <head>
206
+ <script src="path/to/vuejs-2.0.js"></script>
207
+ </head>
208
+ <body>
209
+ <% vue_root do %>
210
+ <h1>My Vue App</h1>
211
+ <% yield %>
212
+ <% end %>
213
+ </body>
214
+ </html>
215
+ ```
216
+
217
+ Result sent to the browser:
218
+ ```html
219
+ <html>
220
+ <head>
221
+ <script src="path/to/vuejs-2.0.js"></script>
222
+ </head>
223
+ <body>
224
+ <div id="vue-root">
225
+ <h1>My Vue App</h1>
226
+ <h2>My Page of Interesting Info</h2>
227
+ <my-component message="Hello World!">
228
+ <p>This block is sent to a Vue slot</p>
229
+ </my-component>
230
+ </div>
231
+
232
+ <script>
233
+ var MyComponent = {
234
+ template: `
235
+ <div>
236
+ <p>This is a VueJS single-file-component {{ message }}</p>
237
+ <slot></slot>
238
+ </div>
239
+ `,
240
+ props: ['message']
241
+ };
242
+ var VueApp = new Vue({
243
+ el: "#vue-root",
244
+ components: {
245
+ MyComponent: MyComponent
246
+ }
247
+ })
248
+ </script>
249
+ </body></html>
250
+ ````
251
+
252
+ After VueJS parses the script body in the browser:
253
+ ```html
254
+ <html>
255
+ <head>
256
+ <script src="path/to/vuejs-2.0.js"></script>
257
+ </head>
258
+ <body>
259
+ <div id="vue-root">
260
+ <h1>My Vue App</h1>
261
+ <h2>My Page of Interesting Info</h2>
262
+ <div>
263
+ <p>This is a VueJS single-file-component Hello World!</p>
264
+ <p>This block is sent to a Vue slot</p>
265
+ </div>
266
+ </div>
267
+
268
+ <script>
269
+ ...
270
+ </script>
271
+ </body></html>
272
+ ```
273
+
274
+
275
+ ## Usage
276
+
277
+ There are only three methods in vue-helpers that you need to know:
278
+
279
+ ```ruby
280
+ vue_component(component-name, <optional-root-name>, <options-hash>, &block)
281
+
282
+ # Inserts/wraps block with Vue component tags...
283
+
284
+
285
+ vue_root(<root-app-name>, <options-hash>, &block)
286
+
287
+ # Inserts/wraps block with Vue root-app tags...
288
+
289
+
290
+ vue_app(<root-app-name>)
291
+
292
+ # Access the Ruby object model representing your Vue app(s) and components...
293
+
294
+ ```
295
+ *Sorry this section is sparse right now, more to come later.*
296
+
297
+ These methods parse your .vue files, insert Vue tags into your Ruby template, and package all the compiled boilerplate and JS code for delivery to the client (browser). You don't need to worry about where to inline your components, where to put the Vue root-app, or how to configure Webpack or Vue Loader.
298
+
299
+
300
+ ## Defaults
301
+
302
+ *This may eventually be replaced by a link to the file where defaults are defined.*
303
+
304
+ ```ruby
305
+ # module Vue::Helpers
306
+ @defaults = {
307
+ cache_store: {},
308
+ callback_prefix: '/vuecallback',
309
+ default_outvar: '@_erbout',
310
+ external_resource: false,
311
+ minify: false,
312
+ register_local: false,
313
+ root_name: 'vue-root',
314
+ template_engine: :erb,
315
+ template_literal: true,
316
+ views_path: ['views', 'app/views'],
317
+ vue_outvar: '@_vue_outvar',
318
+
319
+ component_call_html: '<#{el_name} #{attributes_string}>#{block_content}</#{el_name}>',
320
+ external_resource_html: '<script src="#{callback_prefix}/#{key}"></script>',
321
+ inline_script_html: '<script>#{compiled}</script>',
322
+ root_app_html: '<div id="#{root_name}">#{block_result}</div>#{root_script_output}',
323
+ root_object_js: 'var #{app_name} = new Vue({el: ("##{root_name}"), components: {#{components}}, data: #{vue_data_json}})',
324
+ x_template_html: '<script type="text/x-template" id="#{name}-template">#{template}</script>',
325
+ }
326
+ # end module VueHelpers
327
+ ```
328
+ Vue::Helpers defaults can be accessed as a hash on the @defaults instance variable:
329
+
330
+ ```ruby
331
+ Vue::Helpers.defaults[:views_path] << 'app/views/users'
332
+ Vue::Helpers.defaults[:register_local] = true
333
+ ```
334
+
335
+ Shortcut readers/writers are also available for Vue::Helpers defaults:
336
+
337
+ ```ruby
338
+ Vue::Helpers.views_path << 'app/views/users'
339
+ Vue::Helpers.register_local = true
340
+ ```
341
+
342
+
343
+ ## Development
344
+
345
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
346
+
347
+ 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).
348
+
349
+
350
+ ## Contributing
351
+
352
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ginjo/vue-helpers.
353
+
354
+
355
+ ## License
356
+
357
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).