gma / nesta

File Based CMS and Static Site Generator
http://nestacms.com
MIT License
902 stars 121 forks source link

Nesta ignores theme’s .slim templates #144

Closed agarzola closed 1 year ago

agarzola commented 10 years ago

After following these instructions to switch the templating engine to Slim, Nesta is throwing this error:

No such file or directory - /Users/agarzola/.rvm/gems/ruby-1.9.2-p290/gems/nesta-0.9.13/views/page.slim

However, my theme does contains a page.slim template (I’ve renamed all of my theme’s templates to .slim), so it would seem that Nesta is ignoring my theme’s templates. I tried switching to Erb and did not get this error, so it seems to have something to do with Slim specifically.

Here’s the app.rb in my theme’s directory (/themes/v2/app.rb), in case it helps you spot any mistakes I may have made.

Thanks!

gma commented 10 years ago

Sorry about this. You've discovered a weakness in the way Nesta looks for templates in themes.

Sinatra only looks in one folder for templates, so to support reading templates from different locations (either the theme, or the site's local ./views folder) Nesta redefines the Sinatra methods that render each template (e.g. haml, erb, etc), teaching it how to look in multiple locations.

The code that does it is here (in the Renderers module): https://github.com/gma/nesta/blob/master/lib/nesta/overrides.rb

If you definitely need a theme, the easiest solution would be to define Nesta::Overrides::Renderers#slim (to do the same thing as the existing methods, only for slim) in your app.rb file. If you don't really need a theme (and are just styling one site) you'll probably find that slim will just work if you make a ./views folder and move your templates into that instead.

Thanks for reporting it.

agarzola commented 10 years ago

Thanks for providing options, Graham! I'll follow your suggestion of moving my views directory to the root of the project. I don't really need themes. Not yet, anyway.

Thanks again!

agarzola commented 10 years ago

Actually, I decided to try out defining a slim method to my app.rb. However, is this something you would consider adding to the gem? It would be a more permanent solution, methinks. I’d happily add it and send a pull request if you’d prefer.

gma commented 10 years ago

On 7 Jan 2014, at 15:46, Alfonso notifications@github.com wrote:

Actually, I decided to try out defining a slim method to my app.rb. However, is this something you would consider adding to the gem? It would be a more permanent solution, methinks. I’d happily add it and send a pull request if you’d prefer.

Definitely. There’ll be a nicer solution in the long term, where it just infers what it needs to support (there’s a big discussion on it in one of the other bug reports), but in the meantime I’ll happily accept a pull request.

You’d need to install the gem from gma/master for a while though to get the fix (until I release 0.10.0).

gma commented 1 year ago

This will have been fixed by 19ec573c06a9443091919e9142ded96e92fbf76c, which will be included in the next release (0.14.0).