BrainStormYourWayIn / sierra

Licence: Apache-2.0 license
A Python library to write HTML and CSS in pure Python in a simple yet elegant manner using the DOM API. Take advantage of all of Python's powerful functionalities with Sierra

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to sierra

cmd
Command line tools for Revel.
Stars: ✭ 63 (-24.1%)
Mutual labels:  web-application
blog-nojs-fingerprint-demo
A demo for the no-JavaScript fingerprinting article
Stars: ✭ 443 (+433.73%)
Mutual labels:  web-application
card matching game by ercan
A card-matching game made with Flutter.
Stars: ✭ 16 (-80.72%)
Mutual labels:  web-application
web-config
A Rollup configuration to build modern web applications with sweet features as for example SCSS imports, Service Worker generation with Workbox, Karma testing, live reloading, coping resources, chunking, treeshaking, Typescript, license extraction, filesize visualizer, JSON import, budgets, build progress, minifying and compression with brotli a…
Stars: ✭ 17 (-79.52%)
Mutual labels:  web-application
pali
Pāḷi Tipiṭaka and Pāḷi Dictionaries
Stars: ✭ 20 (-75.9%)
Mutual labels:  web-application
stakes.social
🥨 Stakes.social
Stars: ✭ 67 (-19.28%)
Mutual labels:  web-application
hum2song
Hum2Song: Multi-track Polyphonic Music Generation from Voice Melody Transcription with Neural Networks
Stars: ✭ 61 (-26.51%)
Mutual labels:  web-application
Tech-Writing-Linktree
✨ tech writer portfolio in the style of linktree ✨
Stars: ✭ 26 (-68.67%)
Mutual labels:  html-css
SensorsAndAi
SensorAndAi is an android application which will give you the complete information about all the sensors and some basic information about artificial intelligence.This application will tell you about the use and implementation of the sensor and artificial intelligence.This app will show you how sensor and artificial intelligence is used in any an…
Stars: ✭ 29 (-65.06%)
Mutual labels:  web-application
Vidhub
Video sharing website (YouTube clone) with PHP
Stars: ✭ 34 (-59.04%)
Mutual labels:  web-application
hydralit
A library to create multi-page Streamlit applications with ease.
Stars: ✭ 93 (+12.05%)
Mutual labels:  web-application
payload
A javascript single page application (SPA) driver for REST API payload management.
Stars: ✭ 16 (-80.72%)
Mutual labels:  web-application
writefreely
A clean, Markdown-based publishing platform made for writers. Write together and build a community.
Stars: ✭ 2,866 (+3353.01%)
Mutual labels:  web-application
FlexCanvasJS
RIA Web Application Framework for HTML5 Canvas inspired by Adobe Flex / Flash. Style-able, skin-able, customize-able Javascript UI component set, from shapes to color pickers to data grids. Relative and dynamic layouts, automatic redraw regions, composite effects, and much more. Great for everything 2D, complex web forms to games.
Stars: ✭ 18 (-78.31%)
Mutual labels:  web-application
atrodam
AtroDAM is an open-source digital asset management system (DAM) of a new generation.
Stars: ✭ 45 (-45.78%)
Mutual labels:  web-application
pojde
Develop from any device with a browser.
Stars: ✭ 60 (-27.71%)
Mutual labels:  web-application
sqstorage
A easy to use and quick way to organize your inventory, storages and storage areas
Stars: ✭ 18 (-78.31%)
Mutual labels:  web-application
angular-youtube-player
Simple youtube player created with angular and typescript. See demo.
Stars: ✭ 35 (-57.83%)
Mutual labels:  web-application
ApiLogicServer
Instantly create customizable database web app projects, providing API, Admin UI, and unique declarative business logic.
Stars: ✭ 83 (+0%)
Mutual labels:  web-application
cas-bootadmin-overlay
CAS Spring Boot Admin Server Overlay Template
Stars: ✭ 20 (-75.9%)
Mutual labels:  web-application

sierra

Sierra

GitHub

Downloads

Sierra is a Python library to write HTML and CSS in pure Python using the DOM API in a simple yet elegant manner. Take advantage of Python's powerful functionalities with ease. Loops, variables, functions, libraries - you name it, you have it.

Here are a few advantages of using Sierra over other Python libraries that use the DOM API:

  • Out-of-the-box support for all CSS styling attributes for all tags
  • Display a table by simply putting in a CSV file
  • Create your own tag functions with absolute ease using @tag and @CmTag. You can decide their behavior and use them within content-managers too
  • Improvement in the arrangement look of the code and intelligent handling of tags with
    autoPrettify() - Powered by bs4 and a feature like no other

