Skip to main content

Code Generation library written by python. can use bash script, can be extend python code, can use mustache files or can use any string content for any code generation structure.

Project description

code-gen-library

code-gen-library for Python

alt text

code-gen-lib pip install

pip install codegenlib

code-gen-lib import package

from codegenlib.enums import MUSTACHE
from codegenlib.templateStreaming import TemplateStreaming
from codegenlib.templateFile import TemplateFile
from codegenlib.templateModule import TemplateModule

using example

code_gen_lib_example.py

code-gen-lib generation from json file

config_json_example.py

## with folder
 config_json_with_template_folder_example.py

code-gen-lib generation programming example

You should add your module containing your folder pathname to the 'modules' path. You can add mustache files and template folder/files in your module path

from codegenlib.enums import MUSTACHE
from codegenlib.templateStreaming import TemplateStreaming
from codegenlib.templateFile import TemplateFile
from codegenlib.templateModule import TemplateModule

fileName = "test.swift"

testManagerClassTF = TemplateFile(
    name="manager_class_mustache",
    dict={"service_name": "OneframeMobile", "request_func": MUSTACHE.PARENT},
    output_file="Manager.swift"
)
testGetRequestFuncTF = TemplateFile(
    name="request_get_func_mustache",
    dict={"result_model_name": "String","function_name": "getTest", "query_path" : '"api/getTest?name=query"', "func_param" : "query:String, "},
    output_file=None,
    is_child_template=True,
    parent_mustache="request_func"
)
testPostRequestFuncTF = TemplateFile(
    name="request_post_func_mustache",
    dict={"result_model_name": "UserModel", "function_name": "login", "query_path" : '"api/login"', "func_param" : ""},
    output_file=None,
    is_child_template=True,
    parent_mustache="request_func"
)
testManagerClassTF.childTemplateFiles.append(testGetRequestFuncTF)
testManagerClassTF.childTemplateFiles.append(testPostRequestFuncTF)

testModule = TemplateModule(
    name="networking-swagger-swift",
    templates_files=[testManagerClassTF]
)

tStreaming = TemplateStreaming(
    templateModule=testModule
)
tStreaming.execute()

code-gen-lib generation programming example with your json file

this is written module code by json

{
    "module" : {
        "name" : "oneframe-ios-api-manager",
        "templateFolders" : [
            {
                "source" : "modules/oneframe-ios-api-manager/models",
                "outputPath" : "models",
                "isOnline" : false
            }
        ],
        "templateFiles": [
            {
                "name": "manager_class_mustache",
                "outputFile": "CanikServiceManager.swift",
                "isChildTemplate": false
            },
             {
                "name": "learning_class_mustache",
                "outputFile": "OneFrameLearning.swift",
                "isChildTemplate": false
            }
        ]
    }
}
import os
import sys

from codegenlib.parser import Parser
# Own modules
from codegenlib.templateStreaming import TemplateStreaming

pathname = os.path.dirname(sys.argv[0])
# current path
json_file_name = "sample_config_with_template_folder.json"
json_file_path = pathname + "/" + json_file_name

sampleJsonModule = Parser.jsonToTemplateModule(json_file=json_file_path)
sampleJsonModule.outputDirectory = "oneframe-api-ios"
sampleJsonModule.isAppendOutputPath = True

print(sampleJsonModule.getOutputDirectoryPath())

tStreaming = TemplateStreaming(
    template_module=sampleJsonModule,
    enable_log=False,
)
tStreaming.execute()

Can be Contribution, join us! alt text

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

codegenlib-0.8.0.tar.gz (14.8 kB view hashes)

Uploaded Source

Built Distribution

codegenlib-0.8.0-py3-none-any.whl (17.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page