class WebfaceGenerator

Public Instance Methods

add_node_modules_to_gitignore() click to toggle source
# File lib/generators/webface_generator.rb, line 47
def add_node_modules_to_gitignore
  `echo "spec/webface/node_modules"           >> #{@root_path}/.gitignore` unless File.read("#{@root_path}/.gitignore").include?("spec/webface/node_modules")
  `echo "app/assets/javascripts/node_modules" >> #{@root_path}/.gitignore` unless File.read("#{@root_path}/.gitignore").include?("app/assets/javascripts/node_modules")
end
add_webface() click to toggle source
# File lib/generators/webface_generator.rb, line 6
def add_webface
  @root_path = options["root_path"].present? ? options["root_path"] : Rails.root

  # We'll later change this to fetching webface.js as a node_module, but not now.
  gitmodules = File.readlines("#{@root_path}/.gitmodules") if File.file?("#{@root_path}/.gitmodules")

  if gitmodules.nil? || !gitmodules.join("\n").include?("webface.js.git")
    `rm -rf #{@root_path}/.git/modules/app/assets/javascripts/webface.js`
    `cd #{@root_path}/app/assets/javascripts/ && git submodule add git@gitlab.com:hodl/webface.js.git`
    gitmodules = File.readlines("#{@root_path}/.gitmodules") if File.file?("#{@root_path}/.gitmodules")
  end

  gitmodules.each do |line|
    if line.include?("webface") && line.include?("path =")
      @webface_path = line.strip.sub(/\Apath = /, "")
    end
  end
  puts "Webface path is #{@webface_path}"
end
copy_package_json() click to toggle source
# File lib/generators/webface_generator.rb, line 52
def copy_package_json
  copy_file "#{@root_path}/#{@webface_path}/package.json", "app/assets/javascripts/package.json"
  copy_file "#{@root_path}/#{@webface_path}/package-lock.json", "app/assets/javascripts/package-lock.json"
end
copy_unit_test_server() click to toggle source
# File lib/generators/webface_generator.rb, line 31
def copy_unit_test_server
  copy_file "webface_test_server.js", "spec/webface/test_server.js"
  copy_file "run_webface_test", "spec/webface/run_test"
  `chmod +x #{@root_path}/spec/webface/run_test`
  copy_file "mocha.css", "spec/webface/mocha.css"
  copy_file "mocha.pug", "spec/webface/mocha.pug"
  copy_file "test_utils.js", "spec/webface/test_utils.js"
  copy_file "webface.test.js", "spec/webface/webface.test.js"
  copy_file "webface_init.js", "spec/webface/webface_init.js"
  copy_file "test_animator.js", "spec/webface/test_animator.js"
  copy_file "my_component.test.js", "spec/webface/components/my_component.test.js"

  copy_file "application.js", "app/assets/javascripts/application.js"
  gsub_file "app/assets/javascripts/application.js", "path_to_webface", @webface_path.sub(/\A.*app\/assets\/javascripts\//, "") + "/lib"
end
create_webface_unit_test_dir() click to toggle source
# File lib/generators/webface_generator.rb, line 26
def create_webface_unit_test_dir
  `mkdir -p #{@root_path}/spec/webface/`
  `mkdir -p #{@root_path}/spec/webface/components/`
end
install_node_modules() click to toggle source
# File lib/generators/webface_generator.rb, line 65
def install_node_modules
  puts `cd #{@root_path}/app/assets/javascripts && npm i`
end

Private Instance Methods