Class: Hanami::CLI::Generators::App::Slice Private
- Inherits:
-
Object
- Object
- Hanami::CLI::Generators::App::Slice
- Defined in:
- lib/hanami/cli/generators/app/slice.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Method Summary collapse
- #call(app, slice, url, force: false, **opts) ⇒ Object private
-
#initialize(fs:, inflector:) ⇒ Slice
constructor
private
A new instance of Slice.
Constructor Details
#initialize(fs:, inflector:) ⇒ Slice
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Slice.
15 16 17 18 |
# File 'lib/hanami/cli/generators/app/slice.rb', line 15 def initialize(fs:, inflector:) @fs = fs @inflector = inflector end |
Instance Method Details
#call(app, slice, url, force: false, **opts) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/hanami/cli/generators/app/slice.rb', line 22 def call(app, slice, url, force: false, **opts) # rubocop:disable Metrics/AbcSize skip_route = opts.fetch(:skip_route, false) unless skip_route fs.inject_line_at_class_bottom( fs.join("config", "routes.rb"), "class Routes", <<~ROUTES.chomp slice :#{inflector.underscore(slice)}, at: "#{url}" do end ROUTES ) end fs.mkdir(directory = "slices/#{slice}") RubyClassFile.new( fs: fs, inflector: inflector, namespace: slice, key: "action", base_path: directory, parent_class_name: "#{Hanami.app.namespace}::Action", auto_register: false ).create(force:) RubyClassFile.new( fs: fs, inflector: inflector, namespace: slice, key: "view", base_path: directory, parent_class_name: "#{Hanami.app.namespace}::View", auto_register: false ).create(force:) if Hanami.bundled?("hanami-mailer") RubyClassFile.new( fs:, inflector:, namespace: slice, key: "mailer", base_path: directory, parent_class_name: "#{Hanami.app.namespace}::Mailer", auto_register: false, body: ["# Add common mailer behavior here. See https://hanakai.org/learn/hanami/mailers for details."] ).create(force:) fs.touch(fs.join(directory, "mailers/.keep")) end RubyModuleFile.new( fs: fs, inflector: inflector, namespace: slice, key: "views.helpers", base_path: directory, auto_register: false, body: ["# Add your view helpers here"] ).create(force:) RubyClassFile.new( fs: fs, inflector: inflector, namespace: slice, key: "views.context", base_path: directory, parent_class_name: "#{Hanami.app.namespace}::View::Context", auto_register: false, body: ["# Define your view context here. See https://hanakai.org/learn/hanami/views/context/ for details."] # rubocop:disable Layout/LineLength ).create(force:) fs.create( fs.join(directory, "templates", "layouts", "app.html.erb"), app_layout_template( page_title: "#{inflector.humanize(app)} - #{inflector.humanize(slice)}" ), force: ) fs.create( fs.join(directory, "config", "i18n", "en.yml"), File.read(File.join(__dir__, "..", "i18n.yml")), force: ) if Hanami.bundled?("dry-operation") RubyClassFile.new( fs: fs, inflector: inflector, namespace: slice, key: "operation", base_path: directory, parent_class_name: "#{Hanami.app.namespace}::Operation", auto_register: false ).create(force:) end if Hanami.bundled?("hanami-assets") fs.create( fs.join(directory, "assets", "js", "app.js"), %(import "../css/app.css";\n), force: ) fs.create( fs.join(directory, "assets", "css", "app.css"), <<~CSS, body { background-color: #fff; color: #000; font-family: sans-serif; } CSS force: ) fs.create(fs.join(directory, "assets", "images", "favicon.ico"), file("favicon.ico"), force:) end if Hanami.bundled?("hanami-db") && !opts.fetch(:skip_db, false) RubyClassFile.new( fs: fs, inflector: inflector, namespace: slice, key: "db.relation", base_path: directory, parent_class_name: "#{Hanami.app.namespace}::DB::Relation" ).create(force:) RubyClassFile.new( fs: fs, inflector: inflector, namespace: slice, key: "db.repo", base_path: directory, parent_class_name: "#{Hanami.app.namespace}::DB::Repo" ).create(force:) RubyClassFile.new( fs: fs, inflector: inflector, namespace: slice, key: "db.struct", base_path: directory, parent_class_name: "#{Hanami.app.namespace}::DB::Struct" ).create(force:) fs.touch(fs.join(directory, "relations", ".keep")) fs.touch(fs.join(directory, "repos", ".keep")) fs.touch(fs.join(directory, "structs", ".keep")) end fs.touch(fs.join(directory, "actions/.keep")) fs.touch(fs.join(directory, "views/.keep")) fs.touch(fs.join(directory, "templates/.keep")) fs.touch(fs.join(directory, "templates/layouts/.keep")) end |