Test coverage report: markupmirror.markup.base

# markupmirror.markup.base: 39 total statements, 100.0% covered

Generated: Wed 2012-04-11 05:19 CDT

Source file: /home/buechler/Sites/django-markupmirror/markupmirror/markup/base.py

Stats: 37 executed, 0 missed, 2 excluded, 59 ignored

1. `from django.utils.encoding import force_unicode`
2. ``
3. `from markupmirror.exceptions import *`
4. ``
5. ``
6. `class BaseMarkup(object):`
7. `"""Basic interface for markup converter classes.`
8. ``
9. `"""`
10. `codemirror_mode = ''`
11. `title = ""`
12. ``
13. `@classmethod`
14. `def get_name(cls):`
15. `"""Returns lowercase markup name, without the "Markup" part."""`
16. `return cls.__name__.replace("Markup", "", 1).lower()`
17. ``
18. `def before_convert(self, markup):`
19. `"""Called before ``convert``."""`
20. `return markup`
21. ``
22. `def after_convert(self, markup):`
23. `"""``Called after ``convert``."""`
24. `return markup`
25. ``
26. `def convert(self, markup):`
27. `"""Main conversion method. Use third-pary libraries here."""`
28. `return markup`
29. ``
30. `def __call__(self, markup):`
31. `"""Main entry point. Calls ``before_convert``, ``convert`` and`
32. ```after_convert`` in that order.`
33. ``
34. `"""`
35. `return force_unicode(`
36. `self.after_convert(self.convert(self.before_convert(markup))))`
37. ``
38. ``
39. `class MarkupPool(object):`
40. `"""Pool for markup converters.`
41. ``
42. `Each markup class, subclassing`
43. ```markupmirror.markup.base.BaseMarkup``, must register to this`
44. `pool using ``register_markup`` defined below.`
45. ``
46. `"""`
47. `def __init__(self):`
48. `self.markups = {}`
49. ``
50. `def register_markup(self, markup):`
51. `"""Registers a markup converter class.`
52. ``
53. ```markup`` must be a subclass of ``BaseMarkup`` and may not be`
54. `registered already.`
55. ``
56. `"""`
57. `# check for correct subclassing`
58. `if not issubclass(markup, BaseMarkup):`
59. `raise InvalidMarkup(`
60. `"Markups must be subclasses of "`
61. `"markupmirror.markup.base.BaseMarkup. %r is not."`
62. `% markup)`
63. ``
64. `markup_name = markup.get_name()`
65. `self.markups[markup_name] = markup()`
66. ``
67. `def unregister_markup(self, markup_name):`
68. `"""Unregisters a markup converter with the name ``markup_name``.`
69. `Fails silently if no converter was registered by that name.`
70. `"""`
71. `if markup_name in self.markups:`
72. `del self.markups[markup_name]`
73. ``
74. `def has_markup(self, name):`
75. `return name in self.markups`
76. ``
77. `def get_markup(self, name):`
78. `"""Returns one markup converter by name.`
79. `Raises ``KeyError`` if no converter was registered by ``name``.`
80. ``
81. `"""`
82. `return self.markups[name]`
83. ``
84. `def __contains__(self, key):`
85. `return self.has_markup(key)`
86. ``
87. `def __getitem__(self, key):`
88. `return self.get_markup(key)`
89. ``
90. `def __delitem__(self, key):`
91. `self.unregister_markup(key)`
92. ``
93. ``
94. `markup_pool = MarkupPool()`
95. `register_markup = markup_pool.register_markup`
96. ``
97. ``
98. `__all__ = ('markup_pool', 'register_markup', 'BaseMarkup')`