Skip to content

Commit

Permalink
think this is what i need
Browse files Browse the repository at this point in the history
  • Loading branch information
byteface committed Jul 6, 2020
1 parent 1fc2bab commit be4b85d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 14 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,15 @@ or it will complain the params are in the wrong order. You have to instead put c

div( p("Some content"), _class="container")

which is annoying when a div gets long. You can get around this several ways.
which is annoying when a div gets long.

With 'innerHTML' which is available on every Node:
You can get around this by using 'html' which is available on every Element:

div( _class="container" ).innerHTML("Some content")
div( _class="container" ).html("Some content")

With 'html' which is available on every Node:
This is NOT like jQuery html func that returns just the inner content. use innerHTML for that.

div( _class="container" ).html("Some content")
It is used specifically for rendering.


### Common Errors
Expand Down
2 changes: 1 addition & 1 deletion domonic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
- Call Terminal commands using python 3 (this one requires a nix machine)
"""

__version__ = "0.1.0"
__version__ = "0.1.1"
__license__ = 'MIT'

# from typing import *
Expand Down
20 changes: 16 additions & 4 deletions domonic/dom.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,25 @@ def attributes(self) -> List:
''' Returns a List of an element's attributes'''
return self.attributes

def innerHTML(self, *args) -> str:
@property
def innerHTML(self) -> str:
''' Sets or returns the content of an element'''
self.args = args
# self.args = args
return self.content

@innerHTML.setter
def innerHTML(self, value):

if value is not None:
self.args = (value,) # TODO - will need the parser to work for this to work properly. for now shove all on first content node

return self.content

def html(self, *args) -> str:
return self.innerHTML(*args)

def html(self, *args) -> str :
self.args = args
return self


def blur(self):
'''Removes focus from an element'''
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name = 'domonic',
version = '0.1.0',
version = '0.1.1',
author="@byteface",
author_email="[email protected]",
license="MIT",
Expand Down
8 changes: 5 additions & 3 deletions tests/test_dom.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ def test_dom(self):
self.assertEqual(str(sometag), '<div id="someid">asdfasdf<div></div><div>yo</div></div>')
sometag.html('test')
self.assertEqual(str(sometag), '<div id="someid">test</div>')
sometag.innerHTML('test2')
sometag.innerHTML = 'test2'
self.assertEqual(str(sometag), '<div id="someid">test2</div>')


# same test on body tag
bodytag = body("test", _class="why")
self.assertEqual(str(bodytag), '<body class="why">test</body>')
Expand All @@ -41,6 +40,9 @@ def test_dom(self):
print(sometag.getAttribute('id'))
self.assertEqual(sometag.getAttribute('_id'), 'someid')

mydiv = div("I like cake", div(_class='myclass').html(div("1"),div("2"),div("3")))
print(mydiv)

# print(sometag.innerText())
# print(sometag.nodeName)
# assert(sometag.nodeName, 'DIV') # TODO - i checked one site in chrome, was upper case. not sure if a standard?
Expand Down Expand Up @@ -92,7 +94,7 @@ def test_dom_node_again(self):
somebody = body("test", _class="why")#.html("wn")
print(somebody)

somebody = body("test", _class="why").html("fuck off")
somebody = body("test", _class="why").html("nope")
print(somebody)


Expand Down

0 comments on commit be4b85d

Please sign in to comment.