GeezerVison is showing github.com — Fixed #33 - Implement new API for Plugins · 06linux/ebooklib@401c0db
File treeExpand file treeCollapse file tree Open diff view settings samples/05_plugins_create
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: ebooklib/epub.py +6-2Lines changed: 6 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -449,11 +449,15 @@ def __init__(self, name, book, options = None): | 449 | 449 |
| 450 | 450 | def process(self): | 451 | 451 | # should cache this html parsing so we don't do it for every plugin | | 452 | + for plg in self.options.get('plugins', []): | | 453 | + if hasattr(plg, 'before_write'): | | 454 | + plg.before_write(self.book) | | 455 | + | 452 | 456 | for item in self.book.get_items(): | 453 | 457 | if isinstance(item, EpubHtml): | 454 | 458 | for plg in self.options.get('plugins', []): | 455 | | - if hasattr(plg, 'process_html'): | 456 | | - plg.process_html(self.book, item) | | 459 | + if hasattr(plg, 'html_before_write'): | | 460 | + plg.html_before_write(self.book, item) | 457 | 461 |
| 458 | 462 | def _write_container(self): | 459 | 463 | self.out.writestr(CONTAINER_PATH, CONTAINER_XML) | |
Collapse file Copy file name to clipboardExpand all lines: ebooklib/plugins/base.py +23-3Lines changed: 23 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 16 | 16 |
| 17 | 17 |
| 18 | 18 | class BasePlugin(object): | 19 | | - def before_processing(self, book): | | 19 | + def before_write(self, book): | 20 | 20 | "Processing before save" | 21 | 21 | return True | 22 | 22 |
| 23 | | - def after_processing(self, book): | | 23 | + def after_write(self, book): | 24 | 24 | "Processing after save" | 25 | 25 | return True | 26 | 26 |
| 27 | | - def process_html(self, book, chapter): | | 27 | + def before_read(self, book): | | 28 | + "Processing before save" | | 29 | + return True | | 30 | + | | 31 | + def after_read(self, book): | | 32 | + "Processing after save" | | 33 | + return True | | 34 | + | | 35 | + def item_after_read(self, book, item): | | 36 | + "Process general item after read." | | 37 | + return True | | 38 | + | | 39 | + def item_before_write(self, book, item): | | 40 | + "Process general item before write." | | 41 | + return True | | 42 | + | | 43 | + def html_after_read(self, book, chapter): | | 44 | + "Processing HTML before read." | | 45 | + return True | | 46 | + | | 47 | + def html_before_write(self, book, chapter): | 28 | 48 | "Processing HTML before save." | 29 | 49 | return True |
Collapse file Copy file name to clipboardExpand all lines: ebooklib/plugins/booktype.py +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -23,7 +23,7 @@ class BooktypeLinks(BasePlugin): | 23 | 23 | def __init__(self, booktype_book): | 24 | 24 | self.booktype_book = booktype_book | 25 | 25 |
| 26 | | - def process_html(self, book, chapter): | | 26 | + def html_before_write(self, book, chapter): | 27 | 27 | from lxml import etree | 28 | 28 |
| 29 | 29 | try: | @@ -80,7 +80,7 @@ class BooktypeFootnotes(BasePlugin): | 80 | 80 | def __init__(self, booktype_book): | 81 | 81 | self.booktype_book = booktype_book | 82 | 82 |
| 83 | | - def process_html(self, book, chapter): | | 83 | + def html_before_write(self, book, chapter): | 84 | 84 | from lxml import etree | 85 | 85 |
| 86 | 86 | from ebooklib import epub | |
Collapse file Copy file name to clipboardExpand all lines: ebooklib/plugins/sourcecode.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -21,7 +21,7 @@ class SourceHighlighter(BasePlugin): | 21 | 21 | def __init__(self): | 22 | 22 | pass | 23 | 23 |
| 24 | | - def process_html(self, book, chapter): | | 24 | + def html_before_write(self, book, chapter): | 25 | 25 | from lxml import etree, html | 26 | 26 |
| 27 | 27 | from pygments import highlight | |
Collapse file Copy file name to clipboardExpand all lines: ebooklib/plugins/standard.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -41,7 +41,7 @@ def leave_only(item, tag_list): | 41 | 41 | class SyntaxPlugin(BasePlugin): | 42 | 42 | NAME = 'Check HTML syntax' | 43 | 43 |
| 44 | | - def process_html(self, book, chapter): | | 44 | + def html_before_write(self, book, chapter): | 45 | 45 | from lxml import etree | 46 | 46 |
| 47 | 47 | try: | |
Collapse file Copy file name to clipboardExpand all lines: samples/05_plugins_create/create.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -7,7 +7,7 @@ class SamplePlugin(BasePlugin): | 7 | 7 | NAME = 'Sample Plugin' | 8 | 8 |
| 9 | 9 | # Very useless but example of what can be done | 10 | | - def process_html(self, book, chapter): | | 10 | + def html_before_write(self, book, chapter): | 11 | 11 | from urlparse import urlparse, urljoin | 12 | 12 |
| 13 | 13 | from lxml import html, etree | |
|