| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| (function() { | ||
| "use strict"; | ||
|
|
||
| var WORD = /[\w$]+/, RANGE = 500; | ||
|
|
||
| CodeMirror.registerHelper("hint", "anyword", function(editor, options) { | ||
| var word = options && options.word || WORD; | ||
| var range = options && options.range || RANGE; | ||
| var cur = editor.getCursor(), curLine = editor.getLine(cur.line); | ||
| var start = cur.ch, end = start; | ||
| while (end < curLine.length && word.test(curLine.charAt(end))) ++end; | ||
| while (start && word.test(curLine.charAt(start - 1))) --start; | ||
| var curWord = start != end && curLine.slice(start, end); | ||
|
|
||
| var list = [], seen = {}; | ||
| function scan(dir) { | ||
| var line = cur.line, end = Math.min(Math.max(line + dir * range, editor.firstLine()), editor.lastLine()) + dir; | ||
| for (; line != end; line += dir) { | ||
| var text = editor.getLine(line), m; | ||
| var re = new RegExp(word.source, "g"); | ||
| while (m = re.exec(text)) { | ||
| if (line == cur.line && m[0] === curWord) continue; | ||
| if ((!curWord || m[0].indexOf(curWord) == 0) && !seen.hasOwnProperty(m[0])) { | ||
| seen[m[0]] = true; | ||
| list.push(m[0]); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| scan(-1); | ||
| scan(1); | ||
| return {list: list, from: CodeMirror.Pos(cur.line, start), to: CodeMirror.Pos(cur.line, end)}; | ||
| }); | ||
| })(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| .CodeMirror-Tern-completion { | ||
| padding-left: 22px; | ||
| position: relative; | ||
| } | ||
| .CodeMirror-Tern-completion:before { | ||
| position: absolute; | ||
| left: 2px; | ||
| bottom: 2px; | ||
| border-radius: 50%; | ||
| font-size: 12px; | ||
| font-weight: bold; | ||
| height: 15px; | ||
| width: 15px; | ||
| line-height: 16px; | ||
| text-align: center; | ||
| color: white; | ||
| -moz-box-sizing: border-box; | ||
| box-sizing: border-box; | ||
| } | ||
| .CodeMirror-Tern-completion-unknown:before { | ||
| content: "?"; | ||
| background: #4bb; | ||
| } | ||
| .CodeMirror-Tern-completion-object:before { | ||
| content: "O"; | ||
| background: #77c; | ||
| } | ||
| .CodeMirror-Tern-completion-fn:before { | ||
| content: "F"; | ||
| background: #7c7; | ||
| } | ||
| .CodeMirror-Tern-completion-array:before { | ||
| content: "A"; | ||
| background: #c66; | ||
| } | ||
| .CodeMirror-Tern-completion-number:before { | ||
| content: "1"; | ||
| background: #999; | ||
| } | ||
| .CodeMirror-Tern-completion-string:before { | ||
| content: "S"; | ||
| background: #999; | ||
| } | ||
| .CodeMirror-Tern-completion-bool:before { | ||
| content: "B"; | ||
| background: #999; | ||
| } | ||
|
|
||
| .CodeMirror-Tern-completion-guess { | ||
| color: #999; | ||
| } | ||
|
|
||
| .CodeMirror-Tern-tooltip { | ||
| border: 1px solid silver; | ||
| border-radius: 3px; | ||
| color: #444; | ||
| padding: 2px 5px; | ||
| font-size: 90%; | ||
| font-family: monospace; | ||
| background-color: white; | ||
| white-space: pre-wrap; | ||
|
|
||
| max-width: 40em; | ||
| position: absolute; | ||
| z-index: 10; | ||
| -webkit-box-shadow: 2px 3px 5px rgba(0,0,0,.2); | ||
| -moz-box-shadow: 2px 3px 5px rgba(0,0,0,.2); | ||
| box-shadow: 2px 3px 5px rgba(0,0,0,.2); | ||
|
|
||
| transition: opacity 1s; | ||
| -moz-transition: opacity 1s; | ||
| -webkit-transition: opacity 1s; | ||
| -o-transition: opacity 1s; | ||
| -ms-transition: opacity 1s; | ||
| } | ||
|
|
||
| .CodeMirror-Tern-hint-doc { | ||
| max-width: 25em; | ||
| } | ||
|
|
||
| .CodeMirror-Tern-fname { color: black; } | ||
| .CodeMirror-Tern-farg { color: #70a; } | ||
| .CodeMirror-Tern-farg-current { text-decoration: underline; } | ||
| .CodeMirror-Tern-type { color: #07c; } | ||
| .CodeMirror-Tern-fhint-guess { opacity: .7; } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| var server; | ||
|
|
||
| this.onmessage = function(e) { | ||
| var data = e.data; | ||
| switch (data.type) { | ||
| case "init": return startServer(data.defs, data.plugins, data.scripts); | ||
| case "add": return server.addFile(data.name, data.text); | ||
| case "del": return server.delFile(data.name); | ||
| case "req": return server.request(data.body, function(err, reqData) { | ||
| postMessage({id: data.id, body: reqData, err: err && String(err)}); | ||
| }); | ||
| case "getFile": | ||
| var c = pending[data.id]; | ||
| delete pending[data.id]; | ||
| return c(data.err, data.text); | ||
| default: throw new Error("Unknown message type: " + data.type); | ||
| } | ||
| }; | ||
|
|
||
| var nextId = 0, pending = {}; | ||
| function getFile(file, c) { | ||
| postMessage({type: "getFile", name: file, id: ++nextId}); | ||
| pending[nextId] = c; | ||
| } | ||
|
|
||
| function startServer(defs, plugins, scripts) { | ||
| if (scripts) importScripts.apply(null, scripts); | ||
|
|
||
| server = new tern.Server({ | ||
| getFile: getFile, | ||
| async: true, | ||
| defs: defs, | ||
| plugins: plugins | ||
| }); | ||
| } | ||
|
|
||
| var console = { | ||
| log: function(v) { postMessage({type: "debug", message: v}); } | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| <!doctype html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <title>CodeMirror: Any Word Completion Demo</title> | ||
| <link rel="stylesheet" href="../lib/codemirror.css"> | ||
| <script src="../lib/codemirror.js"></script> | ||
| <script src="../addon/hint/show-hint.js"></script> | ||
| <link rel="stylesheet" href="../addon/hint/show-hint.css"> | ||
| <script src="../addon/hint/anyword-hint.js"></script> | ||
| <script src="../mode/javascript/javascript.js"></script> | ||
| <link rel="stylesheet" href="../doc/docs.css"> | ||
| </head> | ||
| <body> | ||
| <h1>CodeMirror: Any Word Completion Demo</h1> | ||
|
|
||
| <form><textarea id="code" name="code"> | ||
| (function() { | ||
| "use strict"; | ||
|
|
||
| var WORD = /[\w$]+/g, RANGE = 500; | ||
|
|
||
| CodeMirror.registerHelper("hint", "anyword", function(editor, options) { | ||
| var word = options && options.word || WORD; | ||
| var range = options && options.range || RANGE; | ||
| var cur = editor.getCursor(), curLine = editor.getLine(cur.line); | ||
| var start = cur.ch, end = start; | ||
| while (end < curLine.length && word.test(curLine.charAt(end))) ++end; | ||
| while (start && word.test(curLine.charAt(start - 1))) --start; | ||
| var curWord = start != end && curLine.slice(start, end); | ||
|
|
||
| var list = [], seen = {}; | ||
| function scan(dir) { | ||
| var line = cur.line, end = Math.min(Math.max(line + dir * range, editor.firstLine()), editor.lastLine()) + dir; | ||
| for (; line != end; line += dir) { | ||
| var text = editor.getLine(line), m; | ||
| word.lastIndex = 0; | ||
| while (m = word.exec(text)) { | ||
| if ((!curWord || m[0].indexOf(curWord) == 0) && !seen.hasOwnProperty(m[0])) { | ||
| seen[m[0]] = true; | ||
| list.push(m[0]); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| scan(-1); | ||
| scan(1); | ||
| return {list: list, from: CodeMirror.Pos(cur.line, start), to: CodeMirror.Pos(cur.line, end)}; | ||
| }); | ||
| })(); | ||
| </textarea></form> | ||
|
|
||
| <p>Press <strong>ctrl-space</strong> to activate autocompletion. The | ||
| completion uses | ||
| the <a href="../doc/manual.html#addon_anyword-hint">anyword-hint.js</a> | ||
| module, which simply looks at nearby words in the buffer and completes | ||
| to those.</p> | ||
|
|
||
| <script> | ||
| CodeMirror.commands.autocomplete = function(cm) { | ||
| CodeMirror.showHint(cm, CodeMirror.hint.anyword); | ||
| } | ||
| var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | ||
| lineNumbers: true, | ||
| extraKeys: {"Ctrl-Space": "autocomplete"} | ||
| }); | ||
| </script> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| <!doctype html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <title>CodeMirror: Tag Matcher Demo</title> | ||
| <link rel="stylesheet" href="../lib/codemirror.css"> | ||
| <script src="../lib/codemirror.js"></script> | ||
| <script src="../addon/fold/xml-fold.js"></script> | ||
| <script src="../addon/edit/matchtags.js"></script> | ||
| <script src="../mode/xml/xml.js"></script> | ||
| <link rel="stylesheet" href="../doc/docs.css"> | ||
|
|
||
| <style type="text/css"> | ||
| .CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;} | ||
| .CodeMirror-matchingtag { background: rgba(255, 150, 0, .3); } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <h1>CodeMirror: Tag Matcher Demo</h1> | ||
|
|
||
| <div id="editor"></div> | ||
|
|
||
| <script> | ||
| window.onload = function() { | ||
| editor = CodeMirror(document.getElementById("editor"), { | ||
| value: "<html>\n " + document.documentElement.innerHTML + "\n</html>", | ||
| mode: "text/html", | ||
| matchTags: true, | ||
| extraKeys: {"Ctrl-J": "toMatchingTag"} | ||
| }); | ||
| }; | ||
| </script> | ||
|
|
||
| <p>Put the cursor on or inside a pair of tags to highlight them. | ||
| Press Ctrl-J to jump to the tag that matches the one under the | ||
| cursor.</p> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| <!doctype html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <title>CodeMirror: Tern Demo</title> | ||
| <link rel="stylesheet" href="../lib/codemirror.css"> | ||
| <script src="../lib/codemirror.js"></script> | ||
| <script src="../mode/javascript/javascript.js"></script> | ||
| <link rel="stylesheet" href="../doc/docs.css"> | ||
| <script src="../addon/dialog/dialog.js"></script> | ||
| <link rel="stylesheet" href="../addon/dialog/dialog.css"> | ||
| <script src="../addon/hint/show-hint.js"></script> | ||
| <link rel="stylesheet" href="../addon/hint/show-hint.css"> | ||
| <script src="../addon/tern/tern.js"></script> | ||
| <link rel="stylesheet" href="../addon/tern/tern.css"> | ||
|
|
||
| <!-- NOTE: if you are going to actually deploy this in production, | ||
| DO NOT hot-link these files. Host them yourself. --> | ||
| <script src="http://marijnhaverbeke.nl/acorn/acorn.js"></script> | ||
| <script src="http://marijnhaverbeke.nl/acorn/acorn_loose.js"></script> | ||
| <script src="http://marijnhaverbeke.nl/acorn/util/walk.js"></script> | ||
| <script src="http://ternjs.net/lib/signal.js"></script> | ||
| <script src="http://ternjs.net/lib/tern.js"></script> | ||
| <script src="http://ternjs.net/lib/def.js"></script> | ||
| <script src="http://ternjs.net/lib/comment.js"></script> | ||
| <script src="http://ternjs.net/lib/infer.js"></script> | ||
| <script src="http://ternjs.net/plugin/doc_comment.js"></script> | ||
|
|
||
| <style> | ||
| .CodeMirror {border: 1px solid #ddd;} | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <h1>CodeMirror: Tern Demo</h1> | ||
|
|
||
| <form><textarea id="code" name="code">// Use ctrl-space to complete something | ||
| // Put the cursor in or after an expression, press ctrl-i to | ||
| // find its type | ||
|
|
||
| var foo = ["array", "of", "strings"]; | ||
| var bar = foo.slice(0, 2).join("").split("a")[0]; | ||
|
|
||
| // Works for locally defined types too. | ||
|
|
||
| function CTor() { this.size = 10; } | ||
| CTor.prototype.hallo = "hallo"; | ||
|
|
||
| var baz = new CTor; | ||
| baz. | ||
|
|
||
| // You can press ctrl-q when the cursor is on a variable name to | ||
| // rename it. Try it with CTor... | ||
|
|
||
| // When the cursor is in an argument list, the arguments are | ||
| // shown below the editor. | ||
|
|
||
| [1].reduce( ); | ||
|
|
||
| // And a little more advanced code... | ||
|
|
||
| (function(exports) { | ||
| exports.randomElt = function(arr) { | ||
| return arr[Math.floor(arr.length * Math.random())]; | ||
| }; | ||
| exports.strList = "foo".split(""); | ||
| exports.intList = exports.strList.map(function(s) { return s.charCodeAt(0); }); | ||
| })(window.myMod = {}); | ||
|
|
||
| var randomStr = myMod.randomElt(myMod.strList); | ||
| var randomInt = myMod.randomElt(myMod.intList); | ||
| </textarea></p> | ||
|
|
||
| <p>Demonstrates integration of <a href="http://ternjs.net/">Tern</a> | ||
| and CodeMirror. The following keys are bound:</p> | ||
|
|
||
| <dl> | ||
| <dt>Ctrl-Space</dt><dd>Autocomplete</dd> | ||
| <dt>Ctrl-I</dt><dd>Find type at cursor</dd> | ||
| <dt>Alt-.</dt><dd>Jump to definition (Alt-, to jump back)</dd> | ||
| <dt>Ctrl-Q</dt><dd>Rename variable</dd> | ||
| </dl> | ||
|
|
||
| <p>Documentation is sparse for now. See the top of | ||
| the <a href="../addon/tern/tern.js">script</a> for a rough API | ||
| overview.</p> | ||
|
|
||
| <script> | ||
| function getURL(url, c) { | ||
| var xhr = new XMLHttpRequest(); | ||
| xhr.open("get", url, true); | ||
| xhr.send(); | ||
| xhr.onreadystatechange = function() { | ||
| if (xhr.readyState != 4) return; | ||
| if (xhr.status < 400) return c(null, xhr.responseText); | ||
| var e = new Error(xhr.responseText || "No response"); | ||
| e.status = xhr.status; | ||
| c(e); | ||
| }; | ||
| } | ||
|
|
||
| var server; | ||
| getURL("http://ternjs.net/defs/ecma5.json", function(err, code) { | ||
| if (err) throw new Error("Request for ecma5.json: " + err); | ||
| server = new CodeMirror.TernServer({defs: [JSON.parse(code)]}); | ||
| editor.setOption("extraKeys", { | ||
| "Ctrl-Space": function(cm) { server.complete(cm); }, | ||
| "Ctrl-I": function(cm) { server.showType(cm); }, | ||
| "Alt-.": function(cm) { server.jumpToDef(cm); }, | ||
| "Alt-,": function(cm) { server.jumpBack(cm); }, | ||
| "Ctrl-Q": function(cm) { server.rename(cm); }, | ||
| }) | ||
| editor.on("cursorActivity", function(cm) { server.updateArgHints(cm); }); | ||
| }); | ||
|
|
||
| var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | ||
| lineNumbers: true, | ||
| mode: "javascript" | ||
| }); | ||
| </script> | ||
|
|
||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| <!doctype html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <title>CodeMirror: Jade Templating Mode</title> | ||
| <link rel="stylesheet" href="../../lib/codemirror.css"> | ||
| <script src="../../lib/codemirror.js"></script> | ||
| <script src="jade.js"></script> | ||
| <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> | ||
| <link rel="stylesheet" href="../../doc/docs.css"> | ||
| </head> | ||
| <body> | ||
| <h1>CodeMirror: Jade Templating Mode</h1> | ||
| <form><textarea id="code" name="code"> | ||
| doctype 5 | ||
| html | ||
| head | ||
| title= "Jade Templating CodeMirror Mode Example" | ||
| link(rel='stylesheet', href='/css/bootstrap.min.css') | ||
| link(rel='stylesheet', href='/css/index.css') | ||
| script(type='text/javascript', src='/js/jquery-1.9.1.min.js') | ||
| script(type='text/javascript', src='/js/bootstrap.min.js') | ||
| body | ||
| div.header | ||
| h1 Welcome to this Example | ||
| div.spots | ||
| if locals.spots | ||
| each spot in spots | ||
| div.spot.well | ||
| div | ||
| if spot.logo | ||
| img.img-rounded.logo(src=spot.logo) | ||
| else | ||
| img.img-rounded.logo(src="img/placeholder.png") | ||
| h3 | ||
| a(href=spot.hash) ##{spot.hash} | ||
| if spot.title | ||
| span.title #{spot.title} | ||
| if spot.desc | ||
| div #{spot.desc} | ||
| else | ||
| h3 There are no spots currently available. | ||
| </textarea></form> | ||
| <script> | ||
| var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | ||
| mode: {name: "jade", alignCDATA: true}, | ||
| lineNumbers: true | ||
| }); | ||
| </script> | ||
| <h3>The Jade Templating Mode</h3> | ||
| <p> Created by Drew Bratcher. Managed as part of an Adobe Brackets extension at <a href="https://github.com/dbratcher/brackets-jade">https://github.com/dbratcher/brackets-jade</a>.</p> | ||
| <p><strong>MIME type defined:</strong> <code>text/x-jade</code>.</p> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| CodeMirror.defineMode("jade", function () { | ||
| var symbol_regex1 = /^(?:~|!|%|\^|\*|\+|=|\\|:|;|,|\/|\?|&|<|>|\|)/; | ||
| var open_paren_regex = /^(\(|\[)/; | ||
| var close_paren_regex = /^(\)|\])/; | ||
| var keyword_regex1 = /^(if|else|return|var|function|include|doctype|each)/; | ||
| var keyword_regex2 = /^(#|{|}|\.)/; | ||
| var keyword_regex3 = /^(in)/; | ||
| var html_regex1 = /^(html|head|title|meta|link|script|body|br|div|input|span|a|img)/; | ||
| var html_regex2 = /^(h1|h2|h3|h4|h5|p|strong|em)/; | ||
| return { | ||
| startState: function () { | ||
| return { | ||
| inString: false, | ||
| stringType: "", | ||
| beforeTag: true, | ||
| justMatchedKeyword: false, | ||
| afterParen: false | ||
| }; | ||
| }, | ||
| token: function (stream, state) { | ||
| //check for state changes | ||
| if (!state.inString && ((stream.peek() == '"') || (stream.peek() == "'"))) { | ||
| state.stringType = stream.peek(); | ||
| stream.next(); // Skip quote | ||
| state.inString = true; // Update state | ||
| } | ||
|
|
||
| //return state | ||
| if (state.inString) { | ||
| if (stream.skipTo(state.stringType)) { // Quote found on this line | ||
| stream.next(); // Skip quote | ||
| state.inString = false; // Clear flag | ||
| } else { | ||
| stream.skipToEnd(); // Rest of line is string | ||
| } | ||
| state.justMatchedKeyword = false; | ||
| return "string"; // Token style | ||
| } else if (stream.sol() && stream.eatSpace()) { | ||
| if (stream.match(keyword_regex1)) { | ||
| state.justMatchedKeyword = true; | ||
| stream.eatSpace(); | ||
| return "keyword"; | ||
| } | ||
| if (stream.match(html_regex1) || stream.match(html_regex2)) { | ||
| state.justMatchedKeyword = true; | ||
| return "variable"; | ||
| } | ||
| } else if (stream.sol() && stream.match(keyword_regex1)) { | ||
| state.justMatchedKeyword = true; | ||
| stream.eatSpace(); | ||
| return "keyword"; | ||
| } else if (stream.sol() && (stream.match(html_regex1) || stream.match(html_regex2))) { | ||
| state.justMatchedKeyword = true; | ||
| return "variable"; | ||
| } else if (stream.eatSpace()) { | ||
| state.justMatchedKeyword = false; | ||
| if (stream.match(keyword_regex3) && stream.eatSpace()) { | ||
| state.justMatchedKeyword = true; | ||
| return "keyword"; | ||
| } | ||
| } else if (stream.match(symbol_regex1)) { | ||
| state.justMatchedKeyword = false; | ||
| return "atom"; | ||
| } else if (stream.match(open_paren_regex)) { | ||
| state.afterParen = true; | ||
| state.justMatchedKeyword = true; | ||
| return "def"; | ||
| } else if (stream.match(close_paren_regex)) { | ||
| state.afterParen = false; | ||
| state.justMatchedKeyword = true; | ||
| return "def"; | ||
| } else if (stream.match(keyword_regex2)) { | ||
| state.justMatchedKeyword = true; | ||
| return "keyword"; | ||
| } else if (stream.eatSpace()) { | ||
| state.justMatchedKeyword = false; | ||
| } else { | ||
| stream.next(); | ||
| if (state.justMatchedKeyword) { | ||
| return "property"; | ||
| } else if (state.afterParen) { | ||
| return "property"; | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
| }; | ||
| }); | ||
|
|
||
| CodeMirror.defineMIME('text/x-jade', 'jade'); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| (function() { | ||
| var mode = CodeMirror.getMode({indentUnit: 2}, "javascript"); | ||
| function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); } | ||
|
|
||
| MT("locals", | ||
| "[keyword function] [variable foo]([def a], [def b]) { [keyword var] [def c] = [number 10]; [keyword return] [variable-2 a] + [variable-2 c] + [variable d]; }"); | ||
|
|
||
| MT("comma-and-binop", | ||
| "[keyword function](){ [keyword var] [def x] = [number 1] + [number 2], [def y]; }"); | ||
| })(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,167 @@ | ||
| <!doctype html> | ||
| <html> | ||
| <head> | ||
| <title>CodeMirror: NGINX mode</title> | ||
| <link rel="stylesheet" href="../../lib/codemirror.css"> | ||
| <script src="../../lib/codemirror.js"></script> | ||
| <script src="nginx.js"></script> | ||
| <style>.CodeMirror {background: #f8f8f8;}</style> | ||
| <link rel="stylesheet" href="../../doc/docs.css"> | ||
| </head> | ||
|
|
||
| <style> | ||
| body { | ||
| margin: 0em auto; | ||
| } | ||
|
|
||
| .CodeMirror, .CodeMirror-scroll { | ||
| height: 600px; | ||
| } | ||
| </style> | ||
|
|
||
| <body> | ||
| <h1>CodeMirror: NGINX mode</h1> | ||
| <form><textarea id="code" name="code" style="height: 800px;"> | ||
| server { | ||
| listen 173.255.219.235:80; | ||
| server_name website.com.au; | ||
| rewrite / $scheme://www.$host$request_uri permanent; ## Forcibly prepend a www | ||
| } | ||
|
|
||
| server { | ||
| listen 173.255.219.235:443; | ||
| server_name website.com.au; | ||
| rewrite / $scheme://www.$host$request_uri permanent; ## Forcibly prepend a www | ||
| } | ||
|
|
||
| server { | ||
|
|
||
| listen 173.255.219.235:80; | ||
| server_name www.website.com.au; | ||
|
|
||
|
|
||
|
|
||
| root /data/www; | ||
| index index.html index.php; | ||
|
|
||
| location / { | ||
| index index.html index.php; ## Allow a static html file to be shown first | ||
| try_files $uri $uri/ @handler; ## If missing pass the URI to Magento's front handler | ||
| expires 30d; ## Assume all files are cachable | ||
| } | ||
|
|
||
| ## These locations would be hidden by .htaccess normally | ||
| location /app/ { deny all; } | ||
| location /includes/ { deny all; } | ||
| location /lib/ { deny all; } | ||
| location /media/downloadable/ { deny all; } | ||
| location /pkginfo/ { deny all; } | ||
| location /report/config.xml { deny all; } | ||
| location /var/ { deny all; } | ||
|
|
||
| location /var/export/ { ## Allow admins only to view export folder | ||
| auth_basic "Restricted"; ## Message shown in login window | ||
| auth_basic_user_file /rs/passwords/testfile; ## See /etc/nginx/htpassword | ||
| autoindex on; | ||
| } | ||
|
|
||
| location /. { ## Disable .htaccess and other hidden files | ||
| return 404; | ||
| } | ||
|
|
||
| location @handler { ## Magento uses a common front handler | ||
| rewrite / /index.php; | ||
| } | ||
|
|
||
| location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler | ||
| rewrite ^/(.*.php)/ /$1 last; | ||
| } | ||
|
|
||
| location ~ \.php$ { | ||
| if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss | ||
|
|
||
| fastcgi_pass 127.0.0.1:9000; | ||
| fastcgi_index index.php; | ||
| fastcgi_param PATH_INFO $fastcgi_script_name; | ||
| fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | ||
| include /rs/confs/nginx/fastcgi_params; | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
| server { | ||
|
|
||
| listen 173.255.219.235:443; | ||
| server_name website.com.au www.website.com.au; | ||
|
|
||
| root /data/www; | ||
| index index.html index.php; | ||
|
|
||
| ssl on; | ||
| ssl_certificate /rs/ssl/ssl.crt; | ||
| ssl_certificate_key /rs/ssl/ssl.key; | ||
|
|
||
| ssl_session_timeout 5m; | ||
|
|
||
| ssl_protocols SSLv2 SSLv3 TLSv1; | ||
| ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; | ||
| ssl_prefer_server_ciphers on; | ||
|
|
||
|
|
||
|
|
||
| location / { | ||
| index index.html index.php; ## Allow a static html file to be shown first | ||
| try_files $uri $uri/ @handler; ## If missing pass the URI to Magento's front handler | ||
| expires 30d; ## Assume all files are cachable | ||
| } | ||
|
|
||
| ## These locations would be hidden by .htaccess normally | ||
| location /app/ { deny all; } | ||
| location /includes/ { deny all; } | ||
| location /lib/ { deny all; } | ||
| location /media/downloadable/ { deny all; } | ||
| location /pkginfo/ { deny all; } | ||
| location /report/config.xml { deny all; } | ||
| location /var/ { deny all; } | ||
|
|
||
| location /var/export/ { ## Allow admins only to view export folder | ||
| auth_basic "Restricted"; ## Message shown in login window | ||
| auth_basic_user_file htpasswd; ## See /etc/nginx/htpassword | ||
| autoindex on; | ||
| } | ||
|
|
||
| location /. { ## Disable .htaccess and other hidden files | ||
| return 404; | ||
| } | ||
|
|
||
| location @handler { ## Magento uses a common front handler | ||
| rewrite / /index.php; | ||
| } | ||
|
|
||
| location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler | ||
| rewrite ^/(.*.php)/ /$1 last; | ||
| } | ||
|
|
||
| location ~ .php$ { ## Execute PHP scripts | ||
| if (!-e $request_filename) { rewrite /index.php last; } ## Catch 404s that try_files miss | ||
|
|
||
| fastcgi_pass 127.0.0.1:9000; | ||
| fastcgi_index index.php; | ||
| fastcgi_param PATH_INFO $fastcgi_script_name; | ||
| fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | ||
| include /rs/confs/nginx/fastcgi_params; | ||
|
|
||
| fastcgi_param HTTPS on; | ||
| } | ||
|
|
||
| } | ||
| </textarea></form> | ||
| <script> | ||
| var editor = CodeMirror.fromTextArea(document.getElementById("code"), {}); | ||
| </script> | ||
|
|
||
| <p><strong>MIME types defined:</strong> <code>text/nginx</code>.</p> | ||
|
|
||
| </body> | ||
| </html> |