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
|
|
@ -6,7 +6,7 @@ import logging
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
from pelican.generators import (ArticlesGenerator, PagesGenerator,
|
from pelican.generators import (ArticlesGenerator, PagesGenerator,
|
||||||
StaticGenerator, PdfGenerator)
|
StaticGenerator, PdfGenerator, LessCSSGenerator)
|
||||||
from pelican.log import init
|
from pelican.log import init
|
||||||
from pelican.settings import read_settings, _DEFAULT_CONFIG
|
from pelican.settings import read_settings, _DEFAULT_CONFIG
|
||||||
from pelican.utils import clean_output_dir, files_changed
|
from pelican.utils import clean_output_dir, files_changed
|
||||||
|
|
@ -133,6 +133,8 @@ class Pelican(object):
|
||||||
generators = [ArticlesGenerator, PagesGenerator, StaticGenerator]
|
generators = [ArticlesGenerator, PagesGenerator, StaticGenerator]
|
||||||
if self.settings['PDF_GENERATOR']:
|
if self.settings['PDF_GENERATOR']:
|
||||||
generators.append(PdfGenerator)
|
generators.append(PdfGenerator)
|
||||||
|
if self.settings['LESS_GENERATOR']:
|
||||||
|
generators.append(LessCSSGenerator)
|
||||||
return generators
|
return generators
|
||||||
|
|
||||||
def get_writer(self):
|
def get_writer(self):
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import math
|
||||||
import random
|
import random
|
||||||
import logging
|
import logging
|
||||||
import datetime
|
import datetime
|
||||||
|
import subprocess
|
||||||
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
@ -414,3 +415,38 @@ class PdfGenerator(Generator):
|
||||||
|
|
||||||
for page in self.context['pages']:
|
for page in self.context['pages']:
|
||||||
self._create_pdf(page, pdf_path)
|
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)
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,8 @@ _DEFAULT_CONFIG = {'PATH': '.',
|
||||||
'DEFAULT_STATUS': 'published',
|
'DEFAULT_STATUS': 'published',
|
||||||
'ARTICLE_PERMALINK_STRUCTURE': '',
|
'ARTICLE_PERMALINK_STRUCTURE': '',
|
||||||
'TYPOGRIFY': False,
|
'TYPOGRIFY': False,
|
||||||
|
'LESS_GENERATOR': False,
|
||||||
|
'LESS_COMPILER': '/usr/bin/lessc',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue