Created
February 22, 2013 19:09
-
-
Save shaneog/5015773 to your computer and use it in GitHub Desktop.
A Python script to generate a Twig template file for a folder full of images. I use this so that my CSS can use the notation url('ing/name.png') and this does not get rewritten to url('../../Resources/public/img/name.png') I want all my image asset files to be relative to my web path, but I want to keep them located in my bundles
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
#!/usr/bin/env python | |
import os | |
import argparse | |
parser = argparse.ArgumentParser(description='Create Assetic Twig image file list') | |
parser.add_argument('-b','--bundle', help='Bundle name', required=True) | |
parser.add_argument('-f','--folder', help='Image folder') | |
parser.add_argument('-s','--search', help='The location to recursively search & list') | |
args = vars(parser.parse_args()) | |
# Default to "images" | |
if not args['folder']: | |
args['folder'] = 'images' | |
if not args['search']: | |
args['search'] = os.getcwd() | |
assetic = """ | |
{%% image | |
'@%(bundle)s/Resources/public/%(folder)s/%(name)s' | |
output='%(folder)s/%(name)s' %%} | |
{%% endimage %%}""" | |
for root, dirs, files in os.walk(args['search']): | |
for filename in files: | |
# Exclude dotfiles, such as .DS_Store | |
if not filename.startswith("."): | |
print assetic % {'name': os.path.join( root[len(os.getcwd()):], filename ).strip("/"), | |
'bundle': args['bundle'], | |
'folder': args['folder']} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment