Skip to content

Commit 5965644

Browse files
authored
Merge pull request #686 from openedx/sarina/move-xblock-tutorial
Move xblock tutorial docs to this repo
2 parents 342eef9 + b50287c commit 5965644

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+3105
-20
lines changed

docs/conf.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,12 @@
264264

265265
exclude_patterns = ['api/*', 'links.rst']
266266

267+
# Intersphinx Extension Configuration
268+
267269
intersphinx_mapping = {
268270
'python': ('https://docs.python.org/3', None),
271+
"docs-openedx-org": (
272+
f"https://docs.openedx.org/en/latest",
273+
None,
274+
),
269275
}

docs/index.rst

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
.. _EdX XBlock API Guide:
1+
.. _Open edX XBlock API Guide:
22

3-
#####################
4-
EdX XBlock API Guide
5-
#####################
3+
#########################
4+
Open edX XBlock API Guide
5+
#########################
66

77

88
This document provides reference information on the XBlock API. You use this
99
API to build XBlocks.
1010

11-
EdX also provides the `EdX XBlock Tutorial`_, which describes XBlock concepts
11+
This document also contains the Open edX XBlock Tutorial, which describes XBlock concepts
1212
in depth and guides developers through the process of creating an XBlock.
1313

1414
.. toctree::
@@ -22,6 +22,5 @@ in depth and guides developers through the process of creating an XBlock.
2222
fragment
2323
plugins
2424
exceptions
25+
xblock-tutorial/index
2526
xblock-utils/index
26-
27-
.. _EdX XBlock Tutorial: http://edx.readthedocs.org/projects/xblock-tutorial/en/latest/index.html

docs/introduction.rst

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
.. _Introduction to XBlocks:
2-
3-
#############################
1+
#######################
42
Introduction to XBlocks
5-
#############################
3+
#######################
4+
5+
This section introduces XBlocks.
6+
7+
.. contents::
8+
:local:
9+
:depth: 1
10+
11+
********
12+
Overview
13+
********
614

715
As a developer, you build XBlocks that course teams use to create independent
816
course components that work seamlessly with other components in an online
@@ -14,17 +22,18 @@ can build XBlocks to represent larger structures such as lessons, sections, and
1422
entire courses.
1523

1624
A primary advantage to XBlocks is that they are sharable. The code you write
17-
can be deployed in any instance of the edX Platform or other XBlock runtime
25+
can be deployed in any instance of the Open edX Platform or other XBlock runtime
1826
application, then used by any course team using that system.
1927

20-
By combining XBlocks from a wide variety of sources, from text and video, to
21-
multiple choice and numerical questions, to sophisticated collaborative and
22-
interactive learning laboratories, course teams can create rich and engaging
23-
courseware.
28+
In educational applications, XBlocks can be used to represent individual
29+
problems, web-formatted text and videos, interactive simulations and labs, or
30+
collaborative learning experiences. Furthermore, XBlocks are composable,
31+
allowing an XBlock developer to control the display of other XBlocks to compose
32+
lessons, sections, and entire courses.
2433

25-
*****************************************
34+
****************************************
2635
XBlock Independence and Interoperability
27-
*****************************************
36+
****************************************
2837

2938
You must design your XBlock to meet two goals.
3039

@@ -34,9 +43,9 @@ You must design your XBlock to meet two goals.
3443
* The XBlock must work together with other XBlocks. Course teams must be
3544
able to combine different XBlocks in flexible ways.
3645

37-
*****************************************
46+
************************************
3847
XBlocks Compared to Web Applications
39-
*****************************************
48+
************************************
4049

4150
XBlocks are like miniature web applications: they maintain state in a storage
4251
layer, render themselves through views, and process user actions through

docs/links.rst

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
.. Include this file in any file that includes a non-doc link.
2+
3+
.. _thumbs.py: https://github.com/openedx/xblock-sdk/blob/master/sample_xblocks/thumbs/thumbs.py
4+
5+
.. _thumbs.js: https://github.com/openedx/xblock-sdk/blob/master/sample_xblocks/thumbs/static/js/src/thumbs.js
6+
7+
.. _Thumbs XBlock: https://github.com/openedx/xblock-sdk/tree/master/sample_xblocks/thumbs
8+
9+
.. _1.js: https://github.com/openedx/xblock-sdk/blob/master/workbench/static/workbench/js/runtime/1.js
10+
11+
.. _devstack: https://github.com/openedx/devstack
12+
13+
.. _edx.org: http://edx.org
14+
15+
.. _edx-platform: https://github.com/openedx/edx-platform
16+
17+
.. _RST: http://docutils.sourceforge.net/rst.html
18+
19+
.. _Sphinx: http://sphinx-doc.org/
20+
21+
.. _Download Python: https://www.python.org/downloads/release/python-386/
22+
23+
.. _GitHub Help: https://help.github.com/articles/set-up-git
24+
.. _Git: https://help.github.com/articles/set-up-git
25+
26+
.. _VirtualEnv: http://www.virtualenv.org/en/latest/
27+
28+
.. _Virtual Environments: http://docs.python-guide.org/en/latest/dev/virtualenvs/
29+
30+
.. _VirtualEnv Installation: https://virtualenv.pypa.io/en/latest/installation.html
31+
32+
.. _VirtualEnvWrapper: http://virtualenvwrapper.readthedocs.io/en/latest
33+
34+
.. _XBlock SDK: https://github.com/openedx/xblock-sdk
35+
36+
.. _PyEnv: https://github.com/yyuu/pyenv
37+
38+
.. _Problem XBlock: https://github.com/openedx/xblock-sdk/blob/master/sample_xblocks/basic/problem.py
39+
40+
.. _Content XBlocks: https://github.com/openedx/xblock-sdk/blob/master/sample_xblocks/basic/content.py
41+
42+
.. _Slider XBlock: https://github.com/openedx/xblock-sdk/blob/master/sample_xblocks/basic/slider.py
43+
44+
.. _Structure XBlocks: https://github.com/openedx/xblock-sdk/blob/master/sample_xblocks/basic/structure.py
45+
46+
.. _View Counter XBlock: https://github.com/openedx/xblock-sdk/blob/master/sample_xblocks/basic/view_counter.py
47+
48+
.. _requirements/edx/github.txt: https://github.com/openedx/edx-platform/blob/master/requirements/edx/github.txt
49+
50+
.. _thumbs.html: https://github.com/openedx/xblock-sdk/blob/master/sample_xblocks/thumbs/static/html/thumbs.html
51+
52+
.. _thumbs.css: https://github.com/openedx/xblock-sdk/blob/master/sample_xblocks/thumbs/static/css/thumbs.css
53+
54+
.. _Google Drive file tool: https://edx.readthedocs.io/projects/edx-partner-course-staff/en/latest/exercises_tools/google_docs.html
55+
56+
.. _Open Response Assessments: https://edx.readthedocs.io/projects/edx-partner-course-staff/en/latest/exercises_tools/open_response_assessments/OpenResponseAssessments.html
57+
58+
.. _Google calendar tool: https://edx.readthedocs.io/projects/edx-partner-course-staff/en/latest/exercises_tools/google_calendar.html
59+
60+
.. _Finding the Usage ID for Course Content: https://edx.readthedocs.io/projects/edx-partner-course-staff/en/latest/course_features/lti/lti_address_content.html#finding-the-usage-id-for-course-content
61+
62+
.. _Installing, Configuring, and Running the Open edX Platform: https://edx.readthedocs.io/projects/edx-installing-configuring-and-running/en/latest/index.html
63+
64+
.. _Developing Course Components: https://edx.readthedocs.io/projects/edx-partner-course-staff/en/latest/developing_course/course_components.html
Loading
Loading
427 Bytes
Loading
578 Bytes
Loading
709 Bytes
Loading
66 KB
Loading

