Class: Padrino::Generators::App
- Includes:
- Actions, Thor::Actions
- Defined in:
- padrino-gen/lib/padrino-gen/generators/app.rb
Overview
Responsible for applications within a Padrino project. Creates and mounts the application and gives the user related information.
Class Method Summary collapse
Instance Method Summary collapse
-
#create_app ⇒ Object
Copies over the Padrino base admin application.
Methods included from Actions
#already_exists?, #app_skeleton, #apply_component_for, #apply_default_fields, #check_app_existence, #destination_root, #empty_directory_with_keep_file, #execute_component_setup, #fetch_app_name, #fetch_component_choice, #fetch_project_name, #in_app_root?, #include_component_module_for, #initializer, #inject_into_file, #insert_hook, #insert_into_gemfile, #insert_middleware, #invalid_fields, #keep_file, #middleware, #recognize_path, #require_contrib, #require_dependencies, #resolve_valid_choice, #retrieve_component_config, #run_bundler, #store_component_choice, #store_component_config, #test?, #tiny?, #valid_choice?, #valid_constant?, #validate_namespace
Class Method Details
.banner ⇒ Object
11 |
# File 'padrino-gen/lib/padrino-gen/generators/app.rb', line 11 def self.; 'padrino-gen app [name]'; end |
.source_root ⇒ Object
10 |
# File 'padrino-gen/lib/padrino-gen/generators/app.rb', line 10 def self.source_root; __dir__; end |
Instance Method Details
#create_app ⇒ Object
Copies over the Padrino base admin application.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'padrino-gen/lib/padrino-gen/generators/app.rb', line 30 def create_app self.destination_root = [:root] underscore_name = name.gsub(/\W/, '_') @app_folder = underscore_name.underscore @app_name = underscore_name.camelize if in_app_root? @project_name = [:namespace].underscore.camelize @project_name = fetch_project_name(@app_folder) if @project_name.empty? if already_exists?(@app_name, @project_name) if [:destroy] self.behavior = :revoke elsif ![:force] say "#{@app_name} already exists." say 'Please, change the name.' return end end lowercase_app_folder = @app_folder.downcase app_skeleton(lowercase_app_folder, [:tiny]) empty_directory destination_root("public/#{lowercase_app_folder}") mount_command = "\nPadrino.mount('#{@project_name}::#{@app_name}', app_file: Padrino.root('#{lowercase_app_folder}/app.rb')).to('/#{lowercase_app_folder}')\n" if File.read(destination_root('config/apps.rb')).match(%r{^Padrino.mount.*\.to\('/'\)$}) inject_into_file destination_root('config/apps.rb'), mount_command, before: %r{^Padrino.mount.*\.to\('/'\)$} else append_file destination_root('config/apps.rb'), mount_command end return if self.behavior == :revoke say say '=' * 65, :green say "Your #{@app_name} application has been installed." say '=' * 65, :green say "This application has been mounted to /#{@app_name.downcase}" say "You can configure a different path by editing 'config/apps.rb'" else say 'You are not at the root of a Padrino application! (config/boot.rb not found)' end end |