Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding support for code blocks.

  • Loading branch information...
commit 513236df96430caea02e65f1b6f3655fb4525ed1 1 parent 2fdfd18
@anutron authored
View
19 README.md
@@ -103,6 +103,23 @@ Inside of `django/mootools` you'll find `settings.py`. This file contains all th
- DEPENDER_PACKAGE_YMLS - a list of package.yml files to include; defaults to the submodules included in this repository (MooTools Core and MooTools More) as well as the Depender Client.
- DEPENDER_SCRIPTS_JSON - a list of scripts.json manifest files (these are deprecated manifests from < Mootools 1.3 era).
- DEPENDER_YUI_PATH - the path to the YUI compressor jar.
+ - DEPENDER_INCLUDE_BLOCKS - the default list of blocks to include in the build; if not set it will include all code blocks. You can also include "all" for the same effect. This can be overridden with the blocks parameter. See below for the definition of a "code block".
+ - DEPENDER_EXCLUDE_BLOCKS - the default list of blocks to exclude in the build. Can be set to "all" to exclude all blocks; defaults to not exclude any. When the include and exclude lists collide, exclude wins. Can be overridden with the excludeBlocks paramter in the request.
+
+Code Blocks
+-----------
+
+MooTools supports compatibility and features through commented code blocks. Example:
+
+ some code...
+ // <1.2 compatibility>
+ some code that offeres backwards compatibility for 1.2
+ /* <some feature> */
+ some code that offers a feature within the 1.2 compat
+ /* </some feature> */
+ // </1.2 compatibility>
+
+These can be excluded or included at request time by configuration in settings.py or in the request parameters.
Initialization
--------------
@@ -156,6 +173,8 @@ To request a library, you can specify four arguments for the contents of the fil
* requireLibs - a comma separated list of *libraries* to require - these are the names defined the package names in each libary's package.yml or in the settings for those projects that use scripts.json. So, for example, *requireLibs=Core,More* using the default config would include both the complete inventories of MooTools Core and More. This can also be specified as a comma separated list or as `requireLibs=Core&requireLibs=More`).
* exclude - exactly like the `require` value, except it's a list of files to exclude. This is useful if you have already loaded some scripts and now you require another. You can specify the scripts you already have and the one you now need, and the library will return only those you do not have.
* excludeLibs - just like the `exclude` option but instead you can specify entire libraries.
+* blocks - specify which code blocks to *include*. You can specify them as blocks=1.2compat,1.3compat, as blocks=1.2compat&block=1.3compat or blocks=all (to include all code blocks).
+* excludeBlocks - You can also state ?excludeBlocks=... to include all blocks but a specific list
The Depender Client
-------------------
View
2  django/mootools/settings.py
@@ -34,6 +34,8 @@
os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "client", "package.yml")),
)
DEPENDER_SCRIPTS_JSON = []
+DEPENDER_INCLUDE_BLOCKS = []
+DEPENDER_EXCLUDE_BLOCKS = []
# Set to true to re-load all JS every time. (slowish)
DEPENDER_DEBUG = True; ##os.getenv("DEPENDER_DEBUG", "0").lower() not in ["0","false",""]
View
52 django/src/depender/views.py
@@ -8,6 +8,7 @@
from django.http import HttpResponse
from django.conf import settings
from django.core import urlresolvers
+import re
from depender.core import DependerData
@@ -50,12 +51,12 @@ def build(request):
builds a library given required scripts to includes and other arguments
accepted URL arguments:
- require - a comma separated list of *files*(components) to require; can also be specified in the php style as "require[]=foo&require[]=bar"
- requireLibs - a comma separated list of *libraries*(packages) to require - these are the names defined in our *congfig.json* in the *libs* section. So, for example, *requireLibs=mootools-core,mootools-more* using the default config would include both the complete inventories of MooTools Core and More. This can also be specified as a comma separated list or the php style (*requireLibs[]=mootools-core&requireLibs[]=mootools-more*).
+ require - a comma separated list of *files*(components) to require; can also be specified as "require=foo&require=bar"
+ requireLibs - a comma separated list of *libraries*(packages) to require - these are the names defined in our *congfig.json* in the *libs* section. So, for example, *requireLibs=mootools-core,mootools-more* using the default config would include both the complete inventories of MooTools Core and More. This can also be specified as a comma separated list oras (*requireLibs=mootools-core&requireLibs=mootools-more*).
exclude - exactly like the *require* value, except it's a list of files to exclude. This is useful if you have already loaded some scripts and now you require another. You can specify the scripts you already have and the one you now need, and the library will return only those you do not have.
excludeLibs - just like the *exclude* option but instead you can specify entire libraries.
- NOT IMPLEMENTED: cache - if set to *true* you'll be returned a cached version of the script even if the server is set to *false* and vice versa.
compression - you'll be returned the compression type you specify regardless of the server default. Note that if you specify a compression type that the server does not allow, you'll be returned which ever one it does. If it does not support compression at all, you will not be returned a compressed file. You can also specify "none" which is useful for development and debugging.
+ blocks - specify which code blocks to *include*. You can specify them as blocks=1.2compat,1.3compat, as blocks=1.2compat&block=1.3compat or blocks=all (to include all code blocks)
"""
def get(name):
return request.GET.get(name)
@@ -74,7 +75,13 @@ def get_arr(name):
reset = get("reset")
client = get("client")
compression = get("compression")
+ blocks = get_arr("blocks")
+ exclude_blocks = get_arr("excludeBlocks")
+ if len(blocks) == 0:
+ blocks = settings.DEPENDER_INCLUDE_BLOCKS
+ if len(exclude_blocks) == 0:
+ exclude_blocks = settings.DEPENDER_EXCLUDE_BLOCKS
try:
dpdr = get_depender(reset)
except Exception, inst:
@@ -96,6 +103,7 @@ def get_arr(name):
deps = dpdr.get_transitive_dependencies(required, excluded)
files = dpdr.get_files(deps, excluded)
output = "//No files included for build"
+ js = ""
if len(files) > 0:
#TODO: add copyrights
@@ -105,16 +113,44 @@ def get_arr(name):
output += "\n//This library: " + request.build_absolute_uri(request.get_full_path())
output += "\n//Contents: "
output += ", ".join([ i.package.key + ":" + i.shortname for i in files ])
- output += "\n\n"
-
+
for f in files:
- output += "// Begin: " + f.shortname + "\n"
- output += f.content + u"\n\n"
+ js += "// Begin: " + f.shortname + "\n"
+ js += f.content + u"\n\n"
if client == "true":
url = request.build_absolute_uri(
urlresolvers.reverse("depender.views.build"))
- output += dpdr.get_client_js(deps, url)
+ js += dpdr.get_client_js(deps, url)
+
+ included_blocks = []
+ def block_matcher(matchobj):
+ """
+ Finds code blocks that should be included/excluded based on url params.
+ JS code can be marked with named blocks, for example:
+
+ //<1.2compat>
+ ...compat code
+ //</1.2compat>
+
+ The request to Depender can include ?blocks=all or ?blocks=1.2compat,1.3compat,etc
+ and the block will be removed or included accordingly.
+ You can also state ?excludeBlocks=... to include all blocks but a specific list
+ """
+ match = matchobj.group(0)
+ block = re.search('<(.*?)>', match).group(1)
+ if (block in blocks or 'all' in blocks or len(blocks) == 0) and\
+ not (block in exclude_blocks or 'all' in exclude_blocks):
+ if block not in included_blocks:
+ included_blocks.append(block)
+ return match
+ else:
+ return ''
+ js = re.sub(r'((/[/*])\s*<([^>]*)>.+?<\/\3>(?:\s*\*/)?(?s))', block_matcher, js)
+ if len(included_blocks) > 0:
+ output += "\n//included blocks: " + ", ".join(included_blocks)
+ output += "\n\n"
+ output += js
response = HttpResponse(output, content_type="application/x-javascript")
if download == "true":

0 comments on commit 513236d

Please sign in to comment.
Something went wrong with that request. Please try again.