Sha256: 5dc0b82cf5ab7563c1ac47d2867b64f376b1fd5e87a36a5262c4e64f66957456
Contents?: true
Size: 1.27 KB
Versions: 8
Compression:
Stored size: 1.27 KB
Contents
module Middleman module CoreExtensions # Load helpers in `helpers/` class ExternalHelpers < Extension def initialize(app, options_hash={}, &block) super # Setup a default helpers paths app.config.define_setting :helpers_dir, 'helpers', 'Directory to autoload helper modules from' app.config.define_setting :helpers_filename_glob, '**.rb', 'Glob pattern for matching helper ruby files' app.config.define_setting :helpers_filename_to_module_name_proc, proc { |filename| basename = File.basename(filename, File.extname(filename)) basename.camelcase }, 'Proc implementing the conversion from helper filename to module name' end def after_configuration helpers_path = File.join(app.root, app.config[:helpers_dir]) return unless File.exist?(helpers_path) Dir[File.join(helpers_path, app.config[:helpers_filename_glob])].each do |filename| module_name = app.config[:helpers_filename_to_module_name_proc].call(filename) next unless module_name require filename next unless Object.const_defined?(module_name.to_sym) app.template_context_class.send :include, Object.const_get(module_name.to_sym) end end end end end
Version data entries
8 entries across 8 versions & 1 rubygems