From a3b86375c946299c9216412e10c5bcf5234c7fcd Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Fri, 28 Jun 2019 19:12:42 +0200 Subject: Initial commit --- lib/templated.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 lib/templated.rb (limited to 'lib/templated.rb') diff --git a/lib/templated.rb b/lib/templated.rb new file mode 100644 index 0000000..a7e0d63 --- /dev/null +++ b/lib/templated.rb @@ -0,0 +1,24 @@ +def template + ERB.new(File.read(src 'template.html.erb')) +end + +def write_templated_file content_filename, options + content = File.read(src content_filename) + write_templated content, content_filename, options +end + +def write_templated_erb erb_filename, options + content = ERB.new(File.read(src erb_filename)).result + cut_filename = erb_filename.sub /\.erb$/, '' + write_templated content, cut_filename, options +end + +# Options should include +# head_title: used for tag +# h1_title: used for <h1> on top of page +# title: used for both of the above, can be overridden with either +def write_templated content, filename, options + head_title = options[:head_title] || options[:title] || '' + h1_title = options[:h1_title] || options[:title] || '' + File.write build(filename), template.result(binding) +end -- cgit v1.2.3