Commit c929fb53 authored by Jérome Perrin's avatar Jérome Perrin

erp5: add monaco-editor as code editor

parent 48d66e8e
...@@ -6,4 +6,7 @@ if getattr(context.portal_skins, "erp5_ace_editor", None) is not None: ...@@ -6,4 +6,7 @@ if getattr(context.portal_skins, "erp5_ace_editor", None) is not None:
if getattr(context.portal_skins, "erp5_code_mirror", None) is not None: if getattr(context.portal_skins, "erp5_code_mirror", None) is not None:
editor_list.append(("Code Mirror", "codemirror")) editor_list.append(("Code Mirror", "codemirror"))
if getattr(context.portal_skins, "erp5_monaco_editor", None) is not None:
editor_list.append(("Monaco Editor", "monaco"))
return editor_list return editor_list
...@@ -119,6 +119,24 @@ class EditorWidget(Widget.TextAreaWidget): ...@@ -119,6 +119,24 @@ class EditorWidget(Widget.TextAreaWidget):
return ace_editor_support.pt_render(extra_context={'field': field, return ace_editor_support.pt_render(extra_context={'field': field,
'content': value, 'content': value,
'id': key}) 'id': key})
elif text_editor == 'monaco':
monaco_editor_support = getattr(here, 'monaco_editor_support', None)
if monaco_editor_support is not None:
mode = "python"
portal_type = here.getPortalType()
if portal_type == "Web Page":
mode = "htmlmixed"
elif portal_type == "Web Script":
mode = "javascript"
elif portal_type == "Web Style":
mode = "css"
site_root = here.getWebSiteValue() or here.getPortalObject()
return monaco_editor_support(
field=field,
content=value,
field_id=key,
portal_url=site_root.absolute_url(),
mode=mode)
elif text_editor == 'codemirror': elif text_editor == 'codemirror':
code_mirror_support = getattr(here, 'code_mirror_support', None) code_mirror_support = getattr(here, 'code_mirror_support', None)
if code_mirror_support is not None: if code_mirror_support is not None:
......
...@@ -19,7 +19,7 @@ def manage_page_footer(self): ...@@ -19,7 +19,7 @@ def manage_page_footer(self):
except: except:
editor = None editor = None
if editor not in ('ace', 'codemirror'): if editor not in ('ace', 'codemirror', 'monaco'):
return default return default
# REQUEST['PUBLISHED'] can be the form in the acquisition context of the # REQUEST['PUBLISHED'] can be the form in the acquisition context of the
...@@ -92,6 +92,16 @@ def manage_page_footer(self): ...@@ -92,6 +92,16 @@ def manage_page_footer(self):
portal_url=portal_url, portal_url=portal_url,
bound_names=bound_names, bound_names=bound_names,
mode=mode)) mode=mode))
if editor == 'monaco' and getattr(portal, 'monaco_editor_support', None) is not None:
return '''<script type="text/javascript" src="%s/jquery/core/jquery.min.js"></script>
%s
</body>
</html>''' % (portal_url,
portal.monaco_editor_support(
textarea_selector=textarea_selector,
portal_url=portal_url,
bound_names=bound_names,
mode=mode))
else: else:
return ''' return '''
<script type="text/javascript" src="%(portal_url)s/jquery/core/jquery.min.js"></script> <script type="text/javascript" src="%(portal_url)s/jquery/core/jquery.min.js"></script>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment