Пример #1
0
def run():
    classes = []
    directory = "_documentation"
    documentation = bf.config.controllers.documentation
        
    classes = markdown_file.getclass_list()
    classes_simple_name = markdown_file.getclass_list(False)
    addon_classes = markdown_file.list_all_addons()
    
    module_lookup = dict()
    core_index = dict()
    addons_index = dict()
    module_subtitles = dict()
    
    # Create an index of which module each class is in for generated links to other classes
    for class_name in classes:
        clazz = markdown_file.getclass(class_name)
        if clazz.istemplated:
            module_lookup[class_name[:-1]] = clazz.module    
        else:
            module_lookup[class_name] = clazz.module
        
    for clazz_name in classes:
        clazz = markdown_file.getclass(clazz_name)
        if clazz.istemplated:
            clazz.name = clazz.name[:-1]

        clazz.detailed_inline_description = str(clazz.detailed_inline_description.encode('ascii', 'ignore'))
        for class_name in classes_simple_name:
            rep = class_name + "[\s]"
            clazz.detailed_inline_description = re.sub(rep, "<a href=\"../"+module_lookup[class_name]+"/"+class_name+".html\" class=\"docs_class\" >"+class_name+"</a> ", clazz.detailed_inline_description)
            rep = class_name + "[(]"
            clazz.detailed_inline_description = re.sub(rep, "<a href=\"../"+module_lookup[class_name]+"/"+class_name+".html\" class=\"docs_class\" >"+class_name+"</a>(", clazz.detailed_inline_description)

        clazz.reference = str(clazz.reference.encode('ascii', 'ignore'))
        for class_name in classes_simple_name:
            rep = class_name + "[\s]"
            clazz.reference = re.sub(rep, "<a href=\"../"+module_lookup[class_name]+"/"+class_name+".html\" class=\"docs_class\" >"+class_name+"</a> ", clazz.reference)
            rep = class_name + "[(]"
            clazz.reference = re.sub(rep, "<a href=\"../"+module_lookup[class_name]+"/"+class_name+".html\" class=\"docs_class\" >"+class_name+"</a>(", clazz.reference)

        def gen_link(class_name): return "<a href=\"../"+module_lookup[class_name]+"/"+class_name+".html\" class=\"docs_class\" >"+class_name+"</a> " if class_name in module_lookup else ""
        def filter_out_empty(class_name): return class_name!="" 
        clazz.extends = list(filter(filter_out_empty, map(gen_link, clazz.extends)))
            
        functions_file = markdown_file.getfunctionsfile(clazz.name)
        #print clazz.name
        #print clazz.function_list 
        env = {
            "modulename": clazz.name,
            "clazz": clazz,
            "functions": functions_file,
            "classes_list": classes,
            "is_addon": (clazz.name in addon_classes)
        }
        
        bf.template.materialize_template("documentation_class.mako", ('documentation',clazz.module+"/"+clazz.name+".html"), env )
        
        if not clazz.module in addon_classes:
            if not clazz.module in core_index.keys():
                core_index[clazz.module] = []
            if functions_file!=None:
                for function in functions_file.function_list:
                    clazz.function_list.append(function)
            core_index[clazz.module].append(clazz)
        else:
            if not clazz.module in addons_index.keys():
                addons_index[clazz.module] = []
            if functions_file!=None:
                for function in functions_file.function_list:
                    clazz.function_list.append(function)
            addons_index[clazz.module].append(clazz)
        
    
    function_files = markdown_file.getfunctionsfiles_list()
    for functionfile_name in function_files:
        if functionfile_name in classes_simple_name:
            continue
        functions_file = markdown_file.getfunctionsfile(functionfile_name)

# might be needed at some point?
#        functions_file.reference = str(functions_file.reference)
#        for func in function_files:
#            functions_file.reference = str.replace(functions_file.reference, class_name, "<a href=\"../"+clazz.module+"/"+class_name+".html\">"+class_name+"</a>")
        env = {
            "modulename": functions_file.name,
            "clazz": None,
            "functions": functions_file,
            "is_addon": (functions_file.name in addon_classes) 
        }
        bf.template.materialize_template("documentation_class.mako", ('documentation',functions_file.module+"/"+functions_file.name+".html"), env )
        
        if not functions_file.module in addon_classes:
            if not functions_file.module in core_index:
                core_index[functions_file.module] = []
            core_index[functions_file.module].append(functions_file)
        else:
            if not functions_file.module in addons_index:
                addons_index[functions_file.module] = []
            addons_index[functions_file.module].append(functions_file)
        
    
    for root, dirs, files in os.walk(directory):
        """ copy images to their folders """
        for name in files:
            file_split = os.path.splitext(name)
            if file_split[1]==".jpeg" or file_split[1]==".jpg" or file_split[1]==".gif" or file_split[1]==".png":
                try:
                    os.mkdir(os.path.join('_site','documentation',os.path.basename(root)))
                except:
                    pass
                shutil.copyfile(os.path.join(root,name), os.path.join('_site','documentation',os.path.basename(root),name))
                
        """ create module introductions """
        for module in dirs:
            if module!="addons":
                module_intro = os.path.join(root,module,"introduction.markdown")
                if os.path.isfile(module_intro):
                    module_intro_file = open(module_intro)
                    module_intro_content = module_intro_file.read()
                    module_subtitles[module] = module_intro_content.splitlines()[0].strip('##').strip(' ')
                    if module.find("ofx") == 0:
                        bf.template.materialize_template("documentation_module_intro.mako", (os.path.join('documentation', module),"introduction.html"), {"module": module, "content": module_intro_content, "classes": addons_index[module]} )
                    else:
                        bf.template.materialize_template("documentation_module_intro.mako", (os.path.join('documentation', module),"introduction.html"), {"module": module, "content": module_intro_content, "classes": core_index[module]} )
                else:
                    module_subtitles[module] = None
                    print "couldn't find " + module_intro
        

    # process index file        
    bf.template.materialize_template("documentation.mako", ('documentation',"index.html"), {'core':core_index, 'addons':addons_index, 'module_subtitles':module_subtitles} )
Пример #2
0
import markdown_file
import copy
import sys

addons = markdown_file.list_all_addons()
block_list = []

def uniqify(seq):
    seen = set()
    seen_add = seen.add
    return [ x for x in seq if x not in seen and not seen_add(x)]
        
class Block(object):
    def __init__(self, source=""):
        self.source = source
        self.name = None
        self.classes = []
        self.mode = 'module'
        if source!="":
            self.__parse()
        
    
    def __parse(self):
        src_list = self.source.split('\n')
        for element in src_list:
            self.__parse_element(element)
        for clazz in self.classes:
            if 'methods' in clazz:
                clazz['methods'] = uniqify(clazz['methods']) #sets.Set(clazz['methods']) 
            if 'variables' in clazz:
                clazz['variables'] = uniqify(clazz['variables']) #sets.Set(clazz['variables'])
