Module: Lono::Template::Context::Loader::LoadFiles

Included in:
Extensions::Loader, Lono::Template::Context::Loader
Defined in:
lib/lono/template/context/loader/load_files.rb

Instance Method Summary collapse

Instance Method Details

#load_files(root) ⇒ Object

Load custom helper methods from project



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/lono/template/context/loader/load_files.rb', line 4

def load_files(root)
  paths = Dir.glob("#{root}/**/*.rb")
  paths.sort_by! { |p| p.size } # so namespaces are loaded first
  paths.each do |path|
    # lib = gem extensions
    # app = project extensions
    filename = path.sub(%r{.*/lib/},'').sub(%r{.*/app/helpers/},'').sub('.rb','')
    module_name = filename.camelize

    # Prepend a period so require works LONO_ROOT is set to a relative path without a period.
    #
    # Example: LONO_ROOT=tmp/lono_project
    first_char = path[0..0]
    path = "./#{path}" unless %w[. /].include?(first_char)

    require path
    self.class.send :include, module_name.constantize
  end
end