Permalink
Browse files

Merge pull request #1 from pokutnik/master

Support staticfiles.
  • Loading branch information...
2 parents ed03925 + d420363 commit e8b71ea1acee89eb5b45aa930179aa1404c15e53 @lambdalisue committed Apr 10, 2012
Showing with 27 additions and 23 deletions.
  1. +1 −0 .gitignore
  2. 0 codemirror/{javascript → static}/codemirror/LICENSE
  3. 0 codemirror/{javascript → static}/codemirror/bigtest.html
  4. 0 codemirror/{javascript → static}/codemirror/compress.html
  5. 0 codemirror/{javascript → static}/codemirror/contrib/csharp/css/csharpcolors.css
  6. 0 codemirror/{javascript → static}/codemirror/contrib/csharp/index.html
  7. 0 codemirror/{javascript → static}/codemirror/contrib/csharp/js/parsecsharp.js
  8. 0 codemirror/{javascript → static}/codemirror/contrib/csharp/js/tokenizecsharp.js
  9. 0 codemirror/{javascript → static}/codemirror/contrib/freemarker/LICENSE
  10. 0 codemirror/{javascript → static}/codemirror/contrib/freemarker/css/freemarkercolors.css
  11. 0 codemirror/{javascript → static}/codemirror/contrib/freemarker/index.html
  12. 0 codemirror/{javascript → static}/codemirror/contrib/freemarker/js/parsefreemarker.js
  13. 0 codemirror/{javascript → static}/codemirror/contrib/groovy/index.html
  14. 0 codemirror/{javascript → static}/codemirror/contrib/java/LICENSE
  15. 0 codemirror/{javascript → static}/codemirror/contrib/java/css/javacolors.css
  16. 0 codemirror/{javascript → static}/codemirror/contrib/java/index.html
  17. 0 codemirror/{javascript → static}/codemirror/contrib/java/js/parsejava.js
  18. 0 codemirror/{javascript → static}/codemirror/contrib/java/js/tokenizejava.js
  19. 0 codemirror/{javascript → static}/codemirror/contrib/lua/LICENSE
  20. 0 codemirror/{javascript → static}/codemirror/contrib/lua/css/luacolors.css
  21. 0 codemirror/{javascript → static}/codemirror/contrib/lua/index.html
  22. 0 codemirror/{javascript → static}/codemirror/contrib/lua/js/parselua.js
  23. 0 codemirror/{javascript → static}/codemirror/contrib/ometa/LICENSE
  24. 0 codemirror/{javascript → static}/codemirror/contrib/ometa/css/ometacolors.css
  25. 0 codemirror/{javascript → static}/codemirror/contrib/ometa/index.html
  26. 0 codemirror/{javascript → static}/codemirror/contrib/ometa/js/parseometa.js
  27. 0 codemirror/{javascript → static}/codemirror/contrib/ometa/js/tokenizeometa.js
  28. 0 codemirror/{javascript → static}/codemirror/contrib/php/LICENSE
  29. 0 codemirror/{javascript → static}/codemirror/contrib/php/css/phpcolors.css
  30. 0 codemirror/{javascript → static}/codemirror/contrib/php/index.html
  31. 0 codemirror/{javascript → static}/codemirror/contrib/php/js/parsephp.js
  32. 0 codemirror/{javascript → static}/codemirror/contrib/php/js/parsephphtmlmixed.js
  33. 0 codemirror/{javascript → static}/codemirror/contrib/php/js/tokenizephp.js
  34. 0 codemirror/{javascript → static}/codemirror/contrib/plsql/LICENSE
  35. 0 codemirror/{javascript → static}/codemirror/contrib/plsql/css/plsqlcolors.css
  36. 0 codemirror/{javascript → static}/codemirror/contrib/plsql/index.html
  37. 0 codemirror/{javascript → static}/codemirror/contrib/plsql/js/parseplsql.js
  38. 0 codemirror/{javascript → static}/codemirror/contrib/python/LICENSE
  39. 0 codemirror/{javascript → static}/codemirror/contrib/python/css/pythoncolors.css
  40. 0 codemirror/{javascript → static}/codemirror/contrib/python/index.html
  41. 0 codemirror/{javascript → static}/codemirror/contrib/python/js/parsepython.js
  42. 0 codemirror/{javascript → static}/codemirror/contrib/regex/css/js-regexcolors.css
  43. 0 codemirror/{javascript → static}/codemirror/contrib/regex/css/regexcolors.css
  44. 0 codemirror/{javascript → static}/codemirror/contrib/regex/index.html
  45. 0 codemirror/{javascript → static}/codemirror/contrib/regex/js-regex.html
  46. 0 codemirror/{javascript → static}/codemirror/contrib/regex/js/parsejavascript_and_regex.js
  47. 0 codemirror/{javascript → static}/codemirror/contrib/regex/js/parseregex-unicode.js
  48. 0 codemirror/{javascript → static}/codemirror/contrib/regex/js/parseregex.js
  49. 0 codemirror/{javascript → static}/codemirror/contrib/scheme/LICENSE
  50. 0 codemirror/{javascript → static}/codemirror/contrib/scheme/css/schemecolors.css
  51. 0 codemirror/{javascript → static}/codemirror/contrib/scheme/index.html
  52. 0 codemirror/{javascript → static}/codemirror/contrib/scheme/js/parsescheme.js
  53. 0 codemirror/{javascript → static}/codemirror/contrib/scheme/js/tokenizescheme.js
  54. 0 codemirror/{javascript → static}/codemirror/contrib/sql/LICENSE
  55. 0 codemirror/{javascript → static}/codemirror/contrib/sql/css/sqlcolors.css
  56. 0 codemirror/{javascript → static}/codemirror/contrib/sql/index.html
  57. 0 codemirror/{javascript → static}/codemirror/contrib/sql/js/parsesql.js
  58. 0 codemirror/{javascript → static}/codemirror/contrib/xquery/LICENSE
  59. 0 codemirror/{javascript → static}/codemirror/contrib/xquery/css/xqcolors-dark.css
  60. 0 codemirror/{javascript → static}/codemirror/contrib/xquery/css/xqcolors.css
  61. 0 codemirror/{javascript → static}/codemirror/contrib/xquery/css/xqcolors2.css
  62. 0 codemirror/{javascript → static}/codemirror/contrib/xquery/index.html
  63. 0 codemirror/{javascript → static}/codemirror/contrib/xquery/js/parsexquery.js
  64. 0 codemirror/{javascript → static}/codemirror/contrib/xquery/js/tokenizexquery.js
  65. BIN codemirror/{javascript → static}/codemirror/css/baboon.png
  66. 0 codemirror/{javascript → static}/codemirror/css/baboon_vector.ai
  67. 0 codemirror/{javascript → static}/codemirror/css/csscolors.css
  68. 0 codemirror/{javascript → static}/codemirror/css/docs.css
  69. 0 codemirror/{javascript → static}/codemirror/css/font.js
  70. 0 codemirror/{javascript → static}/codemirror/css/jscolors.css
  71. BIN codemirror/{javascript → static}/codemirror/css/people.jpg
  72. 0 codemirror/{javascript → static}/codemirror/css/sparqlcolors.css
  73. 0 codemirror/{javascript → static}/codemirror/css/xmlcolors.css
  74. 0 codemirror/{javascript → static}/codemirror/csstest.html
  75. 0 codemirror/{javascript → static}/codemirror/faq.html
  76. BIN codemirror/{javascript → static}/codemirror/favicon.ico
  77. 0 codemirror/{javascript → static}/codemirror/googleb196c451afc2ee11.html
  78. 0 codemirror/{javascript → static}/codemirror/googlehostedservice.html
  79. 0 codemirror/{javascript → static}/codemirror/highlight.html
  80. 0 codemirror/{javascript → static}/codemirror/htmltest.html
  81. 0 codemirror/{javascript → static}/codemirror/index.html
  82. 0 codemirror/{javascript → static}/codemirror/js/codemirror.js
  83. 0 codemirror/{javascript → static}/codemirror/js/editor.js
  84. 0 codemirror/{javascript → static}/codemirror/js/highlight.js
  85. 0 codemirror/{javascript → static}/codemirror/js/mirrorframe.js
  86. 0 codemirror/{javascript → static}/codemirror/js/parsecss.js
  87. 0 codemirror/{javascript → static}/codemirror/js/parsedummy.js
  88. 0 codemirror/{javascript → static}/codemirror/js/parsehtmlmixed.js
  89. 0 codemirror/{javascript → static}/codemirror/js/parsejavascript.js
  90. 0 codemirror/{javascript → static}/codemirror/js/parsesparql.js
  91. 0 codemirror/{javascript → static}/codemirror/js/parsexml.js
  92. 0 codemirror/{javascript → static}/codemirror/js/select.js
  93. 0 codemirror/{javascript → static}/codemirror/js/stringstream.js
  94. 0 codemirror/{javascript → static}/codemirror/js/tokenize.js
  95. 0 codemirror/{javascript → static}/codemirror/js/tokenizejavascript.js
  96. 0 codemirror/{javascript → static}/codemirror/js/undo.js
  97. 0 codemirror/{javascript → static}/codemirror/js/unittests.js
  98. 0 codemirror/{javascript → static}/codemirror/js/util.js
  99. 0 codemirror/{javascript → static}/codemirror/jstest.html
  100. 0 codemirror/{javascript → static}/codemirror/manual.html
  101. 0 codemirror/{javascript → static}/codemirror/mixedtest.html
  102. 0 codemirror/{javascript → static}/codemirror/sparqltest.html
  103. 0 codemirror/{javascript → static}/codemirror/story.html
  104. 0 codemirror/{javascript → static}/codemirror/unittests.html
  105. 0 codemirror/{javascript → static}/codemirror/xhtmltest.xhtml
  106. 0 codemirror/templates/codemirror/.tmp_javascript.html.5964~
  107. +26 −23 codemirror/widgets.py
View
@@ -1,3 +1,4 @@
/build
/dist
/*.egg-info
+*.pyc
View
@@ -3,23 +3,21 @@
# Created: 2010/09/09
# Author: alisue
#
+import simplejson as json
from django import forms
from django.conf import settings
from django.template.loader import render_to_string
from django.contrib.admin.widgets import AdminTextareaWidget
from django.utils.safestring import mark_safe
from django.core.exceptions import ImproperlyConfigured
-# check is configured correctly
-if not hasattr(settings, "CODEMIRROR_PATH"):
- raise ImproperlyConfigured("You must define the CODEMIRROR_PATH before using the CodeMirrorTextarea.")
-
-if settings.CODEMIRROR_PATH.endswith('/'):
- settings.CODEMIRROR_PATH = settings.CODEMIRROR_PATH[:-1]
# set default settings
-settings.CODEMIRROR_DEFAULT_PARSERFILE = getattr(settings, 'CODEMIRROR_DEFAULT_PARSERFILE', 'parsedummy.js')
-settings.CODEMIRROR_DEFAULT_STYLESHEET = getattr(settings, 'CODEMIRROR_DEFAULT_STYLESHEET', '')
+CODEMIRROR_PATH = getattr(settings, 'CODEMIRROR_PATH', 'codemirror')
+if CODEMIRROR_PATH.endswith('/'):
+ CODEMIRROR_PATH = CODEMIRROR_PATH[:-1]
+CODEMIRROR_DEFAULT_PARSERFILE = getattr(settings, 'CODEMIRROR_DEFAULT_PARSERFILE', 'parsedummy.js')
+CODEMIRROR_DEFAULT_STYLESHEET = getattr(settings, 'CODEMIRROR_DEFAULT_STYLESHEET', '')
class CodeMirrorTextarea(forms.Textarea):
u"""Textarea widget render with `CodeMirror`
@@ -31,7 +29,7 @@ class CodeMirrorTextarea(forms.Textarea):
class Media:
css = {}
js = (
- r"%s/codemirror.js" % settings.CODEMIRROR_PATH,
+ r"%s/js/codemirror.js" % CODEMIRROR_PATH,
)
def __init__(self, attrs=None, path=None, parserfile=None, stylesheet=None, **kwargs):
@@ -44,28 +42,29 @@ def __init__(self, attrs=None, path=None, parserfile=None, stylesheet=None, **kw
Example:
*-------------------------------*
- + javascript
+ + static
+ codemirror
+ css
- xmlcolors.css
+ js
- codemirror.js
- parsexml.js
*-------------------------------*
- settings.CODEMIRROR_PATH = r"javascript/codemirror/js"
+ CODEMIRROR_PATH = r"codemirror"
codemirror = CodeMirrorTextarea(
# parserfile='parsexml.js', # Can be written as the left when only one file is needed.
parserfile=['parsexml.js'],
- # stylesheet=r'javascript/codemirror/css/xmlcolors.css' # Can be written as the left when only one file is needed.
- stylesheet=[r'javascript/codemirror/css/xmlcolors.css'],
+ # stylesheet=r'xmlcolors.css' # Can be written as the left when only one file is needed.
+ stylesheet=[r'css/xmlcolors.css'],
)
document = forms.TextField(widget=codemirror)
"""
super(CodeMirrorTextarea, self).__init__(attrs=attrs, **kwargs)
- self.path = path or settings.CODEMIRROR_PATH
- self.parserfile = parserfile or settings.CODEMIRROR_DEFAULT_PARSERFILE
- self.stylesheet = stylesheet or settings.CODEMIRROR_DEFAULT_STYLESHEET
+ self.path = path or settings.STATIC_URL + CODEMIRROR_PATH + '/js/'
+ self.parserfile = parserfile or CODEMIRROR_DEFAULT_PARSERFILE
+ self.stylesheet = stylesheet or CODEMIRROR_DEFAULT_STYLESHEET
+ self.stylesheet = [settings.STATIC_URL + CODEMIRROR_PATH + '/' + css for css in self.stylesheet]
if not hasattr(self.parserfile, '__iter__'):
self.parserfile = (self.parserfile,)
if not hasattr(self.stylesheet, '__iter__'):
@@ -75,19 +74,23 @@ def render(self, name, value, attrs=None):
u"""Render CodeMirrorTextarea"""
html = super(CodeMirrorTextarea, self).render(name, value, attrs)
kwargs = {
- 'id': "\"id_%s\""%name,
- 'path': "\"%s%s/\""%(settings.MEDIA_URL, self.path),
- 'parserfile': "[%s]" % (", ".join(["\"%s\""%x for x in self.parserfile])),
- 'stylesheet': "[%s]" % (", ".join(["\"%s%s\""%(settings.MEDIA_URL,x) for x in self.stylesheet])),
+ 'id': '"id_%s"' % name,
+ 'path': json.dumps(self.path),
+ 'parserfile': json.dumps(self.parserfile),
+ 'stylesheet': json.dumps(self.stylesheet),
}
- if self.stylesheet == []:
- kwargs['stylesheet'] = '""'
for key in kwargs.keys():
kwargs[key] = mark_safe(kwargs[key])
code = render_to_string(r"codemirror/javascript.html", kwargs)
body = "%s\n%s" % (html, code)
return mark_safe(body)
-
+
class AdminCodeMirrorTextareaWidget(CodeMirrorTextarea, AdminTextareaWidget):
u"""CodeMirrorTextarea for Admin site"""
pass
+
+class AdminHTMLEditor(AdminCodeMirrorTextareaWidget):
+ def __init__(self, *args, **kwargs):
+ kwargs['parserfile'] = ["parsexml.js", "parsecss.js", "tokenizejavascript.js", "parsejavascript.js", "parsehtmlmixed.js"]
+ kwargs['stylesheet'] = ["css/xmlcolors.css", "css/jscolors.css", "css/csscolors.css"]
+ super(AdminHTMLEditor, self).__init__(*args, **kwargs)

0 comments on commit e8b71ea

Please sign in to comment.