Skip to content

Commit 88d6d77

Browse files
committed
BREAKING CHANGE in tools.py - see changelog. bumped version to 0.1.16
1 parent 6c7cd72 commit 88d6d77

File tree

7 files changed

+83
-42
lines changed

7 files changed

+83
-42
lines changed

docs/CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
11
# Changelog
22

3+
## v0.1.16 (2025-03-27) -- BREAKING BACKWARD COMPATIBILITY
4+
5+
- BREAKING: Changed domible.tools.open_html_in_browser to open_html_document_in_browser
6+
- and added domible.tools.open_html_fragment_in_browser
7+
- makes it easier to, for example, create an HTML table using a builder then have that table popped open in the browser
8+
- updated domible.tools.open_object_in_browser
9+
10+
- this change is transpaerent but is good for testing open_html_fragment_in_browser
11+
312
## v0.1.15 (2025-01-13)
413

514
- this version is motivated by a desire to toggle visibility of all details elements
615
- and now, forms... starting with the button
16+
717
- this is a very basic ability to create a button element
818
- any attributes (e.g., type) will be done manually or via a builders class
919
- this is all TBD and might change in subsequent releases
20+
1021
- a new builder to add a toggle button to a page to expand/collapse the content of a details element
22+
1123
- this is also the introduction of JavaScript into domible (sorry, it was inevitable)
1224
- the JS is hard coded into the builder, which might be the long term solution, but I doubt it
1325
- focus is on functionality, no CSS has been added
26+
1427
- added toggle details button into efo.py in tests
1528
- added a toggle details button in open_object_in_browser() in domible tools
1629
- fixed bug in Script element where contents was not being passed to super().__init__

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "domible"
3-
version = "0.1.15"
3+
version = "0.1.16"
44
description = "python classes to create accessible HTML elements and documents "
55
authors = ["Joel Dodson <joeldodson@gmail.com>"]
66
maintainers = ["BlindGumption <blindgumption@gmail.com>"]

src/dicli/main.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from domible.elements import Heading, Anchor, Paragraph
2626
from domible.builders.tableBuilder import TableBuilder, build_table_from_dicts
2727
from domible.starterDocuments import basic_head_empty_body
28-
from domible.tools import open_html_in_browser
28+
from domible.tools import open_html_document_in_browser
2929

3030
import argparse
3131

@@ -51,7 +51,7 @@ def simple(args) -> None:
5151
),
5252
]
5353
)
54-
open_html_in_browser(htmlDoc)
54+
open_html_document_in_browser(htmlDoc)
5555

5656

5757
def elements(args) -> None:
@@ -94,7 +94,7 @@ def elements(args) -> None:
9494
deprecatedTable,
9595
]
9696
)
97-
open_html_in_browser(htmlDoc)
97+
open_html_document_in_browser(htmlDoc)
9898

9999

100100
def ctfd(args) -> None:
@@ -120,7 +120,7 @@ def ctfd(args) -> None:
120120
table,
121121
]
122122
)
123-
open_html_in_browser(htmlDoc)
123+
open_html_document_in_browser(htmlDoc)
124124

125125

126126
def lists(args) -> None:
@@ -238,7 +238,7 @@ def lists(args) -> None:
238238
detailsList,
239239
]
240240
)
241-
open_html_in_browser(htmlDoc)
241+
open_html_document_in_browser(htmlDoc)
242242

243243

244244
def list_builder(args) -> None:
@@ -247,7 +247,7 @@ def list_builder(args) -> None:
247247
htmlDoc = basic_head_empty_body(title)
248248
body = htmlDoc.get_body_element()
249249
body.add_content([])
250-
open_html_in_browser(htmlDoc)
250+
open_html_document_in_browser(htmlDoc)
251251

252252

253253
def headings(args) -> None:
@@ -302,7 +302,7 @@ def headings(args) -> None:
302302
contents="heading level 3 with 'somethingUnique' for unique",
303303
)
304304
)
305-
open_html_in_browser(htmlDoc)
305+
open_html_document_in_browser(htmlDoc)
306306

307307

308308
def run() -> None:

src/distarter/main.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
this file serves as Python code to get started with domible
44
"""
55

6+
import domible
67
from domible.elements import Html, Body, Title
78
from domible.elements import Heading, Anchor, Paragraph, HorizontalRule
89
from domible.starterDocuments import basic_head_empty_body
9-
from domible.tools import open_html_in_browser
10+
from domible.tools import open_html_document_in_browser
1011

1112

1213
#######
@@ -19,16 +20,17 @@ def run() -> None:
1920
cib_anchor = Anchor(
2021
href="http://codinginblind.vip", contents="the Coding In Blind website"
2122
)
23+
version = domible.__version__
2224
htmlDoc = basic_head_empty_body(title)
2325
body = htmlDoc.get_body_element()
2426
body.add_content([
25-
Heading(1, title),
27+
Heading(1, title),
28+
Paragraph(f"using domible version {version}"),
2629
Paragraph(f"check out: {cib_anchor}"),
2730
HorizontalRule(),
2831
Paragraph('Adding a non printable character, codepoint = 0xfeff, in the square brackets [\ufeff] to make sure encodings are set correctly.')
2932
])
30-
open_html_in_browser(htmlDoc)
31-
## open_html_in_browser(htmlDoc, "saved_distarter.html", True)
33+
open_html_document_in_browser(htmlDoc)
3234

3335

3436
if __name__ == "__main__":

src/domible/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
import domible.elements
99
import domible.builders
1010
import domible.starterDocuments
11-
from domible.tools import open_object_in_browser, open_html_in_browser, save_to_file
11+
from domible.tools import open_object_in_browser, open_html_document_in_browser, save_to_file
12+
1213
## end of file

src/domible/tools.py

Lines changed: 52 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
""" domible/src/domible/tools.py
1+
"""domible/src/domible/tools.py
22
33
tools.py has functions for users of the domible package to do simple things
44
like open their HTML doc in the browser,
55
or save the HTML to a specified file.
66
tools.py imports other modules within domible thus should not be used by any of domible's submodules.
7-
Any helper functions needed by domible should be put in utils.py
8-
See the top level comments in utils.py to understand why tools.py exists.
7+
Any helper functions needed by domible should be put in utils.py
8+
See the top level comments in utils.py to understand why tools.py exists.
99
"""
1010

11-
from pathlib import Path
11+
from pathlib import Path
1212
from tempfile import NamedTemporaryFile
1313
import webbrowser as wb
1414

15-
from domible.elements import BaseElement
16-
from domible.elements import Html, Body, Heading
17-
from domible.builders import element_from_object, default_toggle_details_button
18-
from domible.starterDocuments import basic_head_empty_body
15+
from domible.elements import BaseElement
16+
from domible.elements import Html, Body, Heading, Div
17+
from domible.builders import element_from_object, default_toggle_details_button
18+
from domible.starterDocuments import basic_head_empty_body
1919

2020

2121
def save_to_file(element: BaseElement, filename: str, force: bool = False) -> None:
@@ -37,39 +37,64 @@ def save_to_file(element: BaseElement, filename: str, force: bool = False) -> No
3737
f.write(f"{element}")
3838

3939

40-
def open_html_in_browser(html_doc: Html, save_file: str = None, force: bool = False) -> None:
40+
def open_html_document_in_browser(
41+
html_doc: Html, save_file: str = None, force: bool = False
42+
) -> None:
4143
"""
4244
open the html_doc in the default browser.
4345
if a save_to_file is provided, also save the html_doc to that file,
44-
else use a temporary file
46+
else use a temporary file
4547
"""
4648
if save_file:
4749
save_to_file(html_doc, save_file, force)
48-
# path must be absolute to match how temp file works
49-
path = str(Path(save_file).absolute())
50-
else:
51-
path =NamedTemporaryFile(delete=False, suffix='.html')
52-
f=open(path.name, 'w+t', encoding='utf-8')
50+
# path must be absolute to match how temp file works
51+
path = str(Path(save_file).absolute())
52+
else:
53+
path = NamedTemporaryFile(delete=False, suffix=".html")
54+
f = open(path.name, "w+t", encoding="utf-8")
5355
f.write(f"{html_doc}")
5456
f.close()
55-
path = path.name # consistent with path from saving file
56-
wb.open('file://' + path)
57+
path = path.name # consistent with path from saving file
58+
wb.open("file://" + path)
5759

5860

59-
def open_object_in_browser(obj: object, depth:int = 42, title: str = "opening an object in the browser", save_file: str = None, force: bool = False) -> None:
61+
def open_html_fragment_in_browser(
62+
html_frag: BaseElement,
63+
title: str = "opening HTML fragment",
64+
save_file: str = None,
65+
force: bool = False,
66+
) -> None:
6067
"""
61-
get HTML representation of the object then open it in the default browser.
68+
open some bit of HTML you've created in the default browser,
69+
using the default basic HTML doc.
70+
This is useful if you have some HTML you want to view in a browser
71+
and don't want to create the document and get the body and so on...
72+
This is sort of analogous to open_object_in_browser
73+
"""
74+
html_doc: Html = basic_head_empty_body(title)
75+
body: Body = html_doc.get_body_element()
76+
body.add_content(html_frag)
77+
6278

63-
the passed in object is used to get HTML using element_from_object.
64-
That HTML is then put into a simple HtML document using the basicHeadEmptyBody starter document.
65-
that simple document is then opened in the browser.
79+
def open_object_in_browser(
80+
obj: object,
81+
depth: int = 42,
82+
title: str = "opening an object in the browser",
83+
save_file: str = None,
84+
force: bool = False,
85+
) -> None:
86+
"""
87+
get HTML representation of the object then open it in the default browser.
6688
"""
6789
obj_html = element_from_object(obj, depth)
68-
html_doc: Html = basic_head_empty_body(title)
69-
body: Body = html_doc.get_body_element()
70-
body.add_content([Heading(1, f"showing object of type {type(obj).__name__}"), default_toggle_details_button()])
71-
body.add_content(obj_html)
72-
open_html_in_browser(html_doc, save_file, force)
90+
frag: Div = Div(
91+
[
92+
Heading(1, f"showing object of type {type(obj).__name__}"),
93+
default_toggle_details_button(),
94+
obj_html,
95+
]
96+
)
97+
open_html_fragment_in_browser(frag, title, save_file, force)
7398

7499

75100
## end of file

tests/efo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from sys import argv
1616

1717
from domible.builders import element_from_object, ToggleDetailsButton, default_toggle_details_button
18-
from domible import open_html_in_browser, open_object_in_browser
18+
from domible import open_html_document_in_browser, open_object_in_browser
1919
from domible.starterDocuments import basic_head_empty_body
2020
from domible.elements import Html, Body, BaseElement, Heading
2121

@@ -84,7 +84,7 @@
8484
for name, obj in cases.items():
8585
elem = element_from_object(obj, depth)
8686
body.add_content([Heading(2, f"Object {name}"), elem])
87-
open_html_in_browser(html)
87+
open_html_document_in_browser(html)
8888
# print the HTML in case I want to redirect output to a file.
8989
# it's easier than supporting writing to a file in this code.
9090
if len(argv) > 3 and argv[3] == "print":

0 commit comments

Comments
 (0)