Created
November 28, 2012 04:44
-
-
Save pjz/4159060 to your computer and use it in GitHub Desktop.
spec work re: content pipelines
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
from subprocess import Popen, PIPE | |
def cat(*files): | |
result = [] | |
for f in files: | |
result.extend(open(f).readlines()) | |
return result | |
def pipe(cmd, text=None,filename=None): | |
if text is None and filename is None: | |
raise Exception("pipe() needs input!") | |
if text: | |
input = PIPE | |
else: | |
input = open(filename).fileno() | |
p = Popen(cmd, stdin=input, stdout=PIPE, stderr=PIPE) | |
stdout, stderr = p.communicate() | |
if p.returncode != 0: | |
raise Response(500) | |
return stdout | |
def lessc(text=None,filename=None): | |
"""Popular dynamic CSS extension language""" | |
return pipe(['lessc', '-x', '-'], text, filename) | |
"""The above lets you compress css generated by lessc with a simplate like:""" | |
infiles = [ 'foo.less', 'bar.less' ] | |
class Result: | |
response = [] | |
result = Result() | |
for f in infiles: | |
result.response += lessc(filename=f) | |
^L | |
response = result.response | |
^L | |
""" or if you install fabricate you can do: """ | |
from fabricate import * | |
sources = [ 'foo', 'bar' ] | |
class Result: | |
response = None | |
result = Result() | |
def build(): | |
global built_response | |
for f in sources: | |
run('lessc', '-x', f + ".less", ">" + f + ".css", shell=True) | |
result.respose = run('cat', [ f + ".css" for f in sources]) | |
^L | |
main() | |
response = result.response | |
^L | |
"""the first is a little bit simpler (though not much!) but the latter has awesome incremental | |
auto-rebuild magic based on md5s of the source files and such.""" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment