# HG changeset patch # User Marcin Kuzminski # Date 1371775352 -7200 # Node ID 647308db13ff859415a00aa1c3e41b2bf659552e # Parent c9bcfe2d2adea517316c11585ed014febda6b4a4 Added codemirror syntax mode in gists. - autopropose file extension when syntax mode is choosen diff -r c9bcfe2d2ade -r 647308db13ff rhodecode/controllers/admin/gists.py --- a/rhodecode/controllers/admin/gists.py Fri Jun 21 01:11:16 2013 +0200 +++ b/rhodecode/controllers/admin/gists.py Fri Jun 21 02:42:32 2013 +0200 @@ -94,10 +94,11 @@ try: form_result = gist_form.to_python(dict(request.POST)) #TODO: multiple files support, from the form + filename = form_result['filename'] or 'gistfile1.txt' nodes = { - form_result['filename'] or 'gistfile1.txt': { + filename: { 'content': form_result['content'], - 'lexer': None # autodetect + 'lexer': form_result['mimetype'] # None is autodetect } } _public = form_result['public'] diff -r c9bcfe2d2ade -r 647308db13ff rhodecode/model/forms.py --- a/rhodecode/model/forms.py Fri Jun 21 01:11:16 2013 +0200 +++ b/rhodecode/model/forms.py Fri Jun 21 02:42:32 2013 +0200 @@ -431,6 +431,7 @@ v.UnicodeString(strip=True, required=False)) description = v.UnicodeString(required=False, if_missing='') lifetime = v.OneOf(lifetime_options) + mimetype = v.UnicodeString(required=False, if_missing=None) content = v.UnicodeString(required=True, not_empty=True) public = v.UnicodeString(required=False, if_missing='') private = v.UnicodeString(required=False, if_missing='') diff -r c9bcfe2d2ade -r 647308db13ff rhodecode/public/js/mode/meta.js --- a/rhodecode/public/js/mode/meta.js Fri Jun 21 01:11:16 2013 +0200 +++ b/rhodecode/public/js/mode/meta.js Fri Jun 21 02:42:32 2013 +0200 @@ -16,7 +16,6 @@ {name: 'ECL', mime: 'text/x-ecl', mode: 'ecl'}, {name: 'Erlang', mime: 'text/x-erlang', mode: 'erlang'}, {name: 'Gas', mime: 'text/x-gas', mode: 'gas'}, - {name: 'GitHub Flavored Markdown', mode: 'gfm'}, {name: 'GO', mime: 'text/x-go', mode: 'go'}, {name: 'Groovy', mime: 'text/x-groovy', mode: 'groovy'}, {name: 'Haskell', mime: 'text/x-haskell', mode: 'haskell'}, @@ -75,3 +74,232 @@ {name: 'YAML', mime: 'text/x-yaml', mode: 'yaml'}, {name: 'Z80', mime: 'text/x-z80', mode: 'z80'} ]; + + +MIME_TO_EXT = { + 'application/javascript': ['*.js'], + 'text/javascript': ['*.js'], + 'application/json': ['*.json'], + 'application/postscript': ['*.ps', '*.eps'], + 'application/x-actionscript': ['*.as'], + 'application/x-actionscript3': ['*.as'], + 'application/x-awk': ['*.awk'], + 'application/x-befunge': ['*.befunge'], + 'application/x-brainfuck': ['*.bf', '*.b'], + 'application/x-cheetah': ['*.tmpl', '*.spt'], + 'application/x-coldfusion': ['*.cfm', '*.cfml', '*.cfc'], + 'application/x-csh': ['*.tcsh', '*.csh'], + 'application/x-dos-batch': ['*.bat', '*.cmd'], + 'application/x-ecl': ['*.ecl'], + 'application/x-evoque': ['*.evoque'], + 'application/x-fantom': ['*.fan'], + 'application/x-genshi': ['*.kid'], + 'application/x-gettext': ['*.pot', '*.po'], + 'application/x-jsp': ['*.jsp'], + 'application/x-mako': ['*.mao'], + 'application/x-mason': ['*.m', '*.mhtml', '*.mc', '*.mi', 'autohandler', 'dhandler'], + 'application/x-myghty': ['*.myt', 'autodelegate'], + 'application/x-php': ['*.phtml'], + 'application/x-pypylog': ['*.pypylog'], + 'application/x-qml': ['*.qml'], + 'application/x-sh': ['*.sh', '*.ksh', '*.bash', '*.ebuild', '*.eclass', '.bashrc', 'bashrc', '.bash_*', 'bash_*'], + 'application/x-sh-session': ['*.shell-session'], + 'application/x-shell-session': ['*.sh-session'], + 'application/x-smarty': ['*.tpl'], + 'application/x-ssp': ['*.ssp'], + 'application/x-troff': ['*.[1234567]', '*.man'], + 'application/x-urbiscript': ['*.u'], + 'application/xml+evoque': ['*.xml'], + 'application/xml-dtd': ['*.dtd'], + 'application/xsl+xml': ['*.xsl', '*.xslt', '*.xpl'], + 'text/S-plus': ['*.S', '*.R', '.Rhistory', '.Rprofile'], + 'text/coffeescript': ['*.coffee'], + 'text/css': ['*.css'], + 'text/haxe': ['*.hx'], + 'text/html': ['*.html', '*.htm', '*.xhtml', '*.xslt'], + 'text/html+evoque': ['*.html'], + 'text/html+ruby': ['*.rhtml'], + 'text/idl': ['*.pro'], + 'text/livescript': ['*.ls'], + 'text/matlab': ['*.m'], + 'text/octave': ['*.m'], + 'text/plain': ['*.txt'], + 'text/scilab': ['*.sci', '*.sce', '*.tst'], + 'text/smali': ['*.smali'], + 'text/x-abap': ['*.abap'], + 'text/x-ada': ['*.adb', '*.ads', '*.ada'], + 'text/x-apacheconf': ['.htaccess', 'apache.conf', 'apache2.conf'], + 'text/x-aspectj': ['*.aj'], + 'text/x-asymptote': ['*.asy'], + 'text/x-autohotkey': ['*.ahk', '*.ahkl'], + 'text/x-autoit': ['*.au3'], + 'text/x-bmx': ['*.bmx'], + 'text/x-boo': ['*.boo'], + 'text/x-c++hdr': ['*.cpp', '*.hpp', '*.c++', '*.h++', '*.cc', '*.hh', '*.cxx', '*.hxx', '*.C', '*.H', '*.cp','*.CPP'], + 'text/x-c-objdump': ['*.c-objdump'], + 'text/x-ceylon': ['*.ceylon'], + 'text/x-chdr': ['*.c', '*.h', '*.idc'], + 'text/x-clojure': ['*.clj'], + 'text/x-cmake': ['*.cmake', 'CMakeLists.txt'], + 'text/x-cobol': ['*.cob', '*.COB', '*.cpy', '*.CPY'], + 'text/x-common-lisp': ['*.cl', '*.lisp', '*.el'], + 'text/x-coq': ['*.v'], + 'text/x-cpp-objdump': ['*.cpp-objdump', '*.c++-objdump', '*.cxx-objdump'], + 'text/x-crocsrc': ['*.croc'], + 'text/x-csharp': ['*.cs'], + 'text/x-cuda': ['*.cu', '*.cuh'], + 'text/x-cython': ['*.pyx', '*.pxd', '*.pxi'], + 'text/x-d-objdump': ['*.d-objdump'], + 'text/x-dart': ['*.dart'], + 'text/x-dg': ['*.dg'], + 'text/x-diff': ['*.diff', '*.patch'], + 'text/x-dsrc': ['*.d', '*.di'], + 'text/x-duel': ['*.duel', '*.jbst'], + 'text/x-dylan': ['*.dylan', '*.dyl', '*.intr'], + 'text/x-dylan-console': ['*.dylan-console'], + 'text/x-dylan-lid': ['*.lid', '*.hdp'], + 'text/x-echdr': ['*.ec', '*.eh'], + 'text/x-elixir': ['*.ex', '*.exs'], + 'text/x-erl-shellsession': ['*.erl-sh'], + 'text/x-erlang': ['*.erl', '*.hrl', '*.es', '*.escript'], + 'text/x-factor': ['*.factor'], + 'text/x-fancysrc': ['*.fy', '*.fancypack'], + 'text/x-felix': ['*.flx', '*.flxh'], + 'text/x-fortran': ['*.f', '*.f90', '*.F', '*.F90'], + 'text/x-fsharp': ['*.fs', '*.fsi'], + 'text/x-gas': ['*.s', '*.S'], + 'text/x-gherkin': ['*.feature'], + 'text/x-glslsrc': ['*.vert', '*.frag', '*.geo'], + 'text/x-gnuplot': ['*.plot', '*.plt'], + 'text/x-gooddata-cl': ['*.gdc'], + 'text/x-gooddata-maql': ['*.maql'], + 'text/x-gosrc': ['*.go'], + 'text/x-gosu': ['*.gs', '*.gsx', '*.gsp', '*.vark'], + 'text/x-gosu-template': ['*.gst'], + 'text/x-groovy': ['*.groovy'], + 'text/x-haml': ['*.haml'], + 'text/x-haskell': ['*.hs'], + 'text/x-hybris': ['*.hy', '*.hyb'], + 'text/x-ini': ['*.ini', '*.cfg'], + 'text/x-iokesrc': ['*.ik'], + 'text/x-iosrc': ['*.io'], + 'text/x-irclog': ['*.weechatlog'], + 'text/x-jade': ['*.jade'], + 'text/x-java': ['*.java'], + 'text/x-java-properties': ['*.properties'], + 'text/x-julia': ['*.jl'], + 'text/x-kconfig': ['Kconfig', '*Config.in*', 'external.in*', 'standard-modules.in'], + 'text/x-koka': ['*.kk', '*.kki'], + 'text/x-kotlin': ['*.kt'], + 'text/x-lasso': ['*.lasso', '*.lasso[89]'], + 'text/x-literate-haskell': ['*.lhs'], + 'text/x-llvm': ['*.ll'], + 'text/x-logos': ['*.x', '*.xi', '*.xm', '*.xmi'], + 'text/x-logtalk': ['*.lgt'], + 'text/x-lua': ['*.lua', '*.wlua'], + 'text/x-makefile': ['*.mak', 'Makefile', 'makefile', 'Makefile.*', 'GNUmakefile'], + 'text/x-minidsrc': ['*.md'], + 'text/x-markdown': ['*.md'], + 'text/x-modelica': ['*.mo'], + 'text/x-modula2': ['*.def', '*.mod'], + 'text/x-monkey': ['*.monkey'], + 'text/x-moocode': ['*.moo'], + 'text/x-moonscript': ['*.moon'], + 'text/x-nasm': ['*.asm', '*.ASM'], + 'text/x-nemerle': ['*.n'], + 'text/x-newlisp': ['*.lsp', '*.nl'], + 'text/x-newspeak': ['*.ns2'], + 'text/x-nimrod': ['*.nim', '*.nimrod'], + 'text/x-nsis': ['*.nsi', '*.nsh'], + 'text/x-objdump': ['*.objdump'], + 'text/x-objective-c': ['*.m', '*.h'], + 'text/x-objective-c++': ['*.mm', '*.hh'], + 'text/x-objective-j': ['*.j'], + 'text/x-ocaml': ['*.ml', '*.mli', '*.mll', '*.mly'], + 'text/x-ooc': ['*.ooc'], + 'text/x-opa': ['*.opa'], + 'text/x-openedge': ['*.p', '*.cls'], + 'text/x-pascal': ['*.pas'], + 'text/x-perl': ['*.pl', '*.pm'], + 'text/x-php': ['*.php', '*.php[345]', '*.inc'], + 'text/x-povray': ['*.pov', '*.inc'], + 'text/x-powershell': ['*.ps1'], + 'text/x-prolog': ['*.prolog', '*.pro', '*.pl'], + 'text/x-python': ['*.py', '*.pyw', '*.sc', 'SConstruct', 'SConscript', '*.tac', '*.sage'], + 'text/x-python-traceback': ['*.pytb'], + 'text/x-python3-traceback': ['*.py3tb'], + 'text/x-r-doc': ['*.Rd'], + 'text/x-racket': ['*.rkt', '*.rktl'], + 'text/x-rebol': ['*.r', '*.r3'], + 'text/x-robotframework': ['*.txt', '*.robot'], + 'text/x-rpm-spec': ['*.spec'], + 'text/x-rst': ['*.rst', '*.rest'], + 'text/x-ruby': ['*.rb', '*.rbw', 'Rakefile', '*.rake', '*.gemspec', '*.rbx', '*.duby'], + 'text/x-rustsrc': ['*.rs', '*.rc'], + 'text/x-sass': ['*.sass'], + 'text/x-scala': ['*.scala'], + 'text/x-scaml': ['*.scaml'], + 'text/x-scheme': ['*.scm', '*.ss'], + 'text/x-scss': ['*.scss'], + 'text/x-smalltalk': ['*.st'], + 'text/x-snobol': ['*.snobol'], + 'text/x-sourcepawn': ['*.sp'], + 'text/x-sql': ['*.sql'], + 'text/x-sqlite3-console': ['*.sqlite3-console'], + 'text/x-squidconf': ['squid.conf'], + 'text/x-standardml': ['*.sml', '*.sig', '*.fun'], + 'text/x-systemverilog': ['*.sv', '*.svh'], + 'text/x-tcl': ['*.tcl'], + 'text/x-tea': ['*.tea'], + 'text/x-tex': ['*.tex', '*.aux', '*.toc'], + 'text/x-typescript': ['*.ts'], + 'text/x-vala': ['*.vala', '*.vapi'], + 'text/x-vbnet': ['*.vb', '*.bas'], + 'text/x-verilog': ['*.v'], + 'text/x-vhdl': ['*.vhdl', '*.vhd'], + 'text/x-vim': ['*.vim', '.vimrc', '.exrc', '.gvimrc', '_vimrc', '_exrc', '_gvimrc', 'vimrc', 'gvimrc'], + 'text/x-windows-registry': ['*.reg'], + 'text/x-xtend': ['*.xtend'], + 'text/x-yaml': ['*.yaml', '*.yml'], + 'text/xml': ['*.xml', '*.xsl', '*.rss', '*.xslt', '*.xsd', '*.wsdl'], + 'text/xquery': ['*.xqy', '*.xquery', '*.xq', '*.xql', '*.xqm'], + 'text/apl': [], + 'text/x-asterisk': [], + 'text/x-csrc': [], + 'text/x-c++src': ['*.cpp'], + 'text/x-coffeescript': ['*.coffee'], + 'text/x-d': ["*.d"], + 'text/x-ecl': ['*.ecl'], + 'text/x-go': ['*.go'], + 'text/x-haxe': ['*.hx'], + 'application/x-aspx': ['*.aspx'], + 'application/x-ejs': [], + 'message/http': [], + 'application/x-json': ['*.json'], + 'application/typescript': ['*.ts'], + 'jinja2': ['.jinja2'], + 'text/x-less': ['*.less'], + 'text/x-livescript': ['*.ls'], + 'text/mirc': [], + 'text/n-triples': [], + 'application/x-httpd-php': ['*.php'], + 'text/x-pig': [], + 'text/x-properties': ['*.properties'], + 'text/x-rsrc': [], + 'text/x-sh': ['*.sh', '*.ksh', '*.bash', '*.ebuild', '*.eclass', '.bashrc', 'bashrc', '.bash_*', 'bash_*'], + 'application/sieve': [], + 'text/x-stsrc': ['*.rs', '*.rc'], + 'text/x-smarty': ['*.tpl'], + 'application/x-sparql-query': [], + 'text/x-mariadb': ['*.sql'], + 'text/x-stex': [], + 'text/x-latex': ["*.ltx"], + 'text/x-tiddlywiki': [], + 'text/tiki': [], + 'text/x-vb': ['*.vb'], + 'text/vbscript': ['*.vb'], + 'text/velocity': [], + 'application/xml': ['*.xml', '*.xsl', '*.rss', '*.xslt', '*.xsd', '*.wsdl'], + 'application/xquery': ['*.xqy', '*.xquery', '*.xq', '*.xql', '*.xqm'], + 'text/x-z80': [], +} diff -r c9bcfe2d2ade -r 647308db13ff rhodecode/templates/admin/gists/new.html --- a/rhodecode/templates/admin/gists/new.html Fri Jun 21 01:11:16 2013 +0200 +++ b/rhodecode/templates/admin/gists/new.html Fri Jun 21 02:42:32 2013 +0200 @@ -37,14 +37,17 @@ gravatar +
+ + ${h.select('lifetime', '', c.lifetime_options)} +
## ${h.text('filename', size=30, placeholder='gistfile1.txt')} ## - ${h.select('lifetime', '', c.lifetime_options)} - ${h.select('set_mode','plain',[('plain',_('plain'))])} + ${h.select('mimetype','plain',[('plain',_('plain'))])}

@@ -62,16 +65,30 @@
             CodeMirror.modeURL = "${h.url('/js/mode/%N/%N.js')}";
 
             //inject new modes
-            var modes_select = YUD.get('set_mode');
+            var modes_select = YUD.get('mimetype');
             for(var i=0;i