cli icon indicating copy to clipboard operation
cli copied to clipboard

Make Template dir configurable, for easy templates overrides (UI engines extensions writing)

Open swilgosz opened this issue 1 year ago • 3 comments

Background

I'm writing a Bulma support extension for hanami-cli. To make it possible, I need to duplicate some commands, generators and templates, most of which are ruby files that I can safely ignore. This happens, because all our generators use __dir__, to fetch the source file to generate content from.

          def template(path, context)
            require "erb"

            ERB.new(
              File.read(File.join(__dir__, "app", path)),
              trim_mode: "-"
            ).result(context.ctx)
          end

TODO

Make the __dir__ configurable, so gem authors can easly change the base_path for generators. If file does not exists, fall-back to default Hanami::CLI path.

Pros

  • Writing frontent engine support or file interpreters spport will be very easy (bulma, boostrap, or slim/haml, etc)
  • We can minimize the number of files needed to be copied and kept in sync.

swilgosz avatar Oct 12 '24 20:10 swilgosz

POC

I've created a POC that we could use as base to improve upon. Generators NOT updated yet.

Next would be Using this configuration in generators which I can also do, extracting some common functionality to base generator.

e3cc09269c9d6c7e0fb8e11169813dc6da7d76f8

cc: @cllns, I'll follow up with generator updates, if I'll get the greenlight to proceed with this idea.

swilgosz avatar Oct 12 '24 21:10 swilgosz

The generators in hanami-cli are marked as "@api private", and as such I'd like for us to wait before making changes to support third party usage.

You can still add your own "generate" commands to the hanami command - that is already available as public - just use your own method for generating the files.

We can consider making our internal generators available for public use in the future, but this is out of scope for the impending 2.2 release.

timriley avatar Oct 13 '24 04:10 timriley

(Thank you for filing this, though! This is a good example of one of the things we should make configurable)

timriley avatar Oct 13 '24 04:10 timriley