autoPrettify()

See the power of autoPrettify()

You may also use this as a templating engine, although jinja and Django's templating engine is strongly recommended over this


Documentation


Installation

pip install sierra

Upgrade

pip install --upgrade sierra

Starting off is pretty simple and straightforward:

from sierra import *
    
title('Hello World!')

The title() function at the start is mandatory, since it commences the HTML and the CSS file, which is created in the working directory upon execution on the code.

You can create custom tag functions with @tag and @CmTag with just three lines of code. Say you want to create a function for <meta>:

@tag
def meta(**kwargs):
    pass
        
# Using them
    
meta(name="description", content="This is some description")
meta(name="viewport", content="width=device-width", initial_scale=1.0)

Underscores are used for hyphens (same applies to CSS) and Python-conficting arguments are prefixed with a double underscore.

Using argument text inside of a function defined in @tag will create a tag that opens, enters text, and closes. Something like this:

@tag
def script(**kwargs):
    pass
script(__async="", src="some_src", text="some_text")

Is the equivalent of:

<script async="" src="some_src">some_text</script>

Want to add some JS? Simple enough. Just create a function for the <script> tag with a context manager behavior using @CmTag and you're golden.

@CmTag
def script(**kwargs):
    pass

# Here I'll be replicating the script needed to add Google Analytics to a webpage

with script(__aync="", src="https://www.googletagmanager.com/gtag/js?id=UA—XXXXXXXX-X"):
    pass
    
with script():

    writeWA('''
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'UA—XXXXXXXX-X');
  ''')

This is the equivalent of:

<script async src="https://www.googletagmanager.com/gtag/js?id=UA—XXXXXXXX-X"></script>

<script>
    
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'UA—XXXXXXXX-X');
    
</script>

writeWA() writes text entered into it into the HTML file as it is.

You can add fonts using addFont()

addFont("https://fonts.googleapis.com/css2?family=Roboto&display=swap")

Once things at the <head> of the HTML are settled (CSS is automatically linked), begin the body of the HTML with

openBody()
# You can add any number of styling arguments to the body within openBody()
openBody(background_color='yellowgreen', opacity='0.9')

You can create div and section tags this way:

with div(__class="some_class") as d:
    p('This is a paragraph!')
    d.css(background_color="#5886d1")

Let's break this down bit-by-bit:
First, we start a div with a context manager behavior and give it an attribute __class, which is essentially the tag attribute class (remember Python-conflicting arguments are prefixed by a double underscore).

p() is a function, as the name suggests, to add a <p> tag. You can give the tag attributes with **kwargs, if you like.
p('Hello World!', __class='p_class') is the same as <p class="p_class">Hello World!</p>

After the paragraph, there's a d.css(). This adds CSS to the class mentioned within div(). If a class is mentioned, CSS is added to that class as the first priority. If an id is mentioned, CSS is added to that id as a second priority. If none of both are mentioned, CSS is just added to div.

The behavior of div shown above also applies to section.

You can open a new tag with Tag()

with Tag('some_tag', id='some_id') as t:
    p('A paragraph in <some_tag>')
    t.css(color='blue')

Although here, .css() behaves differently. It is independent of tag attributes, meaning CSS is added directly to the tag mentioned, which is some_tag

To add CSS to a specific attribute in the tag, use writeCSS()

writeCSS(tag_name, **kwargs)

writeCSS("#some_id", color='blue')

This adds CSS to the some_id.

You can add a table to the HTML page by inputting in a CSV file this way:

with Table() as t:
    t.get_table("path/to/file.csv")   # Add attributes with **kwargs here
    t.css(border="1px solid black")   # Use writeCSS to add CSS to a specific attribute

There are MANY more functionalities to Sierra that you can see from the documentation

At the end of all development with Sierra, use

autoPrettify()

It takes in no arguments, but provides SO much to the code.

Have a look at this example to see just how autoPrettify() works:

Open In Colab


Contact Us

Email: [email protected]

Or you can contact either of us individually if you like. See our individual GitHub profiles for information.


Open with GitPod

GitPod


License

Copyright 2021 BrainStormYourWayIn

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Pandas (pandas)

Copyright (c) 2008-2011, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team.
Copyright (c) 2011-2020, Open source contributors.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].