vueonrails 1.0.0.beta1 → 1.0.0.beta2

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: 71a42cb10863a34abfe26b347c8e643b9b412fdadcb70010489798e9dabdab92
4
- data.tar.gz: eeef1a565c5687655ed8772e645d039530f5650e6c51ec0e7ca2a96859bd5514
3
+ metadata.gz: db191c0206d670d87864af0aa9a9c72b14bf900cb69484de1c17a670625c3ace
4
+ data.tar.gz: 5631b0e8d8c9af119048f86b7f3e64bfe2943123b474b3ed30482d38f4708103
5
5
  SHA512:
6
- metadata.gz: ea2fb2986ef56e7da2fc1bc3b19f61d3529f7f3aa0ff8c78a0df20b534a50087e17990ef5444933c6166bee270a59c80880e598be5aca2d30020558cde871975
7
- data.tar.gz: 1c9f50475bdfbdcd190baabafc582c6a748ad3eef02d82fc416a3777db42d4d674323db97930e8a193f143b883c73c764617ce4e39d2e40e683972d4155ca5da
6
+ metadata.gz: e9df496e99bdd437dfff15979b016ed5e409a26ce94c0188404887b063216e8f5a02760526a684372f5273c1798eb666e9d572ec76c0be6a7d07ec07b1c6c604
7
+ data.tar.gz: 91262456fc0092fa9b0bca55cac34b1230fcfb763d50c45f7f8e7c577ee93c48772367f106c3ff7fe0271792ee240e3cc3fbf82f5532236f6cfc88b349e2fbdf
data/README.md CHANGED
@@ -1,11 +1,12 @@
1
- # Welcome to Vue on Rails 💎
1
+ ![vue on rails](https://vueonrails.com/assets/img/vueonrails.png)
2
2
 
3
3
  > Vue for your favorite Rails projects
4
4
 
5
5
  The Vue on Rails gem makes it easy to build Vue components on your Rails application.
6
6
 
7
- It uses Rails 5.x, Vue 2.x, Webpacker 3.x, Ruby 2.x, Node 11.x, Yarn 1.12.x.
7
+ It uses Rails 5.x, Vue 2.x, Webpacker 4.x, Ruby 2.x, Node 11.x, Yarn 1.12.x.
8
8
 
9
+ - ❄️ Server Side Rendering using Hypernova
9
10
  - 💎 Compatible with Rails 6/5/4 and Webpacker
10
11
  - 🌎 Internationalization for component parts
11
12
  - 🖖 Vue UI ready
@@ -1,3 +1,5 @@
1
+ require 'hypernova'
2
+
1
3
  module SyntaxHelper
2
4
  def specific_page_vue
3
5
  " #{controller_name} #{action_name} "
@@ -25,4 +27,9 @@ module SyntaxHelper
25
27
  }; nil
26
28
  end
27
29
  end
30
+
31
+ #server side rendering via hypernova
32
+ def render_vue(id, name)
33
+ render_react_component(id, name: name)
34
+ end
28
35
  end
