Provide a core extension class, like Rails::Engine #460

Closed
wants to merge 4 commits into
from

Conversation

Projects
None yet
2 participants
Owner

tdreyno commented Jun 3, 2012

Thinking of sneaking this in the back door... starting to get real annoyed with every extension being jammed into Application by default.

@bhollis bhollis commented on an outdated diff Jun 3, 2012

...core/lib/middleman-core/core_extensions/extensions.rb
ext
else
::Middleman::Extensions.load(ext.to_sym)
end
- if ext_module.nil?
+ $stderr.puts extension_container.to_s
@bhollis

bhollis Jun 3, 2012

Owner

Straggler debugging statement?

Owner

bhollis commented Jun 3, 2012

I like the idea. The only concern would be that you don't get to lazy-require quite as much, but it seems worth it to drop a ton of boilerplate.

Owner

tdreyno commented Jun 3, 2012

I think we're losing a ton of laziness in Bundle.require, maybe we add a lazy require here, like Tilt.

Owner

tdreyno commented Jun 4, 2012

I like this idea a lot. Will wait until 3.1, but I've been thinking about it all weekend and this could be great.

Owner

tdreyno commented Jun 16, 2012

Moving to 3.1

Owner

tdreyno commented Oct 14, 2012

Still trying to figure out the best way to do this, it's liable to become spaghetti. @bhollis, I'd love some input.

Blocks, hooks or methods:

class MyPlugin < Middleman::Extension
  after_configuration do
    # my thing
  end
end
class MyPlugin < Middleman::Extension
  after :configuration, :do_it

  def do_it
    # my thing
  end
end
class MyPlugin < Middleman::Extension
  def after_configuration
    # my thing
  end
end

I think the hooks one provides the most flexibility and lets other pieces of code expose events to be hooked. Like so:

# File Watcher
def file_did_change(path)
  trigger :file_did_change, path
end

# Extension
class MyWatcher < Middleman::Extension
  after :file_did_change, :update_cache

  def update_cache(path)
    # do something
  end
end

Is this kind of binding and eventing sane in Ruby? I feel like my JS brain is creating things that aren't normal in Ruby-land.

Owner

bhollis commented Oct 15, 2012

I think I like the hooks thing (it's sorta like ActiveModel::Callbacks). I'm not sure after is the right name for the method though - will there be a corresponding before?

In general it'd actually be nicer to have methods on Middleman::Extension that you override (allows for inheritance, makes it easier to figure out what's available to override) but maybe that gets complicated and makes things harder to extend? I guess you could always mix in more methods to Middleman::Extension to make new callbacks...

Owner

tdreyno commented Oct 15, 2012

I'm using the ActiveSupport Callback stuff already, so sweet.

tdreyno referenced this pull request in middleman/middleman-blog Nov 16, 2012

Closed

Allow Multiple Blogs #37

Owner

tdreyno commented Apr 11, 2013

This happened, simply, elsewhere

tdreyno closed this Apr 11, 2013

tdreyno deleted the extension_class branch Jan 1, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment