Sha256: 0468b2466b0c782a9b385d7797f2c9b1fc0e0a555584aa67daf9947715fa2792

Contents?: true

Size: 1.37 KB

Versions: 4

Compression:

Stored size: 1.37 KB

Contents

# Load helpers in helpers/
module Middleman
  module CoreExtensions
    module ExternalHelpers

      # Setup extension
      class << self

        # once registered
        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
        alias :included :registered
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
middleman-core-3.3.2 lib/middleman-core/core_extensions/external_helpers.rb
middleman-core-3.3.1 lib/middleman-core/core_extensions/external_helpers.rb
middleman-core-3.3.0 lib/middleman-core/core_extensions/external_helpers.rb
middleman-core-3.2.2 lib/middleman-core/core_extensions/external_helpers.rb