Class: Frontman::Bootstrapper

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/frontman/bootstrapper.rb

Class Method Summary collapse

Class Method Details

.bootstrap_app(app) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/frontman/bootstrapper.rb', line 28

def bootstrap_app(app)
  unless bootstrapped?
    Dotenv.load
    register_default_helpers(app)

    config = Frontman::Config.get(:config_path, fallback: './config.rb')
    app.run(File.read(config)) if File.exist?(config)

    @@bootstrapped = true
  end

  app
end

.bootstrapped?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/frontman/bootstrapper.rb', line 55

def bootstrapped?
  @@bootstrapped ||= false
end

.find_helpers_in(path) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/frontman/bootstrapper.rb', line 16

def find_helpers_in(path)
  Dir.entries(path).map do |file|
    next unless file.end_with?('_helper.rb')

    {
      path: File.join(path, file),
      name: file.split('_').collect(&:capitalize).join.gsub('.rb', '')
    }
  end.compact
end

.resources_from_dir(content_root) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/frontman/bootstrapper.rb', line 43

def resources_from_dir(content_root)
  files = Dir.glob(
    File.join(content_root, '**/*')
  )

  files.reject! { |f| File.directory?(f) || File.fnmatch('**.yml', f) }
  files.sort! { |a, b| a <=> b || 0 }
  files.map do |path|
    Frontman::Resource.from_path(path, path.sub(/^#{content_root}/, ''))
  end
end