Skip to content

Commit

Permalink
feat: Adds word cloud xblock extracting from edx-platform repo
Browse files Browse the repository at this point in the history
  • Loading branch information
farhan committed Jul 30, 2024
1 parent b5c2a62 commit 04617f2
Show file tree
Hide file tree
Showing 14 changed files with 1,323 additions and 0 deletions.
1 change: 1 addition & 0 deletions setup.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ def package_data(pkg, roots, sub_roots):
"xblock.v1": [
# _xblock suffix is added for testing only.
"poll_xblock = xblocks_contrib:PollXBlock",
"word_cloud = xblocks_contrib:WordCloudXBlock",
]
},
package_data=package_data(
Expand Down
2 changes: 2 additions & 0 deletions xblocks_contrib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@

from .poll import PollXBlock

from .word_cloud import WordCloudXBlock

__version__ = "0.1.0"
8 changes: 8 additions & 0 deletions xblocks_contrib/word_cloud/.tx/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[main]
host = https://www.transifex.com

[o:open-edx:p:p:xblocks:r:word_cloud]
file_filter = word_cloud/translations/<lang>/LC_MESSAGES/text.po
source_file = word_cloud/translations/en/LC_MESSAGES/text.po
source_lang = en
type = PO
1 change: 1 addition & 0 deletions xblocks_contrib/word_cloud/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .word_cloud import WordCloudXBlock
Empty file.
93 changes: 93 additions & 0 deletions xblocks_contrib/word_cloud/conf/locale/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Configuration for i18n workflow.

locales:
- en # English - Source Language
# - am # Amharic
- ar # Arabic
# - az # Azerbaijani
# - bg_BG # Bulgarian (Bulgaria)
# - bn_BD # Bengali (Bangladesh)
# - bn_IN # Bengali (India)
# - bs # Bosnian
# - ca # Catalan
# - ca@valencia # Catalan (Valencia)
# - cs # Czech
# - cy # Welsh
# - da # Danish
# - de_DE # German (Germany)
# - el # Greek
# - en_GB # English (United Kingdom)
# # Don't pull these until we figure out why pages randomly display in these locales,
# # when the user's browser is in English and the user is not logged in.
# #- en@lolcat # LOLCAT English
# #- en@pirate # Pirate English
- es_419 # Spanish (Latin America)
# - es_AR # Spanish (Argentina)
# - es_EC # Spanish (Ecuador)
# - es_ES # Spanish (Spain)
# - es_MX # Spanish (Mexico)
# - es_PE # Spanish (Peru)
# - et_EE # Estonian (Estonia)
# - eu_ES # Basque (Spain)
# - fa # Persian
# - fa_IR # Persian (Iran)
# - fi_FI # Finnish (Finland)
# - fil # Filipino
- fr # French
# - gl # Galician
# - gu # Gujarati
- he # Hebrew
- hi # Hindi
# - hr # Croatian
# - hu # Hungarian
# - hy_AM # Armenian (Armenia)
# - id # Indonesian
# - it_IT # Italian (Italy)
# - ja_JP # Japanese (Japan)
# - kk_KZ # Kazakh (Kazakhstan)
# - km_KH # Khmer (Cambodia)
# - kn # Kannada
- ko_KR # Korean (Korea)
# - lt_LT # Lithuanian (Lithuania)
# - ml # Malayalam
# - mn # Mongolian
# - mr # Marathi
# - ms # Malay
# - nb # Norwegian Bokmål
# - ne # Nepali
# - nl_NL # Dutch (Netherlands)
# - or # Oriya
# - pl # Polish
- pt_BR # Portuguese (Brazil)
# - pt_PT # Portuguese (Portugal)
# - ro # Romanian
- ru # Russian
# - si # Sinhala
# - sk # Slovak
# - sl # Slovenian
# - sq # Albanian
# - sr # Serbian
# - sv # Swedish
# - sw # Swahili
# - ta # Tamil
# - te # Telugu
# - th # Thai
# - tr_TR # Turkish (Turkey)
# - uk # Ukranian
# - ur # Urdu
# - uz # Uzbek
# - vi # Vietnamese
- zh_CN # Chinese (China)
# - zh_HK # Chinese (Hong Kong)
# - zh_TW # Chinese (Taiwan)


# The locales used for fake-accented English, for testing.
dummy_locales:
- eo
- rtl # Fake testing language for Arabic

# Directories we don't search for strings.
ignore_dirs:
- '*/css'
- 'public/js/translations'
19 changes: 19 additions & 0 deletions xblocks_contrib/word_cloud/static/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
This static directory is for files that should be included in your kit as plain
static files.

You can ask the runtime for a URL that will retrieve these files with:

url = self.runtime.local_resource_url(self, "static/js/lib.js")

The default implementation is very strict though, and will not serve files from
the static directory. It will serve files from a directory named "public".
Create a directory alongside this one named "public", and put files there.
Then you can get a url with code like this:

url = self.runtime.local_resource_url(self, "public/js/lib.js")

The sample code includes a function you can use to read the content of files
in the static directory, like this:

frag.add_javascript(self.resource_string("static/js/my_block.js"))

29 changes: 29 additions & 0 deletions xblocks_contrib/word_cloud/static/css/word_cloud_xblock.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* CSS for WordCloudXBlock */

@import url("https://fonts.googleapis.com/css?family=Open+Sans:300,400,400i,600,700");

.input-cloud {
margin: 5px;
}

.result_cloud_section {
display: none;
width: 0;
height: 0;
}

.result_cloud_section.active {
display: block;
width: 100%;
height: auto;
margin-top: 1em;
}

.result_cloud_section.active h3 {
font-size: 100%;
}

.your_words {
font-size: 0.85em;
display: block;
}
49 changes: 49 additions & 0 deletions xblocks_contrib/word_cloud/static/html/word_cloud_xblock.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{% load i18n %}

<div
id="word_cloud_{{ element_id }}"
class="word_cloud_block">
{% if display_name %}
<h3 class="hd hd-3" id="word_cloud_{{ element_id }}_heading">{{ display_name }}</h3>
{% endif %}

{% if instructions is not None %}
<div class="input_cloud_section" role="group" aria-labelledby="word_cloud_{{ element_id }}_instructions">
{% elif display_name %}
<div class="input_cloud_section" role="group" aria-labelledby="word_cloud_{{ element_id }}_heading">
{% else %}
<div class="input_cloud_section" role="group">
{% endif %}

{% if instructions is not None %}
<div class="input_cloud_instructions" id="word_cloud_{{ element_id }}_instructions">
{{ instructions }}
</div>
{% endif %}

{% for row in range_num_inputs %}
<label>
<span class="sr">
{% blocktrans with num=row|add:1 %}
{{ num }} of {{ num_inputs }}
{% endblocktrans %}
</span>
<input class="input-cloud" type="text" size="40"
{% if submitted %}style="display: none;"{% endif %}
/>
</label>
{% endfor %}

<div class="action">
<button class="save" type="button">{% trans 'Save' %}</button>
</div>
</div>

<div id="result_cloud_section_{{ element_id }}" class="result_cloud_section">
<div class="word_cloud"></div>
<p class="total_num_words"></p>
<p>{% trans 'Your words were:' %}</p>
<ul class="your_words"></ul>
</div>

</div>
Loading

0 comments on commit 04617f2

Please sign in to comment.