Пример #3
0
    def create_docs(self):
        tasks = {}
        classes = []
        directory = "documentation"

        classes = markdown_file.getclass_list()
        classes_simple_name = markdown_file.getclass_list(False)
        addon_classes = markdown_file.list_all_addons()

        module_lookup = dict()
        core_index = dict()
        addons_index = dict()
        module_subtitles = dict()

        docs_dir = os.path.join(self.site.original_cwd, "documentation")
        md_extensions = self.site.config.get("MARKDOWN_EXTENSIONS")

        # Create an index of which module each class is in for generated links to other classes
        for class_name in classes:
            clazz = markdown_file.getclass(class_name)
            if clazz.istemplated:
                module_lookup[class_name[:-1]] = clazz.module
            else:
                module_lookup[class_name] = clazz.module

        for clazz_name in classes:
            clazz = markdown_file.getclass(clazz_name)
            if clazz.istemplated:
                clazz.name = clazz.name[:-1]

            clazz.detailed_inline_description = markdown(clazz.detailed_inline_description, md_extensions)
            # clazz.description = str(markdown(clazz.description, md_extensions).encode('ascii', 'ignore'))
            for class_name in classes_simple_name:
                rep = class_name + "[\s]"
                clazz.detailed_inline_description = re.sub(
                    rep,
                    '<a href="/documentation/'
                    + module_lookup[class_name]
                    + "/"
                    + class_name
                    + '" class="docs_class" >'
                    + class_name
                    + "</a> ",
                    clazz.detailed_inline_description,
                )
                rep = class_name + "[(]"
                clazz.detailed_inline_description = re.sub(
                    rep,
                    '<a href="/documentation/'
                    + module_lookup[class_name]
                    + "/"
                    + class_name
                    + '" class="docs_class" >'
                    + class_name
                    + "</a>(",
                    clazz.detailed_inline_description,
                )

            clazz.reference = markdown(clazz.reference, md_extensions)
            for class_name in classes_simple_name:
                rep = class_name + "[\s]"
                clazz.reference = re.sub(
                    rep,
                    '<a href="/documentation/'
                    + module_lookup[class_name]
                    + "/"
                    + class_name
                    + '" class="docs_class" >'
                    + class_name
                    + "</a> ",
                    clazz.reference,
                )
                rep = class_name + "[(]"
                clazz.reference = re.sub(
                    rep,
                    '<a href="/documentation/'
                    + module_lookup[class_name]
                    + "/"
                    + class_name
                    + '" class="docs_class" >'
                    + class_name
                    + "</a>(",
                    clazz.reference,
                )

            for function in clazz.function_list:
                function.description = markdown(function.description, md_extensions)
                function.inlined_description = markdown(function.inlined_description, md_extensions)

            def gen_link(class_name):
                return (
                    '<a href="/documentation/'
                    + module_lookup[class_name]
                    + "/"
                    + class_name
                    + '" class="docs_class" >'
                    + class_name
                    + "</a> "
                    if class_name in module_lookup
                    else ""
                )

            def filter_out_empty(class_name):
                return class_name != ""

            clazz.extends = list(filter(filter_out_empty, map(gen_link, clazz.extends)))

            functions_file = markdown_file.getfunctionsfile(clazz.name)
            for function in functions_file.function_list:
                function.description = markdown(function.description, md_extensions)
                function.inlined_description = markdown(function.inlined_description, md_extensions)
            # print clazz.name
            # print clazz.function_list
            env = {
                "modulename": clazz.name,
                "clazz": clazz,
                "functions": functions_file,
                "classes_list": classes,
                "is_addon": (clazz.name in addon_classes),
            }
            # print("class " + clazz_name)

            template_name = "documentation_class.mako"
            for lang in self.kw["translations"]:
                env["lang"] = lang
                env["title"] = clazz.name
                env["permalink"] = (
                    self.kw["translations"][lang] + "/documentation/" + clazz.module + "/" + clazz.name + "/"
                )
                short_tdst = os.path.join(
                    self.kw["translations"][lang], "documentation", clazz.module, clazz.name, "index.html"
                )
                tdst = os.path.normpath(os.path.join(self.kw["output_folder"], short_tdst))
                self.site.render_template(template_name, tdst, env)

            if not clazz.module in addon_classes:
                if not clazz.module in core_index.keys():
                    core_index[clazz.module] = []
                if functions_file != None:
                    for function in functions_file.function_list:
                        clazz.function_list.append(function)
                core_index[clazz.module].append(clazz)
            else:
                if not clazz.module in addons_index.keys():
                    addons_index[clazz.module] = []
                if functions_file != None:
                    for function in functions_file.function_list:
                        clazz.function_list.append(function)
                addons_index[clazz.module].append(clazz)

        function_files = markdown_file.getfunctionsfiles_list()
        for functionfile_name in function_files:
            if functionfile_name in classes_simple_name:
                continue
            functions_file = markdown_file.getfunctionsfile(functionfile_name)

            # might be needed at some point?
            #        functions_file.reference = str(functions_file.reference)
            #        for func in function_files:
            #            functions_file.reference = str.replace(functions_file.reference, class_name, "<a href=\"../"+clazz.module+"/"+class_name+".html\">"+class_name+"</a>")
            for function in functions_file.function_list:
                function.description = markdown(function.description, md_extensions)
                function.inlined_description = markdown(function.inlined_description, md_extensions)

            env = {
                "modulename": functions_file.name,
                "clazz": None,
                "functions": functions_file,
                "is_addon": (functions_file.name in addon_classes),
            }

            template_name = "documentation_class.mako"
            for lang in self.kw["translations"]:
                env["lang"] = lang
                env["title"] = clazz.name
                env["permalink"] = (
                    self.kw["translations"][lang]
                    + "/documentation/"
                    + functions_file.module
                    + "/"
                    + functions_file.name
                    + "/"
                )
                short_tdst = os.path.join(
                    self.kw["translations"][lang],
                    "documentation",
                    functions_file.module,
                    functions_file.name,
                    "index.html",
                )
                tdst = os.path.normpath(os.path.join(self.kw["output_folder"], short_tdst))
                self.site.render_template(template_name, tdst, env)

            if not functions_file.module in addon_classes:
                if not functions_file.module in core_index:
                    core_index[functions_file.module] = []
                core_index[functions_file.module].append(functions_file)
            else:
                if not functions_file.module in addons_index:
                    addons_index[functions_file.module] = []
                addons_index[functions_file.module].append(functions_file)

        for root, dirs, files in os.walk(directory):
            """ copy images to their folders """
            for name in files:
                file_split = os.path.splitext(name)
                if (
                    file_split[1] == ".jpeg"
                    or file_split[1] == ".jpg"
                    or file_split[1] == ".gif"
                    or file_split[1] == ".png"
                ):
                    try:
                        os.mkdir(os.path.join("_site", "documentation", os.path.basename(root)))
                    except:
                        pass
                    shutil.copyfile(
                        os.path.join(root, name), os.path.join("output", "documentation", os.path.basename(root), name)
                    )

            """ create module introductions """
            for module in dirs:
                if module != "addons":
                    module_intro = os.path.join(root, module, "introduction.markdown")
                    if os.path.isfile(module_intro):
                        module_intro_file = open(module_intro)
                        module_intro_content = module_intro_file.read()
                        module_subtitles[module] = module_intro_content.splitlines()[0].strip("##").strip(" ")
                        module_intro_content = markdown(module_intro_content, md_extensions)
                        template_name = "documentation_module_intro.mako"
                        for lang in self.kw["translations"]:
                            context = {}
                            context["lang"] = lang
                            context["title"] = clazz.name
                            context["module"] = module
                            context["intro_content"] = module_intro_content
                            context["permalink"] = (
                                self.kw["translations"][lang] + "/documentation/" + module + "/introduction.html"
                            )
                            short_tdst = os.path.join(
                                self.kw["translations"][lang], "documentation", module, "introduction.html"
                            )
                            tdst = os.path.normpath(os.path.join(self.kw["output_folder"], short_tdst))
                            if module.find("ofx") == 0:
                                context["classes"] = addons_index[module]
                                self.site.render_template(template_name, tdst, context)
                            else:
                                context["classes"] = core_index[module]
                                self.site.render_template(template_name, tdst, context)
                    else:
                        module_subtitles[module] = None
                        print("couldn't find " + module_intro)

        # process index file
        template_name = "documentation.mako"
        for lang in self.kw["translations"]:
            # lang_suffix = self.kw['translations'][lang]
            docs_intro_path = os.path.join(docs_dir, "index.md")
            if lang != self.site.config["DEFAULT_LANG"]:
                docs_intro_lang_path = utils.get_translation_candidate(self.site.config, docs_intro_path, lang)
                p = pathlib.Path(docs_intro_lang_path)
                if p.exists():
                    docs_intro_path = docs_intro_lang_path
            docs_intro = open(docs_intro_path).read()
            for key in self.site.GLOBAL_CONTEXT.keys():
                if isinstance(self.site.GLOBAL_CONTEXT[key], str):
                    docs_intro = docs_intro.replace("${" + key + "}", self.site.GLOBAL_CONTEXT[key])
            docs_intro = markdown(docs_intro, md_extensions)
            context = {}
            context["lang"] = lang
            context["title"] = "documentation"
            context["docs_intro"] = docs_intro
            context["core"] = core_index
            context["addons"] = addons_index
            context["module_subtitles"] = module_subtitles
            context["permalink"] = self.kw["translations"][lang] + "/documentation/"
            short_tdst = os.path.join(self.kw["translations"][lang], "documentation", "index.html")
            tdst = os.path.normpath(os.path.join(self.kw["output_folder"], short_tdst))
            self.site.render_template(template_name, tdst, context)
Пример #4
0
    def create_docs(self):
        tasks = {}
        classes = []
        directory = "documentation"
            
        classes = markdown_file.getclass_list()
        classes_simple_name = markdown_file.getclass_list(False)            
        addon_classes = markdown_file.list_all_addons()
        
        module_lookup = dict()
        core_index = dict()
        addons_index = dict()
        module_subtitles = dict()
        
        docs_dir = os.path.join(self.site.original_cwd, "documentation")
        md_extensions = self.site.config.get("MARKDOWN_EXTENSIONS")
        content_js = {}
        
        class_template = "documentation_class.mako"
        class_template_dep = self.site.template_system.template_deps(class_template)
        module_template = "documentation_module_intro.mako"
        
        # start js string for docs search
        for lang in self.kw['translations']:
            content_js[lang] = 'var tipuesearch = {"pages": ['
        
        # Create an index of which module each class is in for generated links to other classes
        for class_name in classes:
            clazz = markdown_file.getclass(class_name)
            if clazz.istemplated:
                module_lookup[class_name[:-1]] = clazz.module    
            else:
                module_lookup[class_name] = clazz.module
        
        # classes docs
        for clazz_name in classes:
            clazz = markdown_file.getclass(clazz_name)
            if clazz.istemplated:
                clazz.name = clazz.name[:-1]

            clazz.detailed_inline_description = relative_urls(clazz.detailed_inline_description)
            clazz.detailed_inline_description = markdown(clazz.detailed_inline_description, md_extensions)
            clazz.detailed_inline_description = of_classes_to_links(clazz.detailed_inline_description, classes_simple_name, module_lookup)

            clazz.reference = relative_urls(clazz.reference)
            clazz.reference = markdown(clazz.reference, md_extensions)
            clazz.reference = of_classes_to_links(clazz.reference, classes_simple_name, module_lookup)
            
            # methods in class
            for function in clazz.function_list:
                function.description = relative_urls(function.description)
                function.description = of_classes_to_links(function.description, classes_simple_name, module_lookup)
                function.description = markdown(function.description, md_extensions)
                
                function.inlined_description = relative_urls(function.inlined_description)
                function.inlined_description = of_classes_to_links(function.inlined_description, classes_simple_name, module_lookup)
                function.inlined_description = markdown(function.inlined_description, md_extensions)
                for lang in self.kw['translations']: 
                    content_js[lang] += method_to_js(function, clazz, self.site, lang)
                
            # inheritance
            def gen_link(class_name): 
                return "<a href=\"/documentation/" + module_lookup[class_name] + "/" + class_name + "\" class=\"docs_class\" >"+class_name+"</a> " if class_name in module_lookup else ""
            def filter_out_empty(class_name): 
                return class_name!="" 
            clazz.extends = list(filter(filter_out_empty, map(gen_link, clazz.extends)))
                
            # c functions in the class file
            functions_file = markdown_file.getfunctionsfile(clazz.name)
            for function in functions_file.function_list:
                function.description = relative_urls(function.description)
                function.description = of_classes_to_links(function.description, classes_simple_name, module_lookup)
                function.description = markdown(function.description, md_extensions)
                
                function.inlined_description = relative_urls(function.inlined_description)
                function.inlined_description = of_classes_to_links(function.inlined_description, classes_simple_name, module_lookup)
                function.inlined_description = markdown(function.inlined_description, md_extensions)
                for lang in self.kw['translations']:
                    content_js[lang] += function_to_js(function, functions_file, self.site, lang)
                    
            # render template + js for search
            env = {
                "modulename": clazz.name,
                "clazz": clazz,
                "functions": functions_file,
                "classes_list": classes,
                "is_addon": (clazz.name in addon_classes)
            }
            md_file = "documentation/" + module_lookup[class_name] + "/" + class_name + ".markdown"
            for lang in self.kw['translations']:
                env["lang"] = lang
                env["title"] = clazz.name
                env["permalink"] = self.kw['translations'][lang] + '/documentation/' + clazz.module + "/" + clazz.name + "/" 
                short_tdst = os.path.join(self.kw['translations'][lang], 'documentation', clazz.module, clazz.name,"index.html")
                tdst = os.path.normpath(os.path.join(self.kw['output_folder'], short_tdst))
                """yield utils.apply_filters({
                    'basename': self.name,
                    'name': clazz.name,
                    'file_dep': class_template_dep + md_file,
                    'targets': tdst,
                    'actions': [
                        (self.site.render_template, (template_name, tdst, env))
                    ],
                    'clean': True,
                    'uptodate': [utils.config_changed({
                        1: self.kw,
                    })],
                }, self.kw['filters'])"""
                self.site.render_template(class_template, tdst, env)
                content_js[lang] += class_to_js(clazz, self.site, lang)
            
            # add to index core or addons
            if not clazz.module in addon_classes:
                if not clazz.module in core_index.keys():
                    core_index[clazz.module] = []
                if functions_file!=None:
                    for function in functions_file.function_list:
                        clazz.function_list.append(function)
                core_index[clazz.module].append(clazz)
            else:
                if not clazz.module in addons_index.keys():
                    addons_index[clazz.module] = []
                if functions_file!=None:
                    for function in functions_file.function_list:
                        clazz.function_list.append(function)
                addons_index[clazz.module].append(clazz)
            
            
        # generate c functions docs
        function_files = markdown_file.getfunctionsfiles_list()
        for functionfile_name in function_files:
            if functionfile_name in classes_simple_name:
                continue
            functions_file = markdown_file.getfunctionsfile(functionfile_name)

    # might be needed at some point?
    #        functions_file.reference = str(functions_file.reference)
    #        for func in function_files:
    #            functions_file.reference = str.replace(functions_file.reference, class_name, "<a href=\"../"+clazz.module+"/"+class_name+".html\">"+class_name+"</a>")
            
            for function in functions_file.function_list:
                function.description = relative_urls(function.description)
                function.description = of_classes_to_links(function.description, classes_simple_name, module_lookup)
                function.description = markdown(function.description, md_extensions)
                
                function.inlined_description = relative_urls(function.inlined_description)
                function.inlined_description = of_classes_to_links(function.inlined_description, classes_simple_name, module_lookup)
                function.inlined_description = markdown(function.inlined_description, md_extensions)
                for lang in self.kw['translations']:
                    content_js[lang] += function_to_js(function, functions_file, self.site, lang)
                
            # render template + js for search
            env = {
                "modulename": functions_file.name,
                "clazz": None,
                "functions": functions_file,
                "is_addon": (functions_file.name in addon_classes) 
            }
            for lang in self.kw['translations']:
                env["lang"] = lang
                env["title"] = clazz.name
                env["permalink"] = self.kw['translations'][lang] + '/documentation/' + functions_file.module + "/" + functions_file.name + "/" 
                short_tdst = os.path.join(self.kw['translations'][lang], 'documentation', functions_file.module, functions_file.name,"index.html")
                tdst = os.path.normpath(os.path.join(self.kw['output_folder'], short_tdst))
                self.site.render_template(class_template, tdst, env)
                content_js[lang] += functions_file_to_js(functions_file, self.site, lang)
            
            # add to index core or addons
            if not functions_file.module in addon_classes:
                if not functions_file.module in core_index:
                    core_index[functions_file.module] = []
                core_index[functions_file.module].append(functions_file)
            else:
                if not functions_file.module in addons_index:
                    addons_index[functions_file.module] = []
                addons_index[functions_file.module].append(functions_file)
            
        
        # copy images and render intros
        for root, dirs, files in os.walk(directory):
            """ copy images to their folders """
            for name in files:
                file_split = os.path.splitext(name)
                if file_split[1]==".jpeg" or file_split[1]==".jpg" or file_split[1]==".gif" or file_split[1]==".png":
                    try:
                        os.mkdir(os.path.join('_site','documentation',os.path.basename(root)))
                    except:
                        pass
                    shutil.copyfile(os.path.join(root,name), os.path.join('output','documentation',os.path.basename(root),name))
                    
            """ create module introductions """
            for module in dirs:
                if module!="addons":
                    module_intro = os.path.join(root,module,"introduction.markdown")
                    if os.path.isfile(module_intro):
                        module_intro_file = open(module_intro)
                        module_intro_content = module_intro_file.read()
                        module_subtitles[module] = module_intro_content.splitlines()[0].strip('##').strip(' ')
                        module_intro_content = markdown(module_intro_content, md_extensions)
                        for lang in self.kw['translations']:
                            context = {}
                            context["lang"] = lang
                            context["title"] = module
                            context["module"] = module
                            context["intro_content"] = module_intro_content
                            context["permalink"] = self.kw['translations'][lang] + '/documentation/' + module + "/"
                            if lang == self.site.config['DEFAULT_LANG']: 
                                short_tdst = os.path.join('documentation', module, "index.html")
                            else:
                                short_tdst = os.path.join(self.kw['translations'][lang], 'documentation', module, "index.html")
                            tdst = os.path.normpath(os.path.join(self.kw['output_folder'], short_tdst))
                            if module.find("ofx") == 0:
                                context["classes"] = addons_index[module]
                                self.site.render_template(module_template, tdst, context)
                            else:
                                context["classes"] = core_index[module]
                                self.site.render_template(module_template, tdst, context)
                        
                            content_js[lang] += module_to_js(module, module_intro_content, self.site, lang)
                    else:
                        module_subtitles[module] = None
            
        # close js for docs search and save per language
        for lang in self.kw['translations']:
            content_js[lang] += ']};'
            content_js_file = open("output" + lang_prefix(lang, self.site) + "/tipuesearch_content.js","w")
            content_js_file.write(content_js[lang])
            content_js_file.close()
        
        # render index file
        template_name = "documentation.mako"
        for lang in self.kw['translations']:
            #lang_suffix = self.kw['translations'][lang]
            docs_intro_path = os.path.join(docs_dir, "index.md")   
            if lang != self.site.config['DEFAULT_LANG']: 
                docs_intro_lang_path = utils.get_translation_candidate(self.site.config, docs_intro_path, lang)
                p = pathlib.Path(docs_intro_lang_path)
                if p.exists():
                    docs_intro_path = docs_intro_lang_path 
            docs_intro = open(docs_intro_path).read()
            for key in self.site.GLOBAL_CONTEXT.keys():
                if isinstance(self.site.GLOBAL_CONTEXT[key], str):
                   docs_intro = docs_intro.replace('${' + key + '}', self.site.GLOBAL_CONTEXT[key])
            docs_intro = markdown(docs_intro, md_extensions)
            context = {}
            context["lang"] = lang
            context["title"] = "documentation"
            context["docs_intro"] = docs_intro
            context['core'] = core_index
            context['addons'] = addons_index
            context['module_subtitles'] = module_subtitles
            context["permalink"] = self.kw['translations'][lang] + '/documentation/'
            short_tdst = os.path.join(self.kw['translations'][lang], "documentation", "index.html")
            tdst = os.path.normpath(os.path.join(self.kw['output_folder'], short_tdst))
            self.site.render_template(template_name, tdst, context)
