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
- #content(path) ⇒ Object
- #dimensions(hash, casing: :camelize) ⇒ Object
- #file_s3_key(name, options = {}) ⇒ Object (also: #s3_key)
- #render_file(folder, path) ⇒ Object
- #render_path(path) ⇒ Object
- #s3_bucket ⇒ Object
- #setting ⇒ Object
- #tag_list(list, casing: :camelize) ⇒ Object
- #tags(list = {}) ⇒ Object
- #user_data(path) ⇒ Object
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) (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, ={}) Lono::AppFile::Registry.register(name, @blueprint, ) "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 = "WARNING: path #{path} not found" puts .color(:yellow) puts "Called from:" puts caller[2] 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_bucket ⇒ Object
76 77 78 |
# File 'lib/lono/template/dsl/builder/helpers/core_helper.rb', line 76 def s3_bucket Lono::S3::Bucket.name end |
#setting ⇒ Object
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 (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 |