Skip to main content

Xtyle (Toolkit)

Project description

Xtyle

Python (JSX-Toolkit) Documentation

Introduction

Welcome to the Xtyle! This tool allows you to work with JSX components, compile them, and save them as static files for use with other frameworks like Flask. It is powered by py-mini-racer, css-html-js-minify, and libsass.

Getting Started

To get started with the JSX Python Tool, follow these steps:

  1. Initialization: Initialize the JSX engine using JSX.init(BASE_DIR) where BASE_DIR is the base directory for your project.

  2. Loading Components: Load a JSX component folder using JSX.component(component_name). This will allow you to work with the specified component.

  3. Compilation and Saving: Compile the loaded component, and save the compiled JavaScript and CSS files using JSX.save().

  4. API: Use the API to create or delete components using JSX.api(action, component_name). Available actions are "create" and "delete".

  5. Build Configuration: Use JSX.build() to build your components. This can be useful for printing or further processing.

  6. Config File: To use the saved static files with other tools like Flask, you can load the configuration file using JSX.get_config().

Examples

Here's an example of how to use the JSX Python Tool:

from pathlib import Path
from xtyle import JSX

# Root Path
BASE_DIR = Path(__file__).parent

# Initialize the JSX engine
JSX.init(BASE_DIR)

# Load and work with a component
JSX.component("hello-world")

# Create and delete components using the API
JSX.api("create", "button")
JSX.api("delete", "button")

# Save compiled files
JSX.save()

Flask Example

Python

from flask import Flask, render_template
from xtyle import JSX

# Initialize the JSX engine
BASE_DIR = Path(__file__).parent
JSX.init(BASE_DIR)

# Initialize Flask App
app = Flask(__name__)
gui = JSX.get_config() # JSX Configuration

def dev_component(*components):
    for name in components:
        JSX.component(name)
    return ""

# Routes
@app.route("/")
def index():
    return render_template(
        "index.html",
        jsx=dev_component,
        jsx_code=JSX.dev,
        static_url_js=gui.js,
        static_url_css=gui.css,
    )

HTML

<!DOCTYPE html>
<html>
  <head>
    <title>My Flask App</title>

    <!-- Xtyle (JS) -->
    <script
      src="https://unpkg.com/xtyle@latest"
      type="text/javascript"
    ></script>

    <!-- Components -->
    {{ jsx("demo", "hello-world") }}

    <!-- JSX Code -->
    {{ jsx_code() | safe }}
  </head>

  <body>
    <script type="text/javascript">
      /* @Register */
      xtyle.use({
        elements: GUI,
      });

      /* @Router */
      const router = {
        history: false,
        baseURL: null,
      };

      /* @Render */
      xtyle.init(GUI.demo, document.body, router);
    </script>
  </body>
</html>

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

xtyle-0.1.0.tar.gz (795.8 kB view hashes)

Uploaded Source

Built Distribution

xtyle-0.1.0-py3-none-any.whl (798.0 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