Permalink
Browse files

Greatly simplify

  • Loading branch information...
kynikos committed Apr 11, 2015
1 parent 2442f22 commit 624b31ea3366d691fbf78f141003ed3ef2804028
Showing with 108 additions and 151 deletions.
  1. +1 −1 .gitignore
  2. +105 −39 wembler/__init__.py
  3. +0 −17 wembler/processes/__init__.py
  4. +0 −40 wembler/processes/jinja.py
  5. +0 −54 wembler/processes/sass.py
  6. +2 −0 wembler_.py
@@ -1,4 +1,4 @@
/assemblyline
/assemblyline.py
__pycache__
*.pyc
*.pyo
@@ -18,56 +18,122 @@
# You should have received a copy of the GNU General Public License
# along with Wembler. If not, see <http://www.gnu.org/licenses/>.
from importlib import import_module
import os
# TODO: Remember to mention python-yaml and assemblyline in the dependencies
import yaml
import assemblyline
# TODO: JS minifier
# TODO: Remember to mention python-yaml and assemblyline in the dependencies
# Also mention the dependencies for the various bundled processes
# TODO: Allow using custom processes from a local folder
# test = """
# import sys
#
# b = 3
# c = 2
#
# def aaa():
# return b + c
# """
#
# namespace = {}
# exec(test, namespace)
# print(namespace["aaa"]())
# TODO: Make the following dependencies optional
import jinja2
# Documentation: http://hongminhee.org/libsass-python/
# TODO: Contribute support for the .sass (indented) syntax
import sass
# TODO: See also https://github.com/Kronuz/pyScss
# import scss
class Wembler:
# The parameters for __init__ must reflect the attributes set through
# argparse by the launcher script
def __init__(self, config):
def __init__(self, config, debug=False):
# TODO: Make more values configurable
# TODO: Allow using custom processes from a local folder
# test = """
# import sys
#
# b = 3
# c = 2
#
# def aaa():
# return b + c
# """
#
# namespace = {}
# exec(test, namespace)
# print(namespace["aaa"]())
if not isinstance(config, dict):
with open(config, 'r') as cf:
config = yaml.load(cf)
workersN = config['max_threads']
begin_inputs = config['begin_inputs']
TEMPLATE_DIR = "./templates"
workersN = 12
if debug:
url_prefix = ""
css_style = 'nested'
else:
url_prefix = config["url_prefix"]
css_style = 'compressed'
stations = {}
for name in config['tasks']:
taskconf = config['tasks'][name]
pname = taskconf['process']
inputname = taskconf['input']
outputnames = taskconf['outputs']
del taskconf['process']
del taskconf['input']
del taskconf['outputs']
try:
Process = import_module('.'.join(
('wembler.processes', pname))).Process
except ImportError:
Process = import_module('.'.join(
('assemblyline.processes', pname))).Process
stations[name] = (Process(**taskconf), inputname, outputnames)
self.factory = assemblyline.Factory(workersN, begin_inputs, stations)
stations["loader"] = (_Loader(
basedir=TEMPLATE_DIR,
), None, ("templates", ))
stations["simple"] = (_SimpleStaticWebsite(
template_dir=TEMPLATE_DIR,
url_prefix=url_prefix,
css_dir='./scss',
css_style=css_style,
output_dir='www',
), "templates", ())
self.factory = assemblyline.Factory(workersN, stations)
def build(self):
self.factory.begin()
class _Loader:
def __init__(self, basedir):
self.basedir = basedir
def process(self, dummy):
for fname in os.listdir(self.basedir):
if os.path.isfile(os.path.join(self.basedir, fname)):
yield (fname, )
class _SimpleStaticWebsite:
# TODO: JS minifier
def __init__(self, template_dir, url_prefix, css_dir, css_style,
output_dir):
self.url_prefix = url_prefix
self.css_dir = css_dir
self.css_style = css_style
self.output_dir = output_dir
self.jinja_env = jinja2.Environment(
loader=jinja2.FileSystemLoader(template_dir),
trim_blocks=True,
lstrip_blocks=True,
autoescape=True
)
def process(self, template):
css = self._compile_scss(template)
self._compile_jinja(template, css)
yield ()
def _compile_scss(self, template):
fname = os.path.splitext(template)[0]
scssf = ".".join((fname, "scss"))
return sass.compile(filename=os.path.join(self.css_dir, scssf),
output_style=self.css_style,
custom_functions={
sass.SassFunction('relurl', ('$url', ),
self._relurl),
})
def _relurl(self, url):
return "url('{}')".format(os.path.join(self.url_prefix,
self.dequote(url)))
def _compile_jinja(self, template, css):
base_url = os.path.join(self.url_prefix, template) \
if self.url_prefix else None
self.jinja_env.get_template(template).stream(
css=css,
page=template,
base_url=base_url,
).dump(os.path.join(self.output_dir, os.path.basename(template)))
@staticmethod
def dequote(string):
# TODO: Move to more generic library
if string[0] == string[-1] and string.startswith(("'", '"')):
return string[1:-1]
return string

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
@@ -29,6 +29,8 @@ def _parse_cli_args():
default='./wembler.yaml', type=str, metavar='FILE',
help='the path to the configuration file '
'(default: %(default)s)')
cliparser.add_argument('--debug', action='store_true',
help='enable debug mode')
return vars(cliparser.parse_args())
Wembler(**_parse_cli_args()).build()

0 comments on commit 624b31e

Please sign in to comment.