class Granule::Feature::SemanticReact

Constants

APPLICATION_HTML_ERB_PATH
APPLICATION_JS_PATH
PACKAGE_JSON_PATH
ROUTES_PATH

Public Class Methods

source_root() click to toggle source
# File lib/granule/feature/semantic_react.rb, line 37
def self.source_root
  "#{File.dirname(__FILE__)}/semantic_react"
end

Public Instance Methods

call() click to toggle source
# File lib/granule/feature/semantic_react.rb, line 14
def call
  check_files

  copy_file 'homes_controller.rb', './app/controllers/homes_controller.rb'
  copy_file 'hello_react.jsx', './app/javascript/packs/hello_react.jsx', force: true
  copy_file 'index.html.erb', './app/views/homes/index.html.erb'

  insert_into_file APPLICATION_JS_PATH,
                   "import 'semantic-ui-css/semantic.min.css';\n\n",
                   before: 'require("@rails/ujs").start()'

  insert_into_file APPLICATION_HTML_ERB_PATH,
                   "\t\t<%= javascript_pack_tag 'hello_react' %>",
                   after: "<%= javascript_pack_tag 'application' %>\n"

  insert_into_file ROUTES_PATH, "\troot 'homes#index'\n", after: "Rails.application.routes.draw do\n"

  insert_into_file PACKAGE_JSON_PATH,
                   "\t\t\"semantic-ui-css\": \"^2.4.1\",\n\t\t\"semantic-ui-react\": \"^0.88.1\",\n",
                   after: "\"dependencies\": {\n"
end

Private Instance Methods

check_files() click to toggle source
# File lib/granule/feature/semantic_react.rb, line 43
def check_files
  [APPLICATION_JS_PATH, ROUTES_PATH, APPLICATION_HTML_ERB_PATH, PACKAGE_JSON_PATH].each do |file_path|
    raise Granule::Error, "#{file_path} doesn't exist" unless File.file?(file_path)
  end
end