Skip to content

Instantly share code, notes, and snippets.

@djberg96
Created August 1, 2025 14:21
Show Gist options
  • Save djberg96/cabf9a8dee87a58dea062e74f957b63f to your computer and use it in GitHub Desktop.
Save djberg96/cabf9a8dee87a58dea062e74f957b63f to your computer and use it in GitHub Desktop.
#!/bin/bash
# Script to convert HamlC templates to ERB templates
# This handles basic HamlC to ERB conversion
convert_hamlc_to_erb() {
local hamlc_file="$1"
local erb_file="${hamlc_file%.hamlc}.html.erb"
# Basic HamlC to ERB conversion
# Note: This is a basic conversion and may need manual review for complex templates
# Read the HamlC file and convert basic syntax
sed -E \
-e 's/^%([a-zA-Z0-9_-]+)/\<\1/g' \
-e 's/^\.([a-zA-Z0-9_-]+)/\<div class="\1"/g' \
-e 's/^#([a-zA-Z0-9_-]+)/\<div id="\1"/g' \
-e 's/!= @([a-zA-Z0-9_]+)/<%== @\1 %>/g' \
-e 's/= @([a-zA-Z0-9_]+)/<%= @\1 %>/g' \
-e 's/%img\./\<img /g' \
-e 's/%button\./\<button /g' \
-e 's/%div\./\<div /g' \
-e 's/%span\./\<span /g' \
-e 's/%p\./\<p /g' \
-e 's/%a\./\<a /g' \
-e 's/%ul\./\<ul /g' \
-e 's/%li\./\<li /g' \
-e 's/%h([1-6])\./\<h\1 /g' \
-e 's/{ *([^}]+) *}/ \1/g' \
-e 's/src *: *"([^"]+)"/src="\1"/g' \
-e 's/alt *: *"([^"]+)"/alt="\1"/g' \
-e 's/class *: *"([^"]+)"/class="\1"/g' \
-e 's/id *: *"([^"]+)"/id="\1"/g' \
-e 's/type *: *"([^"]+)"/type="\1"/g' \
-e 's/aria-[a-zA-Z-]+ *: *"([^"]+)"/&/g' \
"$hamlc_file" > "$erb_file"
# Add closing tags (basic approach)
# This would need more sophisticated logic for proper HTML structure
echo "Converted $hamlc_file to $erb_file"
echo "Note: Please review the converted file for proper HTML structure and closing tags"
}
# Find all HamlC files and convert them
find /Users/daniel.berger/Dev/Work/dashboard/app/assets/templates -name "*.hamlc" -type f | while read -r file; do
convert_hamlc_to_erb "$file"
done
echo "Conversion complete. Please review all converted files manually."
echo "The HamlC files have been left in place for reference."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment