Pārlūkot izejas kodu

Start work on serializing; clean up languages.

tags/v1.0^2
Ben Kurtovic pirms 10 gadiem
vecāks
revīzija
326be3050f
3 mainītis faili ar 18 papildinājumiem un 3 dzēšanām
  1. +15
    -0
      bitshift/codelet.py
  2. +0
    -0
      bitshift/languages.json
  3. +3
    -3
      bitshift/languages.py

+ 15
- 0
bitshift/codelet.py Parādīt failu

@@ -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 Parādīt failu


+ 3
- 3
bitshift/languages.py Parādīt failu

@@ -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"]]

Notiek ielāde…
Atcelt
Saglabāt