Class: TyboInstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/tybo_install/tybo_install_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_javascript_controllersObject



38
39
40
41
42
43
44
45
46
# File 'lib/generators/tybo_install/tybo_install_generator.rb', line 38

def add_javascript_controllers
  inject_into_file 'app/javascript/controllers/application.js', after: "const application = Application.start()\n" do 
    "import { Dropdown, Flash, SearchForm, TsSearch, TsSelect, Sidebar } from \"@tymate/tybo_js\"\n"
  end

  inject_into_file 'app/javascript/controllers/application.js', before: "export { application }" do 
    "application.register('dropdown', Dropdown)\napplication.register('flash', Flash)\napplication.register('search-form', SearchForm)\napplication.register('ts--search', TsSearch)\napplication.register('ts--select', TsSelect)\napplication.register('sidebar', Sidebar)\n"
  end
end

#add_ransack_attributesObject



48
49
50
51
52
53
54
55
56
# File 'lib/generators/tybo_install/tybo_install_generator.rb', line 48

def add_ransack_attributes
  inject_into_file 'app/models/application_record.rb', after: "primary_abstract_class\n" do
    "def self.ransackable_attributes(_auth_object = nil)
      column_names + _ransackers.keys
  end\ndef self.ransackable_associations(_auth_object = nil)
      reflect_on_all_associations.map { |a| a.name.to_s }
    end\n"
  end
end

#create_configuration_filesObject



15
16
17
18
19
20
21
22
# File 'lib/generators/tybo_install/tybo_install_generator.rb', line 15

def create_configuration_files
  create_base_translation_files
  template 'application.tailwind.css', File.join('app/assets/stylesheets/application.tailwind.css'), force: true
  template 'tailwind.config.js', File.join('config/tailwind.config.js'), force: true
  template 'tom-select.css', File.join('app/assets/stylesheets/tom-select.css')
  template 'simple_form_tailwind.rb', File.join('config/initializers/simple_form_tailwind.rb')
  template 'tybo_config.rb', File.join('config/initializers/tybo.rb')
end

#create_routesObject



29
30
31
32
# File 'lib/generators/tybo_install/tybo_install_generator.rb', line 29

def create_routes
  route "root to: 'tybo/login#home'"
  route "mount Tybo::Engine => \"/tybo\""
end

#install_administratorsObject



34
35
36
# File 'lib/generators/tybo_install/tybo_install_generator.rb', line 34

def install_administrators
  run 'rails g bo_namespace Administrator'
end

#install_dependenciesObject



7
8
9
10
11
12
13
# File 'lib/generators/tybo_install/tybo_install_generator.rb', line 7

def install_dependencies
  run './bin/bundle add tailwindcss-rails' unless Bundler.locked_gems.specs.any? { |gem| gem.name == 'tailwindcss-rails' }
  gem 'simple_form' unless Bundler.locked_gems.specs.any? { |gem| gem.name == 'simple_form' }
  gem 'simple_form-tailwind', '~> 0.1.1' unless Bundler.locked_gems.specs.any? { |gem| gem.name == 'simple_form-tailwind' }
  run 'bundle install'
  run "rails tailwindcss:install"
end

#pin_js_dependenciesObject



24
25
26
27
# File 'lib/generators/tybo_install/tybo_install_generator.rb', line 24

def pin_js_dependencies
  run "./bin/importmap pin tom-select --download"
  run "./bin/importmap pin @tymate/tybo_js"
end