Module: Lono::Template::Strategy::Dsl::Builder::Helpers::FileHelper

Extended by:
Memoist
Included in:
Lono::Template::Strategy::Dsl::Builder::Helpers
Defined in:
lib/lono/template/strategy/dsl/builder/helpers/file_helper.rb

Instance Method Summary collapse

Instance Method Details

#content(path) ⇒ Object



5
6
7
# File 'lib/lono/template/strategy/dsl/builder/helpers/file_helper.rb', line 5

def content(path)
  render_file(Lono.config.content_path, path)
end

#render_file(folder, path) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/lono/template/strategy/dsl/builder/helpers/file_helper.rb', line 30

def render_file(folder, path)
  path = "#{folder}/#{path}"
  if File.exist?(path)
    render_path(path)
  else
    message = "WARNING: path #{path} not found"
    puts message.color(:yellow)
    puts "Called from:"
    puts caller[2]
    message
  end
end

#render_path(path) ⇒ Object



44
45
46
# File 'lib/lono/template/strategy/dsl/builder/helpers/file_helper.rb', line 44

def render_path(path)
  RenderMePretty.result(path, context: self)
end

#user_data(path) ⇒ Object



9
10
11
# File 'lib/lono/template/strategy/dsl/builder/helpers/file_helper.rb', line 9

def user_data(path)
  render_file(Lono.config.user_data_path, path)
end

#user_data_scriptObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/lono/template/strategy/dsl/builder/helpers/file_helper.rb', line 13

def user_data_script
  unless @user_data_script
    return <<~EOL
      # @user_data_script variable not set. IE: @user_data_script = "configs/#{@blueprint}/user_data/boostrap.sh"
      # Also, make sure that "configs/#{@blueprint}/user_data/boostrap.sh" path you're using exists.
    EOL
  end

  if File.exist?(@user_data_script)
    render_path(@user_data_script)
  else
    message = "WARN: #{@user_data_script} not found"
    puts message.color(:yellow)
    "# #{message}"
  end
end