Skip to content

Commit

Permalink
Merge pull request #31 from EmpowrOrg/dev
Browse files Browse the repository at this point in the history
Beta 1
  • Loading branch information
dri94 authored Aug 8, 2022
2 parents 0398476 + 58c5692 commit 2b6fe43
Show file tree
Hide file tree
Showing 17 changed files with 775 additions and 120 deletions.
Binary file added .DS_Store
Binary file not shown.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ venv.bak/
.spyproject

# Rope project settings
.ropeproject
.ropeprojectig

# mkdocs documentation
/site
Expand All @@ -129,3 +129,4 @@ dmypy.json
.pyre/

.DS_Store
.idea/
94 changes: 91 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,37 @@

An XBlock for Empowr's course platform that allows for the input and checking of any programming language.

![Code Editor Screenshot](code-editor.png)

<!-- TOC -->
* [CodeEditorXblock](#codeeditorxblock)
* [TODO](#todo)
* [Installation](#installation)
* [Run the Django development server](#run-the-django-development-server)
* [Supported Languages](#supported-languages)
* [Adding support for a language](#adding-support-for-a-language)
* [To find the mime-type](#to-find-the-mime-type)
* [To find the url](#to-find-the-url)
<!-- TOC -->


## TODO

- Fix Solution Tab. Most work for a solution tab is done, however it doesn't properly display.
- Add support for all CodeMirror languages. This is an easy task, just tedious.

## Installation

1. Make sure you have have Python 3.8 installed on your computer.

2. Clone the repo with `git clone --recurse-submodules [email protected]:EmpowrOrg/CodeEditorXblock.git`. This will give you the repo including the xblock-sdk submodule.
2. Clone the repo with `git clone --recurse-submodules [email protected]:EmpowrOrg/CodeEditorXblock.git`. This will give
you the repo including the xblock-sdk submodule.

3. Create and Activate the Virtual Environment:

You must have a virtual environment tool installed on your computer. For more information, see [Install XBlock Prerequisites](https://edx.readthedocs.io/projects/xblock-tutorial/en/latest/getting_started/prereqs.html).
You must have a virtual environment tool installed on your computer. For more information,
see [Install XBlock Prerequisites](https://edx.readthedocs.io/projects/xblock-tutorial/en/latest/getting_started/prereqs.html)
.

Then create the virtual environment in your CodeEditorXblock directory.

Expand All @@ -22,11 +44,15 @@ Run the following command to activate the virtual environment.

`source venv/bin/activate`

Install the plugin with

`pip install -e swiftplugin`

4. Navigate to the xblock-sdk directory and run the following command to install the requirements.

`pip install -r requirements/base.txt`

## Run the Django development server
### Run the Django development server

Navigate to the xblock-sdk directory and run the following commands.

Expand All @@ -35,3 +61,65 @@ Navigate to the xblock-sdk directory and run the following commands.
`python manage.py migrate`

`python manage.py runserver`

## Supported Languages

When specifying a language you must put in the correct mime-type for the plugin. Here all the supported languages and
their mime-types

| Language Name | Mime-Type |
|---------------|-------------------|
| APL | text/apl |
| ASN.1 | text/x-ttcn-asn |
| C | text/x-csrc |
| C++ | text/x-c++src |
| C# | text/x-csharp |
| Java | text/x-java |
| Kotlin | text/x-kotlin |
| Python | text/x-python |
| Scala | text/x-scala |
| Squirrel | text/x-squirrel |
| Swift | text/x-swift |
| Objective-C | text/x-objectivec |


Code Mirror supports many more languages. If you do not see your language supported just check out the
[doc](https://codemirror.net/5/mode/).

### Adding support for a language

It's really simple to add plugin support for
any [language already supported by CodeMirror](https://codemirror.net/5/mode/).
Open ![swiftplugin.py](/swiftplugin/swiftplugin/swiftplugin.py) and scroll down to the dictionary of mime-types and
urls.

To add support you need both the mime-type and the url.

#### To find the mime-type
Add the mime-type you wish to add support for. You can find this by looking at the list of supported languages, clicking
on the langauge you want, and then scrolling to the bottom of the page.
Ex: `text/x-kotlin`

#### To find the url
You can find the url needed by going to
the [CodeMirror git folder for their supported modes](https://github.com/codemirror/codemirror5/blob/master/mode/index.html)

Look for the folder name of the language you wish to support.

Ex: If you want to add Kotlin, then you search for Kotlin in the file, and see it's folder name
is `clike`.
Ex:`<li><a href="clike/index.html">Kotlin</a></li>`

Go [here](https://github.com/codemirror/codemirror5/tree/master/mode) and click into the folder name you just discovered
of the language you wish to support.

Notice the name of the `.js` file in this folder.
Ex: If you were adding Kotlin, the js is `clike.js`

Now just append the folder name and the .js name to this
path `https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.2/mode/`

The final Url for Kotlin would look like: `https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.2/mode/clike/clike.js`

And now you can just add the mime-type and url to the dictionary like
`"text/x-kotlin": "https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.2/mode/clike/clike.js",`
Binary file added code-editor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion codingxblock/codingxblock/__init__.py

This file was deleted.

82 changes: 0 additions & 82 deletions codingxblock/codingxblock/codingxblock.py

This file was deleted.

1 change: 0 additions & 1 deletion codingxblock/codingxblock/static/css/codingxblock.css

This file was deleted.

4 changes: 0 additions & 4 deletions codingxblock/codingxblock/static/html/codingxblock.html

This file was deleted.

22 changes: 0 additions & 22 deletions codingxblock/codingxblock/static/js/src/codingxblock.js

This file was deleted.

13 changes: 7 additions & 6 deletions codingxblock/setup.py → swiftplugin/setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Setup for codingxblock XBlock."""
"""Setup for swiftplugin XBlock."""


import os
Expand All @@ -23,20 +23,21 @@ def package_data(pkg, roots):


setup(
name='codingxblock-xblock',
name='swiftplugin-xblock',
version='0.1',
description='codingxblock XBlock', # TODO: write a better description.
description='swiftplugin XBlock', # TODO: write a better description.
license='UNKNOWN', # TODO: choose a license: 'AGPL v3' and 'Apache 2.0' are popular.
packages=[
'codingxblock',
'swiftplugin',
],
install_requires=[
'XBlock',
'xblock-utils'
],
entry_points={
'xblock.v1': [
'codingxblock = codingxblock:CodeEditorXBlock',
'swiftplugin = swiftplugin:SwiftPluginXBlock',
]
},
package_data=package_data("codingxblock", ["static", "public"]),
package_data=package_data("swiftplugin", ["static", "public"]),
)
1 change: 1 addition & 0 deletions swiftplugin/swiftplugin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .swiftplugin import SwiftPluginXBlock
File renamed without changes.
Loading

0 comments on commit 2b6fe43

Please sign in to comment.