Sha256: 5854ddeb3defdf4180811a938af6b84a2f45f4bb032dd6e8be1069f337773c37

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

class VueGenerator < Rails::Generators::NamedBase
  source_root File.expand_path('../../generator_templates', __FILE__)

  argument :name, :type => :string, :default => :index 
  class_option :single, type: :boolean, default: false
  class_option :vuex, type: :boolean, default: false
  # class_option :helpers, type: :boolean, default: false

  PACKS_PATH = "app/javascript/packs"
  PARTS_PATH = "app/javascript/parts"

  def vue 
    if options[:single] 
      create_single_file_component_using(name) 
    else 
      create_component_with_seperate_concern_using(name)
    end
      
    # options[:vuex] ? add_vuex_to_component(name) : nil
    # options[:helpers] ? add_helpers_to_component(name) : nil
  end

  private
  def add_helpers_to_component name
    puts "adding helpers"
  end

  def add_vuex_to_component name
    puts "adding vuex"
    # yarn add vuex
    # import vuex from 'vuex'
    # Vue.use(vuex)
    # Generate a vuex.html.erb
  end

  def create_component_with_seperate_concern_using name
    template "pack.js", "#{PACKS_PATH}/#{name}.js"      
    template "index.vue", "#{PARTS_PATH}/#{name}/#{name}.vue"    
    template "index.js", "#{PARTS_PATH}/#{name}/#{name}.js"
    copy_file "index.css", "#{PARTS_PATH}/#{name}/#{name}.css"
  end

  def create_single_file_component_using name
    template "pack.js", "#{PACKS_PATH}/#{name}.js" 
    template "single.vue", "#{PARTS_PATH}/#{name}.vue"    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vuejs-1.0.39 lib/generators/vue/vue_generator.rb