Skip to content

Commit

Permalink
Merge pull request adamzap#126 from akrabat/embedded-images-in-local-css
Browse files Browse the repository at this point in the history
fix to embed images defined in CSS
  • Loading branch information
adamzap committed Oct 15, 2012
2 parents 43aa231 + 01c95f2 commit b66f64b
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/landslide/generator.py
Expand Up @@ -482,12 +482,35 @@ def render(self):

for img_url in images:
img_url = img_url.replace('"', '').replace("'", '')

source = os.path.join(THEMES_DIR, self.theme, 'css')
if self.theme_dir:
source = os.path.join(self.theme_dir, 'css')
else:
source = os.path.join(THEMES_DIR, self.theme, 'css')

encoded_url = utils.encode_image_from_url(img_url, source)
if encoded_url:
html = html.replace(img_url, encoded_url, 1)
self.log("Embedded theme image %s from theme directory %s" % (img_url, source))
else:
# Missing file in theme directory. Try user_css folders
found = False
for css_entry in context['user_css']:
directory = os.path.dirname(css_entry['path_url'])
if not directory:
directory = "."

encoded_url = utils.encode_image_from_url(img_url, directory)

if encoded_url:
found = True
html = html.replace(img_url, encoded_url, 1)
self.log("Embedded theme image %s from directory %s" % (img_url, directory))

if not found:
#Missing image file, etc...
self.log(u"Failed to embed theme image %s" % img_url)


html = html.replace(img_url, encoded_url, 1)

return html

Expand Down

0 comments on commit b66f64b

Please sign in to comment.