Пример #5
0
def run():
    classes = []
    directory = "_documentation"
    documentation = bf.config.controllers.documentation

    classes = markdown_file.getclass_list()
    classes_simple_name = markdown_file.getclass_list(False)
    addon_classes = markdown_file.list_all_addons()

    module_lookup = dict()
    core_index = dict()
    addons_index = dict()

    # Create an index of which module each class is in for generated links to other classes
    for class_name in classes:
        clazz = markdown_file.getclass(class_name)
        if clazz.istemplated:
            module_lookup[class_name[:-1]] = clazz.module
        else:
            module_lookup[class_name] = clazz.module

    for clazz_name in classes:
        clazz = markdown_file.getclass(clazz_name)
        if clazz.istemplated:
            clazz.name = clazz.name[:-1]

        methods_to_remove = []
        for method in clazz.function_list:
            if method.name[0] == "~" or method.name.find(
                    "OF_DEPRECATED_MSG") != -1:
                methods_to_remove.append(method)
        for method in methods_to_remove:
            clazz.function_list.remove(method)

        clazz.detailed_inline_description = str(
            clazz.detailed_inline_description.encode('ascii', 'ignore'))
        for class_name in classes_simple_name:
            rep = class_name + "[\s]"
            clazz.detailed_inline_description = re.sub(
                rep, "<a href=\"../" + module_lookup[class_name] + "/" +
                class_name + ".html\" class=\"docs_class\" >" + class_name +
                "</a> ", clazz.detailed_inline_description)
            rep = class_name + "[(]"
            clazz.detailed_inline_description = re.sub(
                rep, "<a href=\"../" + module_lookup[class_name] + "/" +
                class_name + ".html\" class=\"docs_class\" >" + class_name +
                "</a>(", clazz.detailed_inline_description)

        clazz.reference = str(clazz.reference.encode('ascii', 'ignore'))
        for class_name in classes_simple_name:
            rep = class_name + "[\s]"
            clazz.reference = re.sub(
                rep, "<a href=\"../" + module_lookup[class_name] + "/" +
                class_name + ".html\" class=\"docs_class\" >" + class_name +
                "</a> ", clazz.reference)
            rep = class_name + "[(]"
            clazz.reference = re.sub(
                rep, "<a href=\"../" + module_lookup[class_name] + "/" +
                class_name + ".html\" class=\"docs_class\" >" + class_name +
                "</a>(", clazz.reference)

        functions_file = markdown_file.getfunctionsfile(clazz.name)
        #print clazz.name
        #print clazz.function_list
        env = {
            "modulename": clazz.name,
            "clazz": clazz,
            "functions": functions_file,
            "classes_list": classes,
            "is_addon": (clazz.name in addon_classes)
        }

        bf.template.materialize_template(
            "documentation_class.mako",
            ('documentation', clazz.module + "/" + clazz.name + ".html"), env)

        if not clazz.module in addon_classes:
            if not clazz.module in core_index.keys():
                core_index[clazz.module] = []
            if functions_file != None:
                for function in functions_file.function_list:
                    clazz.function_list.append(function)
            core_index[clazz.module].append(clazz)
        else:
            if not clazz.module in addons_index.keys():
                addons_index[clazz.module] = []
            if functions_file != None:
                for function in functions_file.function_list:
                    clazz.function_list.append(function)
            addons_index[clazz.module].append(clazz)

    function_files = markdown_file.getfunctionsfiles_list()
    for functionfile_name in function_files:
        if functionfile_name in classes_simple_name:
            continue
        functions_file = markdown_file.getfunctionsfile(functionfile_name)

        # might be needed at some point?
        #        functions_file.reference = str(functions_file.reference)
        #        for func in function_files:
        #            functions_file.reference = str.replace(functions_file.reference, class_name, "<a href=\"../"+clazz.module+"/"+class_name+".html\">"+class_name+"</a>")

        functions_to_remove = []
        for function in functions_file.function_list:
            if function.name.find("OF_DEPRECATED_MSG") != -1:
                functions_to_remove.append(method)
        for function in functions_to_remove:
            functions_file.function_list.remove(method)
        env = {
            "modulename": functions_file.name,
            "clazz": None,
            "functions": functions_file,
            "is_addon": (functions_file.name in addon_classes)
        }
        bf.template.materialize_template(
            "documentation_class.mako",
            ('documentation',
             functions_file.module + "/" + functions_file.name + ".html"), env)

        if not functions_file.module in addon_classes:
            if not functions_file.module in core_index:
                core_index[functions_file.module] = []
            core_index[functions_file.module].append(functions_file)
        else:
            if not functions_file.module in addons_index:
                addons_index[functions_file.module] = []
            addons_index[functions_file.module].append(functions_file)

    # process index file
    bf.template.materialize_template("documentation.mako",
                                     ('documentation', "index.html"), {
                                         'core': core_index,
                                         'addons': addons_index
                                     })

    for root, dirs, files in os.walk(directory):
        for name in files:
            file_split = os.path.splitext(name)
            if file_split[1] == ".jpeg" or file_split[
                    1] == ".jpg" or file_split[1] == ".gif" or file_split[
                        1] == ".png":
                try:
                    os.mkdir(
                        os.path.join('_site', 'documentation',
                                     os.path.basename(root)))
                except:
                    pass
                shutil.copyfile(
                    os.path.join(root, name),
                    os.path.join('_site', 'documentation',
                                 os.path.basename(root), name))
