Skip to content

Commit

Permalink
Merge branch 'release/0.11' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
miracle2k committed Aug 21, 2015
2 parents 74926ae + 0c1c0f9 commit 3435556
Show file tree
Hide file tree
Showing 28 changed files with 528 additions and 110 deletions.
7 changes: 7 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
0.11 (2015-08-21)
- Add libsass filter (Mantas, sirex).
- Add SlimitIt filter (Michael Fladischer).
- Prevent filters from crashing if the input file is empty (empty string
passed).
- A number of smaller improvements.

0.10.1 (2014-07-03)
- Python 3 fixes.
- Windows fix (Ionel Cristian Mărieș).
Expand Down
21 changes: 20 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,27 @@ Documentation: |travis|
You can `download a tarball`__ of the development version, or
install it via ``pip install webassets==dev``.


Development:
For development, to run all the tests, you need to have at least Java 7
installed (required for example to run the `Google closure`_ filter).

1. Install Python requirements (preferable in a virtual env)::

$ pip install -r requirements-dev.pip
$ pip install -r requirements-dev-2.x.pip

2. Install other requirements::

$ ./requirements-dev.sh

3. Run the tests::

./run_tests.sh

__ http://github.com/miracle2k/webassets/tarball/master#egg=webassets-dev

.. _`Google closure`: https://github.com/google/closure-compiler/wiki/FAQ#the-compiler-crashes-with-unsupportedclassversionerror-or-unsupported-majorminor-version-510

.. |travis| image:: https://secure.travis-ci.org/miracle2k/webassets.png?branch=master
:target: http://travis-ci.org/miracle2k/webassets

14 changes: 13 additions & 1 deletion docs/builtin_filters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ Javascript compressors
.. autoclass:: webassets.filter.jspacker.JSPacker


``slimit``
~~~~~~~~~~~~

.. autoclass:: webassets.filter.slimit.Slimit


CSS compressors
---------------

Expand Down Expand Up @@ -149,6 +155,12 @@ JS/CSS compilers
.. autoclass:: webassets.filter.coffeescript.CoffeeScript


``requirejs``
~~~~~~~~~~~~~

.. autoclass:: webassets.filter.requirejs.RequireJSFilter


JavaScript templates
--------------------

Expand Down Expand Up @@ -194,7 +206,7 @@ Other


``autoprefixer``
~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~

.. autoclass:: webassets.filter.autoprefixer.AutoprefixerFilter

Expand Down
2 changes: 2 additions & 0 deletions docs/custom_filters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,5 @@ More?
You can have a look inside the ``webassets.filter`` module source
code to see a large number of example filters.
.. automodule:: webassets.filter
18 changes: 11 additions & 7 deletions docs/generic/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Using ``webassets`` in standalone mode
======================================

You don't need to use one of the frameworks into which ``webassets`` can
integrate. Using the underlaying facilites directly it is almost as easy.
integrate. Using the underlying facilites directly is almost as easy.

And depending on what libraries you use, there may still be some things
*webassets* can help you with, see :doc:`/integration/index`.
Expand All @@ -17,16 +17,20 @@ First, create an environment instance:
.. code-block:: python
from webassets import Environment
my_env = Environment('../static/media', '/media')
my_env = Environment(
directory='../static/media',
url='/media')
As you can see, the environment requires two arguments, the path in which
your media files are located, as well as the url prefix under which the
media directory is available. This prefix will be used when generating
output urls.
As you can see, the environment requires two arguments:

- the path in which your media files are located

- the url prefix under which the media directory is available. This prefix will be used when generating
output urls.

Next, you need to define your assets, in the form of so called *bundles*,
and register them with the environment. The easist way to do it is directly
and register them with the environment. The easiest way to do it is directly
in code:

.. code-block:: python
Expand Down
4 changes: 2 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ Framework integration
---------------------

For some web frameworks, ``webassets`` provides special
integration. If you are using one of the supported frameworks, to go
integration. If you are using one of the supported frameworks, go to
the respective page:

.. toctree::
:maxdepth: 1

