Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
"config" object for setting defaults #41
I was using breadcrumbs_on_rails along with a twitter bootstrap-friendly builder (https://gist.github.com/riyad/1933884) and it felt tedious and wrong explicitly passing the "builder" and "separator" options to every "render_breadcrumbs" invocation when these things weren't changing, so I added a Breadcrumbs "config" module member (and supporting logic to the view helpers and SimpleBuilder) so that I could just stick this in an initializer:
Merge if you see fit.
referenced this pull request
Jul 17, 2013
Wow, it took almost 1 year to check this PR. Sorry for the long time.
I'm not a big fan of using OpenStruct in this case. In fact, the set of defined options should be constrained to prevent typos or simply passing anything into the config object.
Moreover, I would prefer
Here's a possible implementation
class BreadcrumbsOnRails class Configuration attr_accessor :default_separator, :default_builder def initialize self.default_separator = " » " self.default_builder = Breadcrumbs::SimpleBuilder end end class << self def configure @config ||= Configuration.new block_given? ? yield(@config) : @config end alias :config :configure end end
This will make possible to write
BreadcrumbsOnRails.configure do |config| config.default_separator = ' ... ' end