lib/generators/vue/vue_generator.rb in vueonrails-1.0.0.beta1 vs lib/generators/vue/vue_generator.rb in vueonrails-1.0.0.beta2
- old
+ new
@@ -2,10 +2,11 @@
class VueGenerator < Rails::Generators::NamedBase
PACKS_PATH = "app/javascript/packs"
PARTS_PATH = "app/javascript/parts"
TESTS_PATH = "app/javascript/tests"
+ SSR_PATH = "app/javascript/ssr"
source_root File.expand_path('../../templates', __FILE__)
argument :name, type: :string, default: nil
@@ -16,12 +17,15 @@
tab: {type: :boolean, default: false},
list: {type: :boolean, default: false},
table: {type: :boolean, default: false},
modal: {type: :boolean, default: false},
click: {type: :boolean, default: false},
+ pug: {type: :boolean, default: false}
}.freeze
+ class_option :ssr, type: :string, default: nil
+
class_option :child, type: :string, default: nil
class_option :parent, type: :string, default: nil
class_option :seperate, type: :boolean, default: false
class_option :turbolinks, type: :boolean, default: false
@@ -30,11 +34,13 @@
end
def vue
return if name.empty?
- if options[:child]
+ if options[:ssr]
+ add_ssr_component()
+ elsif options[:child]
adding_nested_component(:child, name, nil, options[:child])
elsif options[:parent]
adding_nested_component(:parent, name, options[:parent], nil)
else
if options[:seperate]
@@ -91,9 +97,17 @@
def adding_nested_component(example, name, parent, child)
namespace = OpenStruct.new(TESTS_PATH: TESTS_PATH, PARTS_PATH: PARTS_PATH, PACKS_PATH: PACKS_PATH, name: name, child: child, parent: parent)
template = File.read(File.expand_path("../options/#{example}.rb", __dir__))
erbtemplate = ERB.new(template).result(namespace.instance_eval { binding })
eval erbtemplate
+ end
+
+ def add_ssr_component()
+ namespace = OpenStruct.new(SSR_PATH: SSR_PATH)
+ template = File.read(File.expand_path("../options/ssr.rb", __dir__))
+ erbtemplate = ERB.new(template).result(namespace.instance_eval { binding })
+ eval erbtemplate
+
end
def add_to_component(example, name)
namespace = OpenStruct.new(TESTS_PATH: TESTS_PATH, PARTS_PATH: PARTS_PATH, PACKS_PATH: PACKS_PATH, name: name)
template = File.read(File.expand_path("../options/#{example}.rb", __dir__))