diff options
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | python-htmlbuilder.spec | 579 | ||||
| -rw-r--r-- | sources | 1 |
3 files changed, 581 insertions, 0 deletions
@@ -0,0 +1 @@ +/htmlBuilder-1.0.0.tar.gz diff --git a/python-htmlbuilder.spec b/python-htmlbuilder.spec new file mode 100644 index 0000000..1538471 --- /dev/null +++ b/python-htmlbuilder.spec @@ -0,0 +1,579 @@ +%global _empty_manifest_terminate_build 0 +Name: python-htmlBuilder +Version: 1.0.0 +Release: 1 +Summary: A beautiful html builder library. +License: MIT +URL: https://github.com/jaimevp54/htmlBuilder +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/45/a1/da87d642b31831fb6731cbec6c5dceb3f770dd0b147beefbb1426eb8f0c6/htmlBuilder-1.0.0.tar.gz +BuildArch: noarch + + +%description +# HtmlBuilder + +HtmlBuilder is a python library that allows you to render HTML files by writing python code. And to make use of python features, clean syntax, and object-oriented design to their full potential. + +[](https://codecov.io/gh/jaimevp54/htmlBuilder) + +# Why should you care about this library? + +When rendering HTML programmatically, there are other options available (template engines and other rendering libraries). Still, these are often limited in what they can do, or it's necessary to learn a new level of abstraction before being productive. HtmlBuilder tries to improve on this by following the next few ideas: + +- **Minimal learning curve**: Users should need no more than Python and HTML knowledge to be productive using this tool. +- **Real python code**: The final code looks and behaves as you would expect from other python code. +- **Easily testable**: Users can introspect and unit test the HTML object structure **before** rendering the HTML string. + +## Installation +run `pip install htmlbuilder` +## Use examples: + +### A simple example +```python +# import necessary tags and attributes +from htmlBuilder.tags import * +from htmlBuilder.attributes import Class, Style as InlineStyle + + +# html tags are represented by classes +html = Html([], + # any tag can receive another tag as constructor parameter + Head([], + Title([], "A beautiful site") + ), + Body([Class('btn btn-success'), InlineStyle(background_color='red', bottom='35px')], + Hr(), + Div([], + Div() + ) + ) +) +# no closing tags are required + +# call the render() method to return tag instances as html text +print(html.render(pretty=True)) +``` + +#### Output +```html + <html> + <head> + <title> + A beautiful site + </title> + </head> + <body class='btn btn-success' style='background-color: red; bottom: 35px'> + <hr/> + <div> + <div></div> + </div> + </body> + </html> +``` + +### A not so simple example +```python +from htmlBuilder.attributes import Class +from htmlBuilder.tags import Html, Head, Title, Body, Nav, Div, Footer, Ul, Li + +# declare data +users = [ + { + "name": "Jose", + "movies": ['A beautiful mind', 'Red'], + "favorite-number": 42, + }, + { + "name": "Jaime", + "movies": ['The breakfast club', 'Fight club'], + "favorite-number": 7, + }, + { + "name": "Jhon", + "movies": ['The room', 'Yes man'], + "favorite-number": 987654321, + }, +] + + +# functions can be used to handle recurring tag structures +def my_custom_nav(): + # these functions can return a tag or a list of tags ( [tag1,tag2,tag3] ) + return Nav([Class("nav pretty")], + Div([], "A beautiful NavBar") + ) + + +html = Html([], + Head([], + Title([], "An awesome site") + ), + Body([], + my_custom_nav(), # calling previously defined function + [Div([Class(f"user-{user['name'].lower()}")], + Div([], user['name']), + Ul([], + [Li([], movie) for movie in user["movies"]] # list comprehensions can be used to easily render multiple tags + ) if user['favorite-number'] < 100 else "Favorite number is too high" # python's ternary operation is allowed too + ) for user in users], + Footer([], "My Footer"), + ) +) + +print(html.render(pretty=True, doctype=True)) # pass doctype=True to add a document declaration +``` + +#### Output + +```html + <!DOCTYPE html> + <html> + <head> + <title> + An awesome site + </title> + </head> + <body> + <nav class='nav pretty'> + <div> + A beautiful NavBar + </div> + </nav> + <div class='user-jose'> + <div> + Jose + </div> + <ul> + <li> + A beautiful mind + </li> + <li> + Red + </li> + </ul> + </div> + <div class='user-jaime'> + <div> + Jaime + </div> + <ul> + <li> + The breakfast club + </li> + <li> + Fight club + </li> + </ul> + </div> + <div class='user-jhon'> + <div> + Jhon + </div> + Favorite number is too high + </div> + <footer> + My Footer + </footer> + </body> + </html> +``` + + + + +%package -n python3-htmlBuilder +Summary: A beautiful html builder library. +Provides: python-htmlBuilder +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-htmlBuilder +# HtmlBuilder + +HtmlBuilder is a python library that allows you to render HTML files by writing python code. And to make use of python features, clean syntax, and object-oriented design to their full potential. + +[](https://codecov.io/gh/jaimevp54/htmlBuilder) + +# Why should you care about this library? + +When rendering HTML programmatically, there are other options available (template engines and other rendering libraries). Still, these are often limited in what they can do, or it's necessary to learn a new level of abstraction before being productive. HtmlBuilder tries to improve on this by following the next few ideas: + +- **Minimal learning curve**: Users should need no more than Python and HTML knowledge to be productive using this tool. +- **Real python code**: The final code looks and behaves as you would expect from other python code. +- **Easily testable**: Users can introspect and unit test the HTML object structure **before** rendering the HTML string. + +## Installation +run `pip install htmlbuilder` +## Use examples: + +### A simple example +```python +# import necessary tags and attributes +from htmlBuilder.tags import * +from htmlBuilder.attributes import Class, Style as InlineStyle + + +# html tags are represented by classes +html = Html([], + # any tag can receive another tag as constructor parameter + Head([], + Title([], "A beautiful site") + ), + Body([Class('btn btn-success'), InlineStyle(background_color='red', bottom='35px')], + Hr(), + Div([], + Div() + ) + ) +) +# no closing tags are required + +# call the render() method to return tag instances as html text +print(html.render(pretty=True)) +``` + +#### Output +```html + <html> + <head> + <title> + A beautiful site + </title> + </head> + <body class='btn btn-success' style='background-color: red; bottom: 35px'> + <hr/> + <div> + <div></div> + </div> + </body> + </html> +``` + +### A not so simple example +```python +from htmlBuilder.attributes import Class +from htmlBuilder.tags import Html, Head, Title, Body, Nav, Div, Footer, Ul, Li + +# declare data +users = [ + { + "name": "Jose", + "movies": ['A beautiful mind', 'Red'], + "favorite-number": 42, + }, + { + "name": "Jaime", + "movies": ['The breakfast club', 'Fight club'], + "favorite-number": 7, + }, + { + "name": "Jhon", + "movies": ['The room', 'Yes man'], + "favorite-number": 987654321, + }, +] + + +# functions can be used to handle recurring tag structures +def my_custom_nav(): + # these functions can return a tag or a list of tags ( [tag1,tag2,tag3] ) + return Nav([Class("nav pretty")], + Div([], "A beautiful NavBar") + ) + + +html = Html([], + Head([], + Title([], "An awesome site") + ), + Body([], + my_custom_nav(), # calling previously defined function + [Div([Class(f"user-{user['name'].lower()}")], + Div([], user['name']), + Ul([], + [Li([], movie) for movie in user["movies"]] # list comprehensions can be used to easily render multiple tags + ) if user['favorite-number'] < 100 else "Favorite number is too high" # python's ternary operation is allowed too + ) for user in users], + Footer([], "My Footer"), + ) +) + +print(html.render(pretty=True, doctype=True)) # pass doctype=True to add a document declaration +``` + +#### Output + +```html + <!DOCTYPE html> + <html> + <head> + <title> + An awesome site + </title> + </head> + <body> + <nav class='nav pretty'> + <div> + A beautiful NavBar + </div> + </nav> + <div class='user-jose'> + <div> + Jose + </div> + <ul> + <li> + A beautiful mind + </li> + <li> + Red + </li> + </ul> + </div> + <div class='user-jaime'> + <div> + Jaime + </div> + <ul> + <li> + The breakfast club + </li> + <li> + Fight club + </li> + </ul> + </div> + <div class='user-jhon'> + <div> + Jhon + </div> + Favorite number is too high + </div> + <footer> + My Footer + </footer> + </body> + </html> +``` + + + + +%package help +Summary: Development documents and examples for htmlBuilder +Provides: python3-htmlBuilder-doc +%description help +# HtmlBuilder + +HtmlBuilder is a python library that allows you to render HTML files by writing python code. And to make use of python features, clean syntax, and object-oriented design to their full potential. + +[](https://codecov.io/gh/jaimevp54/htmlBuilder) + +# Why should you care about this library? + +When rendering HTML programmatically, there are other options available (template engines and other rendering libraries). Still, these are often limited in what they can do, or it's necessary to learn a new level of abstraction before being productive. HtmlBuilder tries to improve on this by following the next few ideas: + +- **Minimal learning curve**: Users should need no more than Python and HTML knowledge to be productive using this tool. +- **Real python code**: The final code looks and behaves as you would expect from other python code. +- **Easily testable**: Users can introspect and unit test the HTML object structure **before** rendering the HTML string. + +## Installation +run `pip install htmlbuilder` +## Use examples: + +### A simple example +```python +# import necessary tags and attributes +from htmlBuilder.tags import * +from htmlBuilder.attributes import Class, Style as InlineStyle + + +# html tags are represented by classes +html = Html([], + # any tag can receive another tag as constructor parameter + Head([], + Title([], "A beautiful site") + ), + Body([Class('btn btn-success'), InlineStyle(background_color='red', bottom='35px')], + Hr(), + Div([], + Div() + ) + ) +) +# no closing tags are required + +# call the render() method to return tag instances as html text +print(html.render(pretty=True)) +``` + +#### Output +```html + <html> + <head> + <title> + A beautiful site + </title> + </head> + <body class='btn btn-success' style='background-color: red; bottom: 35px'> + <hr/> + <div> + <div></div> + </div> + </body> + </html> +``` + +### A not so simple example +```python +from htmlBuilder.attributes import Class +from htmlBuilder.tags import Html, Head, Title, Body, Nav, Div, Footer, Ul, Li + +# declare data +users = [ + { + "name": "Jose", + "movies": ['A beautiful mind', 'Red'], + "favorite-number": 42, + }, + { + "name": "Jaime", + "movies": ['The breakfast club', 'Fight club'], + "favorite-number": 7, + }, + { + "name": "Jhon", + "movies": ['The room', 'Yes man'], + "favorite-number": 987654321, + }, +] + + +# functions can be used to handle recurring tag structures +def my_custom_nav(): + # these functions can return a tag or a list of tags ( [tag1,tag2,tag3] ) + return Nav([Class("nav pretty")], + Div([], "A beautiful NavBar") + ) + + +html = Html([], + Head([], + Title([], "An awesome site") + ), + Body([], + my_custom_nav(), # calling previously defined function + [Div([Class(f"user-{user['name'].lower()}")], + Div([], user['name']), + Ul([], + [Li([], movie) for movie in user["movies"]] # list comprehensions can be used to easily render multiple tags + ) if user['favorite-number'] < 100 else "Favorite number is too high" # python's ternary operation is allowed too + ) for user in users], + Footer([], "My Footer"), + ) +) + +print(html.render(pretty=True, doctype=True)) # pass doctype=True to add a document declaration +``` + +#### Output + +```html + <!DOCTYPE html> + <html> + <head> + <title> + An awesome site + </title> + </head> + <body> + <nav class='nav pretty'> + <div> + A beautiful NavBar + </div> + </nav> + <div class='user-jose'> + <div> + Jose + </div> + <ul> + <li> + A beautiful mind + </li> + <li> + Red + </li> + </ul> + </div> + <div class='user-jaime'> + <div> + Jaime + </div> + <ul> + <li> + The breakfast club + </li> + <li> + Fight club + </li> + </ul> + </div> + <div class='user-jhon'> + <div> + Jhon + </div> + Favorite number is too high + </div> + <footer> + My Footer + </footer> + </body> + </html> +``` + + + + +%prep +%autosetup -n htmlBuilder-1.0.0 + +%build +%py3_build + +%install +%py3_install +install -d -m755 %{buildroot}/%{_pkgdocdir} +if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi +if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi +if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi +if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi +pushd %{buildroot} +if [ -d usr/lib ]; then + find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/lib64 ]; then + find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/bin ]; then + find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/sbin ]; then + find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst +fi +touch doclist.lst +if [ -d usr/share/man ]; then + find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst +fi +popd +mv %{buildroot}/filelist.lst . +mv %{buildroot}/doclist.lst . + +%files -n python3-htmlBuilder -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Mon May 29 2023 Python_Bot <Python_Bot@openeuler.org> - 1.0.0-1 +- Package Spec generated @@ -0,0 +1 @@ +bef39a2c1a74b87d1aee2977eec61ced htmlBuilder-1.0.0.tar.gz |
