lotusrb 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +57 -14
- data/FEATURES.md +21 -0
- data/LICENSE.md +1 -1
- data/README.md +8 -7
- data/bin/lotus +1 -0
- data/lib/lotus.rb +6 -0
- data/lib/lotus/action/csrf_protection.rb +1 -1
- data/lib/lotus/application.rb +4 -4
- data/lib/lotus/application_name.rb +8 -6
- data/lib/lotus/cli.rb +75 -66
- data/lib/lotus/cli_sub_commands/assets.rb +29 -0
- data/lib/lotus/{commands → cli_sub_commands}/db.rb +24 -29
- data/lib/lotus/cli_sub_commands/destroy.rb +102 -0
- data/lib/lotus/cli_sub_commands/generate.rb +127 -0
- data/lib/lotus/commands/assets/precompile.rb +35 -0
- data/lib/lotus/commands/console.rb +28 -8
- data/lib/lotus/commands/db/abstract.rb +6 -2
- data/lib/lotus/commands/db/console.rb +5 -5
- data/lib/lotus/commands/generate/abstract.rb +63 -0
- data/lib/lotus/commands/generate/action.rb +262 -0
- data/lib/lotus/commands/generate/app.rb +116 -0
- data/lib/lotus/commands/generate/mailer.rb +118 -0
- data/lib/lotus/commands/generate/migration.rb +63 -0
- data/lib/lotus/commands/generate/model.rb +96 -0
- data/lib/lotus/commands/new/abstract.rb +128 -0
- data/lib/lotus/commands/new/app.rb +116 -0
- data/lib/lotus/commands/new/container.rb +102 -0
- data/lib/lotus/commands/routes.rb +19 -2
- data/lib/lotus/commands/server.rb +16 -2
- data/lib/lotus/config/framework_configuration.rb +13 -1
- data/lib/lotus/configuration.rb +24 -76
- data/lib/lotus/container.rb +15 -2
- data/lib/lotus/environment.rb +43 -4
- data/lib/lotus/frameworks.rb +1 -0
- data/lib/lotus/generators/action/action_spec.minitest.tt +1 -1
- data/lib/lotus/generators/action/action_spec.rspec.tt +1 -1
- data/lib/lotus/generators/action/view_spec.minitest.tt +1 -1
- data/lib/lotus/generators/action/view_spec.rspec.tt +1 -1
- data/lib/lotus/generators/{slice → app}/.gitkeep.tt +0 -0
- data/lib/lotus/generators/{slice → app}/application.rb.tt +61 -23
- data/lib/lotus/generators/app/config/initializers/.gitkeep +0 -0
- data/lib/lotus/generators/{slice → app}/config/routes.rb.tt +0 -0
- data/lib/lotus/generators/app/favicon.ico +0 -0
- data/lib/lotus/generators/{slice → app}/templates/application.html.erb.tt +2 -1
- data/lib/lotus/generators/app/views/application_layout.rb.tt +7 -0
- data/lib/lotus/generators/application/app/.env.development.tt +1 -0
- data/lib/lotus/generators/application/app/.env.test.tt +1 -0
- data/lib/lotus/generators/application/app/Gemfile.tt +1 -0
- data/lib/lotus/generators/application/app/Rakefile.minitest.tt +1 -0
- data/lib/lotus/generators/application/app/Rakefile.rspec.tt +1 -0
- data/lib/lotus/generators/application/app/config/application.rb.tt +56 -18
- data/lib/lotus/generators/application/app/config/initializers/.gitkeep +0 -0
- data/lib/lotus/generators/application/app/favicon.ico +0 -0
- data/lib/lotus/generators/application/app/gitignore.tt +2 -0
- data/lib/lotus/generators/application/app/lotusrc.tt +3 -3
- data/lib/lotus/generators/application/app/spec_helper.rb.rspec.tt +5 -1
- data/lib/lotus/generators/application/app/templates/application.html.erb.tt +1 -0
- data/lib/lotus/generators/application/container/.env.development.tt +1 -0
- data/lib/lotus/generators/application/container/.env.test.tt +1 -0
- data/lib/lotus/generators/application/container/Gemfile.tt +1 -1
- data/lib/lotus/generators/application/container/Rakefile.minitest.tt +1 -0
- data/lib/lotus/generators/application/container/Rakefile.rspec.tt +1 -0
- data/lib/lotus/generators/application/container/config/initializers/.gitkeep +0 -0
- data/lib/lotus/generators/application/container/gitignore.tt +2 -0
- data/lib/lotus/generators/application/container/lib/chirp/mailers/.gitkeep +0 -0
- data/lib/lotus/generators/application/container/lib/chirp/mailers/templates/.gitkeep +0 -0
- data/lib/lotus/generators/application/container/lotusrc.tt +3 -3
- data/lib/lotus/generators/application/container/spec_helper.rb.rspec.tt +5 -1
- data/lib/lotus/generators/database_config.rb +17 -4
- data/lib/lotus/generators/generatable.rb +51 -0
- data/lib/lotus/generators/generator.rb +35 -0
- data/lib/lotus/generators/test_framework.rb +42 -0
- data/lib/lotus/loader.rb +43 -0
- data/lib/lotus/lotusrc.rb +50 -49
- data/lib/lotus/middleware.rb +28 -10
- data/lib/lotus/rake_helper.rb +68 -0
- data/lib/lotus/rake_tasks.rb +2 -0
- data/lib/lotus/rendering_policy.rb +2 -2
- data/lib/lotus/repositories/car_repository.rb +3 -0
- data/lib/lotus/repositories/name_repository.rb +3 -0
- data/lib/lotus/setup.rb +1 -3
- data/lib/lotus/static.rb +77 -0
- data/lib/lotus/templates/welcome.html.erb +7 -4
- data/lib/lotus/version.rb +1 -1
- data/lib/lotus/views/default.rb +2 -1
- data/lib/lotus/views/default_template_finder.rb +4 -3
- data/lotusrb.gemspec +11 -9
- metadata +79 -60
- data/lib/lotus/commands/generate.rb +0 -97
- data/lib/lotus/commands/new.rb +0 -43
- data/lib/lotus/config/assets.rb +0 -81
- data/lib/lotus/generators/abstract.rb +0 -31
- data/lib/lotus/generators/action.rb +0 -235
- data/lib/lotus/generators/app.rb +0 -39
- data/lib/lotus/generators/app/.gitkeep +0 -1
- data/lib/lotus/generators/application/app.rb +0 -129
- data/lib/lotus/generators/application/container.rb +0 -111
- data/lib/lotus/generators/mailer.rb +0 -112
- data/lib/lotus/generators/migration.rb +0 -58
- data/lib/lotus/generators/model.rb +0 -90
- data/lib/lotus/generators/slice.rb +0 -94
- data/lib/lotus/generators/slice/views/application_layout.rb.tt +0 -7
| @@ -0,0 +1,118 @@ | |
| 1 | 
            +
            require "lotus/commands/generate/abstract"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Lotus
         | 
| 4 | 
            +
              module Commands
         | 
| 5 | 
            +
                class Generate
         | 
| 6 | 
            +
                  # @since 0.5.0
         | 
| 7 | 
            +
                  # @api private
         | 
| 8 | 
            +
                  class Mailer < Abstract
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                    attr_reader :name, :name_underscored, :from, :to, :subject
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                    # @since 0.5.0
         | 
| 13 | 
            +
                    # @api private
         | 
| 14 | 
            +
                    TXT_FORMAT  = ".txt".freeze
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                    # @since 0.5.0
         | 
| 17 | 
            +
                    # @api private
         | 
| 18 | 
            +
                    HTML_FORMAT  = ".html".freeze
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                    # @since 0.5.0
         | 
| 21 | 
            +
                    # @api private
         | 
| 22 | 
            +
                    DEFAULT_ENGINE = "erb".freeze
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                    # @since 0.5.0
         | 
| 25 | 
            +
                    # @api private
         | 
| 26 | 
            +
                    DEFAULT_FROM = "'<from>'".freeze
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                    # @since 0.5.0
         | 
| 29 | 
            +
                    # @api private
         | 
| 30 | 
            +
                    DEFAULT_TO = "'<to>'".freeze
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                    # @since 0.5.0
         | 
| 33 | 
            +
                    # @api private
         | 
| 34 | 
            +
                    DEFAULT_SUBJECT = "'Hello'".freeze
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                    # @since 0.5.0
         | 
| 37 | 
            +
                    # @api private
         | 
| 38 | 
            +
                    def initialize(options, name)
         | 
| 39 | 
            +
                      super(options)
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                      @name_underscored = Utils::String.new(name).underscore
         | 
| 42 | 
            +
                      @name             = Utils::String.new(name_underscored).classify
         | 
| 43 | 
            +
                      @from             = options[:from] || DEFAULT_FROM
         | 
| 44 | 
            +
                      @to               = options[:to] || DEFAULT_TO
         | 
| 45 | 
            +
                      @subject          = options[:subject] || DEFAULT_SUBJECT
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                      assert_name!
         | 
| 48 | 
            +
                    end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                    # @since 0.x.x
         | 
| 51 | 
            +
                    # @api private
         | 
| 52 | 
            +
                    def map_templates
         | 
| 53 | 
            +
                      add_mapping("mailer_spec.rb.tt", mailer_spec_path)
         | 
| 54 | 
            +
                      add_mapping("mailer.rb.tt", mailer_path)
         | 
| 55 | 
            +
                      add_mapping("template.txt.tt", txt_template_path)
         | 
| 56 | 
            +
                      add_mapping("template.html.tt", html_template_path)
         | 
| 57 | 
            +
                    end
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                    def template_options
         | 
| 60 | 
            +
                      {
         | 
| 61 | 
            +
                        mailer:  name,
         | 
| 62 | 
            +
                        from:    from,
         | 
| 63 | 
            +
                        to:      to,
         | 
| 64 | 
            +
                        subject: subject,
         | 
| 65 | 
            +
                      }
         | 
| 66 | 
            +
                    end
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                    private
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                    # @since 0.5.0
         | 
| 71 | 
            +
                    # @api private
         | 
| 72 | 
            +
                    def assert_name!
         | 
| 73 | 
            +
                      if name.nil? || name.strip.empty?
         | 
| 74 | 
            +
                        raise ArgumentError.new("Missing mailer name")
         | 
| 75 | 
            +
                      end
         | 
| 76 | 
            +
                    end
         | 
| 77 | 
            +
             | 
| 78 | 
            +
                    # @since 0.5.0
         | 
| 79 | 
            +
                    # @api private
         | 
| 80 | 
            +
                    def mailer_path
         | 
| 81 | 
            +
                      core_root.join('mailers', "#{ name_underscored }.rb").to_s
         | 
| 82 | 
            +
                    end
         | 
| 83 | 
            +
             | 
| 84 | 
            +
                    # @since 0.5.0
         | 
| 85 | 
            +
                    # @api private
         | 
| 86 | 
            +
                    def mailer_spec_path
         | 
| 87 | 
            +
                      spec_root.join(::File.basename(Dir.getwd), "mailers", "#{ name_underscored }_spec.rb")
         | 
| 88 | 
            +
                    end
         | 
| 89 | 
            +
             | 
| 90 | 
            +
                    # @since 0.5.0
         | 
| 91 | 
            +
                    # @api private
         | 
| 92 | 
            +
                    def txt_template_path
         | 
| 93 | 
            +
                      template_path(TXT_FORMAT)
         | 
| 94 | 
            +
                    end
         | 
| 95 | 
            +
             | 
| 96 | 
            +
                    # @since 0.5.0
         | 
| 97 | 
            +
                    # @api private
         | 
| 98 | 
            +
                    def html_template_path
         | 
| 99 | 
            +
                      template_path(HTML_FORMAT)
         | 
| 100 | 
            +
                    end
         | 
| 101 | 
            +
             | 
| 102 | 
            +
                    # @since 0.5.0
         | 
| 103 | 
            +
                    # @api private
         | 
| 104 | 
            +
                    def template_path(format)
         | 
| 105 | 
            +
                      core_root.join("mailers", "templates", "#{ name_underscored }#{ format }.#{ DEFAULT_ENGINE }")
         | 
| 106 | 
            +
                    end
         | 
| 107 | 
            +
             | 
| 108 | 
            +
                    def spec_root
         | 
| 109 | 
            +
                      Pathname.new("spec")
         | 
| 110 | 
            +
                    end
         | 
| 111 | 
            +
             | 
| 112 | 
            +
                    def core_root
         | 
| 113 | 
            +
                      Pathname.new("lib").join(::File.basename(Dir.getwd))
         | 
| 114 | 
            +
                    end
         | 
| 115 | 
            +
                  end
         | 
| 116 | 
            +
                end
         | 
| 117 | 
            +
              end
         | 
| 118 | 
            +
            end
         | 
| @@ -0,0 +1,63 @@ | |
| 1 | 
            +
            require 'lotus/commands/generate/abstract'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Lotus
         | 
| 4 | 
            +
              module Commands
         | 
| 5 | 
            +
                class Generate
         | 
| 6 | 
            +
                  class Migration < Abstract
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                    attr_reader :name, :underscored_name
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                    # @since 0.6.0
         | 
| 11 | 
            +
                    # @api private
         | 
