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, **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, **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 |
# File 'lib/hanami/cli/generators/app/slice.rb', line 22 def call(app, slice, url, **opts) skip_route = opts.fetch(:skip_route, false) unless skip_route fs.inject_line_at_class_bottom( fs.join("config", "routes.rb"), "class Routes", "\n slice :\#{inflector.underscore(slice)}, at: \"\#{url}\" do\n end\n ROUTES\n )\n end\n\n fs.mkdir(directory = \"slices/\#{slice}\")\n\n RubyClassFile.new(\n fs: fs,\n inflector: inflector,\n namespace: slice,\n key: \"action\",\n base_path: directory,\n parent_class_name: \"\#{Hanami.app.namespace}::Action\",\n auto_register: false\n ).create\n\n RubyClassFile.new(\n fs: fs,\n inflector: inflector,\n namespace: slice,\n key: \"view\",\n base_path: directory,\n parent_class_name: \"\#{Hanami.app.namespace}::View\",\n auto_register: false\n ).create\n\n RubyModuleFile.new(\n fs: fs,\n inflector: inflector,\n namespace: slice,\n key: \"views.helpers\",\n base_path: directory,\n auto_register: false,\n body: [\"# Add your view helpers here\"]\n ).create\n\n RubyClassFile.new(\n fs: fs,\n inflector: inflector,\n namespace: slice,\n key: \"views.context\",\n base_path: directory,\n parent_class_name: \"\#{Hanami.app.namespace}::View::Context\",\n auto_register: false,\n body: [\"# Define your view context here. See https://guides.hanamirb.org/views/context/ for details.\"]\n ).create\n\n fs.create(\n fs.join(directory, \"templates\", \"layouts\", \"app.html.erb\"),\n app_layout_template(\n page_title: \"\#{inflector.humanize(app)} - \#{inflector.humanize(slice)}\"\n )\n )\n\n if Hanami.bundled?(\"dry-operation\")\n RubyClassFile.new(\n fs: fs,\n inflector: inflector,\n namespace: slice,\n key: \"operation\",\n base_path: directory,\n parent_class_name: \"\#{Hanami.app.namespace}::Operation\",\n auto_register: false\n ).create\n end\n\n if Hanami.bundled?(\"hanami-assets\")\n fs.create(\n fs.join(directory, \"assets\", \"js\", \"app.js\"),\n %(import \"../css/app.css\";\\n)\n )\n fs.create(\n fs.join(directory, \"assets\", \"css\", \"app.css\"),\n <<~CSS\n body {\n background-color: #fff;\n color: #000;\n font-family: sans-serif;\n }\n CSS\n )\n fs.create(fs.join(directory, \"assets\", \"images\", \"favicon.ico\"), file(\"favicon.ico\"))\n end\n\n if Hanami.bundled?(\"hanami-db\") && !opts.fetch(:skip_db, false)\n RubyClassFile.new(\n fs: fs,\n inflector: inflector,\n namespace: slice,\n key: \"db.relation\",\n base_path: directory,\n parent_class_name: \"\#{Hanami.app.namespace}::DB::Relation\",\n ).create\n\n RubyClassFile.new(\n fs: fs,\n inflector: inflector,\n namespace: slice,\n key: \"db.repo\",\n base_path: directory,\n parent_class_name: \"\#{Hanami.app.namespace}::DB::Repo\",\n ).create\n\n RubyClassFile.new(\n fs: fs,\n inflector: inflector,\n namespace: slice,\n key: \"db.struct\",\n base_path: directory,\n parent_class_name: \"\#{Hanami.app.namespace}::DB::Struct\",\n ).create\n\n fs.touch(fs.join(directory, \"relations\", \".keep\"))\n fs.touch(fs.join(directory, \"repos\", \".keep\"))\n fs.touch(fs.join(directory, \"structs\", \".keep\"))\n end\n\n fs.touch(fs.join(directory, \"actions/.keep\"))\n fs.touch(fs.join(directory, \"views/.keep\"))\n fs.touch(fs.join(directory, \"templates/.keep\"))\n fs.touch(fs.join(directory, \"templates/layouts/.keep\"))\nend\n".chomp |