-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Hanami::CLI::RubyFileGenerator, convert Operation to use it inste…
…ad of ERB (#186) * Add dry-operation to default Gemfile * Add base Operation class, based on dry-operation * Fix view spec * Add Operation generators * Add empty `call` method definition * Remove ostruct * Allow slash separator for generator * Allow slash separator for generator * Rename module to admin * Remove newlines in generated files By adding new templates for un-nested operations * Remove input as default args * Remove Operations namespace, generate in app/ or slices/SLICE_NAME/ * Prevent generating operation without namespace * Revert "Prevent generating operation without namespace" This reverts commit a5bd2f3. * Add recommendation to add namespace to operations * Change examples * Switch to outputting directly, remove Files#recommend * Add Hanami::CLI::RubyFileGenerator * x.x.x => 2.2.0 * x.x.x => 2.2.0 * Include Dry::Monads[:result] in base Action * Add .module tests * Convert top-level app operation to use RubyFileGenerator * Convert nested app operation to use RubyFileGenerator * Support slash separators * Convert top-level slice operation to use RubyFileGenerator * Remove OperationContext * Remove namespaces instance variable * Refactor to variables * Remove last temporary instance variable * Refactor * More refactoring, for clarity * Rename variable for clarity * Rename helper method * Simplify RubyFileGenerator, support older versions * Convert Operation generator to use simplified RubyFileGenerator * Remove un-used errors * Refactor * Older kwargs forwarding style * Refactor * Rename variable * Add explanatory comment Add dry-monads include for slice base action * Fix base slice action * Remove un-used ERB templates * Remove OperationContext * Ternary over and/or * Fix missing 'end' from bad merge * Fix namespace recommendation * Extract App::Generate::Command * Specify full name, to use App::Command * Use constants file * Move class methods above initialize * Use constants file * Add yard comments * Revert "Use constants file" This reverts commit 303f502. Would need to namespace it and we may want to this to standalone so keeping it here. It's just two little spaces anyway * Fix indent to be two spaces
- Loading branch information
Showing
13 changed files
with
525 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# frozen_string_literal: true | ||
|
||
require "dry/inflector" | ||
require "dry/files" | ||
require "shellwords" | ||
require_relative "../../../naming" | ||
require_relative "../../../errors" | ||
|
||
module Hanami | ||
module CLI | ||
module Commands | ||
module App | ||
module Generate | ||
# @since 2.2.0 | ||
# @api private | ||
class Command < App::Command | ||
argument :name, required: true, desc: "Name" | ||
option :slice, required: false, desc: "Slice name" | ||
|
||
attr_reader :generator | ||
private :generator | ||
|
||
# @since 2.2.0 | ||
# @api private | ||
def initialize( | ||
fs:, | ||
inflector:, | ||
generator_class: nil, | ||
**opts | ||
) | ||
raise "Provide a generator class (that takes fs and inflector)" if generator_class.nil? | ||
|
||
super(fs: fs, inflector: inflector, **opts) | ||
@generator = generator_class.new(fs: fs, inflector: inflector, out: out) | ||
end | ||
|
||
# @since 2.2.0 | ||
# @api private | ||
def call(name:, slice: nil, **) | ||
normalized_slice = inflector.underscore(Shellwords.shellescape(slice)) if slice | ||
generator.call(app.namespace, name, normalized_slice) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 0 additions & 10 deletions
10
lib/hanami/cli/generators/app/operation/nested_app_operation.erb
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
lib/hanami/cli/generators/app/operation/nested_slice_operation.erb
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
lib/hanami/cli/generators/app/operation/top_level_app_operation.erb
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
lib/hanami/cli/generators/app/operation/top_level_slice_operation.erb
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.