コード例 #1
0
def render_snippet_template(service, app_dir, context, template_file='') -> str:
    try:
        if template_file == '':
            if 'snippets' not in service:
                print('No snippets defined in meta-cnc.yaml file! Cannot determine what to render...')
                raise SnippetNotFoundException

            template_name = service['snippets'][0]['file']
        else:
            template_name = template_file

        if 'snippet_path' in service:
            template_full_path = os.path.join(service['snippet_path'], template_name)
        else:
            raise CCFParserError('Could not locate .meta-cnc')

        print(template_full_path)
        with open(template_full_path, 'r') as template:
            template_string = template.read()
            environment = Environment(loader=BaseLoader())

            for f in jinja_filters.defined_filters:
                if hasattr(jinja_filters, f):
                    environment.filters[f] = getattr(jinja_filters, f)

            template_template = environment.from_string(template_string)
            rendered_template = template_template.render(context)
            return rendered_template
    except Exception as e:
        print(e)
        print('Caught an error rendering snippet')
        if 'snippet_path' in service:
            print(f"Caught error rendering snippet at path: {service['snippet_path']}")

        return 'Error'
コード例 #2
0
ファイル: __init__.py プロジェクト: sysr-q/flask-themes2
 def __init__(self, as_blueprint=False):
     self.as_blueprint = as_blueprint
     BaseLoader.__init__(self)
コード例 #3
0
 def __init__(self, as_blueprint=False):
     self.as_blueprint = as_blueprint
     BaseLoader.__init__(self)
コード例 #4
0
ファイル: themes.py プロジェクト: yask123/final
 def __init__(self):
     BaseLoader.__init__(self)
コード例 #5
0
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""

import os

import pkg_resources
from jinja2 import Environment
from jinja2.environment import Template
from jinja2.loaders import BaseLoader

ENVIRONMENT = Environment(loader=BaseLoader())

with open('dist_summary.jinja2', 'r', encoding='utf-8') as fp:
    template: Template = ENVIRONMENT.from_string(fp.read())

with open('dist/DIST_SUMMARY.md', 'w', encoding='utf-8') as fp:
    output = template.render(
        env=os.getenv,
        package=pkg_resources.get_distribution('jishaku'),
    )

    # Jinja loves obliterating trailing newlines
    if not output.endswith('\n'):
        output += '\n'

    fp.write(output)
コード例 #6
0
 def __init__(self):
     BaseLoader.__init__(self)