Commit 96d6d9fd by Kyle MacFarlane Committed by Timothée Peignier

improving windows support

Signed-off-by: Timothée Peignier <timothee.peignier@tryphon.org>
parent e91abcb2
......@@ -2,33 +2,29 @@ import os
import tempfile
from pipeline.conf import settings
from pipeline.compilers import CompilerBase
from pipeline.compilers import SubProcessCompiler
class LessCompiler(CompilerBase):
class LessCompiler(SubProcessCompiler):
output_extension = 'css'
def match_file(self, filename):
return filename.endswith('.less')
def compile_file(self, content):
tmp_file = tempfile.NamedTemporaryFile(mode='w+b')
tmp_file.write(content)
tmp_file.flush()
output_file = tempfile.NamedTemporaryFile(mode='w+b')
command = '%s %s %s %s' % (
settings.PIPELINE_LESS_BINARY, tmp_file.name,
settings.PIPELINE_LESS_ARGUMENTS, output_file.name
in_file, in_filename = tempfile.mkstemp()
in_file = os.fdopen(in_file, 'w+b')
in_file.write(content)
in_file.flush()
command = '%s %s %s' % (
settings.PIPELINE_LESS_BINARY,
in_filename,
settings.PIPELINE_LESS_ARGUMENTS
)
content = self.execute_command(command, content)
command_output = os.popen(command).read()
compiled_content = output_file.read()
output_file.close()
tmp_file.close()
in_file.close()
os.remove(in_filename)
if self.verbose:
print command_output
return compiled_content
return content
......@@ -4,6 +4,8 @@ import re
import subprocess
import urlparse
from django.utils.encoding import filepath_to_uri
from pipeline.conf import settings
from pipeline.storage import storage
from pipeline.utils import to_class
......@@ -128,7 +130,10 @@ class Compressor(object):
return "__EMBED__%s" % public_path
if not os.path.isabs(asset_path):
asset_path = self.relative_path(public_path)
return urlparse.urljoin(settings.PIPELINE_URL, asset_path[1:])
return urlparse.urljoin(
settings.PIPELINE_URL,
filepath_to_uri(asset_path[1:])
)
def embeddable(self, path, variant):
"""Is the asset embeddable ?"""
......
import os
import warnings
import tempfile
from pipeline.conf import settings
from pipeline.compressors import CompressorBase
from pipeline.compressors import SubProcessCompressor
warnings.simplefilter('ignore', RuntimeWarning)
class CSSTidyCompressor(CompressorBase):
class CSSTidyCompressor(SubProcessCompressor):
def compress_css(self, css):
tmp_file = tempfile.NamedTemporaryFile(mode='w+b')
tmp_file.write(css)
tmp_file.flush()
output_file = tempfile.NamedTemporaryFile(mode='w+b')
out_file, out_filename = tempfile.mkstemp()
out_file = os.fdopen(out_file, 'rb')
command = '%s %s %s %s' % (
settings.PIPELINE_CSSTIDY_BINARY, tmp_file.name,
settings.PIPELINE_CSSTIDY_ARGUMENTS, output_file.name
command = '%s - %s %s' % (
settings.PIPELINE_CSSTIDY_BINARY,
settings.PIPELINE_CSSTIDY_ARGUMENTS,
out_filename
)
self.execute_command(command, css)
command_output = os.popen(command).read()
filtered_css = output_file.read()
output_file.close()
tmp_file.close()
if self.verbose:
print command_output
filtered_css = out_file.read()
out_file.close()
os.remove(out_filename)
return filtered_css
......@@ -33,8 +33,8 @@ PIPELINE_TEMPLATE_NAMESPACE = getattr(settings, 'PIPELINE_TEMPLATE_NAMESPACE', "
PIPELINE_TEMPLATE_EXT = getattr(settings, 'PIPELINE_TEMPLATE_EXT', ".jst")
PIPELINE_TEMPLATE_FUNC = getattr(settings, 'PIPELINE_TEMPLATE_FUNC', "_.template")
PIPELINE_CSSTIDY_BINARY = '/usr/local/bin/csstidy'
PIPELINE_CSSTIDY_ARGUMENTS = '--template=highest'
PIPELINE_CSSTIDY_BINARY = getattr(settings, 'PIPELINE_CSSTIDY_BINARY', '/usr/local/bin/csstidy')
PIPELINE_CSSTIDY_ARGUMENTS = getattr(settings, 'PIPELINE_CSSTIDY_ARGUMENTS', '--template=highest')
PIPELINE_YUI_BINARY = getattr(settings, 'PIPELINE_YUI_BINARY', '/usr/local/bin/yuicompressor')
PIPELINE_YUI_CSS_ARGUMENTS = getattr(settings, 'PIPELINE_YUI_CSS_ARGUMENTS', '')
......@@ -53,7 +53,7 @@ PIPELINE_SASS_BINARY = getattr(settings, 'PIPELINE_SASS_BINARY', '/usr/local/bin
PIPELINE_SASS_ARGUMENTS = getattr(settings, 'PIPELINE_SASS_ARGUMENTS', '')
PIPELINE_LESS_BINARY = getattr(settings, 'PIPELINE_LESS_BINARY', '/usr/local/bin/lessc')
PIPELINE_LESS_ARGUMENTS = getattr(settings, 'PIPELINE_LESS_ARGUMENTS', '')
PIPELINE_LESS_ARGUMENTS = getattr(settings, 'PIPELINE_LESS_ARGUMENTS', '-x')
if PIPELINE_COMPILERS is None:
PIPELINE_COMPILERS = []
......@@ -30,7 +30,7 @@ class CompressedCSSNode(template.Node):
context = {}
if not 'template' in package:
package['template'] = "pipeline/css.html"
if not 'context' in package:
if 'context' in package:
context = package['context']
context.update({
'url': self.packager.individual_url(path)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment