Sha256: f8fbe5ba9d0630bb747c26d554036ebd605825b9cd0d29b2e018aec29dbceec4

Contents?: true

Size: 1.16 KB

Versions: 39

Compression:

Stored size: 1.16 KB

Contents

module Middleman
  module CoreExtensions
    # Load helpers in `helpers/`
    class ExternalHelpers < Extension
      define_setting :helpers_dir, 'helpers', 'Directory to autoload helper modules from'
      define_setting :helpers_filename_glob, '**.rb', 'Glob pattern for matching helper ruby files'
      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'

      def after_configuration
        helpers_path = File.join(app.root, app.config[:helpers_dir])

        return unless File.exist?(helpers_path)

        glob = File.join(helpers_path, app.config[:helpers_filename_glob])
        ::Middleman::Util.glob_directory(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

39 entries across 39 versions & 3 rubygems

Version Path
middleman-core-4.5.1 lib/middleman-core/core_extensions/external_helpers.rb
middleman-core-4.5.0 lib/middleman-core/core_extensions/external_helpers.rb
middleman-core-4.4.3 lib/middleman-core/core_extensions/external_helpers.rb
middleman-core-4.4.2 lib/middleman-core/core_extensions/external_helpers.rb
middleman-core-4.4.0 lib/middleman-core/core_extensions/external_helpers.rb
middleman-core-4.3.11 lib/middleman-core/core_extensions/external_helpers.rb
middleman-core-4.3.10 lib/middleman-core/core_extensions/external_helpers.rb
middleman-core-4.3.8 lib/middleman-core/core_extensions/external_helpers.rb
middleman-core-4.3.7 lib/middleman-core/core_extensions/external_helpers.rb
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/middleman-core-4.3.3/lib/middleman-core/core_extensions/external_helpers.rb
middleman-core-4.3.6 lib/middleman-core/core_extensions/external_helpers.rb
middleman-core-4.3.5 lib/middleman-core/core_extensions/external_helpers.rb
middleman-core-4.3.4 lib/middleman-core/core_extensions/external_helpers.rb
middleman-core-4.3.3 lib/middleman-core/core_extensions/external_helpers.rb
middleman-core-4.3.2 lib/middleman-core/core_extensions/external_helpers.rb
middleman-core-4.3.1 lib/middleman-core/core_extensions/external_helpers.rb
middleman-core-4.3.0 lib/middleman-core/core_extensions/external_helpers.rb
middleman-core-4.3.0.rc.3 lib/middleman-core/core_extensions/external_helpers.rb
middleman-core-4.3.0.rc.2 lib/middleman-core/core_extensions/external_helpers.rb
middleman-core-with-external-sources-watch-fix-4.1.10 lib/middleman-core/core_extensions/external_helpers.rb