Sha256: ac094873b10bd64e1ac7c2f1923813d08655acda4355ef741a4e1cbb21a1371a

Contents?: true

Size: 1.56 KB

Versions: 4

Compression:

Stored size: 1.56 KB

Contents

# 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.0.0
          # @api private
          class View < App::Command
            # TODO: make this configurable
            DEFAULT_FORMAT = "html"
            private_constant :DEFAULT_FORMAT

            # TODO: make engine configurable

            argument :name, required: true, desc: "View name"
            option :slice, required: false, desc: "Slice name"

            example [
              %(books.index               (MyApp::Actions::Books::Index)),
              %(books.index --slice=admin (Admin::Actions::Books::Index)),
            ]
            attr_reader :generator
            private :generator

            # @since 2.0.0
            # @api private
            def initialize(
              fs: Hanami::CLI::Files.new,
              inflector: Dry::Inflector.new,
              generator: Generators::App::View.new(fs: fs, inflector: inflector),
              **
            )
              @generator = generator
              super(fs: fs)
            end

            # @since 2.0.0
            # @api private
            def call(name:, format: DEFAULT_FORMAT, slice: nil, **)
              slice = inflector.underscore(Shellwords.shellescape(slice)) if slice

              generator.call(app.namespace, name, format, slice)
            end
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
hanami-cli-2.1.0.rc2 lib/hanami/cli/commands/app/generate/view.rb
hanami-cli-2.1.0.rc1 lib/hanami/cli/commands/app/generate/view.rb
hanami-cli-2.1.0.beta2 lib/hanami/cli/commands/app/generate/view.rb
hanami-cli-2.1.0.beta1 lib/hanami/cli/commands/app/generate/view.rb