Module: Middleman::CoreExtensions::ExternalHelpers
- Defined in:
- lib/middleman-core/core_extensions/external_helpers.rb
Class Method Summary collapse
-
.registered(app) ⇒ Object
(also: included)
once registered.
Class Method Details
.registered(app) ⇒ Object Also known as: included
once registered
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/middleman-core/core_extensions/external_helpers.rb', line 10 def registered(app) # 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.new { |filename| basename = File.basename(filename, File.extname(filename)) basename.camelcase }, 'Proc implementing the conversion from helper filename to module name' # After config app.after_configuration do helpers_path = File.join(root, config[:helpers_dir]) next unless File.exists?(helpers_path) Dir[File.join(helpers_path, config[:helpers_filename_glob])].each do |filename| module_name = config[:helpers_filename_to_module_name_proc].call(filename) next unless module_name require filename next unless Object.const_defined?(module_name.to_sym) helpers Object.const_get(module_name.to_sym) end end end |