Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: newline bug when building *_by_lua directives #86

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crossplane/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from .builder import build
from .formatter import format
from .ext.lua import LuaBlockPlugin
from .ext.by_lua import LuaPlugin

__all__ = ['parse', 'lex', 'build', 'format']

Expand All @@ -19,6 +20,6 @@
__license__ = 'Apache 2.0'
__copyright__ = 'Copyright 2018 NGINX, Inc.'

default_enabled_extensions = [LuaBlockPlugin()]
default_enabled_extensions = [LuaBlockPlugin(), LuaPlugin()]
for extension in default_enabled_extensions:
extension.register_extension()
36 changes: 36 additions & 0 deletions crossplane/ext/by_lua.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
from crossplane.analyzer import register_external_directives
from crossplane.builder import register_external_builder
from crossplane.ext.abstract import CrossplaneExtension


class LuaPlugin(CrossplaneExtension):
directives = {
'init_by_lua': [],
'init_worker_by_lua': [],
'set_by_lua': [],
'rewrite_by_lua': [],
'access_by_lua': [],
'content_by_lua': [],
'header_filter_by_lua': [],
'body_filter_by_lua': [],
'log_by_lua': [],
}

def register_extension(self):
register_external_builder(directives=self.directives, builder=self.build)

def lex(self, token_iterator, directive):
raise NotImplementedError

def parse(self, stmt, parsing, tokens, ctx=(), consume=False):
raise NotImplementedError

def build(self, stmt, padding, state, indent=4, tabs=False):
built = stmt['directive']
if built == 'set_by_lua':
block = stmt['args'][1]
built += " %s" % stmt['args'][0]
else:
block = stmt['args'][0]
return built + " '" + block + "';"