Пример #6
0
import markdown_file

addons = markdown_file.list_all_addons()

for addon in addons:
    print '//----------------------\n\n'
    print "##" + addon + "##\n\n"
    files = markdown_file.list_all_addon_files(addon)
    for f in files:
        print "###" + f + "###\n\n"
        print "__visible: true__\n\n"
        print "__advanced: false__\n\n"
    
Пример #7
0
    def create_docs(self):
        tasks = {}
        classes = []
        directory = "documentation"

        classes = markdown_file.getclass_list()
        classes_simple_name = markdown_file.getclass_list(False)
        addon_classes = markdown_file.list_all_addons()

        module_lookup = dict()
        core_index = dict()
        addons_index = dict()
        module_subtitles = dict()

        docs_dir = os.path.join(self.site.original_cwd, "documentation")
        md_extensions = self.site.config.get("MARKDOWN_EXTENSIONS")
        content_js = {}

        class_template = "documentation_class.mako"
        class_template_dep = self.site.template_system.template_deps(
            class_template)
        module_template = "documentation_module_intro.mako"

        # start js string for docs search
        for lang in self.kw['translations']:
            content_js[lang] = 'var tipuesearch = {"pages": ['

        # Create an index of which module each class is in for generated links to other classes
        for class_name in classes:
            clazz = markdown_file.getclass(class_name)
            if clazz.istemplated:
                module_lookup[class_name[:-1]] = clazz.module
            else:
                module_lookup[class_name] = clazz.module

        # classes docs
        for clazz_name in classes:
            clazz = markdown_file.getclass(clazz_name)
            if clazz.istemplated:
                clazz.name = clazz.name[:-1]

            clazz.detailed_inline_description = relative_urls(
                clazz.detailed_inline_description)
            clazz.detailed_inline_description = markdown(
                clazz.detailed_inline_description, md_extensions)
            clazz.detailed_inline_description = of_classes_to_links(
                clazz.detailed_inline_description, classes_simple_name,
                module_lookup)

            clazz.reference = relative_urls(clazz.reference)
            clazz.reference = markdown(clazz.reference, md_extensions)
            clazz.reference = of_classes_to_links(clazz.reference,
                                                  classes_simple_name,
                                                  module_lookup)

            # methods in class
            for function in clazz.function_list:
                function.description = relative_urls(function.description)
                function.description = markdown(function.description,
                                                md_extensions)
                function.description = of_classes_to_links(
                    function.description, classes_simple_name, module_lookup)

                function.inlined_description = relative_urls(
                    function.inlined_description)
                function.inlined_description = markdown(
                    function.inlined_description, md_extensions)
                function.inlined_description = of_classes_to_links(
                    function.inlined_description, classes_simple_name,
                    module_lookup)
                for lang in self.kw['translations']:
                    content_js[lang] += method_to_js(function, clazz,
                                                     self.site, lang)

            # inheritance
            def gen_link(class_name):
                return "<a href=\"/documentation/" + module_lookup[
                    class_name] + "/" + class_name + "\" class=\"docs_class\" >" + class_name + "</a> " if class_name in module_lookup else ""

            def filter_out_empty(class_name):
                return class_name != ""

            clazz.extends = list(
                filter(filter_out_empty, map(gen_link, clazz.extends)))

            # c functions in the class file
            functions_file = markdown_file.getfunctionsfile(clazz.name)
            for function in functions_file.function_list:
                function.description = relative_urls(function.description)
                function.description = markdown(function.description,
                                                md_extensions)
                function.description = of_classes_to_links(
                    function.description, classes_simple_name, module_lookup)

                function.inlined_description = relative_urls(
                    function.inlined_description)
                function.inlined_description = markdown(
                    function.inlined_description, md_extensions)
                function.inlined_description = of_classes_to_links(
                    function.inlined_description, classes_simple_name,
                    module_lookup)
                for lang in self.kw['translations']:
                    content_js[lang] += function_to_js(function,
                                                       functions_file,
                                                       self.site, lang)

            # render template + js for search
            env = {
                "modulename": clazz.name,
                "clazz": clazz,
                "functions": functions_file,
                "classes_list": classes,
                "is_addon": (clazz.name in addon_classes)
            }
            md_file = "documentation/" + module_lookup[
                class_name] + "/" + class_name + ".markdown"
            for lang in self.kw['translations']:
                env["lang"] = lang
                env["title"] = clazz.name
                env["permalink"] = self.kw['translations'][
                    lang] + '/documentation/' + clazz.module + "/" + clazz.name + "/"
                short_tdst = os.path.join(self.kw['translations'][lang],
                                          'documentation', clazz.module,
                                          clazz.name, "index.html")
                tdst = os.path.normpath(
                    os.path.join(self.kw['output_folder'], short_tdst))
                """yield utils.apply_filters({
                    'basename': self.name,
                    'name': clazz.name,
                    'file_dep': class_template_dep + md_file,
                    'targets': tdst,
                    'actions': [
                        (self.site.render_template, (template_name, tdst, env))
                    ],
                    'clean': True,
                    'uptodate': [utils.config_changed({
                        1: self.kw,
                    })],
                }, self.kw['filters'])"""
                self.site.render_template(class_template, tdst, env)
                content_js[lang] += class_to_js(clazz, self.site, lang)

            # add to index core or addons
            if not clazz.module in addon_classes:
                if not clazz.module in core_index.keys():
                    core_index[clazz.module] = []
                if functions_file != None:
                    for function in functions_file.function_list:
                        clazz.function_list.append(function)
                core_index[clazz.module].append(clazz)
            else:
                if not clazz.module in addons_index.keys():
                    addons_index[clazz.module] = []
                if functions_file != None:
                    for function in functions_file.function_list:
                        clazz.function_list.append(function)
                addons_index[clazz.module].append(clazz)

        # generate c functions docs
        function_files = markdown_file.getfunctionsfiles_list()
        for functionfile_name in function_files:
            if functionfile_name in classes_simple_name:
                continue
            functions_file = markdown_file.getfunctionsfile(functionfile_name)

            # might be needed at some point?
            #        functions_file.reference = str(functions_file.reference)
            #        for func in function_files:
            #            functions_file.reference = str.replace(functions_file.reference, class_name, "<a href=\"../"+clazz.module+"/"+class_name+".html\">"+class_name+"</a>")

            for function in functions_file.function_list:
                function.description = relative_urls(function.description)
                function.description = markdown(function.description,
                                                md_extensions)
                function.description = of_classes_to_links(
                    function.description, classes_simple_name, module_lookup)

                function.inlined_description = relative_urls(
                    function.inlined_description)
                function.inlined_description = markdown(
                    function.inlined_description, md_extensions)
                function.inlined_description = of_classes_to_links(
                    function.inlined_description, classes_simple_name,
                    module_lookup)
                for lang in self.kw['translations']:
                    content_js[lang] += function_to_js(function,
                                                       functions_file,
                                                       self.site, lang)

            # render template + js for search
            env = {
                "modulename": functions_file.name,
                "clazz": None,
                "functions": functions_file,
                "is_addon": (functions_file.name in addon_classes)
            }
            for lang in self.kw['translations']:
                env["lang"] = lang
                env["title"] = clazz.name
                env["permalink"] = self.kw['translations'][
                    lang] + '/documentation/' + functions_file.module + "/" + functions_file.name + "/"
                short_tdst = os.path.join(self.kw['translations'][lang],
                                          'documentation',
                                          functions_file.module,
                                          functions_file.name, "index.html")
                tdst = os.path.normpath(
                    os.path.join(self.kw['output_folder'], short_tdst))
                self.site.render_template(class_template, tdst, env)
                content_js[lang] += functions_file_to_js(
                    functions_file, self.site, lang)

            # add to index core or addons
            if not functions_file.module in addon_classes:
                if not functions_file.module in core_index:
                    core_index[functions_file.module] = []
                core_index[functions_file.module].append(functions_file)
            else:
                if not functions_file.module in addons_index:
                    addons_index[functions_file.module] = []
                addons_index[functions_file.module].append(functions_file)

        # copy images and render intros
        for root, dirs, files in os.walk(directory):
            """ copy images to their folders """
            for name in files:
                file_split = os.path.splitext(name)
                if file_split[1] == ".jpeg" or file_split[
                        1] == ".jpg" or file_split[1] == ".gif" or file_split[
                            1] == ".png":
                    try:
                        os.mkdir(
                            os.path.join('_site', 'documentation',
                                         os.path.basename(root)))
                    except:
                        pass
                    shutil.copyfile(
                        os.path.join(root, name),
                        os.path.join('output', 'documentation',
                                     os.path.basename(root), name))
            """ create module introductions """
            for module in dirs:
                if module != "addons":
                    module_intro = os.path.join(root, module,
                                                "introduction.markdown")
                    if os.path.isfile(module_intro):
                        module_intro_file = open(module_intro)
                        module_intro_content = module_intro_file.read()
                        module_subtitles[
                            module] = module_intro_content.splitlines(
                            )[0].strip('##').strip(' ')
                        module_intro_content = markdown(
                            module_intro_content, md_extensions)
                        for lang in self.kw['translations']:
                            context = {}
                            context["lang"] = lang
                            context["title"] = module
                            context["module"] = module
                            context["intro_content"] = module_intro_content
                            context["permalink"] = self.kw['translations'][
                                lang] + '/documentation/' + module + "/"
                            if lang == self.site.config['DEFAULT_LANG']:
                                short_tdst = os.path.join(
                                    'documentation', module, "index.html")
                            else:
                                short_tdst = os.path.join(
                                    self.kw['translations'][lang],
                                    'documentation', module, "index.html")
                            tdst = os.path.normpath(
                                os.path.join(self.kw['output_folder'],
                                             short_tdst))
                            if module.find("ofx") == 0:
                                context["classes"] = addons_index[module]
                                self.site.render_template(
                                    module_template, tdst, context)
                            else:
                                context["classes"] = core_index[module]
                                self.site.render_template(
                                    module_template, tdst, context)

                            content_js[lang] += module_to_js(
                                module, module_intro_content, self.site, lang)
                    else:
                        module_subtitles[module] = None

        # close js for docs search and save per language
        for lang in self.kw['translations']:
            content_js[lang] += ']};'
            content_js_file = open(
                "output" + lang_prefix(lang, self.site) +
                "/tipuesearch_content.js", "w")
            content_js_file.write(content_js[lang])
            content_js_file.close()

        # render index file
        template_name = "documentation.mako"
        for lang in self.kw['translations']:
            #lang_suffix = self.kw['translations'][lang]
            docs_intro_path = os.path.join(docs_dir, "index.md")
            if lang != self.site.config['DEFAULT_LANG']:
                docs_intro_lang_path = utils.get_translation_candidate(
                    self.site.config, docs_intro_path, lang)
                p = pathlib.Path(docs_intro_lang_path)
                if p.exists():
                    docs_intro_path = docs_intro_lang_path
            docs_intro = open(docs_intro_path).read()
            for key in self.site.GLOBAL_CONTEXT.keys():
                if isinstance(self.site.GLOBAL_CONTEXT[key], str):
                    docs_intro = docs_intro.replace(
                        '${' + key + '}', self.site.GLOBAL_CONTEXT[key])
            docs_intro = markdown(docs_intro, md_extensions)
            context = {}
            context["lang"] = lang
            context["title"] = "documentation"
            context["docs_intro"] = docs_intro
            context['core'] = core_index
            context['addons'] = addons_index
            context['module_subtitles'] = module_subtitles
            context["permalink"] = self.kw['translations'][
                lang] + '/documentation/'
            short_tdst = os.path.join(self.kw['translations'][lang],
                                      "documentation", "index.html")
            tdst = os.path.normpath(
                os.path.join(self.kw['output_folder'], short_tdst))
            self.site.render_template(template_name, tdst, context)
Пример #8
0
def run():
    classes = []
    directory = "_documentation"
    documentation = bf.config.controllers.documentation

    classes = markdown_file.getclass_list()
    classes_simple_name = markdown_file.getclass_list(False)
    addon_classes = markdown_file.list_all_addons()

    module_lookup = dict()
    core_index = dict()
    addons_index = dict()
    module_subtitles = dict()

    # Create an index of which module each class is in for generated links to other classes
    for class_name in classes:
        clazz = markdown_file.getclass(class_name)
        if clazz.istemplated:
            module_lookup[class_name[:-1]] = clazz.module
        else:
            module_lookup[class_name] = clazz.module

    for clazz_name in classes:
        clazz = markdown_file.getclass(clazz_name)
        if clazz.istemplated:
            clazz.name = clazz.name[:-1]

        clazz.detailed_inline_description = str(
            clazz.detailed_inline_description.encode('ascii', 'ignore'))
        for class_name in classes_simple_name:
            rep = class_name + "[\s]"
            clazz.detailed_inline_description = re.sub(
                rep, "<a href=\"../" + module_lookup[class_name] + "/" +
                class_name + ".html\" class=\"docs_class\" >" + class_name +
                "</a> ", clazz.detailed_inline_description)
            rep = class_name + "[(]"
            clazz.detailed_inline_description = re.sub(
                rep, "<a href=\"../" + module_lookup[class_name] + "/" +
                class_name + ".html\" class=\"docs_class\" >" + class_name +
                "</a>(", clazz.detailed_inline_description)

        clazz.reference = str(clazz.reference.encode('ascii', 'ignore'))
        for class_name in classes_simple_name:
            rep = class_name + "[\s]"
            clazz.reference = re.sub(
                rep, "<a href=\"../" + module_lookup[class_name] + "/" +
                class_name + ".html\" class=\"docs_class\" >" + class_name +
                "</a> ", clazz.reference)
            rep = class_name + "[(]"
            clazz.reference = re.sub(
                rep, "<a href=\"../" + module_lookup[class_name] + "/" +
                class_name + ".html\" class=\"docs_class\" >" + class_name +
                "</a>(", clazz.reference)

        def gen_link(class_name):
            return "<a href=\"../" + module_lookup[
                class_name] + "/" + class_name + ".html\" class=\"docs_class\" >" + class_name + "</a> " if class_name in module_lookup else ""

        def filter_out_empty(class_name):
            return class_name != ""

        clazz.extends = list(
            filter(filter_out_empty, map(gen_link, clazz.extends)))

        functions_file = markdown_file.getfunctionsfile(clazz.name)
        #print clazz.name
        #print clazz.function_list
        env = {
            "modulename": clazz.name,
            "clazz": clazz,
            "functions": functions_file,
            "classes_list": classes,
            "is_addon": (clazz.name in addon_classes)
        }

        bf.template.materialize_template(
            "documentation_class.mako",
            ('documentation', clazz.module + "/" + clazz.name + ".html"), env)

        if not clazz.module in addon_classes:
            if not clazz.module in core_index.keys():
                core_index[clazz.module] = []
            if functions_file != None:
                for function in functions_file.function_list:
                    clazz.function_list.append(function)
            core_index[clazz.module].append(clazz)
        else:
            if not clazz.module in addons_index.keys():
                addons_index[clazz.module] = []
            if functions_file != None:
                for function in functions_file.function_list:
                    clazz.function_list.append(function)
            addons_index[clazz.module].append(clazz)

    function_files = markdown_file.getfunctionsfiles_list()
    for functionfile_name in function_files:
        if functionfile_name in classes_simple_name:
            continue
        functions_file = markdown_file.getfunctionsfile(functionfile_name)

        # might be needed at some point?
        #        functions_file.reference = str(functions_file.reference)
        #        for func in function_files:
        #            functions_file.reference = str.replace(functions_file.reference, class_name, "<a href=\"../"+clazz.module+"/"+class_name+".html\">"+class_name+"</a>")
        env = {
            "modulename": functions_file.name,
            "clazz": None,
            "functions": functions_file,
            "is_addon": (functions_file.name in addon_classes)
        }
        bf.template.materialize_template(
            "documentation_class.mako",
            ('documentation',
             functions_file.module + "/" + functions_file.name + ".html"), env)

        if not functions_file.module in addon_classes:
            if not functions_file.module in core_index:
                core_index[functions_file.module] = []
            core_index[functions_file.module].append(functions_file)
        else:
            if not functions_file.module in addons_index:
                addons_index[functions_file.module] = []
            addons_index[functions_file.module].append(functions_file)

    for root, dirs, files in os.walk(directory):
        """ copy images to their folders """
        for name in files:
            file_split = os.path.splitext(name)
            if file_split[1] == ".jpeg" or file_split[
                    1] == ".jpg" or file_split[1] == ".gif" or file_split[
                        1] == ".png":
                try:
                    os.mkdir(
                        os.path.join('_site', 'documentation',
                                     os.path.basename(root)))
                except:
                    pass
                shutil.copyfile(
                    os.path.join(root, name),
                    os.path.join('_site', 'documentation',
                                 os.path.basename(root), name))
        """ create module introductions """
        for module in dirs:
            if module != "addons":
                module_intro = os.path.join(root, module,
                                            "introduction.markdown")
                if os.path.isfile(module_intro):
                    module_intro_file = open(module_intro)
                    module_intro_content = module_intro_file.read()
                    module_subtitles[module] = module_intro_content.splitlines(
                    )[0].strip('##').strip(' ')
                    if module.find("ofx") == 0:
                        bf.template.materialize_template(
                            "documentation_module_intro.mako", (os.path.join(
                                'documentation', module), "introduction.html"),
                            {
                                "module": module,
                                "content": module_intro_content,
                                "classes": addons_index[module]
                            })
                    else:
                        bf.template.materialize_template(
                            "documentation_module_intro.mako", (os.path.join(
                                'documentation', module), "introduction.html"),
                            {
                                "module": module,
                                "content": module_intro_content,
                                "classes": core_index[module]
                            })
                else:
                    module_subtitles[module] = None
                    print "couldn't find " + module_intro

    # process index file
    bf.template.materialize_template(
        "documentation.mako", ('documentation', "index.html"), {
            'core': core_index,
            'addons': addons_index,
            'module_subtitles': module_subtitles
        })