With Django <http://django-assets.readthedocs.org/en/latest/>
With Flask <http://flask-assets.readthedocs.org/en/latest/a>
With Flask <http://flask-assets.readthedocs.org/en/latest/>
With Pyramid <https://github.com/sontek/pyramid_webassets>
Other or no framework <generic/index>

Expand Down
2 changes: 1 addition & 1 deletion docs/script.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Start a daemon which monitors your bundle source files, and automatically
rebuilds bundles when a change is detected.

This can be useful during development, if building is not instantaneous, and
you are loosing valuable time waiting for the build to finish while trying to
you are losing valuable time waiting for the build to finish while trying to
access your site.


Expand Down
3 changes: 3 additions & 0 deletions requirements-dev.pip
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Jinja2>=2.5
cssutils
yuicompressor
closure
slimit==0.8.1
ply==3.4 # https://github.com/rspivak/slimit/issues/76
libsass

# Python libs that requiring manual installation
#cssprefixer
9 changes: 6 additions & 3 deletions requirements-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

# External filter binaries to install for testing.

gem install sass --version 3.2.19
gem install compass --version 0.12.6
# Disable, because there are issues with the install on Travis CI.
#gem install sass --version 3.2.19
#gem install compass --version 0.12.6


# Only install NodeJS version by default.
#gem install less --version 1.2.21

npm install -g less
npm install -g less@2.5.1
npm install -g [email protected]
npm install -g [email protected]
npm install -g [email protected]
Expand Down
2 changes: 1 addition & 1 deletion src/webassets/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = (0, 10, 1)
__version__ = (0, 11)


# Make a couple frequently used things available right here.
Expand Down
2 changes: 1 addition & 1 deletion src/webassets/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def config(self):
def _get_debug(self):
return self.config.get('debug', None)
def _set_debug(self, value):
self.config['debug'] = True
self.config['debug'] = value
debug = property(_get_debug, _set_debug)

def _get_filters(self):
Expand Down
2 changes: 2 additions & 0 deletions src/webassets/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ def set(self, key, data):
with os.fdopen(fd, 'wb') as f:
pickle.dump(data, f)
f.flush()
if os.path.isfile(filename):
os.unlink(filename)
os.rename(temp_filename, filename)
except:
os.unlink(temp_filename)
Expand Down
7 changes: 5 additions & 2 deletions src/webassets/env.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from os import path
from itertools import chain
from webassets import six
Expand Down Expand Up @@ -203,6 +204,10 @@ def query_url_mapping(self, ctx, filepath):
if needle.startswith(candidate):
# Found it!
rel_path = needle[len(candidate)+1:]
# If there are any subdirs in rel_path, ensure
# they use HTML-style path separators, in case
# the local OS (Windows!) has a different scheme
rel_path = rel_path.replace(os.sep, "/")
return url_prefix_join(url, rel_path)
raise ValueError('Cannot determine url for %s' % filepath)

Expand Down Expand Up @@ -520,8 +525,6 @@ def _get_manifest(self):
No manifest is used.
Any custom manifest implementation.
The default value is ``None``.
""")

def _set_versions(self, versions):
Expand Down
2 changes: 1 addition & 1 deletion src/webassets/filter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ def created(self):
data = data.encode('utf-8')

if input_file.created:
if not data:
if data is None:
raise ValueError(
'{input} placeholder given, but no data passed')
with open(input_file.filename, 'wb') as f:
Expand Down
12 changes: 10 additions & 2 deletions src/webassets/filter/cleancss.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,25 @@ class CleanCSS(ExternalTool):
Clean-css is an external tool written for NodeJS; this filter assumes that
the ``cleancss`` executable is in the path. Otherwise, you may define
a ``CLEANCSS_BIN`` setting.
Additional options may be passed to ``cleancss`` binary using the setting
``CLEANCSS_EXTRA_ARGS``, which expects a list of strings.
"""

name = 'cleancss'
options = {
'binary': 'CLEANCSS_BIN',
'extra_args': 'CLEANCSS_EXTRA_ARGS',
}

def output(self, _in, out, **kw):
self.subprocess([self.binary or 'cleancss'], out, _in)
args = [self.binary or 'cleancss']
if self.extra_args:
args.extend(self.extra_args)
self.subprocess(args, out, _in)

