Skip to content

Instantly share code, notes, and snippets.

@lucafaggianelli
Created January 7, 2015 16:02
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 lucafaggianelli/187060823dd3d0d0094b to your computer and use it in GitHub Desktop.
Save lucafaggianelli/187060823dd3d0d0094b to your computer and use it in GitHub Desktop.
Font Awesome LESS to Android XML
import sys
import urllib2
import re
# LESS source file
FA_LESS_URL = 'https://raw.githubusercontent.com/FortAwesome/Font-Awesome/master/less/variables.less'
# REGEX
re_less_var = re.compile('.*:\s*"(.*)";')
re_fa_var = re.compile('^@fa-var-(.*):\s*"\\\\(.*)";')
fa_version = ''
OUT_FILENAME = 'fontawesome.xml'
f = urllib2.urlopen(FA_LESS_URL)
out = None
if f:
out = open(OUT_FILENAME,'w')
out.write('<?xml version="1.0" encoding="utf-8"?>\n<resources>\n')
else:
sys.exit()
res = None
line = ''
while True:
line = f.readline()
if not line:
break
elif line == '\n':
continue
# Remove newline
line = line[:-1]
# FA version
if line.startswith('@fa-version:'):
res = re_less_var.search(line)
if res is not None:
fa_version = res.group(1)
# Icons var
else:
res = re_fa_var.search(line)
if res is not None and res.group(1) and res.group(2):
out.write(' <string name="fa_%s">&#x%s;</string>\n' %
(res.group(1).replace('-','_'),res.group(2)))
# Close XML tag
out.write('</resources>')
out.close()
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment