m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/lib/templated.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/templated.rb')
-rw-r--r--lib/templated.rb24
1 files changed, 24 insertions, 0 deletions
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 <title> 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