mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Implement LessCSSGenerator
This commit is contained in:
parent
a9f798eae1
commit
50f2cd295f
3 changed files with 41 additions and 1 deletions
|
|
@ -4,6 +4,7 @@ import math
|
|||
import random
|
||||
import logging
|
||||
import datetime
|
||||
import subprocess
|
||||
|
||||
from collections import defaultdict
|
||||
from functools import partial
|
||||
|
|
@ -414,3 +415,38 @@ class PdfGenerator(Generator):
|
|||
|
||||
for page in self.context['pages']:
|
||||
self._create_pdf(page, pdf_path)
|
||||
|
||||
|
||||
class LessCSSGenerator(Generator):
|
||||
"""Compile less css files. This assumes we have `lessc` in our PATH."""
|
||||
|
||||
def generate_context(self):
|
||||
pass
|
||||
|
||||
def _compile(self, less_file, source_dir, dest_dir):
|
||||
base = os.path.relpath(less_file, source_dir)
|
||||
target = os.path.splitext(
|
||||
os.path.join(self.output_path, base))[0] + '.css'
|
||||
target_dir = os.path.dirname(target)
|
||||
|
||||
if not os.path.exists(target_dir):
|
||||
try:
|
||||
os.makedirs(target_dir)
|
||||
except OSError:
|
||||
logger.error("Couldn't create the pdf output folder in " +
|
||||
target_dir)
|
||||
pass
|
||||
|
||||
cmd = ' '.join([self.settings['LESS_COMPILER'], less_file, target])
|
||||
subprocess.call(cmd, shell=True)
|
||||
logger.info(u' [ok] compiled %s' % base)
|
||||
|
||||
def generate_output(self, writer=None):
|
||||
logger.info(u' Compiling less css')
|
||||
|
||||
for static_path in self.settings['STATIC_PATHS']:
|
||||
for f in self.get_files(
|
||||
os.path.join(self.path, static_path),
|
||||
extensions=['less']):
|
||||
|
||||
self._compile(f, self.path, self.output_path)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue