Module: Exercise::RenderMethods

Includes:
Commandline::Output, DigestMethods, Instructions
Included in:
Helpers
Defined in:
lib/commands/exercise/render_methods.rb

Instance Method Summary collapse

Methods included from DigestMethods

#digest, #excluded_files, #paths

Methods included from Instructions

#after_rendering_run, #capture, #cd, #command, #command_output, #env, #last_command_output, #path, #substitute, #wait_until, #write_to_file

Methods included from Commandline::Output

#error, #ok, #output, #prefix, #say

Methods included from Commandline

#capture_output, #execute, #run

Instance Method Details

#render_exercise(template, digest_component: '') ⇒ Object

rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/commands/exercise/render_methods.rb', line 64

def render_exercise(template, digest_component: '')
  say "Rendering: #{template}"
  template = full_path(template)
  current_dir = Dir.pwd

  content = render(template)
  File.open(filename(template), 'w') { |f| f.write("#{content}\n#{stamp(digest_component, template)}") }

  say ok "Finished: #{template}"
  true
rescue StandardError => e
  say error "Failed to generate file from: #{template}"
  say "#{e.message}\n#{e.backtrace}"
  false
ensure
  Dir.chdir(current_dir)
end

#render_file_path(template) ⇒ Object

rubocop:enable Metrics/AbcSize rubocop:enable Metrics/MethodLength



85
86
87
# File 'lib/commands/exercise/render_methods.rb', line 85

def render_file_path(template)
  template.gsub(%r{.templates/.*?erb}, File.basename(template)).gsub('.erb', '')
end

#templates_directory(template) ⇒ Object



89
90
91
# File 'lib/commands/exercise/render_methods.rb', line 89

def templates_directory(template)
  full_path(File.dirname(template))
end