You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
939 B

4 years ago
  1. from traitlets import Unicode
  2. from ipywidgets import DOMWidget
  3. from ._version import semver
  4. class VueComponent(DOMWidget):
  5. _model_name = Unicode('VueComponentModel').tag(sync=True)
  6. _model_module = Unicode('jupyter-vue').tag(sync=True)
  7. _model_module_version = Unicode(semver).tag(sync=True)
  8. name = Unicode().tag(sync=True)
  9. component = Unicode().tag(sync=True)
  10. vue_component_registry = {}
  11. def register_component_from_string(name, value):
  12. components = vue_component_registry
  13. if name in components.keys():
  14. comp = components[name]
  15. comp.component = value
  16. else:
  17. comp = VueComponent(name=name, component=value)
  18. components[name] = comp
  19. def register_component_from_file(self, name, file_name):
  20. with open(file_name) as f:
  21. register_component_from_string(name, f.read())
  22. __all__ = ['VueComponent', 'register_component_from_string', 'register_component_from_file']