'
+
+ def build(self, document, style_sheets=None, dev=True):
+ if style_sheets:
+ for path in style_sheets:
+ self._start += f''
+
+ if self._title:
+ self._start += f'{self._title}'
+
+ self._middle += document
+
+ if dev:
+ # adds watermark for dev renderings
+ self._start += """
+"""
+
+ self._middle += self._watermark
+
+ return self._start + self._middle + self._end
diff --git a/packages/client-py/onedoc/onedoc.py b/packages/client-py/onedoc/onedoc.py
index 0a50beb..50432c0 100644
--- a/packages/client-py/onedoc/onedoc.py
+++ b/packages/client-py/onedoc/onedoc.py
@@ -1,5 +1,6 @@
import requests
import json
+from htmlBuilder import HtmlBuilder
from typing import Dict, Union, List, Any, BinaryIO
@@ -9,14 +10,14 @@
"upsert": False,
}
-class _HtmlBuilder:
- def __init__(self, title: str = None):
- self.title = title or "Document"
+# class _HtmlBuilder:
+# def __init__(self, title: str = None):
+# self.title = title or "Document"
- def build(self, html_content: str, stylesheets: List[str] = None, test: bool = True) -> str:
- # Implementation of HTML building logic goes here
- # This is a placeholder implementation
- return "{}{}".format(self.title, html_content)
+# def build(self, html_content: str, stylesheets: List[str] = None, test: bool = True) -> str:
+# # Implementation of HTML building logic goes here
+# # This is a placeholder implementation
+# return "{}{}".format(self.title, html_content)
class Onedoc:
def __init__(self, api_key: str):
@@ -80,7 +81,7 @@ def render(self, document: Dict) -> Dict:
self._upload_to_signed_url(e['signedUrl'], e['path'], asset['content'])
elif e['path'] == "/index.html":
- html_builder = _HtmlBuilder(document.get('title'))
+ html_builder = HtmlBuilder(document.get('title'))
style_sheets = [asset['path'] for asset in document.get('assets', []) if asset['path'].endswith(".css")]
html = html_builder.build(document['html'], style_sheets, test)
self._upload_to_signed_url(e['signedUrl'], e['path'], html)
diff --git a/packages/client-py/onedoc/styles.css b/packages/client-py/onedoc/styles.css
new file mode 100644
index 0000000..2db0fdd
--- /dev/null
+++ b/packages/client-py/onedoc/styles.css
@@ -0,0 +1,3 @@
+body{
+ background-color: aqua;
+}
\ No newline at end of file
diff --git a/packages/client-py/onedoc/test.py b/packages/client-py/onedoc/test.py
index 440d378..d6a4c85 100644
--- a/packages/client-py/onedoc/test.py
+++ b/packages/client-py/onedoc/test.py
@@ -6,17 +6,30 @@
onedoc = Onedoc(getenv("ONEDOC_API_KEY"))
+
+with open("packages/client-py/onedoc/styles.css", 'r') as file:
+ # Read the entire content of the file into a variable
+ css_content = file.read()
+print(css_content)
+
# Define your document
document = {
"html": "
Table of contents
First page Second page", # Simple HTML content
"title": "My First Document",
- "test": True, # Set to False to use in production
- "save": False, # Set to True if you want to save the document
+ "test": False, # Set to False to use in production
+ "save": True, # Set to True if you want to save the document
+ "assets":[
+ {
+ "content": css_content ,
+ "path": "/styles.css"
+ }
+ ]
}
# Render the document
-#result = onedoc.render(document)
+result = onedoc.render(document)
+print(result)
#for files that are not saved, remember to use "wb" when writing file
# onedoc = Onedoc(api_key)
@@ -40,12 +53,12 @@
#f.write(result.get("file"))
#f.close()
-firstFile = open("toc.pdf", "rb")
-secondFile = open("test.pdf", "rb")
+# firstFile = open("toc.pdf", "rb")
+# secondFile = open("test.pdf", "rb")
-result = onedoc.merge(firstFile, "toc.pdf", secondFile, "test.pdf")
+# result = onedoc.merge(firstFile, "toc.pdf", secondFile, "test.pdf")
-# Result is a pdf file
-f = open("merged.pdf", "wb")
-f.write(result.get('file'))
-f.close()
+# # Result is a pdf file
+# f = open("merged.pdf", "wb")
+# f.write(result.get('file'))
+# f.close()