Skip to main content

webez

A versatile tool to convert HTML to Twig and CSS to SCSS


Overview

webez simplifies the conversion of HTML content to Twig templates and CSS stylesheets to SCSS formats. By leveraging this tool, developers can accelerate their workflow when working with modern templating systems and SCSS frameworks.


Features

  • HTML to Twig Conversion: Quickly convert HTML files into Twig template format with appropriate variable mappings.
  • CSS to SCSS Conversion: Replace CSS color values with predefined SCSS variables to streamline your styling workflow.

Installation

pip install webez

Usage

webez provides a command-line interface for converting files. Below are the available commands and their usage.

HTML to Twig

Convert an HTML file to a Twig file:

python <script_name>.py html2twig <html_file> <output_file>

Example:

python <script_name>.py html2twig input.html output.twig

CSS to SCSS

Convert a CSS file to SCSS format using variable mappings from an SCSS variables file:

python <script_name>.py css2scss <css_file> <variables_file> <output_file>

Example:

python <script_name>.py css2scss styles.css variables.scss output.scss

Example Code

Convert HTML to Twig using Python

# Import required modules
from webez.html_converter import convert_html_to_twig
from IPython.display import HTML, display

# Sample HTML content
sample_html = """
<!DOCTYPE html>
<html>
<head>
    <title>Test Page</title>
</head>
<body>
    <h1>Welcome</h1>
    <div class="container">
        <p>This is a test paragraph</p>
        <ul>
            <li>Item 1</li>
            <li>Item 2</li>
        </ul>
    </div>
</body>
</html>
"""

# Convert HTML to Twig
twig_output = convert_html_to_twig(sample_html)

# Display original HTML
print("Original HTML:")
print("-" * 50)
display(HTML(sample_html))

# Display converted Twig
print("\nConverted Twig:")
print("-" * 50)
print(twig_output)

Code Explanation

webez consists of two main converters:

HTML Converter

The html_converter.py module leverages BeautifulSoup to parse and modify HTML content into Twig templates. This includes converting text and attributes into Twig variable placeholders.

CSS Converter

The css_converter.py module reads an SCSS variable file, creates a mapping of color values to variables, and replaces corresponding CSS values with SCSS variables.


Example Input and Output

HTML to Twig

Input HTML:

<div class="example">Welcome</div>

Output Twig:

<!-- `{{ div_content }}`: Content for <div> -->
<div class="{{ class_div }}">{{ div_content }}</div>

CSS to SCSS

Input CSS:

body {
  background-color: #ffffff;
  color: #333333;
}

Variable File (variables.scss):

$white: #ffffff;
$gray-dark: #333333;

Output SCSS:

body {
  background-color: $white;
  color: $gray-dark;
}

License

This project is licensed under the MIT License.


Author


Contributing

Contributions, issues, and feature requests are welcome! Feel free to fork the repository and submit pull requests on GitHub.


Additional Information

Package Metadata

Metadata

Release files for webez 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for webez 0.1.0
File Size Uploaded Provenance
webez-0.1.0.tar.gz 5.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for webez 0.1.0
File Interpreter ABI Platform
webez-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.0 kB

Release files / webez-0.1.0.tar.gz

Download URL webez-0.1.0.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c1746a73d1fd4efd3c233420a90d3366978a5b535600cac53da08ecea96c440d
BLAKE2b-256 checksum
How to use checksums
06cab623f966b4b4e022fe5595b6bf13072d57d3308e6ab05fb0ae73059c4056
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.11.5

Release files / webez-0.1.0-py3-none-any.whl

Download URL webez-0.1.0-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
75ba4cfd13e5f37c07c7c9e621da902d78fb983c83f717f32d4cf63789552db0
BLAKE2b-256 checksum
How to use checksums
80103ef327fb91b07db7c0df19717e7e7b2c0829cfe0702482c9f06681b2ce00
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.11.5

Security for webez 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page