Class: Padrino::Generators::Project
- Defined in:
- padrino-gen/lib/padrino-gen/generators/project.rb
Overview
Responsible for generating new Padrino projects based on the specified project components.
Class Method Summary collapse
Instance Method Summary collapse
-
#bundle_dependencies ⇒ Object
Bundle all required components using bundler and Gemfile.
-
#finish_message ⇒ Object
Finish message.
-
#git_author_email ⇒ Object
Returns the git author email config or a fill-in value.
-
#git_author_name ⇒ Object
Returns the git author name config or a fill-in value.
-
#setup_components ⇒ Object
For each component, retrieve a valid choice and then execute the associated generator.
-
#setup_project ⇒ Object
Copies over the Padrino base application app.
-
#setup_test_files ⇒ Object
Generates test files for tiny app skeleton.
Methods included from Runner
#app, #generate, #git, #project, #rake
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
13 |
# File 'padrino-gen/lib/padrino-gen/generators/project.rb', line 13 def self.; "padrino-gen project [name] [options]"; end |
.source_root ⇒ Object
12 |
# File 'padrino-gen/lib/padrino-gen/generators/project.rb', line 12 def self.source_root; File.(File.dirname(__FILE__)); end |
Instance Method Details
#bundle_dependencies ⇒ Object
Bundle all required components using bundler and Gemfile.
128 129 130 131 132 |
# File 'padrino-gen/lib/padrino-gen/generators/project.rb', line 128 def bundle_dependencies if [:bundle] run_bundler end end |
#finish_message ⇒ Object
Finish message.
137 138 139 140 141 142 143 144 145 146 |
# File 'padrino-gen/lib/padrino-gen/generators/project.rb', line 137 def say say '=' * 65, :green say "#{name} is ready for development!", :green say '=' * 65, :green say "$ cd #{[:root]}/#{name}" say "$ bundle --binstubs" unless [:bundle] say "=" * 65, :green say end |
#git_author_email ⇒ Object
Returns the git author email config or a fill-in value.
159 160 161 162 |
# File 'padrino-gen/lib/padrino-gen/generators/project.rb', line 159 def = `git config user.email`.chomp rescue '' .empty? ? "TODO: Write your email address" : end |
#git_author_name ⇒ Object
Returns the git author name config or a fill-in value.
151 152 153 154 |
# File 'padrino-gen/lib/padrino-gen/generators/project.rb', line 151 def = `git config user.name`.chomp rescue '' .empty? ? "TODO: Write your name" : end |
#setup_components ⇒ Object
For each component, retrieve a valid choice and then execute the associated generator.
87 88 89 90 91 92 93 94 95 96 97 |
# File 'padrino-gen/lib/padrino-gen/generators/project.rb', line 87 def setup_components return if [:template] @_components = .class.new .select{ |key,_| self.class.component_types.include?(key.to_sym) } self.class.component_types.each do |comp| choice = @_components[comp] = resolve_valid_choice(comp) execute_component_setup(comp, choice) end store_component_config('.components', :force => true) store_component_choice(:namespace, @project_name) store_component_choice(:migration_format, [:migration_format]) end |
#setup_project ⇒ Object
Copies over the Padrino base application app.
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 73 74 75 76 77 78 79 80 81 82 |
# File 'padrino-gen/lib/padrino-gen/generators/project.rb', line 45 def setup_project valid_constant? name app = ([:app] || "App") @project_name = name.gsub(/\W/, '_').underscore.camelize fail "Constant `#{@project_name}` already exists. Please, use another name" if already_exists?(@project_name) @app_name = app.gsub(/\W/, '_').camelize self.destination_root = File.join([:root], name) if [:template] execute_runner(:template, [:template]) else directory('project/', destination_root) empty_directory destination_root('public/images') empty_directory destination_root('public/javascripts') empty_directory destination_root('public/stylesheets') store_component_config('.components') unless [:lean] app_skeleton('app', [:tiny]) append_file destination_root('config/apps.rb'), "Padrino.mount('#{@project_name}::#{@app_name}', :app_file => Padrino.root('app/app.rb')).to('/')\n" end template 'templates/Gemfile.tt', destination_root('Gemfile') template 'templates/Rakefile.tt', destination_root('Rakefile') template 'templates/project_bin.tt', destination_root("exe/#{name}") File.chmod(0755, destination_root("exe/#{name}")) if .gem? template 'templates/gem/gemspec.tt', destination_root(name + '.gemspec') inject_into_file destination_root('Rakefile'), "require 'bundler/gem_tasks'\n", :after => "require 'bundler/setup'\n" template 'templates/gem/README.md.tt', destination_root('README.md') template 'templates/gem/lib/libname.tt', destination_root("lib/#{name}.rb") template 'templates/gem/lib/libname/version.tt', destination_root("lib/#{name}/version.rb") else empty_directory_with_keep_file destination_root('tmp') empty_directory_with_keep_file destination_root('log') end end end |
#setup_test_files ⇒ Object
Generates test files for tiny app skeleton.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'padrino-gen/lib/padrino-gen/generators/project.rb', line 102 def setup_test_files if [:tiny] && @_components[:test] != :none test_component = @_components[:test] test_component = "rspec" if test_component == "cucumber" uppercase_test_component = test_component.upcase controller_template_name = "#{uppercase_test_component}_CONTROLLER_TEST" helper_template_name = "#{uppercase_test_component}_HELPER_TEST" return unless defined?(controller_template_name) controller_content = instance_eval(controller_template_name).gsub(/!PATH!/, "Controller").gsub(/!NAME!/, "").gsub(/!EXPANDED_PATH!/, "/") helper_content = instance_eval(helper_template_name).gsub(/!NAME!/, "#{@project_name}::#{@app_name}::#{DEFAULT_HELPER_NAME}") proc{|*args| args.map{|str| str.gsub!(/!PATH!/, recognize_path)} }.call(controller_content, helper_content) directory_name = [:rspec].include?(test_component.to_sym) ? "spec" : "test" base_path = File.join(directory_name, "app") create_file destination_root("#{base_path}/controllers/controllers_#{directory_name}.rb"), controller_content, :skip => true create_file destination_root("#{base_path}/helpers/helpers_#{directory_name}.rb"), helper_content, :skip => true helper_path = destination_root(File.join(directory_name, "#{directory_name == "spec" ? "spec_helper" : "test_config"}.rb")) gsub_file helper_path, %r{helpers/\*\*/\*\.rb}, "helpers.rb" end end |