| 12 | 
            +
                    #
         | 
| 13 | 
            +
                    # @example
         | 
| 14 | 
            +
                    #   20150612160502
         | 
| 15 | 
            +
                    TIMESTAMP_FORMAT = '%Y%m%d%H%M%S'.freeze
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                    # @since 0.6.0
         | 
| 18 | 
            +
                    # @api private
         | 
| 19 | 
            +
                    #
         | 
| 20 | 
            +
                    # @example
         | 
| 21 | 
            +
                    #   20150612160502_create_books.rb
         | 
| 22 | 
            +
                    FILENAME_PATTERN = '%{timestamp}_%{name}.rb'.freeze
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                    def initialize(options, name)
         | 
| 25 | 
            +
                      super(options)
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                      @name = name
         | 
| 28 | 
            +
                      @underscored_name = Utils::String.new(@name).underscore
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                      environment.require_application_environment
         | 
| 31 | 
            +
                      assert_migration_name!
         | 
| 32 | 
            +
                    end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                    def map_templates
         | 
| 35 | 
            +
                      add_mapping('migration.rb.tt', destination_path)
         | 
| 36 | 
            +
                    end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                    private
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                    def destination_path
         | 
| 41 | 
            +
                      existing_migration_path || new_migration_path
         | 
| 42 | 
            +
                    end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                    def existing_migration_path
         | 
| 45 | 
            +
                      Dir.glob("#{Lotus::Model.configuration.migrations}/[0-9]*_#{underscored_name}.rb").first
         | 
| 46 | 
            +
                    end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                    def new_migration_path
         | 
| 49 | 
            +
                      timestamp = Time.now.utc.strftime(TIMESTAMP_FORMAT)
         | 
| 50 | 
            +
                      filename = FILENAME_PATTERN % { timestamp: timestamp, name: underscored_name}
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                      Lotus::Model.configuration.migrations.join(filename)
         | 
| 53 | 
            +
                    end
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                    def assert_migration_name!
         | 
| 56 | 
            +
                      if name.nil? || name.strip.empty?
         | 
| 57 | 
            +
                        raise ArgumentError.new('Migration name nil or empty')
         | 
| 58 | 
            +
                      end
         | 
| 59 | 
            +
                    end
         | 
| 60 | 
            +
                  end
         | 
| 61 | 
            +
                end
         | 
| 62 | 
            +
              end
         | 
| 63 | 
            +
            end
         | 
| @@ -0,0 +1,96 @@ | |
| 1 | 
            +
            require 'lotus/commands/generate/abstract'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Lotus
         | 
| 4 | 
            +
              module Commands
         | 
| 5 | 
            +
                class Generate
         | 
| 6 | 
            +
                  class Model < Abstract
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                    attr_reader :model_name
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                    def initialize(options, model_name)
         | 
| 11 | 
            +
                      super(options)
         | 
| 12 | 
            +
                      @model_name = Utils::String.new(model_name).classify
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                      assert_model_name!
         | 
| 15 | 
            +
                    end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                    def map_templates
         | 
| 18 | 
            +
                      add_mapping('entity.rb.tt', entity_path)
         | 
| 19 | 
            +
                      add_mapping('repository.rb.tt', repository_path)
         | 
| 20 | 
            +
                      add_mapping("entity_spec.#{ test_framework.framework }.tt", entity_spec_path,)
         | 
| 21 | 
            +
                      add_mapping("repository_spec.#{ test_framework.framework }.tt", repository_spec_path)
         | 
| 22 | 
            +
                    end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                    def template_options
         | 
| 25 | 
            +
                      {
         | 
| 26 | 
            +
                        model_name: model_name
         | 
| 27 | 
            +
                      }
         | 
| 28 | 
            +
                    end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                    private
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                    # @since 0.6.0
         | 
| 33 | 
            +
                    # @api private
         | 
| 34 | 
            +
                    def assert_model_name!
         | 
| 35 | 
            +
                      model_name_not_blank
         | 
| 36 | 
            +
                      model_name_valid
         | 
| 37 | 
            +
                    end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                    # Validates that a model name was provided
         | 
| 40 | 
            +
                    #
         | 
| 41 | 
            +
                    # @since 0.6.0
         | 
| 42 | 
            +
                    # @api private
         | 
| 43 | 
            +
                    def model_name_not_blank
         | 
| 44 | 
            +
                      if model_name.nil? || model_name.strip.empty?
         | 
| 45 | 
            +
                        raise ArgumentError.new('Model name nil or empty.')
         | 
