Sha256: 5b036998025904b6552167ea55230f6732ccb0d68b2e0ce730c314ffc21af584

Contents?: true

Size: 829 Bytes

Versions: 5

Compression:

Stored size: 829 Bytes

Contents

context = ChefDK::Generator.context
cookbook_dir = File.join(context.cookbook_root, context.cookbook_name)
template_dir = File.join(cookbook_dir, "templates", "default")
template_filename = context.new_file_basename

unless File.extname(template_filename) == ".erb"
  # new_file_basename is a frozen string, so we have to create an entirely
  # new string here instead of using concat.
  template_filename = "#{template_filename}.erb"
end

template_path = File.join(cookbook_dir, "templates", "default", template_filename)

directory template_dir do
  recursive true
end

if source_file = context.content_source

  file template_path do
    content(IO.read(source_file))
  end

else

  template template_path do
    source "template.erb"
    helpers(ChefDK::Generator::TemplateHelper)
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
chef-dk-0.15.15 lib/chef-dk/skeletons/code_generator/recipes/template.rb
chef-dk-0.15.9 lib/chef-dk/skeletons/code_generator/recipes/template.rb
chef-dk-0.13.21 lib/chef-dk/skeletons/code_generator/recipes/template.rb
chef-dk-0.12.0 lib/chef-dk/skeletons/code_generator/recipes/template.rb
chef-dk-0.9.0 lib/chef-dk/skeletons/code_generator/recipes/template.rb