Class: Kowl::PagesGenerator

Inherits:
Generators::Base show all
Defined in:
lib/kowl/generators/pages_generator.rb

Instance Method Summary collapse

Methods inherited from Generators::Base

default_source_root, source_paths

Methods included from Docker

#alpine_docker_dependencies, #app_js_volumes, #app_volumes, #db_volumes, #debian_database_dependencies, #debian_docker_dependencies, #docker_app_command, #docker_compose_database_string, #docker_databases, #docker_depends_on, #docker_port_watcher, #docker_redis_service, #docker_sidekiq_service, #docker_variables, #docker_volumes, #docker_webpacker_service, #dockerfile_database_args, #dockerfile_migration_snip, #js_volumes, #mysql_volumes, #postgresql_volumes, #redis_volumes

Methods included from Actions

#add_extension_routes, #add_package, #append_to_file, #database_route, #dev_config, #dup_file, #file_exists?, #mailer_gems, #mailer_route, #mk_dir, #move_file, #pry_gems, #rails_cmd, #remove_dir, #remove_file, #remove_gem, #replace_string_in_file, #robocop_test_engine, #sidekiq_route, #template_linter_gems

Instance Method Details

#copy_welcome_pagesObject

Copy over a basic welcome page view dependant on the CSS framework and template engine specified for the application



27
28
29
30
31
32
33
# File 'lib/kowl/generators/pages_generator.rb', line 27

def copy_welcome_pages
  if %w[bootstrap semantic].include? options[:framework]
    copy_file "pages/welcome/#{options[:framework]}.html.#{options[:template_engine]}", "app/views/pages/welcome.html.#{options[:template_engine]}", force: true
  else
    copy_file "pages/welcome/default.html.#{options[:template_engine]}", "app/views/pages/welcome.html.#{options[:template_engine]}", force: true
  end
end

#disable_authObject

Add a skip_before_action for the welcome page if authentication is being used with the application



36
37
38
39
40
41
42
43
44
# File 'lib/kowl/generators/pages_generator.rb', line 36

def disable_auth
  action_str = <<~STR
    # Allow pages to be displayed without requiring authentication
    skip_before_action :authenticate_user!

  STR

  inject_into_file 'app/controllers/pages_controller.rb', optimize_indentation(action_str, 2), after: "class PagesController < ApplicationController\n" unless options[:noauth]
end

#make_controller_immuatableObject



22
23
24
# File 'lib/kowl/generators/pages_generator.rb', line 22

def make_controller_immuatable
  inject_into_file 'app/controllers/pages_controller.rb', "# frozen_string_literal: true\n\n", before: "class PagesController < ApplicationController\n"
end

#setup_welcome_pageObject

Generate a basic welcome page for the application



15
16
17
18
19
20
# File 'lib/kowl/generators/pages_generator.rb', line 15

def setup_welcome_page
  generate('controller Pages welcome --skip')

  # I don't want to skip or remove all tests created for pages, I just want to remove the generated controller test
  remove_file('spec/requests/pages_request_spec.rb')
end