def get_pattern_markdown(template_name): replace_pattern = '{}$'.format(get_pattern_template_suffix()) md_path = re.sub(replace_pattern, '', template_name) md_name = md_path + '.md' try: md_file = get_template(md_name) except TemplateDoesNotExist: return '' with open(md_file.origin.name, 'r', encoding='utf-8') as f: return markdown.markdown(f.read())
def get_pattern_config_str(template_name): replace_pattern = '{}$'.format(get_pattern_template_suffix()) context_file = re.sub(replace_pattern, '', template_name) context_file = context_file + '.yaml' context_file = os.path.join(get_pattern_template_dir(), context_file) try: # Default encoding is platform-dependant, so we explicitly open it as utf-8. with open(context_file, 'r', encoding='utf-8') as f: return str(f.read()) except IOError: return ''
def get_pattern_markdown(template_name): replace_pattern = '{}$'.format(get_pattern_template_suffix()) md_file = re.sub(replace_pattern, '', template_name) md_file = md_file + '.md' md_file = os.path.join(get_pattern_template_dir(), md_file) try: # Default encoding is platform-dependant, so we explicitly open it as utf-8. with open(md_file, 'r', encoding='utf-8') as f: htmlmarkdown = markdown.markdown(f.read()) return htmlmarkdown except IOError: return ''
def get_pattern_config_str(template_name): replace_pattern = "{}$".format(get_pattern_template_suffix()) context_path = re.sub(replace_pattern, "", template_name) context_name = context_path + ".yaml" try: context_file = get_template(context_name) except TemplateDoesNotExist: context_name = context_path + ".yml" try: context_file = get_template(context_name) except TemplateDoesNotExist: return "" return context_file.render()
def is_pattern(template_name): return ( template_name.startswith(get_pattern_template_prefix()) and template_name.endswith(get_pattern_template_suffix()) )
from django.conf.urls import url from pattern_library import get_pattern_template_suffix, views app_name = 'pattern_library' urlpatterns = [ # UI url(r'^$', views.IndexView.as_view(), name='index'), url(r'^pattern/(?P<pattern_template_name>[\w./-]+%s)$' % (get_pattern_template_suffix()), views.IndexView.as_view(), name='display_pattern'), # iframe rendering url(r'^render-pattern/(?P<pattern_template_name>[\w./-]+%s)$' % (get_pattern_template_suffix()), views.RenderPatternView.as_view(), name='render_pattern'), ]
from django.conf.urls import url from pattern_library import ( get_pattern_template_prefix, get_pattern_template_suffix, views ) app_name = 'pattern_library' urlpatterns = [ # UI url(r'^$', views.IndexView.as_view(), name='index'), url( r'^pattern/(?P<pattern_template_name>%s/[\w./-]+%s)$' % ( get_pattern_template_prefix(), get_pattern_template_suffix() ), views.IndexView.as_view(), name='display_pattern' ), # iframe rendering url( r'^render-pattern/(?P<pattern_template_name>%s/[\w./-]+%s)$' % ( get_pattern_template_prefix(), get_pattern_template_suffix() ), views.RenderPatternView.as_view(), name='render_pattern' ), ]