Last active
December 12, 2019 21:20
-
-
Save funkyfuture/266f60181808e8a2dde9f01c720da902 to your computer and use it in GitHub Desktop.
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
# read on mixins: https://www.linuxjournal.com/article/4540 | |
# i have just read the first or two paragraphs, but it resembles what i remember | |
# please inform me if you think applying that concept makes no sense, and inheritence would be preferable | |
# the methods would be implemented by the plugin/extension/mixin-class, | |
# this provides a client code perspective | |
class Document: | |
def exist_push(): | |
self.config.exist.client._update_document(data=str(self), self.config.exist.docuemnt_path) | |
@property | |
def parent_document(): | |
if self.config.exist.node_id == 1: | |
raise delb.InvalidOperatoion("I AM MY FATHER.") | |
# or return None? | |
# querying via exist_client | |
# possible interfaces to obtain a document | |
document = Document("existb+path://<authority>/<collection>/<document_path>") | |
document = Document("existb+id://<authority>/<document_id>") | |
# me thinks when viable schemes are figured out, these should be proposed in the eXist-db community | |
# possible interfaces to obtain a set of subdocuments | |
documents = exist_client.get_nodes(xpath) | |
# we figured that the documentation should clearly how existdb's node term relates to delb's/snakesist's Document term | |
def existdb_loader(source: Any): | |
if not (isinstance(source, str) and source.startwith(("existdb+path://", "existb+id://")): | |
return None, {} | |
# derive ExistClient from URL authority (and collection?) | |
# use it to query the document | |
# detach the actual document from the response body and return it / invoke other suited loader | |
@hookimpl(…) | |
def register_loader(loaders): | |
loaders.append(existdb_loader) | |
# stupid use-case that demonstrates how existdb:nodes/delb:(sub)documents can be used in conjunction w/ whole document | |
def add_trailer(node: Document): # input is one result of exist_client.get_nodes | |
containing_doc = node.parent_document | |
node_in_containing_document = containing_doc.xpath(node.config.exist.node_id) # the node_id property needs to be tarnsformed into XPath grammer | |
node_in_containing_document.add_next(tag("supplement")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment