-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
started working on my own html generator library
- Loading branch information
István Bozsó
committed
Feb 20, 2020
1 parent
0a0dd62
commit cd64160
Showing
6 changed files
with
95 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
from utils.utils import * | ||
from utils.path import * | ||
from utils.enforce import * | ||
from utils.cli import * | ||
from utils.cmd import * | ||
from utils.ninja import * | ||
from utils.project import * | ||
from utils.simpledoc import * | ||
from utils.html import * | ||
from utils.jslibs import * | ||
from .utils import * | ||
from .path import * | ||
from .enforce import * | ||
from .cli import * | ||
from .cmd import * | ||
from .ninja import * | ||
from .project import * | ||
from .simpledoc import * | ||
from .html import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .html import * | ||
from .tag import * | ||
from .jslibs import * |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from utils import export, str_t | ||
|
||
def parse_options(kwargs): | ||
if "klass" in kwargs: | ||
kwargs["class"] = kwargs.pop("klass") | ||
|
||
return " ".join( | ||
"%s=%s" % (key, val) | ||
if val is not True | ||
else "%s" % key | ||
for key, val in kwargs.items() | ||
) | ||
|
||
class BaseTag(object): | ||
__slots__ = ( | ||
"options", | ||
) | ||
|
||
def __init__(self, *args, **kwargs): | ||
self.options = kwargs | ||
|
||
|
||
class Tag(BaseTag): | ||
__slots__ = ( | ||
"children", | ||
) | ||
|
||
def __init__(self, *args, **kwargs): | ||
BaseTag.__init__(self, *args, **kwargs) | ||
self.children = args | ||
|
||
|
||
def render(self): | ||
name = self.__class__.__name__ | ||
|
||
return "<%s %s>%s</%s>" % ( | ||
name, parse_options(self.options), | ||
self.render_children(), name | ||
) | ||
|
||
def render_children(self): | ||
return "".join( | ||
child.render() | ||
if not isinstance(child, str_t) | ||
else str(child) | ||
for child in self.children | ||
) | ||
|
||
|
||
class SelfClosingTag(BaseTag): | ||
def render(self): | ||
return "<%s %s>" % ( | ||
self.__class__.__name__, | ||
self.options | ||
) | ||
|
||
|
||
@export | ||
class html(Tag): | ||
pass | ||
|
||
@export | ||
class p(Tag): | ||
pass | ||
|
||
@export | ||
class div(Tag): | ||
pass | ||
|
||
@export | ||
class img(SelfClosingTag): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from utils.html.tag import * | ||
|
||
|
||
def main(): | ||
t = div(p("a"), p("b"), controls=True, src="a/b") | ||
|
||
print(t.render()) | ||
|
||
if __name__ == "__main__": | ||
main() |