Module: Lono::Template::Dsl::Builder::Helpers::CoreHelper

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

Instance Method Summary collapse

Instance Method Details

#content(path) ⇒ Object



50
51
52
# File 'lib/lono/template/dsl/builder/helpers/core_helper.rb', line 50

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

#dimensions(hash, casing: :camelize) ⇒ Object



43
44
45
46
47
48
# File 'lib/lono/template/dsl/builder/helpers/core_helper.rb', line 43

def dimensions(hash, casing: :camelize)
  tags(hash, casing: casing).map { |h|
    h[:Name] = h.delete(:Key) || h.delete(:key)
    h
  }
end

#file_s3_key(name, options = {}) ⇒ Object Also known as: s3_key



80
81
82
83
# File 'lib/lono/template/dsl/builder/helpers/core_helper.rb', line 80

def file_s3_key(name, options={})
  Lono::AppFile::Registry.register(name, @blueprint, options)
  "file://app/files/#{name}" # placeholder for post processing
end

#render_file(folder, path) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/lono/template/dsl/builder/helpers/core_helper.rb', line 58

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



72
73
74
# File 'lib/lono/template/dsl/builder/helpers/core_helper.rb', line 72

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

#s3_bucketObject



76
77
78
# File 'lib/lono/template/dsl/builder/helpers/core_helper.rb', line 76

def s3_bucket
  Lono::S3::Bucket.name
end

#settingObject



86
87
88
# File 'lib/lono/template/dsl/builder/helpers/core_helper.rb', line 86

def setting
  Lono::Setting.new
end

#tag_list(list, casing: :camelize) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/lono/template/dsl/builder/helpers/core_helper.rb', line 14

def tag_list(list, casing: :camelize)
  raise "tags list cannot be empty" if list == nil

  if list.is_a?(Array)
    hash = list.inject({}) do |h,i|
      i.symbolize_keys!
      h[i[:Key]] = i[:Value]
      h
    end
    return tag_list(hash) # recursive call tag_list to normalized the argument with a Hash
  end

  list.map do |k,v|
    k = k.to_s
    k = case casing
    when :camelize
      k.camelize
    when :underscore
      k.underscore
    when :dasherize
      k.dasherize
    else # leave alone
      k
    end

    {Key: k, Value: v}
  end
end

#tags(list = {}) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/lono/template/dsl/builder/helpers/core_helper.rb', line 5

def tags(list={})
  casing = list.delete(:casing) || :camelize
  if list.empty?
    tag_list(@tags) if @tags # when list is empty, use @tags variable. If not set then return nil
  else
    tag_list(list, casing: casing)
  end
end

#user_data(path) ⇒ Object



54
55
56
# File 'lib/lono/template/dsl/builder/helpers/core_helper.rb', line 54

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