| 46 | 
            +
                      end
         | 
| 47 | 
            +
                    end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                    # Validates that the provided model name doesn't start with numbers
         | 
| 50 | 
            +
                    #
         | 
| 51 | 
            +
                    # @since 0.6.0
         | 
| 52 | 
            +
                    # @api private
         | 
| 53 | 
            +
                    def model_name_valid
         | 
| 54 | 
            +
                      unless model_name.match(/^[a-z]/i)
         | 
| 55 | 
            +
                        raise ArgumentError.new("Invalid model name. The model name shouldn't begin with a number.")
         | 
| 56 | 
            +
                      end
         | 
| 57 | 
            +
                    end
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                    def model_root
         | 
| 60 | 
            +
                      Pathname.new('lib').join(::File.basename(Dir.getwd))
         | 
| 61 | 
            +
                    end
         | 
| 62 | 
            +
             | 
| 63 | 
            +
                    # @since 0.5.0
         | 
| 64 | 
            +
                    # @api private
         | 
| 65 | 
            +
                    def entity_path
         | 
| 66 | 
            +
                      model_root.join('entities', "#{ model_name_underscored }.rb").to_s
         | 
| 67 | 
            +
                    end
         | 
| 68 | 
            +
             | 
| 69 | 
            +
                    # @since 0.5.0
         | 
| 70 | 
            +
                    # @api private
         | 
| 71 | 
            +
                    def repository_path
         | 
| 72 | 
            +
                      model_root.join('repositories', "#{ model_name_underscored }_repository.rb").to_s
         | 
| 73 | 
            +
                    end
         | 
| 74 | 
            +
             | 
| 75 | 
            +
                    # @since 0.5.0
         | 
| 76 | 
            +
                    # @api private
         | 
| 77 | 
            +
                    def entity_spec_path
         | 
| 78 | 
            +
                      target_path.join('spec', ::File.basename(Dir.getwd), 'entities', "#{ model_name_underscored }_spec.rb")
         | 
| 79 | 
            +
                    end
         | 
| 80 | 
            +
             | 
| 81 | 
            +
                    # @since 0.5.0
         | 
| 82 | 
            +
                    # @api private
         | 
| 83 | 
            +
                    def repository_spec_path
         | 
| 84 | 
            +
                      target_path.join('spec', ::File.basename(Dir.getwd), 'repositories',
         | 
| 85 | 
            +
                        "#{ model_name_underscored }_repository_spec.rb")
         | 
| 86 | 
            +
                    end
         | 
| 87 | 
            +
             | 
| 88 | 
            +
                    # @since 0.5.0
         | 
| 89 | 
            +
                    # @api private
         | 
| 90 | 
            +
                    def model_name_underscored
         | 
| 91 | 
            +
                      Utils::String.new(model_name).underscore
         | 
| 92 | 
            +
                    end
         | 
| 93 | 
            +
                  end
         | 
| 94 | 
            +
                end
         | 
| 95 | 
            +
              end
         | 
| 96 | 
            +
            end
         | 
| @@ -0,0 +1,128 @@ | |
| 1 | 
            +
            require 'shellwords'
         | 
| 2 | 
            +
            require 'lotus/application_name'
         | 
| 3 | 
            +
            require 'lotus/generators/database_config'
         | 
| 4 | 
            +
            require 'lotus/generators/generatable'
         | 
| 5 | 
            +
            require 'lotus/generators/test_framework'
         | 
| 6 | 
            +
            require 'lotus/utils/hash'
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            module Lotus
         | 
| 9 | 
            +
              module Commands
         | 
| 10 | 
            +
                class New
         | 
| 11 | 
            +
                  class Abstract
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                    include Lotus::Generators::Generatable
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                    DEFAULT_ARCHITECTURE = 'container'.freeze
         | 
| 16 | 
            +
                    DEFAULT_APPLICATION_BASE_URL = '/'.freeze
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                    attr_reader :options, :target_path, :database_config
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                    def initialize(options, name)
         | 
| 21 | 
            +
                      @options = Lotus::Utils::Hash.new(options).symbolize!
         | 
| 22 | 
            +
                      @name = name
         | 
| 23 | 
            +
                      @options[:database] ||= Lotus::Generators::DatabaseConfig::DEFAULT_ENGINE
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                      assert_options!
         | 
| 26 | 
            +
                      assert_name!
         | 
| 27 | 
            +
                      assert_architecture!
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                      @lotus_model_version = '~> 0.5'
         | 
