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 it possible to put templates in a different directory #14

Closed
dukejones opened this issue Dec 12, 2011 · 6 comments
Closed

Make it possible to put templates in a different directory #14

dukejones opened this issue Dec 12, 2011 · 6 comments

Comments

@dukejones
Copy link

The latest Sprockets is giving me errors when I try to put my templates directory directly in app/assets.

Uncaught Error: Sprockets::FileOutsidePaths: /Users/dorje/work/cms/app/assets/templates/about.hamlc isn't in paths: /Users/dorje/work/cms/app/assets/images, /Users/dorje/work/cms/app/assets/javascripts, /Users/dorje/work/cms/app/assets/stylesheets, /Users/dorje/work/cms/vendor/assets/images, /Users/dorje/work/cms/vendor/assets/javascripts, /Users/dorje/work/cms/vendor/assets/stylesheets, /Users/dorje/.rvm/gems/ruby-1.9.2-p290/gems/haml_coffee_assets-0.4.0/vendor/assets/javascripts, /Users/dorje/.rvm/gems/ruby-1.9.2-p290/gems/rails-backbone-0.5.5/vendor/assets/javascripts, /Users/dorje/.rvm/gems/ruby-1.9.2-p290/gems/jquery-rails-1.0.19/vendor/assets/javascripts

It also gives me much cognitive dissonance not to put my templates with the rest of my JS application.

Is there a way I can configure the app to view a certain directory as the base dir? I've been reading through all kinds of Tilt stuff but I can't quite figure out what this scope.logical_path stuff is about.

@netzpirat
Copy link
Collaborator

That's strange, I have my templates folder also directly in app/assets without problems. Can you try to add your path to the assets path in your environment config:

config.assets.paths << "#{ Rails.root }/app/assets/templates"

@netzpirat
Copy link
Collaborator

You can now enable the Sprockets JST processor by switching to the .jst.hamlc extension, so Haml Coffee Assets isn't responsible for creating the JST.

I'm closing this since it's not related to Haml Coffee Assets, it's a Sprockets configuration issue. The way it's describe in the README is just my personal setup, but you can configure Sprockets to your needs easily.

@dukejones
Copy link
Author

It's actually working without error now without that change for some reason.

The real reason I asked for the change was that I wanted my templates in my javascripts/ directory alongside my models/ routers/ and views/ directories. But I'll give this a shot and see how it feels.

@jingoro
Copy link
Collaborator

jingoro commented Jan 31, 2012

I ran into a similar issue. Putting templates in app/assets/templates can lead to a path collisions. For example, if you have both of the following it will lead to only one being loaded in the development environment:

  • app/assets/javascripts/foo.js
  • app/assets/templates/foo.hamlc

I would recommend re-opening this issue because I don't think putting the templates in app/assets works out of the box. I handled this by:

  1. putting templates in app/assets/javascripts/templates
  2. modifying the evaluate method in HamlCoffeeAssets::HamlCoffeeTemplate to use a customizable name_filter proc.

See https://github.com/jingoro/haml_coffee_assets/commit/309d1428c42a750df0cacfaf48ca3a84be4db8a8

Let me know what you think about this general approach.

@netzpirat netzpirat reopened this Jan 31, 2012
@netzpirat
Copy link
Collaborator

This is a very nice solution. I'll pull you commit today and update the README. I'd only change the name_filter to be lambda { |n| n.sub /^templates\//, '' } by default, because I think this is what most people want.

@netzpirat
Copy link
Collaborator

Thanks @jingoro for the nice pull request!

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

3 participants