In [10]:
%%html
<link rel="stylesheet" type="text/css" href="theme/sixty_north.css">
Let's look at an example showing the Elm architecture.
def do_execute(self, code, . . .):
self._code.append(code)
if self._should_compile:
try:
code = "\n".join(self._code)
self._code = []
self._compile(code)
except Exception as exc:
self._send_error_result(str(exc))
return {'status': 'error' . . . }
return {'status': 'ok' . . . }
def _compile(self, code):
with self._tempfile('input.elm') as infile,\
self._tempfile('index.js') as outfile:
with open(infile, mode='wt') as f:
f.write(code)
try:
# compile in a subprocess (next slide)
except subprocess.CalledProcessError as err:
self._send_error_result(err.stdout)
except Exception as err:
self._send_error_result(repr(err))
raise
subprocess.run(
['elm-make', infile, '--yes', '--output={}'.format(outfile)],
cwd=self._tempdir.name,
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
encoding=sys.getdefaultencoding())
with open(outfile, mode='rt') as f:
javascript = f.read()
self._send_success_result(javascript)
module_name = "Main"
div_id = 'elm-div-' + str(self.execution_count)
template = """
var defineElm = function(cb) {{
if (this.Elm) {{
this.oldElm = this.Elm;
}}
var define = null;
{js}
cb();
}};
var obj = new Object();
defineElm.bind(obj)(function(){{
var mountNode = document.getElementById('{div_id}');
obj.Elm. {module_name}.embed(mountNode);
}});"""
elm-package.jsonYou can find everything at the github project page: https://github.com/abingham/jupyter-elm-kernel
You can help with: