middleman / middleman-sprockets

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

Expose Sprockets environment to extensions #20

Closed datapimp closed 11 years ago

datapimp commented 11 years ago

When middleman-sprockets is used, it would be nice to be able to access the sprockets environment in other extensions.

From looking at the code, it does seem as if I should be able to access it in the app variable that gets passed to the registered method. However it may be a load order problem, but my current attempts in the middleman extension I am writing have not been successful.

I will include a pull request when I figure it out. Any advice in the meantime would be appreciated

tdreyno commented 11 years ago

You're on the right track and I think the solution shouldn't be too difficult. Happy to help out with the PR

bhollis commented 11 years ago

I think you can access the Sprockets environment already via the sprockets method on the middleman application. It's defined here: https://github.com/middleman/middleman-sprockets/blob/master/lib/middleman-sprockets/extension.rb#L63

Is that not what you mean?

datapimp commented 11 years ago

Yeah, I thought so too, but in my extension:

  module CodeSync::MiddlemanExtension
    class << self  
      def registered app
        app.send :include, InstanceMethods

        raise unless app.respond_to?(:sprockets)
      end
    end
end

This actually raises an error. And I confirmed that the middleman-sprockets extension was being loaded prior to it. So i'm not sure what is going on exactly.

It seems like there may be some issues with the autoload_sprockets behavior in middleman-core extension code.

The app is using middleman-core 3.0.13 which doesn't seem to have the updates you made here:

https://github.com/middleman/middleman/commit/a50ca56fbcea6d508fad56e59c1e631a5fe52a5b

I will keep investigating

bhollis commented 11 years ago

I know why this is - we register the :sprockets extension too late. I'm fixing this on middleman master, but for now you can do:

app.after_configuration do
  sprockets.append_path "whatever"
end
bhollis commented 11 years ago

This is fixed on Middleman master now.