@@ -0,0 +1,14 @@
1
+ pugtemplate = <<-eos
2
+ <template lang="pug">
3
+ ##{name}
4
+ p {{ message }}
5
+ </template>
6
+ eos
7
+
8
+ if options[:seperate] == true
9
+ gsub_file Rails.root.join("#{PARTS_PATH}/#{name}/#{name}.vue").to_s,
10
+ /<template>[^\]]*<\/template>/, pugtemplate
11
+ else
12
+ gsub_file Rails.root.join("#{PARTS_PATH}/#{name}.vue").to_s,
13
+ /<template>[^\]]*<\/template>/, pugtemplate
14
+ end
@@ -0,0 +1,10 @@
1
+ template "ssr/component.js.erb", "#{SSR_PATH}/#{name}.js"
2
+
3
+ puts "\nAdd the following line into your ssr.js:
4
+
5
+ getComponent(name) {
6
+ // Add this!
7
+ if (name === '#{name}.js') {
8
+ return require('./app/javascript/ssr/#{name}.js')
9
+ }
10
+ "
@@ -0,0 +1,11 @@
1
+ // Generated by Vue on Rails https://github.com/vueonrails/vueonrails
2
+ // Embed this component
3
+ // To generate this component, run `rails generate vue something --ssr`
4
+
5
+ console.log("Hello, <%= name %>")
6
+ const Vue = require("vue")
7
+ const renderVue = require("hypernova-vue").renderVue
8
+ const component = Vue.extend({
9
+ template: '<h1>hello, <%= name %></h1>'
10
+ })
11
+ module.exports = renderVue("<%= name %>.js", component)
@@ -4,6 +4,7 @@ class VueGenerator < Rails::Generators::NamedBase
4
4
  PACKS_PATH = "app/javascript/packs"
5
5
  PARTS_PATH = "app/javascript/parts"
6
6
  TESTS_PATH = "app/javascript/tests"
7
+ SSR_PATH = "app/javascript/ssr"
7
8
 
8
9
  source_root File.expand_path('../../templates', __FILE__)
9
10
 
@@ -18,8 +19,11 @@ class VueGenerator < Rails::Generators::NamedBase
18
19
  table: {type: :boolean, default: false},
19
20
  modal: {type: :boolean, default: false},
20
21
  click: {type: :boolean, default: false},
22
+ pug: {type: :boolean, default: false}
21
23
  }.freeze
22
24
 
25
+ class_option :ssr, type: :string, default: nil
26
+
23
27
  class_option :child, type: :string, default: nil
24
28
  class_option :parent, type: :string, default: nil
25
29
  class_option :seperate, type: :boolean, default: false
@@ -32,7 +36,9 @@ class VueGenerator < Rails::Generators::NamedBase
32
36
  def vue
33
37
  return if name.empty?
34
38
 
35
- if options[:child]
39
+ if options[:ssr]
40
+ add_ssr_component()
41
+ elsif options[:child]
36
42
  adding_nested_component(:child, name, nil, options[:child])
37
43
  elsif options[:parent]
38
44
  adding_nested_component(:parent, name, options[:parent], nil)
@@ -95,6 +101,14 @@ class VueGenerator < Rails::Generators::NamedBase
95
101
  eval erbtemplate
96
102
  end
97
103
 
104
+ def add_ssr_component()
105
+ namespace = OpenStruct.new(SSR_PATH: SSR_PATH)
106
+ template = File.read(File.expand_path("../options/ssr.rb", __dir__))
107
+ erbtemplate = ERB.new(template).result(namespace.instance_eval { binding })
108
+ eval erbtemplate
109
+
110
+ end
111
+
98
112
  def add_to_component(example, name)
99
113
  namespace = OpenStruct.new(TESTS_PATH: TESTS_PATH, PARTS_PATH: PARTS_PATH, PACKS_PATH: PACKS_PATH, name: name)
100
114
  template = File.read(File.expand_path("../options/#{example}.rb", __dir__))
