sam / harbor

Harbor is a Ruby Web Framework.
https://github.com/sam/harbor
MIT License
3 stars 6 forks source link

Proposal: Provide an easy way to register view helpers #62

Closed fgrehm closed 12 years ago

fgrehm commented 12 years ago

We should have an easier way to register view helpers than

Harbor::ViewContext.send(:include, CaptainsBlog::Helpers)

I'd be happy to have that as a simple shortcut on config/default.rb but we might not have required the helper file yet at "configuration time" or we would need to have autoloading in place for it to work.

config.helpers.register CaptainsBlog::Helpers

We could also have a "helper module" that sends the include:

module Harbor::ViewHelper
  def self.extended(base)
    Harbor::ViewContext.send :include, base
  end
end

module CapitainsBlog::Helpers
  extend Harbor::ViewHelper

  def my_awesome_helper_method
    # ... some crazy code ...
  end
end

Any other thoughts on how can we handle this? Are you guys happy with the current way of doing it?

sam commented 12 years ago

I like config.helpers.register as the underlying mechanics. I do think we should grep /helpers/*.rb and auto-register those files though.

Adding a new helper should be as easy as dropping the file in the right place IMO.

fgrehm commented 12 years ago

We need some kind of convention to make this work, like having helpers defined under AppName::Helpers or just Helpers module so we can figure out from where we should grab the module to include.

Other thoughts?

sam commented 12 years ago

AppName::Helpers works I think.