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

Allow users to override admin templates on a file by file basis #1226

Merged
merged 2 commits into from Jul 1, 2013

Conversation

Projects
None yet
4 participants
@xavriley

xavriley commented Apr 5, 2013

This change lets users override single templates by including them in a generators/templates folder in the project root. It only uses the files that are there and falls back to the gem otherwise.

For example, if I want to include my company logo in every edit page I can add a file like so:

.
├── Gemfile
├── Gemfile.lock
├── Rakefile
├── admin
├── app
... other files in project
├── generators
│   ├── admin_extensions.rb
│   └── templates
│       └── haml
│           └── page
│               └── edit.haml.tt
├── lib
├── models
├── public
...etc

The admin generator will use my custom thor template for every edit page and fall back to the gem for everything else.

My use case for this has been when I'd like the admin generator to include image uploads by for models with a field name containing '_img' or a position widget for a field called 'position'. Being able to tweak the admin page generator to do this speeds up development when you have lots of models.

If the folder isn't there it doesn't complain and the generator works as standard. I've added tests for both the admin app and page generator.

What do people think?

@dariocravero

This comment has been minimized.

Show comment
Hide comment
@dariocravero

dariocravero Apr 8, 2013

Contributor

Hey @xavierRiley,

I think you have a valid point here, thanks for submitting the patch.

I'm just not sure about the implementation and if the main gem is the right place for it (perhaps it goes into plugins or something). Let me have a look at it in more depth.

Darío

Contributor

dariocravero commented Apr 8, 2013

Hey @xavierRiley,

I think you have a valid point here, thanks for submitting the patch.

I'm just not sure about the implementation and if the main gem is the right place for it (perhaps it goes into plugins or something). Let me have a look at it in more depth.

Darío

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost commented Apr 9, 2013

👍

DAddYE added a commit that referenced this pull request Jul 1, 2013

Merge pull request #1226 from xavriley/override_admin_templates
Allow users to override admin templates on a file by file basis

@DAddYE DAddYE merged commit 2afae0f into padrino:master Jul 1, 2013

1 check passed

default The Travis build passed
Details
@DAddYE

This comment has been minimized.

Show comment
Hide comment
@DAddYE

DAddYE Jul 1, 2013

Member

Looks good, @xavriley , 10 points if we can catch also a ENV['PADRINO_GENERATOR_TEMPLATES'] so you can share your templates across different applications!

Member

DAddYE commented Jul 1, 2013

Looks good, @xavriley , 10 points if we can catch also a ENV['PADRINO_GENERATOR_TEMPLATES'] so you can share your templates across different applications!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment