Changeset - 647308db13ff
[Not reviewed]
default
0 4 0
Marcin Kuzminski - 12 years ago 2013-06-21 02:42:32
marcin@python-works.com
Added codemirror syntax mode in gists.
- autopropose file extension when syntax mode is choosen
4 files changed with 256 insertions and 9 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/admin/gists.py
Show inline comments
 
@@ -94,10 +94,11 @@ class GistsController(BaseController):
 
        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']
rhodecode/model/forms.py
Show inline comments
 
@@ -431,6 +431,7 @@ def GistForm(lifetime_options):
 
                       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='')
rhodecode/public/js/mode/meta.js
Show inline comments
 
@@ -16,7 +16,6 @@ CodeMirror.modeInfo = [
 
  {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 @@ CodeMirror.modeInfo = [
 
  {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': [],
 
}
rhodecode/templates/admin/gists/new.html
Show inline comments
 
@@ -37,14 +37,17 @@
 
                   <img alt="gravatar" src="${h.gravatar_url(h.email_or_none(c.rhodecode_user.full_contact),32)}"/>
 
                </div>
 
                <textarea style="resize:vertical; width:400px;border: 1px solid #ccc;border-radius: 3px;" id="description" name="description" placeholder="${_('Gist description ...')}"></textarea>
 
                <div style="padding:0px 0px 0px 42px">
 
                <label for='lifetime'>${_('Gist lifetime')}</label>
 
                ${h.select('lifetime', '', c.lifetime_options)}
 
                </div>
 
            </div>
 
            <div id="body" class="codeblock">
 
                <div style="padding: 10px 10px 10px 26px;color:#666666">
 
                    ##<input type="text" value="" size="30" name="filename" id="filename" placeholder="gistfile1.txt">
 
                    ${h.text('filename', size=30, placeholder='gistfile1.txt')}
 
                    ##<input type="text" value="" size="30" name="filename" id="filename" placeholder="gistfile1.txt">
 
                    ${h.select('lifetime', '', c.lifetime_options)}
 
                    ${h.select('set_mode','plain',[('plain',_('plain'))])}
 
                    ${h.select('mimetype','plain',[('plain',_('plain'))])}
 
                </div>
 
                <div id="editor_container">
 
                    <pre id="editor_pre"></pre>
 
@@ -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<CodeMirror.modeInfo.length;i++){
 
                var m = CodeMirror.modeInfo[i];
 
                var opt = new Option(m.name, m.mode);
 
                modes_select.options[i+1] = opt
 
                var opt = new Option(m.name, m.mime);
 
                YUD.setAttribute(opt, 'mode', m.mode)
 
                modes_select.options[i+1] = opt;
 
            }
 
            YUE.on(modes_select, 'change', function(e){
 
                var selected = e.currentTarget;
 
                var new_mode = selected.options[selected.selectedIndex].value;
 
                var node = selected.options[selected.selectedIndex];
 
                var mimetype = node.value;
 
                var new_mode = YUD.getAttribute(node, 'mode')
 
                setCodeMirrorMode(myCodeMirror, new_mode);
 

	
 
                var proposed_mimetypes = MIME_TO_EXT[mimetype] || [];
 
                if(proposed_mimetypes.length < 1){
 
                    //fallback to text/plain
 
                    proposed_mimetypes = ['.txt']
 
                }
 
                var mt = proposed_mimetypes[0];
 
                if(mt[0] == '*'){
 
                    mt = mt.substr(1)
 
                }
 
                YUD.get('filename').value = 'filename1' + mt;
 
            })
 
            </script>
 
        </div>
0 comments (0 inline, 0 general)