Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
swilgosz opened this issue Oct 12, 2024 · 3 comments

Comments

@swilgosz
Copy link
Member

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
Copy link
Member Author

swilgosz commented Oct 12, 2024

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.

e3cc092

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

swilgosz pushed a commit to swilgosz/hanami-cli that referenced this issue Oct 12, 2024
@timriley
Copy link
Member

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
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants