Skip to content

Instantly share code, notes, and snippets.

@ttscoff
Created April 19, 2019 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ttscoff/13c73483716cc9278dbe7087af4fac10 to your computer and use it in GitHub Desktop.
Save ttscoff/13c73483716cc9278dbe7087af4fac10 to your computer and use it in GitHub Desktop.
Convert liquid-style tags for Mac symbols into HTML entities
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