Skip to content

Commit

Permalink
feat: readd fragment as passthrough to webfragement.fragment (#739)
Browse files Browse the repository at this point in the history
a previous deprecation of this pass-through causes wide-spread consequences.
  • Loading branch information
connorhaugh authored Apr 19, 2024
1 parent 4b8775c commit 2ae4557
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ Change history for XBlock
Unreleased
----------

4.0.0 - 2024-04-18
------------------

* xblock.fragment has returned as a pass-though component to web_fragments.fragment


3.0.0 - 2024-03-18
------------------
Expand All @@ -15,7 +20,7 @@ will be unaffected by this change. Some improvements have also been made to the

Specific changes:

* **Removed:**
* **Removed:**

* ``xblock.XBlockMixin`` (still available as ``xblock.core.XBlockMixin``)
* ``xblock.core.SharedBlockBase`` (replaced with ``xblock.core.Blocklike``)
Expand Down Expand Up @@ -53,7 +58,7 @@ Specific changes:

* Various docstrings have been improved, some of which are published in the docs.
* XBlockAside will now be represented in the API docs, right below XBlock on the "XBlock API" page.
* XBlockMixin has been removed from the docs.
* XBlockMixin has been removed from the docs.
It was only ever documented under the "Fields API" page (which didn't make any sense),
and it was barely even documented there. We considered adding it back to the "XBlock API" page,
but as noted in the class's new docstring, we do not want to encourage any new use of XBlockMixin.
Expand Down
2 changes: 1 addition & 1 deletion xblock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
XBlock Courseware Components
"""

__version__ = '3.1.0'
__version__ = '4.0.0'
25 changes: 25 additions & 0 deletions xblock/fragment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
Makes the Fragment class available through the old namespace location.
"""
import warnings

import web_fragments.fragment


class Fragment(web_fragments.fragment.Fragment):
"""
A wrapper around web_fragments.fragment.Fragment that provides
backwards compatibility for the old location.
Deprecated.
"""
def __init__(self, *args, **kwargs):
warnings.warn(
'xblock.fragment is deprecated. Please use web_fragments.fragment instead',
DeprecationWarning,
stacklevel=2
)
super().__init__(*args, **kwargs)

# Provide older names for renamed methods
add_frag_resources = web_fragments.fragment.Fragment.add_fragment_resources
add_frags_resources = web_fragments.fragment.Fragment.add_resources
21 changes: 21 additions & 0 deletions xblock/test/test_fragment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
Unit tests for the Fragment class.
Note: this class has been deprecated in favor of web_fragments.fragment.Fragment
"""
from unittest import TestCase

from xblock.fragment import Fragment


class TestFragment(TestCase):
"""
Unit tests for fragments.
"""
def test_fragment(self):
"""
Test the delegated Fragment class.
"""
TEST_HTML = '<p>Hello, world!</p>' # pylint: disable=invalid-name
fragment = Fragment()
fragment.add_content(TEST_HTML)
self.assertEqual(fragment.body_html(), TEST_HTML)

0 comments on commit 2ae4557

Please sign in to comment.