def input(self, _in, out, **kw):
args = [self.binary or 'cleancss', '--root', os.path.dirname(kw['source_path'])]
if self.extra_args:
args.extend(self.extra_args)
self.subprocess(args, out, _in)

8 changes: 5 additions & 3 deletions src/webassets/filter/compass.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import tempfile
import shutil
import subprocess
from io import open
from webassets import six

from webassets.exceptions import FilterError
Expand Down Expand Up @@ -91,7 +92,7 @@ class Compass(Filter):
COMPASS_CONFIG
An optional dictionary of Compass `configuration options
<http://compass-style.org/help/tutorials/configuration-reference/>`_.
<http://compass-style.org/help/documentation/configuration-reference/>`_.
The values are emitted as strings, and paths are relative to the
Environment's ``directory`` by default; include a ``project_path``
entry to override this.
Expand Down Expand Up @@ -233,7 +234,7 @@ def open(self, out, source_path, **kw):

guessed_outputfilename = path.splitext(path.basename(source_path))[0]
guessed_outputfilepath = path.join(tempout, guessed_outputfilename)
output_file = open("%s.css" % guessed_outputfilepath)
output_file = open("%s.css" % guessed_outputfilepath, encoding='utf-8')
if config.get('sourcemap'):
sourcemap_file = open("%s.css.map" % guessed_outputfilepath)
sourcemap_output_filepath = path.join(
Expand All @@ -245,7 +246,8 @@ def open(self, out, source_path, **kw):
sourcemap_output_file = open(sourcemap_output_filepath, 'w')
sourcemap_output_file.write(sourcemap_file.read())
try:
out.write(output_file.read())
contents = output_file.read()
out.write(contents)
finally:
output_file.close()
finally:
Expand Down
8 changes: 7 additions & 1 deletion src/webassets/filter/jsmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,10 @@ def setup(self):
self.jsmin = jsmin

def output(self, _in, out, **kw):
self.jsmin.JavascriptMinify().minify(_in, out)
if hasattr(self.jsmin, 'JavaScriptMinifier'):
# jsmin.py from v8
minifier = self.jsmin.JavaScriptMinifier()
minified = minifier.JSMinify(_in.read())
out.write(minified)
else:
self.jsmin.JavascriptMinify().minify(_in, out)
15 changes: 14 additions & 1 deletion src/webassets/filter/jst.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import re
try:
import json
except ImportError:
Expand Down Expand Up @@ -121,6 +122,10 @@ class JST(JSTemplateFilter):
of the ``window`` object, or you won't be able to access the
templates.
JST_DIR_SEPARATOR (separator)
The separator character to use for templates within directories.
Defaults to '/'
.. _Jammit:
.. _underscore.js: http://documentcloud.github.com/underscore/#template
"""
Expand All @@ -132,6 +137,8 @@ class JST(JSTemplateFilter):
'namespace': 'JST_NAMESPACE',
# Wrap everything in a closure
'bare': 'JST_BARE',
# The path separator to use with templates in different directories
'separator': 'JST_DIR_SEPARATOR'
}
max_debug_level = None

Expand All @@ -155,7 +162,7 @@ def process_templates(self, out, hunks, **kwargs):
# Make it a valid Javascript string.
contents = json.dumps(hunk.data())

out.write("%s['%s'] = " % (namespace, name))
out.write("%s['%s'] = " % (namespace, self._get_jst_name(name)))
if self.template_function is False:
out.write("%s;\n" % (contents))
else:
Expand All @@ -165,6 +172,12 @@ def process_templates(self, out, hunks, **kwargs):
if self.bare is False:
out.write("})();")

def _get_jst_name(self, name):
"""Return the name for the JST with any path separators normalised"""
return _path_separator_re.sub(self.separator or "/", name)


_path_separator_re = re.compile(r'[/\\]+')

_jst_script = 'var template = function(str){var fn = new Function(\'obj\', \'var \
__p=[],print=function(){__p.push.apply(__p,arguments);};\
Expand Down
Loading

0 comments on commit 3435556

Please sign in to comment.