Пример #9
0
def run():
    classes = []
    directory = "_documentation"
    documentation = bf.config.controllers.documentation
        
    classes = markdown_file.getclass_list()
    classes_simple_name = markdown_file.getclass_list(False)
    addon_classes = markdown_file.list_all_addons()
    
    module_lookup = dict()
    core_index = dict()
    addons_index = dict()
    
    # Create an index of which module each class is in for generated links to other classes
    for class_name in classes:
        clazz = markdown_file.getclass(class_name)
        if clazz.istemplated:
            module_lookup[class_name[:-1]] = clazz.module    
        else:
            module_lookup[class_name] = clazz.module
        
    for clazz_name in classes:
        clazz = markdown_file.getclass(clazz_name)
        if clazz.istemplated:
            clazz.name = clazz.name[:-1]

        methods_to_remove = []
        for method in clazz.function_list:
            if method.name[0]=="~" or method.name.find("OF_DEPRECATED_MSG")!=-1:
                methods_to_remove.append(method)
        for method in methods_to_remove:
            clazz.function_list.remove(method)

        clazz.detailed_inline_description = str(clazz.detailed_inline_description.encode('ascii', 'ignore'))
        for class_name in classes_simple_name:
            rep = class_name + "[\s]"
            clazz.detailed_inline_description = re.sub(rep, "<a href=\"../"+module_lookup[class_name]+"/"+class_name+".html\" class=\"docs_class\" >"+class_name+"</a> ", clazz.detailed_inline_description)
            rep = class_name + "[(]"
            clazz.detailed_inline_description = re.sub(rep, "<a href=\"../"+module_lookup[class_name]+"/"+class_name+".html\" class=\"docs_class\" >"+class_name+"</a>(", clazz.detailed_inline_description)

        clazz.reference = str(clazz.reference.encode('ascii', 'ignore'))
        for class_name in classes_simple_name:
            rep = class_name + "[\s]"
            clazz.reference = re.sub(rep, "<a href=\"../"+module_lookup[class_name]+"/"+class_name+".html\" class=\"docs_class\" >"+class_name+"</a> ", clazz.reference)
            rep = class_name + "[(]"
            clazz.reference = re.sub(rep, "<a href=\"../"+module_lookup[class_name]+"/"+class_name+".html\" class=\"docs_class\" >"+class_name+"</a>(", clazz.reference)

        functions_file = markdown_file.getfunctionsfile(clazz.name)
        #print clazz.name
        #print clazz.function_list 
        env = {
            "modulename": clazz.name,
            "clazz": clazz,
            "functions": functions_file,
            "classes_list": classes,
            "is_addon": (clazz.name in addon_classes)
        }
        
        bf.template.materialize_template("documentation_class.mako", ('documentation',clazz.module+"/"+clazz.name+".html"), env )
        
        if not clazz.module in addon_classes:
            if not clazz.module in core_index.keys():
                core_index[clazz.module] = []
            if functions_file!=None:
                for function in functions_file.function_list:
                    clazz.function_list.append(function)
            core_index[clazz.module].append(clazz)
        else:
            if not clazz.module in addons_index.keys():
                addons_index[clazz.module] = []
            if functions_file!=None:
                for function in functions_file.function_list:
                    clazz.function_list.append(function)
            addons_index[clazz.module].append(clazz)
        
    
    function_files = markdown_file.getfunctionsfiles_list()
    for functionfile_name in function_files:
        if functionfile_name in classes_simple_name:
            continue
        functions_file = markdown_file.getfunctionsfile(functionfile_name)

