Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from nikola.plugin_categories import Task
from nikola import utils
from nikola.utils import LOGGER
plugin_path = os.path.dirname(os.path.realpath(__file__))
base_path = plugin_path.split("plugins")[0]
def get_entries(path):
for dirName, _, fileList in os.walk(path, topdown=False):
for fname in fileList:
if fname.endswith(".png"):
yield(os.path.join(dirName, fname))
class CopyPics(Task):
"""Render code listings."""
name = "copy_pics"
def register_output_name(self, input_folder, rel_name, rel_output_name):
"""Register proper and improper file mappings."""
self.improper_input_file_mapping[rel_name].add(rel_output_name)
self.proper_input_file_mapping[os.path.join(input_folder, rel_name)] = rel_output_name
self.proper_input_file_mapping[rel_output_name] = rel_output_name
def set_site(self, site):
"""Set Nikola site."""
def gen_tasks(self):
for in_name in get_entries(os.path.join(base_path, "../examples")):
name_image = os.path.basename(in_name)
url = site.abs_link( lang_prefix(lang, site) + '/documentation/' + module + "/" )
return "{" + entry_js.format(title=module, text=reference, tags="module " + module, url=url) + "},\n"
rel_url_regex = re.compile(r'\[([^\]]*)\]\(([^/]((?!://).)*)\)')
def relative_urls(text):
return rel_url_regex.sub(r'[\1](../\2)', text)
def of_classes_to_links(text, classes_simple_name, module_lookup):
for class_name in classes_simple_name:
rep = "(?!\[[^[\]]*)"+class_name+"(?=[\s(])(?![^[\]]*\])"
#rep = "/("+class_name + "[\s(])(?![^\[]*\])/g"
dst_pattern = "<a class="\"docs_class\"" href="\"/documentation/"+module_lookup[class_name]+"/"+class_name+"\"">"+class_name+"</a>"
text = re.sub(rep,dst_pattern,text)
return text
class DocsTask(Task):
"""Generates the tutorials contents."""
name = "documentation"
description = "Generate OF docs"
def create_docs(self):
tasks = {}
classes = []
directory = "documentation"
classes = markdown_file.getclass_list()
classes_simple_name = markdown_file.getclass_list(False)
addons = markdown_file.list_all_addons()
module_lookup = dict()
core_index = dict()
if line.find(':translator_site:')!=-1:
self.translator_site = stripFileLine(line[line[1:].find(':')+2:]).strip(' ')
continue
if stripFileLine(line).find(":")!=0:
return
def create_file(in_path, out_path):
try:
os.makedirs(os.path.dirname(out_path))
except:
pass
shutil.copyfile(in_path, out_path)
class TutorialsTask(Task):
"""Generates the tutorials contents."""
name = "tutorials"
description = "Generate OF tutorials"
def gen_tasks(self):
self.kw = {
'strip_indexes': self.site.config['STRIP_INDEXES'],
'output_folder': self.site.config['OUTPUT_FOLDER'],
'cache_folder': self.site.config['CACHE_FOLDER'],
'default_lang': self.site.config['DEFAULT_LANG'],
'filters': self.site.config['FILTERS'],
'translations': self.site.config['TRANSLATIONS'],
'global_context': self.site.GLOBAL_CONTEXT,
'tzinfo': self.site.tzinfo,
}