@@ -0,0 +1,3 @@
1
+ # Insert locale.js as a default i18n and add second locale cn.yml
2
+ copy_file "#{__dir__}/../generators/templates/i18n/index.js", Rails.root.join("app/javascript/locales/locale.js").to_s
3
+ copy_file "#{__dir__}/../generators/templates/i18n/cn.yml", Rails.root.join("config/locales/cn.yml").to_s
@@ -0,0 +1,15 @@
1
+ // Generated by Vue on Rails https://github.com/vueonrails/vueonrails
2
+ // This is required to support Pug in Vue on Rails.
3
+
4
+ module.exports = {
5
+ test: /\.pug$/,
6
+ oneOf: [
7
+ {
8
+ resourceQuery: /^\?vue/,
9
+ use: ['pug-plain-loader']
10
+ },
11
+ {
12
+ use: ['raw-loader', 'pug-plain-loader']
13
+ }
14
+ ]
15
+ }
@@ -0,0 +1,12 @@
1
+ # install pug dependencies
2
+ run "yarn add pug pug-plain-loader"
3
+
4
+ # add the pug loader
5
+ copy_file "#{__dir__}/loaders/pug.js", Rails.root.join("config/webpack/loaders/pug.js").to_s
6
+
7
+ # insert pug into the environment.js
8
+ insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
9
+ "const pug = require('./loaders/pug')\n", after: "require('@rails/webpacker')\n"
10
+
11
+ insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
12
+ "environment.loaders.prepend('pug', pug)\n", before: "module.exports = environment"
@@ -1,3 +1,29 @@
1
+ # Check for the lack of .babelrc or webpacker 4
2
+ def check_version_and_babel
3
+ #should i check for evidence of webpacker:install?
4
+ File.exists?(Rails.root.join(".babelrc")) == false \
5
+ || (Gem.loaded_specs["webpacker"].version < Gem::Version.new('4.x')) == false
6
+ end
7
+
8
+ begin
9
+ if(check_version_and_babel)
10
+ say "You are using Vue on Rails #{Vueonrails::VERSION} and it does not support webpacker 4.
11
+
12
+ Please use the latest Vue on Rails (1.x) in your Gemfile:
13
+ gem 'webpacker', '~> 4.x'
14
+ gem 'vueonrails', '~> 1.x'
15
+
16
+ or switch back to webpacker 3:
17
+ gem 'webpacker', '~> 3.x'
18
+ gem 'vueonrails', '~> 0.x'", :yellow
19
+ exit!
20
+ end
21
+ rescue Errno::ENOENT => e
22
+ say "You need webpacker 4."
23
+ exit!
24
+ end
25
+
26
+ # the start of the setup script
1
27
  say "Adding vueonrails, internationalization, @vue/test-utils and other Jest devdependencies"
2
28
  run "yarn add vueonrails vue-i18n @vue/test-utils jest jest-serializer-vue vue-jest babel-jest --dev"
3
29
 
@@ -11,6 +37,7 @@ pack_tag = <<-eos
11
37
  <%= javascript_pack_tag 'application' %>
12
38
  <%= stylesheet_pack_tag 'application' %>
13
39
  eos
40
+
14
41
  insert_into_file Rails.root.join("app/views/layouts/application.html.erb").to_s,
15
42
  pack_tag, before: " </head>\n"
16
43
 
File without changes
@@ -0,0 +1,7 @@
1
+ console.log("hello, component")
2
+ const Vue = require("vue")
3
+ const renderVue = require("hypernova-vue").renderVue
4
+ const component = Vue.extend({
5
+ template: '<h1>hello world</h1>'
6
+ })
7
+ module.exports = renderVue("component.js", component)
@@ -0,0 +1,9 @@
1
+ require 'hypernova'
2
+ require 'hypernova/plugins/development_mode_plugin'
3
+
4
+ Hypernova.add_plugin!(DevelopmentModePlugin.new)
5
+
6
+ Hypernova.configure do |config|
7
+ config.host = "0.0.0.0"
8
+ config.port = 7777 # The port where the node service is listening
9
+ end
@@ -0,0 +1,13 @@
1
+ var hypernova = require('hypernova/server');
2
+
3
+ hypernova({
4
+ devMode: true,
5
+ getComponent(name) {
6
+ // console.log("The component name is -> " + name)
7
+ if (name === 'component.js') {
8
+ return require('./app/javascript/ssr/component.js')
9
+ }
10
+ return null;
11
+ },
12
+ port: 7777,
13
+ });
@@ -0,0 +1,26 @@
1
+ # Check that webpacker + vueonrails are installed before proceeding
2
+ begin
3
+ $stdout.puts "Webpacker: #{Webpacker::VERSION}"
4
+ rescue NameError
5
+ $stdout.puts "Webpacker: Not installed"
6
+ end
7
+
8
+ # install the dependencies
9
+ gem 'hypernova'
10
+ run "yarn add hypernova hypernova-vue vue-server-renderer"
11
+
12
+ #insert the application helper and also import
13
+ insert_into_file Rails.root.join("app/controllers/application_controller.rb").to_s,
14
+ "require 'hypernova'\n", before: "class"
15
+
16
+ insert_into_file Rails.root.join("app/controllers/application_controller.rb").to_s,
17
+ "around_action :hypernova_render_support\n", before: "end"
18
+
19
+ # copy the configuration file into config/initializer
20
+ copy_file "#{__dir__}/ssr/hypernova.rb", Rails.root.join("config/initializers/hypernova.rb").to_s
21
+
22
+ # copy hypernova.js to the project root level
23
+ copy_file "#{__dir__}/ssr/ssr.js", Rails.root.join("ssr.js").to_s
24
+
25
+ # copy the first component server-rendered into the
26
+ copy_file "#{__dir__}/ssr/component.js", Rails.root.join("app/javascript/ssr/component.js").to_s
@@ -0,0 +1,2 @@
1
+ # Insert store.js as a simple store for components' state
2
+ copy_file "#{__dir__}/../generators/templates/stores/index.js", Rails.root.join("app/javascript/parts/store.js").to_s
data/lib/installs/test.rb CHANGED
@@ -28,16 +28,4 @@ insert_into_file Rails.root.join("package.json").to_s,
28
28
  "#{scripts}",
29
29
  after: "\"private\": true,\n"
30
30
 
31
- babelrc = <<-eos
32
- "test": {
33
- "presets": [
34
- ["env", { "targets": { "node": "current" }}]
35
- ]
36
- },
37
- eos
38
-
39
- insert_into_file Rails.root.join(".babelrc").to_s,
40
- "#{babelrc}",
41
- before: " \"presets\": ["
42
-
43
- run "yarn add jest-serializer-vue vue-jest babel-jest --no-progress --silent"
31
+ run "yarn add jest-serializer-vue vue-jest babel-jest --no-progress --silent"
data/lib/installs/ui.rb CHANGED
@@ -1 +1,37 @@
1
- run "yarn list @vue/cli-service --no-progress --silent"
1
+ # Jest and scripts configuration. Essential for Jest test and Vue Ui
2
+ scripts = <<-eos
3
+ "scripts": {
4
+ "yarn test": "jest",
5
+ "yarn install": "yarn install --check-files",
6
+ "rails assets:precompile": "yarn install --check-files; rails assets:precompile",
7
+ "rails server": "rails server",
8
+ "webpack-dev-server": "./bin/webpack-dev-server"
9
+ },
10
+ "jest": {
11
+ "moduleFileExtensions": [
12
+ "js",
13
+ "vue"
14
+ ],
15
+ "moduleNameMapper": {
16
+ "^@/(.*)$": "<rootDir>/app/javascript/parts/$1"
17
+ },
18
+ "transform": {
19
+ "^.+\\\\\\.js$": "<rootDir>/node_modules/babel-jest",
20
+ ".*\\\\\\.(vue)$": "<rootDir>/node_modules/vue-jest"
21
+ },
22
+ "transformIgnorePatterns": [
23
+ "node_modules/(?!(vueonrails)/)"
24
+ ],
25
+ "testPathIgnorePatterns": [
26
+ "<rootDir>/config/webpack/"
27
+ ],
28
+ "snapshotSerializers": [
29
+ "<rootDir>/node_modules/jest-serializer-vue"
30
+ ]
31
+ },
32
+ eos
33
+
34
+ insert_into_file Rails.root.join("package.json").to_s,
35
+ scripts, after: "\"private\": true,\n"
36
+
37
+ puts "Vue UI Ready!"
@@ -2,7 +2,7 @@ namespace :vue do
2
2
  desc "Translate Rails' locale into Vue's locale"
3
3
  task :translate do
4
4
  Dir.foreach("config/locales/").each do |locale|
5
- next if locale == '.' or locale == '..'
5
+ next if File.extname(locale).strip.downcase != ".yml"
6
6
  config = YAML.load_file("config/locales/#{locale}")
7
7
  name = locale.to_s.split('.').first if locale.to_s.split('.') != nil
8
8
  if name != nil
@@ -16,4 +16,4 @@ namespace :vue do
16
16
  end
17
17
  end
18
18
  end
19
- end
19
+ end
data/lib/tasks/vue.rake CHANGED
@@ -1,13 +1,15 @@
1
1
  bin_path = ENV["BUNDLE_BIN"] || "./bin"
2
2
 
3
3
  TASKS = {
4
- locale: "install vue-i18n",
4
+ spv: "Install Specific-page Vue",
5
+ store: "Install simple state management",
6
+ i18n: "Install i18n dependencies",
7
+ ssr: "Install server-side rendering using hypernova",
8
+ setup: "Setup and install Vue on Rails dependencies",
9
+ test: "Install Jest tests",
10
+ ui: "Check if Vue-ui is installed",
11
+ vuex: "Check if Vuex is installed",
5
12
  turbolinks: "Check Vue-turbolinks ready",
6
- setup: "Check Vue on Rails ready",
7
- test: "Check Jest tests ready",
8
- vuex: "Check Vuex ready",
9
- ui: "Check Vue-ui ready",
10
- specific_page_vue: "Check Specific-page Vue ready?"
11
13
  }.freeze
12
14
 
13
15
  namespace :vue do
@@ -1,3 +1,3 @@
1
1
  module Vueonrails
2
- VERSION = "1.0.0.beta1"
2
+ VERSION = "1.0.0.beta2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vueonrails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta1
4
+ version: 1.0.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Lim
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-07 00:00:00.000000000 Z
11
+ date: 2019-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -57,8 +57,10 @@ files:
57
57
  - lib/generators/options/list.rb
58
58
  - lib/generators/options/modal.rb
59
59
  - lib/generators/options/parent.rb
60
+ - lib/generators/options/pug.rb
60
61
  - lib/generators/options/seperate.rb
61
62
  - lib/generators/options/single.rb
63
+ - lib/generators/options/ssr.rb
62
64
  - lib/generators/options/table.rb
63
65
  - lib/generators/options/test.rb
64
66
  - lib/generators/options/turbolinks_seperate.rb
@@ -72,6 +74,7 @@ files:
72
74
  - lib/generators/templates/packs/index.vue
73
75
  - lib/generators/templates/packs/pack.js.erb
74
76
  - lib/generators/templates/single_file_components/index.vue
77
+ - lib/generators/templates/ssr/component.js.erb
75
78
  - lib/generators/templates/stores/index.js
76
79
  - lib/generators/templates/tests/index.js.erb
77
80
  - lib/generators/templates/turbolinks/index.js.erb
@@ -79,9 +82,16 @@ files:
79
82
  - lib/generators/vue/vue_generator.rb
80
83
  - lib/installs/Procfile
81
84
  - lib/installs/config/alias.js
82
- - lib/installs/locale.rb
85
+ - lib/installs/i18n.rb
86
+ - lib/installs/loaders/pug.js
87
+ - lib/installs/pug.rb
83
88
  - lib/installs/setup.rb
84
- - lib/installs/specific_page_vue.rb
89
+ - lib/installs/spv.rb
90
+ - lib/installs/ssr.rb
91
+ - lib/installs/ssr/component.js
92
+ - lib/installs/ssr/hypernova.rb
93
+ - lib/installs/ssr/ssr.js
94
+ - lib/installs/store.rb
85
95
  - lib/installs/test.rb
86
96
  - lib/installs/turbolinks.rb
87
97
  - lib/installs/ui.rb
@@ -111,8 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
121
  - !ruby/object:Gem::Version
112
122
  version: 1.3.1
113
123
  requirements: []
114
- rubyforge_project:
115
- rubygems_version: 2.7.6
124
+ rubygems_version: 3.0.3
116
125
  signing_key:
117
126
  specification_version: 4
118
127
  summary: Vue on Rails https://vueonrails.com
@@ -1 +0,0 @@
1
- run "yarn add vue-i18n"