# might be needed at some point?
#        functions_file.reference = str(functions_file.reference)
#        for func in function_files:
#            functions_file.reference = str.replace(functions_file.reference, class_name, "<a href=\"../"+clazz.module+"/"+class_name+".html\">"+class_name+"</a>")


        functions_to_remove = []
        for function in functions_file.function_list:
            if function.name.find("OF_DEPRECATED_MSG")!=-1:
                functions_to_remove.append(method)
        for function in functions_to_remove:
            functions_file.function_list.remove(method)
        env = {
            "modulename": functions_file.name,
            "clazz": None,
            "functions": functions_file,
            "is_addon": (functions_file.name in addon_classes) 
        }
        bf.template.materialize_template("documentation_class.mako", ('documentation',functions_file.module+"/"+functions_file.name+".html"), env )
        
        if not functions_file.module in addon_classes:
            if not functions_file.module in core_index:
                core_index[functions_file.module] = []
            core_index[functions_file.module].append(functions_file)
        else:
            if not functions_file.module in addons_index:
                addons_index[functions_file.module] = []
            addons_index[functions_file.module].append(functions_file)
        
        

    # process index file        
    bf.template.materialize_template("documentation.mako", ('documentation',"index.html"), {'core':core_index,'addons':addons_index} )
    
    for root, dirs, files in os.walk(directory):
        for name in files:
            file_split = os.path.splitext(name)
            if file_split[1]==".jpeg" or file_split[1]==".jpg" or file_split[1]==".gif" or file_split[1]==".png":
                try:
                    os.mkdir(os.path.join('_site','documentation',os.path.basename(root)))
                except:
                    pass
                shutil.copyfile(os.path.join(root,name), os.path.join('_site','documentation',os.path.basename(root),name))
Пример #10
0
def run():
    classes = []
    directory = "_documentation"
    documentation = bf.config.controllers.documentation
    
    module_lookup = dict()
        
    classes = markdown_file.getclass_list()
    addon_classes = markdown_file.list_all_addons()
      
    for class_name in classes:
        module_lookup[class_name] = markdown_file.getclass(class_name,True).module
    for clazz_name in classes:
        clazz = markdown_file.getclass(clazz_name,True)

        methods_to_remove = []
        for method in clazz.function_list:
            if method.name[0]=="~" or method.name.find("OF_DEPRECATED_MSG")!=-1:
                methods_to_remove.append(method)
        for method in methods_to_remove:
            clazz.function_list.remove(method)

        clazz.detailed_inline_description = str(clazz.detailed_inline_description.encode('ascii', 'ignore'))
        for class_name in classes:
                rep = class_name + "[\s]"
                clazz.detailed_inline_description = re.sub(rep, "<a href=\"../"+module_lookup[class_name]+"/"+class_name+".html\" class=\"docs_class\" >"+class_name+"</a> ", clazz.detailed_inline_description)
                rep = class_name + "[(]"
                clazz.detailed_inline_description = re.sub(rep, "<a href=\"../"+module_lookup[class_name]+"/"+class_name+".html\" class=\"docs_class\" >"+class_name+"</a>(", clazz.detailed_inline_description)
        
        clazz.reference = str(clazz.reference.encode('ascii', 'ignore'))
        for class_name in classes:
                rep = class_name + "[\s]"
                clazz.reference = re.sub(rep, "<a href=\"../"+module_lookup[class_name]+"/"+class_name+".html\" class=\"docs_class\" >"+class_name+"</a> ", clazz.reference)
                rep = class_name + "[(]"
                clazz.reference = re.sub(rep, "<a href=\"../"+module_lookup[class_name]+"/"+class_name+".html\" class=\"docs_class\" >"+class_name+"</a>(", clazz.reference)
                #print "Going through " + clazz.module + ":" + clazz.name +", replacing " + module_lookup[class_name] + ":" + class_name

        functions_file = markdown_file.getfunctionsfile(clazz_name)
        #print clazz.name
        #print clazz.function_list 
        env = {
            "modulename": clazz.name,
            "clazz": clazz,
            "functions": functions_file,
            "classes_list": classes,
            "is_addon": (clazz.name in addon_classes)
        }
        bf.template.materialize_template("documentation_class.mako", ('documentation',clazz.module+"/"+clazz.name+".html"), env )
    
    function_files = markdown_file.getfunctionsfiles_list()
    for functionfile_name in function_files:
        if functionfile_name in classes:
            continue
        functions_file = markdown_file.getfunctionsfile(functionfile_name)

# might be needed at some point?
#        functions_file.reference = str(functions_file.reference)
#        for func in function_files:
#            functions_file.reference = str.replace(functions_file.reference, class_name, "<a href=\"../"+clazz.module+"/"+class_name+".html\">"+class_name+"</a>")


        functions_to_remove = []
        for function in functions_file.function_list:
            if function.name.find("OF_DEPRECATED_MSG")!=-1:
                functions_to_remove.append(method)
        for function in functions_to_remove:
            functions_file.function_list.remove(method)
        env = {
            "modulename": functions_file.name,
            "clazz": None,
            "functions": functions_file
        }
        bf.template.materialize_template("documentation_class.mako", ('documentation',functions_file.module+"/"+functions_file.name+".html"), env )
        

    # process index file
    indexhtml_file = open("_documentation/" + "index.markdown",'r')
    indexhtml = indexhtml_file.read()
    columns = []
    columns_src = indexhtml.split('___column___')
    for column in columns_src:    
        blocks_src = column.split('//----------------------')
        blocks = []
        for block in blocks_src:
            b = Block(block)
            if b.name is not None and b.name != "":
                blocks.append(b)
        blocks = sorted(blocks, key=lambda block: block.name)
        columns.append(blocks)
    
    
    indexhtml_file = open("_documentation/" + "indexAddons.markdown",'r')
    indexhtml = indexhtml_file.read()
    addons_columns = []
    columns_src = indexhtml.split('___column___')
    for column in columns_src:    
        blocks_src = column.split('//----------------------')
        blocks = []
        for block in blocks_src:
            b = Block(block)
            if b.name is not None and b.name != "":
                blocks.append(b)
        blocks = sorted(blocks, key=lambda block: block.name)
        addons_columns.append(blocks)
        
    bf.template.materialize_template("documentation.mako", ('documentation',"index.html"), {'columns':columns,'addons_columns':addons_columns} )
    
    for root, dirs, files in os.walk(directory):
        for name in files:
            file_split = os.path.splitext(name)
            if file_split[1]==".jpeg" or file_split[1]==".jpg" or file_split[1]==".gif" or file_split[1]==".png":
                try:
                    os.mkdir(os.path.join('_site','documentation',os.path.basename(root)))
                except:
                    pass
                shutil.copyfile(os.path.join(root,name), os.path.join('_site','documentation',os.path.basename(root),name))