Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Expose Sprockets environment to extensions #20

Closed
datapimp opened this Issue · 5 comments

3 participants

@datapimp

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
Owner

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

@bhollis
Owner

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

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:

middleman/middleman@a50ca56

I will keep investigating

@bhollis
Owner

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
Owner

This is fixed on Middleman master now.

@bhollis bhollis closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.