| 30 | 
            +
                      @database_config = Lotus::Generators::DatabaseConfig.new(options[:database], app_name)
         | 
| 31 | 
            +
                    end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                    def start
         | 
| 34 | 
            +
                      FileUtils.mkdir_p(@name)
         | 
| 35 | 
            +
                      Dir.chdir(@name) do
         | 
| 36 | 
            +
                        @target_path = Pathname.pwd
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                        super
         | 
| 39 | 
            +
                      end
         | 
| 40 | 
            +
                    end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                    private
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                    def test_framework
         | 
| 45 | 
            +
                      @test_framework ||= Lotus::Generators::TestFramework.new(lotusrc, options[:test])
         | 
| 46 | 
            +
                    end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                    def lotusrc
         | 
| 49 | 
            +
                      @lotusrc ||= Lotusrc.new(Pathname.new('.'))
         | 
| 50 | 
            +
                    end
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                    def start_in_app_dir
         | 
| 53 | 
            +
                      raise NotImplementedError
         | 
| 54 | 
            +
                    end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                    def add_sql_templates
         | 
| 57 | 
            +
                      return if !database_config.sql?
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                      add_mapping('schema.sql.tt', 'db/schema.sql')
         | 
| 60 | 
            +
                    end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                    def add_git_templates
         | 
| 63 | 
            +
                      return if git_dir_present?
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                      source = database_config.filesystem? ? 'gitignore.tt' : '.gitignore'
         | 
| 66 | 
            +
                      target = '.gitignore'
         | 
| 67 | 
            +
                      add_mapping(source, target)
         | 
| 68 | 
            +
                    end
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                    def real_app_name
         | 
| 71 | 
            +
                      @name == '.' ? ::File.basename(Dir.getwd) : @name
         | 
| 72 | 
            +
                    end
         | 
| 73 | 
            +
             | 
| 74 | 
            +
                    def app_name
         | 
| 75 | 
            +
                      ApplicationName.new(real_app_name)
         | 
| 76 | 
            +
                    end
         | 
| 77 | 
            +
             | 
| 78 | 
            +
                    def target
         | 
| 79 | 
            +
                      Pathname.new('.')
         | 
| 80 | 
            +
                    end
         | 
| 81 | 
            +
             | 
| 82 | 
            +
                    def init_git
         | 
| 83 | 
            +
                      return if git_dir_present?
         | 
| 84 | 
            +
             | 
| 85 | 
            +
                      generator.run("git init #{Shellwords.escape(target)}", capture: true)
         | 
| 86 | 
            +
                    end
         | 
| 87 | 
            +
             | 
| 88 | 
            +
                    def git_dir_present?
         | 
| 89 | 
            +
                      File.directory?(target.join('.git'))
         | 
| 90 | 
            +
                    end
         | 
| 91 | 
            +
             | 
| 92 | 
            +
                    def lotus_model_version
         | 
| 93 | 
            +
                      @lotus_model_version
         | 
| 94 | 
            +
                    end
         | 
| 95 | 
            +
             | 
| 96 | 
            +
                    def lotus_head?
         | 
| 97 | 
            +
                      options.fetch(:lotus_head, false)
         | 
| 98 | 
            +
                    end
         | 
| 99 | 
            +
             | 
| 100 | 
            +
                    def architecture
         | 
| 101 | 
            +
                      options.fetch(:architecture, DEFAULT_ARCHITECTURE)
         | 
| 102 | 
            +
                    end
         | 
| 103 | 
            +
             | 
| 104 | 
            +
                    def assert_name!
         | 
| 105 | 
            +
                      if @name.nil? || @name.strip == '' || @name.include?(File::SEPARATOR)
         | 
| 106 | 
            +
                        raise ArgumentError.new("APPLICATION_NAME is requried and must not contain #{File::SEPARATOR}.")
         | 
| 107 | 
            +
                      end
         | 
| 108 | 
            +
                    end
         | 
| 109 | 
            +
             | 
| 110 | 
            +
                    def assert_architecture!
         | 
| 111 | 
            +
                      if !['app', 'container'].include?(architecture)
         | 
| 112 | 
            +
                        raise ArgumentError.new("Architecture must be one of 'app', 'container' but was '#{architecture}'")
         | 
| 113 | 
            +
                      end
         | 
| 114 | 
            +
                    end
         | 
| 115 | 
            +
             | 
| 116 | 
            +
                    def application_base_url
         | 
| 117 | 
            +
                      options[:application_base_url] || DEFAULT_APPLICATION_BASE_URL
         | 
| 118 | 
            +
                    end
         | 
| 119 | 
            +
             | 
| 120 | 
            +
                    def assert_options!
         | 
| 121 | 
            +
                      if options.nil?
         | 
| 122 | 
            +
                        raise ArgumentError.new('options must not be nil')
         | 
| 123 | 
            +
                      end
         | 
| 124 | 
            +
                    end
         | 
| 125 | 
            +
                  end
         | 
| 126 | 
            +
                end
         | 
| 127 | 
            +
              end
         | 
| 128 | 
            +
            end
         | 
| @@ -0,0 +1,116 @@ | |
| 1 | 
            +
            require 'lotus/commands/new/abstract'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Lotus
         | 
| 4 | 
            +
              module Commands
         | 
| 5 | 
            +
                class New
         | 
| 6 | 
            +
                  class App < Abstract
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                    def initialize(options, name)
         | 
| 9 | 
            +
                      super(options, name)
         | 
| 10 | 
            +
                    end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                    def map_templates
         | 
| 13 | 
            +
                      add_application_templates
         | 
| 14 | 
            +
                      add_empty_directories
         | 
| 15 | 
            +
                      add_test_templates
         | 
| 16 | 
            +
                      add_sql_templates
         | 
| 17 | 
            +
                      add_git_templates
         | 
| 18 | 
            +
                    end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                    def template_options
         | 
| 21 | 
            +
                      {
         | 
| 22 | 
            +
                        app_name:              app_name,
         | 
| 23 | 
            +
                        upcase_app_name:       upcase_app_name,
         | 
| 24 | 
            +
                        classified_app_name:   classified_app_name,
         | 
| 25 | 
            +
                        application_base_url:  application_base_url,
         | 
| 26 | 
            +
                        lotus_head:            lotus_head?,
         | 
| 27 | 
            +
                        test:                  test_framework.framework,
         | 
| 28 | 
            +
                        database:              database_config.type,
         | 
| 29 | 
            +
                        database_config:       database_config.to_hash,
         | 
| 30 | 
            +
                        lotus_model_version:   lotus_model_version,
         | 
| 31 | 
            +
                      }
         | 
| 32 | 
            +
                    end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                    def post_process_templates
         | 
| 35 | 
            +
                      init_git
         | 
| 36 | 
            +
                    end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                    private
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                    def add_application_templates
         | 
| 41 | 
            +
                      add_mapping('lotusrc.tt', '.lotusrc')
         | 
| 42 | 
            +
                      add_mapping('.env.tt', '.env')
         | 
| 43 | 
            +
                      add_mapping('.env.development.tt', '.env.development')
         | 
| 44 | 
            +
                      add_mapping('.env.test.tt', '.env.test')
         | 
| 45 | 
            +
                      add_mapping('Gemfile.tt', 'Gemfile')
         | 
| 46 | 
            +
                      add_mapping('config.ru.tt', 'config.ru')
         | 
| 47 | 
            +
                      add_mapping('config/environment.rb.tt', 'config/environment.rb')
         | 
| 48 | 
            +
                      add_mapping('lib/app_name.rb.tt', "lib/#{ app_name }.rb")
         | 
| 49 | 
            +
                      add_mapping('lib/config/mapping.rb.tt', 'lib/config/mapping.rb')
         | 
| 50 | 
            +
                      add_mapping('config/application.rb.tt', 'config/application.rb')
         | 
| 51 | 
            +
                      add_mapping('config/routes.rb.tt', 'config/routes.rb')
         | 
| 52 | 
            +
                      add_mapping('views/application_layout.rb.tt', 'app/views/application_layout.rb')
         | 
| 53 | 
            +
                      add_mapping('templates/application.html.erb.tt', 'app/templates/application.html.erb')
         | 
| 54 | 
            +
                      add_mapping('favicon.ico', 'app/assets/favicon.ico')
         | 
| 55 | 
            +
                    end
         | 
| 56 | 
            +
             | 
| 57 | 
            +
                    def add_test_templates
         | 
| 58 | 
            +
                      if test_framework.rspec?
         | 
| 59 | 
            +
                        add_mapping('Rakefile.rspec.tt', 'Rakefile')
         | 
| 60 | 
            +
                        add_mapping('rspec.rspec.tt', '.rspec')
         | 
| 61 | 
            +
                        add_mapping('spec_helper.rb.rspec.tt', 'spec/spec_helper.rb')
         | 
| 62 | 
            +
                        add_mapping('features_helper.rb.rspec.tt', 'spec/features_helper.rb')
         | 
