Commit 1b126475 authored by Patrik Dufresne's avatar Patrik Dufresne

Import project from lektor-asciidoc

parents
dist
build
*.pyc
*.pyo
*.egg-info
.cache
/.project
/.pydevproject
eclipse.preferences.version=1
encoding/lektor_asciidoc.py=utf-8
# Lektor AsciiDoc Plugin
A [Lektor](https://www.getlektor.com/) plugin to add an AsciiDoc field type.
## Installation
Add lektor-asciidoc to your project from command line:
```
lektor plugins add lektor-asciidoc
```
# -*- coding: utf-8 -*-
from subprocess import PIPE, Popen
from lektor.pluginsystem import Plugin
from lektor.types import Type
def asciidoc_to_html(text):
p = Popen(['asciidoc', '--no-header-footer', '--backend=html5', '-'],
stdin=PIPE, stdout=PIPE, stderr=PIPE)
out, err = p.communicate(text)
if p.returncode != 0:
raise RuntimeError('asciidoc: "%s"' % err)
return out
# Wrapper with an __html__ method prevents Lektor from escaping HTML tags.
class HTML(object):
def __init__(self, html):
self.html = html
def __html__(self):
return self.html
class AsciiDocType(Type):
widget = 'multiline-text'
def value_from_raw(self, raw):
return HTML(asciidoc_to_html(raw.value or u''))
class AsciiDocPlugin(Plugin):
name = u'AsciiDoc'
description = u'Adds AsciiDoc field type to Lektor.'
def on_setup_env(self, **extra):
self.env.add_type(AsciiDocType)
import ast
import io
import re
from setuptools import setup
with io.open('README.md', 'rt', encoding="utf8") as f:
readme = f.read()
_description_re = re.compile(r'description\s+=\s+(?P<description>.*)')
with open('lektor_asciidoc.py', 'rb') as f:
description = str(ast.literal_eval(_description_re.search(
f.read().decode('utf-8')).group(1)))
setup(
author=u'A. Jesse Jiryu Davis',
author_email='jesse@emptysquare.net',
description=description,
keywords='Lektor plugin static-site blog asciidoc',
license='MIT',
long_description=readme,
long_description_content_type='text/markdown',
name='lektor-asciidoc',
py_modules=['lektor_asciidoc'],
tests_require=['pytest'],
version='0.3',
url='https://github.com/nixjdm/lektor-asciidoc',
classifiers=[
'Environment :: Plugins',
'Environment :: Web Environment',
'Framework :: Lektor',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
],
entry_points={
'lektor.plugins': [
'asciidoc = lektor_asciidoc:AsciiDocPlugin',
]
}
)
body:
== Header 1
Some text.
-----
code here
-----
[model]
name = Page
[fields.body]
label = Body
type = asciidoc
<html>
<body>
<div>
{{ this.body }}
</div>
</body>
'''
Created on Jun 8, 2018
@author: ikus060
'''
from lektor.builder import Builder
from lektor.db import Database
from lektor.environment import Environment
from lektor.project import Project
import os
import shutil
import tempfile
import unittest
class TestLektorAsciidoc(unittest.TestCase):
def setUp(self):
self.project = Project.from_path(os.path.join(os.path.dirname(__file__), 'demo-project'))
self.env = Environment(self.project)
self.pad = Database(self.env).new_pad()
self.out = tempfile.mkdtemp()
self.builder = Builder(self.pad, self.out)
def tearDown(self):
try:
shutil.rmtree(self.out)
except (OSError, IOError):
pass
def test_basic(self):
failures = self.builder.build_all()
assert not failures
page_path = os.path.join(self.builder.destination_path, 'index.html')
html = open(page_path).read()
assert '<h2 id="_header_1">Header 1</h2>' in html
assert '<pre>code here</pre>' in html
if __name__ == "__main__":
# import sys;sys.argv = ['', 'Test.testName']
unittest.main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment