Created
April 19, 2019 18:31
-
-
Save ttscoff/13c73483716cc9278dbe7087af4fac10 to your computer and use it in GitHub Desktop.
Convert liquid-style tags for Mac symbols into HTML entities
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class String | |
def replace_with_entity | |
case self.downcase | |
when /apple/ | |
"" | |
when /(comm(and)?|cmd|clover)/ | |
"⌘" | |
when /(cont(rol)?|ctl|ctrl)/ | |
"⌃" | |
when /(opt(ion)?|alt)/ | |
"⌥" | |
when /shift/ | |
"⇧" | |
when /tab/ | |
"⇥" | |
when /caps(lock)?/ | |
"⇪" | |
when /eject/ | |
"⏏" | |
when /return/ | |
"⏎" | |
when /enter/ | |
"⌤" | |
when /(del(ete)?|back(space)?)/ | |
"⌫" | |
when /fwddel(ete)?/ | |
"⌦" | |
when /(esc(ape)?)/ | |
"⎋" | |
when /right/ | |
"→" | |
when /left/ | |
"←" | |
when /up/ | |
"↑" | |
when /down/ | |
"↓" | |
when /pgup/ | |
"⇞" | |
when /pgdn/ | |
"⇟" | |
when /home/ | |
"↖" | |
when /end/ | |
"↘" | |
when /clear/ | |
"⌧" | |
when /gear/ | |
"⚙" | |
else | |
"{{#{self}}}" | |
end | |
end | |
def render | |
# Replace {{insertions}} | |
self.gsub(/\{\{(.*?)\}\}/) {|mtch| | |
m = Regexp.last_match | |
m[1].strip.replace_with_entity | |
} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment