Sha256: d9dce2d9712e969ee64d623d2f1cfcc0b7179553bde8eb734c526b4122ef944d
Contents?: true
Size: 1.86 KB
Versions: 2
Compression:
Stored size: 1.86 KB
Contents
# frozen_string_literal: true require "erb" require "dry/files" require "hanami/cli/generators/app/slice_context" module Hanami module CLI module Generators module App class Slice def initialize(fs:, inflector:) @fs = fs @inflector = inflector end def call(app, slice, url, context: SliceContext.new(inflector, app, slice, url)) fs.inject_line_at_class_bottom( fs.join("config", "routes.rb"), "class Routes", t("routes.erb", context).chomp ) fs.mkdir(directory = "slices/#{slice}") # fs.write("#{directory}/config/slice.rb", t("slice.erb", context)) fs.write(fs.join(directory, "action.rb"), t("action.erb", context)) # fs.write(fs.join(directory, "/view.rb"), t("view.erb", context)) # fs.write(fs.join(directory, "/entities.rb"), t("entities.erb", context)) # fs.write(fs.join(directory, "/repository.rb"), t("repository.erb", context)) fs.write(fs.join(directory, "actions/.keep"), t("keep.erb", context)) # fs.write(fs.join(directory, views/.keep"), t("keep.erb", context)) # fs.write(fs.join(directory, templates/.keep"), t("keep.erb", context)) # fs.write(fs.join(directory, templates/layouts/.keep"), t("keep.erb", context)) # fs.write(fs.join(directory, entities/.keep"), t("keep.erb", context)) # fs.write(fs.join(directory, repositories/.keep"), t("keep.erb", context)) end private attr_reader :fs attr_reader :inflector def template(path, context) require "erb" ERB.new( File.read(__dir__ + "/slice/#{path}") ).result(context.ctx) end alias_method :t, :template end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
hanami-cli-2.0.0.rc1 | lib/hanami/cli/generators/app/slice.rb |
hanami-cli-2.0.0.beta4 | lib/hanami/cli/generators/app/slice.rb |