middleman / middleman-sprockets

Sprockets support for Middleman
http://middlemanapp.com
MIT License
62 stars 53 forks source link

No longer have access to `sprockets` instance in template #95

Closed robertwbradford closed 8 years ago

robertwbradford commented 8 years ago

I see in v4.0.0.rc.1 that this is using the new pattern for Middleman extensions. I've been working to update an app from v3 and realized I'm using something like the following in one of my layouts to see if an image exists before including a default image:

topic_image_path = "some/image/path.jpg"
default_topic_image_path = "some/default/path.jpg"
topic_image = sprockets.find_asset(topic_image_path) ? topic_image_path : default_topic_image_path

However, because the new version of the extension only exposes the sprockets instance to the config file, I'm getting an error. Is adding the following a possibility if I were to do a PR?

expose_to_template sprockets: :environment

Or is there a better way to accomplish this?

stevenosloan commented 8 years ago

Hmmm, yeah I know I have used that in a few places to dump svgs as well. I'll look into it -- for now you should be able to do this though:

topic_image = extensions[:sprockets].environment.find_asset(topic_image_path) ? topic_image_path : default_topic_image_path
tdreyno commented 8 years ago

That code sample, exposing that var to the template sandbox, should work.

stevenosloan commented 8 years ago

Yep, @robertwbradford if you use the gem from master you should be good now:

gem 'middleman-sprockets', github: 'middleman/middleman-sprockets'
robertwbradford commented 8 years ago

Beauty! I'll have to look at this later, but thanks for the change. Middleman has been a great platform to work in, btw.