Browse Source

Start work on serializing; clean up languages.

tags/v1.0^2
Ben Kurtovic 10 years ago
parent
commit
326be3050f
3 changed files with 18 additions and 3 deletions
  1. +15
    -0
      bitshift/codelet.py
  2. +0
    -0
      bitshift/languages.json
  3. +3
    -3
      bitshift/languages.py

+ 15
- 0
bitshift/codelet.py View File

@@ -1,3 +1,7 @@
import json

from .languages import LANGS

__all__ = ["Codelet"]

class Codelet(object):
@@ -65,3 +69,14 @@ class Codelet(object):
self.rank = rank
self.symbols = symbols or {}
self.origin = origin or (None, None, None)

def serialize(self):
"""
Convert the codelet into a JSON string representation for the frontend.

:return: The JSON codelet representation.
:rtype: str
"""
lang = LANGS[self.language]
data = {"name": self.name, "code": self.code, "lang": lang}
return json.dumps(data)

bitshift/resources/languages.json → bitshift/languages.json View File


+ 3
- 3
bitshift/languages.py View File

@@ -1,5 +1,5 @@
import json
from os import path

with open("bitshift/resources/languages.json") as lang_json:
LANGS = [lang.encode("ascii","ignore") for lang in
json.load(lang_json)["languages"]]
with open(path.join(path.dirname(__file__), "languages.json")) as lang_json:
LANGS = [lang for lang in json.load(lang_json)["languages"]]

Loading…
Cancel
Save