docs/xblock-tutorial/anatomy/html.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
.. _The XBlock HTML File:
2+
3+
####################
4+
The XBlock HTML File
5+
####################
6+
7+
This section of the tutorial walks through the HTML file, `thumbs.html`_, that
8+
is part of the Thumbs XBlock in the XBlock SDK.
9+
10+
If you completed the steps in :ref:`Build an XBlock Quick Start`, you can find
11+
this file locally at ``xblock_development/xblock-sdk/sample_xblocks/thumbs/static/html/thumbs.html``.
12+
13+
In the XBlock HTML file, you define the HTML content that is added to a
14+
:ref:`fragment <XBlock Fragments>`. The HTML content can reference the XBlock
15+
:ref:`fields <XBlock Fields>`. The fragment is returned by the :ref:`view
16+
method <View Methods>`, to be displayed by the :ref:`runtime <XBlock
17+
Runtimes>` application.
18+
19+
.. include:: ../reusable/code_thumbs_html.rst
20+
21+
Note the following details about the HTML file.
22+
23+
* The ``class`` values reference styles in the ``thumbs.css`` file. For more
24+
information, see :ref:`The XBlock Stylesheets`.
25+
26+
* The values ``self.upvotes`` and ``self.downvotes`` reference the fields in
27+
the XBlock Python class.
28+
29+
.. include:: ../../links.rst
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.. _Anatomy of an XBlock:
2+
3+
####################
4+
Anatomy of an XBlock
5+
####################
6+
7+
This part of the tutorial explains the XBlock skeleton, and uses examples from
8+
the `Thumbs XBlock`_ that is installed with the XBlock SDK.
9+
10+
The Thumbs XBlock enables learners to vote up or down. The Thumbs XBlock keeps
11+
track of vote totals.
12+
13+
For information about making the XBlock that you created function like the
14+
example Thumbs XBlock, see :ref:`Customize Your XBlock`.
15+
16+
.. toctree::
17+
:maxdepth: 2
18+
19+
python
20+
html
21+
javascript
22+
stylesheets
23+
24+
.. include:: ../../links.rst
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
.. _The XBlock JavaScript File:
2+
3+
##########################
4+
The XBlock JavaScript File
5+
##########################
6+
7+
This section of the tutorial walks through the JavaScript file, `thumbs.js`_,
8+
that is part of the Thumbs XBlock in the XBlock SDK.
9+
10+
If you completed the steps in :ref:`Build an XBlock Quick Start`, you can find
11+
this file locally at ``xblock_development/xblock-sdk/sample_xblocks/thumbs/static/js/source/thumbs.js``.
12+
13+
In the XBlock JavaScript file, you define code that manages user interaction
14+
with the XBlock. The code is added to a :ref:`fragment <XBlock
15+
Fragments>`.
16+
17+
The XBlock’s JavaScript uses the runtime handler, and can use the ``children``
18+
and ``childMap`` functions as needed.
19+
20+
The JavaScript references the XBlock :ref:`fields <XBlock Fields>`
21+
and :ref:`methods <XBlock Methods>`. The fragment is returned by the :ref:`view
22+
method <View Methods>`, to be displayed by the :ref:`runtime <XBlock Runtimes>`
23+
application.
24+
25+
.. include:: ../reusable/code_thumbs_javascript.rst
26+
27+
Note the following details about the JavaScript file.
28+
29+
* The function ``ThumbsBlock`` initializes the XBlock. A JavaScript function to
30+
initialize the XBlock is required.
31+
32+
* The ``ThumbsBlock`` function maps to the contstructor in the :ref:`XBlock
33+
Python file <The XBlock Python File>` and provides access to its methods and
34+
fields.
35+
36+
* The ``ThumbsBlock`` function uses the runtime handler.
37+
38+
.. code-block:: javascript
39+
40+
var handlerUrl = runtime.handlerUrl(element, 'vote');
41+
42+
* The ``ThumbsBlock`` function includes the ``Post`` commands to increase the up
43+
and down votes in the XBlock.
44+
45+
The XBlock JavaScript code can also use the ``children`` and ``childMap``
46+
functions as needed. For more information, see :ref:`XBlock Children`.
47+
48+
.. include:: ../../links.rst
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
.. _The XBlock Python File:
2+
3+
#######################
4+
The XBlock Python File
5+
#######################
6+
7+
This section of the tutorial walks through the Python file, `thumbs.py`_, for
8+
the Thumbs XBlock example in the XBlock SDK.
9+
10+
If you completed the steps in :ref:`Build an XBlock Quick Start`, you can find
11+
this file locally at ``xblock_development/xblock-sdk/sample_xblocks/thumbs/thumbs.py``.
12+
13+
In the XBlock Python file, you define :ref:`fields <XBlock Fields>`,
14+
:ref:`views <View Methods>`, :ref:`handlers <Handler Methods>`, and workbench
15+
scenarios.
16+
17+
.. contents::
18+
:local:
19+
:depth: 1
20+
21+
********************
22+
Thumb XBlock Fields
23+
********************
24+
25+
The ``thumbs.py`` file defines the following fields for the XBlock in the
26+
``ThumbsBlockBase`` class.
27+
28+
.. include:: ../reusable/code_thumbs_fields.rst
29+
30+
Note the following details about the fields in the Thumbs XBlock.
31+
32+
* ``upvotes`` and ``downvotes`` store the cumulative up and down votes of
33+
users.
34+
35+
These fields have the scope ``Scope.user_state_summary``. This indicates that
36+
the data in these fields are specific to the XBlock and the same for all
37+
users.
38+
39+
* ``voted`` stores whether the user has voted. This field has the scope
40+
``Scope.user_state``. This indicates that the data in this field applies to
41+
the XBlock and to the specific user.
42+
43+
For more information, see :ref:`XBlock Fields`.
44+
45+
**************************
46+
Thumb XBlock Student View
47+
**************************
48+
49+
The ``thumbs.py`` file defines the student view for the XBlock in the
50+
``ThumbsBlockBase`` class.
51+
52+
.. include:: ../reusable/code_thumbs_student_view.rst
53+
54+
The student view composes and returns the fragment from static HTML,
55+
JavaScript, and CSS files. A web page displays the fragment to learners.
56+
57+
Note the following details about student view.
58+
59+
* The static HTML content is added when the fragment is initialized.
60+
61+
.. code-block:: python
62+
63+
html_str = pkg_resources.resource_string(__name__, "static/html/thumbs.html")
64+
frag = Fragment(unicode(html_str).format(self=self))
65+
66+
* The JavaScript and CSS file contents are added to the fragment with the
67+
``add_javascript()`` and ``add_css`` methods.
68+
69+
* The JavaScript in the fragment must be initialized using the name of the
70+
XBlock class. The name also maps to the function that initializes the XBlock in the :ref:`JavaScript file <The XBlock JavaScript File>`.
71+
72+
.. code-block:: python
73+
74+
frag.initialize_js('ThumbsBlock')
75+
76+
For more information, see :ref:`View Methods`.
77+
78+
**************************
79+
Thumb XBlock Vote Handler
80+
**************************
81+
82+
The ``thumbs.py`` file defines a handler that adds a user's vote to the XBlock.
83+
84+
.. include:: ../reusable/code_thumbs_vote_handler.rst
85+
86+
Note the following details about the vote handler.
87+
88+
* The ``upvotes`` or ``downvotes`` fields are updated based on the user's vote.
89+
90+
* The ``voted`` field is set to ``True`` for the user.
91+
92+
* The updated ``upvotes`` and ``downvotes`` fields are returned.
93+
94+
For more information, see :ref:`Handler Methods`.
95+
96+
.. include:: ../../links.rst
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.. _The XBlock Stylesheets:
2+
3+
######################
4+
The XBlock Stylesheets
5+
######################
6+
7+
This section of the tutorial walks through the CSS file, `thumbs.css`_, that
8+
is part of the Thumbs XBlock in the XBlock SDK.
9+
10+
If you completed the steps in :ref:`Build an XBlock Quick Start`, you can find
11+
this file locally at ``xblock_development/xblock-sdk/sample_xblocks/thumbs/static/css/thumbs.css``.
12+
13+
In the XBlock CSS file, you define the styles that are added to the
14+
fragment that is returned by the view method to be displayed by the runtime
15+
application.
16+
17+
.. include:: ../reusable/code_thumbs_css.rst
18+
19+
The styles in ``thumbs.css`` are referenced in the :ref:`XBlock HTML file <The
20+
XBlock HTML File>`.
21+
22+
.. include:: ../../links.rst

0 commit comments

Comments
 (0)