| 63 | 
            +
                        add_mapping('capybara.rb.rspec.tt', 'spec/support/capybara.rb')
         | 
| 64 | 
            +
                      else
         | 
| 65 | 
            +
                        add_mapping('Rakefile.minitest.tt', 'Rakefile')
         | 
| 66 | 
            +
                        add_mapping('spec_helper.rb.minitest.tt', 'spec/spec_helper.rb')
         | 
| 67 | 
            +
                        add_mapping('features_helper.rb.minitest.tt', 'spec/features_helper.rb')
         | 
| 68 | 
            +
                      end
         | 
| 69 | 
            +
                    end
         | 
| 70 | 
            +
             | 
| 71 | 
            +
                    def add_empty_directories
         | 
| 72 | 
            +
                      add_mapping('.gitkeep', 'config/initializers/.gitkeep')
         | 
| 73 | 
            +
                      add_mapping('.gitkeep', 'app/controllers/.gitkeep')
         | 
| 74 | 
            +
                      add_mapping('.gitkeep', 'app/views/.gitkeep')
         | 
| 75 | 
            +
                      add_mapping('.gitkeep', 'app/assets/images/.gitkeep')
         | 
| 76 | 
            +
                      add_mapping('.gitkeep', 'app/assets/javascripts/.gitkeep')
         | 
| 77 | 
            +
                      add_mapping('.gitkeep', 'app/assets/stylesheets/.gitkeep')
         | 
| 78 | 
            +
                      add_mapping('.gitkeep', "lib/#{ app_name }/entities/.gitkeep")
         | 
| 79 | 
            +
                      add_mapping('.gitkeep', "lib/#{ app_name }/repositories/.gitkeep")
         | 
| 80 | 
            +
                      add_mapping('.gitkeep', "lib/#{ app_name }/mailers/.gitkeep")
         | 
| 81 | 
            +
                      add_mapping('.gitkeep', "lib/#{ app_name }/mailers/templates/.gitkeep")
         | 
| 82 | 
            +
                      add_mapping('.gitkeep', 'public/.gitkeep')
         | 
| 83 | 
            +
             | 
| 84 | 
            +
                      add_mapping('.gitkeep', 'spec/features/.gitkeep')
         | 
| 85 | 
            +
                      add_mapping('.gitkeep', 'spec/controllers/.gitkeep')
         | 
| 86 | 
            +
                      add_mapping('.gitkeep', 'spec/views/.gitkeep')
         | 
| 87 | 
            +
                      add_mapping('.gitkeep', "spec/#{ app_name }/entities/.gitkeep")
         | 
| 88 | 
            +
                      add_mapping('.gitkeep', "spec/#{ app_name }/repositories/.gitkeep")
         | 
| 89 | 
            +
                      add_mapping('.gitkeep', "spec/#{ app_name }/mailers/.gitkeep")
         | 
| 90 | 
            +
                      add_mapping('.gitkeep', 'spec/support/.gitkeep')
         | 
| 91 | 
            +
             | 
| 92 | 
            +
                      if database_config.sql?
         | 
| 93 | 
            +
                        add_mapping('.gitkeep', 'db/migrations/.gitkeep')
         | 
| 94 | 
            +
                      else
         | 
| 95 | 
            +
                        add_mapping('.gitkeep', 'db/.gitkeep')
         | 
| 96 | 
            +
                      end
         | 
| 97 | 
            +
                    end
         | 
| 98 | 
            +
                    def template_source_path
         | 
| 99 | 
            +
                      Pathname.new(::File.dirname(__FILE__)).join('..', '..', 'generators', 'application', 'app').realpath
         | 
| 100 | 
            +
                    end
         | 
| 101 | 
            +
             | 
| 102 | 
            +
                    def upcase_app_name
         | 
| 103 | 
            +
                      app_name.to_env_s
         | 
| 104 | 
            +
                    end
         | 
| 105 | 
            +
             | 
| 106 | 
            +
                    def classified_app_name
         | 
| 107 | 
            +
                      Utils::String.new(app_name).classify
         | 
| 108 | 
            +
                    end
         | 
| 109 | 
            +
             | 
| 110 | 
            +
                    # def application_base_path
         | 
| 111 | 
            +
                    #   [ 'apps', app_name ].join(::File::SEPARATOR)
         | 
| 112 | 
            +
                    # end
         | 
| 113 | 
            +
                  end
         | 
| 114 | 
            +
                end
         | 
| 115 | 
            +
              end
         | 
| 116 | 
            +
            end
         |