diff --git a/src/languages/ruby.js b/src/languages/ruby.js index bce2aaf8..0ec539db 100644 --- a/src/languages/ruby.js +++ b/src/languages/ruby.js @@ -1,41 +1,39 @@ /* -Language: Ruby -Description: Ruby is a dynamic, open source programming language with a focus on simplicity and productivity. +Language: Rails Unicorn Logging +Description: Mod of the Ruby language pack for better Unicorn logging syntax highlighting. Website: https://www.ruby-lang.org/ -Author: Anton Kovalyov -Contributors: Peter Leonov , Vasily Polovnyov , Loren Segal , Pascal Hurni , Cedric Sohrauer +Author: Russell Gray +Contributors: Anton Kovalyov Peter Leonov , Vasily Polovnyov , Loren Segal , Pascal Hurni , Cedric Sohrauer Category: common */ -export default function(hljs) { +export default function (hljs) { var RUBY_METHOD_RE = '[a-zA-Z_]\\w*[!?=]?|[-+~]\\@|<<|>>|=~|===?|<=>|[<>]=?|\\*\\*|[-/+%^&*~`|]|\\[\\]=?'; var RUBY_KEYWORDS = { - keyword: - 'and then defined module in return redo if BEGIN retry end for self when ' + + keyword: 'and then defined module in return redo if BEGIN retry end for self when ' + 'next until do begin unless END rescue else break undef not super class case ' + - 'require yield alias while ensure elsif or include attr_reader attr_writer attr_accessor', - literal: - 'true false nil' + 'require yield alias while ensure elsif or include attr_reader attr_writer attr_accessor ' + + 'Rendering Rendered Completed Started POST Processing by Redirected to Delivered mail Performed GET', + literal: 'true false nil' }; var YARDOCTAG = { className: 'doctag', begin: '@[A-Za-z]+' }; var IRB_OBJECT = { - begin: '#<', end: '>' + begin: '#<', + end: '>' }; var COMMENT_MODES = [ hljs.COMMENT( '#', - '$', - { + '$', { contains: [YARDOCTAG] } ), hljs.COMMENT( '^\\=begin', - '^\\=end', - { + '^\\=end', { contains: [YARDOCTAG], relevance: 10 } @@ -44,24 +42,57 @@ export default function(hljs) { ]; var SUBST = { className: 'subst', - begin: '#\\{', end: '}', + begin: '#\\{', + end: '}', keywords: RUBY_KEYWORDS }; var STRING = { className: 'string', contains: [hljs.BACKSLASH_ESCAPE, SUBST], - variants: [ - {begin: /'/, end: /'/}, - {begin: /"/, end: /"/}, - {begin: /`/, end: /`/}, - {begin: '%[qQwWx]?\\(', end: '\\)'}, - {begin: '%[qQwWx]?\\[', end: '\\]'}, - {begin: '%[qQwWx]?{', end: '}'}, - {begin: '%[qQwWx]?<', end: '>'}, - {begin: '%[qQwWx]?/', end: '/'}, - {begin: '%[qQwWx]?%', end: '%'}, - {begin: '%[qQwWx]?-', end: '-'}, - {begin: '%[qQwWx]?\\|', end: '\\|'}, + variants: [{ + begin: /'/, + end: /'|\n/ + }, + { + begin: /"/, + end: /"|\n/ + }, + { + begin: /`/, + end: /`|'|\n/ + }, + { + begin: '%[qQwWx]?\\(', + end: '\\)' + }, + { + begin: '%[qQwWx]?\\[', + end: '\\]' + }, + { + begin: '%[qQwWx]?{', + end: '}' + }, + { + begin: '%[qQwWx]?<', + end: '>' + }, + { + begin: '%[qQwWx]?/', + end: '/' + }, + { + begin: '%[qQwWx]?%', + end: '%' + }, + { + begin: '%[qQwWx]?-', + end: '-' + }, + { + begin: '%[qQwWx]?\\|', + end: '\\|' + }, { // \B in the beginning suppresses recognition of ?-sequences where ? // is the last character of a preceding identifier, as in: `func?4` @@ -70,19 +101,23 @@ export default function(hljs) { { // heredocs begin: /<<[-~]?'?(\w+)(?:.|\n)*?\n\s*\1\b/, returnBegin: true, - contains: [ - { begin: /<<[-~]?'?/ }, - hljs.END_SAME_AS_BEGIN({ - begin: /(\w+)/, end: /(\w+)/, + contains: [{ + begin: /<<[-~]?'?/ + }, + { + begin: /\w+/, + endSameAsBegin: true, contains: [hljs.BACKSLASH_ESCAPE, SUBST], - }) + } ] } ] }; var PARAMS = { className: 'params', - begin: '\\(', end: '\\)', endsParent: true, + begin: '\\(', + end: '\\)', + endsParent: true, keywords: RUBY_KEYWORDS }; @@ -91,10 +126,13 @@ export default function(hljs) { IRB_OBJECT, { className: 'class', - beginKeywords: 'class module', end: '$|;', + beginKeywords: 'class module', + end: '$|;', illegal: /=/, contains: [ - hljs.inherit(hljs.TITLE_MODE, {begin: '[A-Za-z_]\\w*(::\\w+)*(\\?|\\!)?'}), + hljs.inherit(hljs.TITLE_MODE, { + begin: '[A-Za-z_]\\w*(::\\w+)*(\\?|\\!)?' + }), { begin: '<\\s*', contains: [{ @@ -105,9 +143,12 @@ export default function(hljs) { }, { className: 'function', - beginKeywords: 'def', end: '$|;', + beginKeywords: 'def', + end: '$|;', contains: [ - hljs.inherit(hljs.TITLE_MODE, {begin: RUBY_METHOD_RE}), + hljs.inherit(hljs.TITLE_MODE, { + begin: RUBY_METHOD_RE + }), PARAMS ].concat(COMMENT_MODES) }, @@ -123,7 +164,9 @@ export default function(hljs) { { className: 'symbol', begin: ':(?!\\s)', - contains: [STRING, {begin: RUBY_METHOD_RE}], + contains: [STRING, { + begin: RUBY_METHOD_RE + }], relevance: 0 }, { @@ -135,9 +178,9 @@ export default function(hljs) { begin: '(\\$\\W)|((\\$|\\@\\@?)(\\w+))' // variables }, { - className: 'params', - begin: /\|/, end: /\|/, - keywords: RUBY_KEYWORDS + className: 'comment', + begin: '\\[(?!([0-9]*m|\\[|"))', + end: "]|\\n" }, { // regexp container begin: '(' + hljs.RE_STARTERS_RE + '|unless)\\s*', @@ -148,12 +191,22 @@ export default function(hljs) { className: 'regexp', contains: [hljs.BACKSLASH_ESCAPE, SUBST], illegal: /\n/, - variants: [ - {begin: '/', end: '/[a-z]*'}, - {begin: '%r{', end: '}[a-z]*'}, - {begin: '%r\\(', end: '\\)[a-z]*'}, - {begin: '%r!', end: '![a-z]*'}, - {begin: '%r\\[', end: '\\][a-z]*'} + variants: [{ + begin: '%r{', + end: '}[a-z]*' + }, + { + begin: '%r\\(', + end: '\\)[a-z]*' + }, + { + begin: '%r!', + end: '![a-z]*' + }, + { + begin: '%r\\[', + end: '\\][a-z]*' + } ] } ].concat(COMMENT_MODES), @@ -168,27 +221,28 @@ export default function(hljs) { var DEFAULT_PROMPT = "[\\w#]+\\(\\w+\\):\\d+:\\d+>"; var RVM_PROMPT = "(\\w+-)?\\d+\\.\\d+\\.\\d(p\\d+)?[^>]+>"; - var IRB_DEFAULT = [ - { + var IRB_DEFAULT = [{ begin: /^\s*=>/, starts: { - end: '$', contains: RUBY_DEFAULT_CONTAINS + end: '$', + contains: RUBY_DEFAULT_CONTAINS } }, { className: 'meta', - begin: '^('+SIMPLE_PROMPT+"|"+DEFAULT_PROMPT+'|'+RVM_PROMPT+')', + begin: '^(' + SIMPLE_PROMPT + "|" + DEFAULT_PROMPT + '|' + RVM_PROMPT + ')', starts: { - end: '$', contains: RUBY_DEFAULT_CONTAINS + end: '$', + contains: RUBY_DEFAULT_CONTAINS } } ]; return { - name: 'Ruby', + name: 'Rails log', aliases: ['rb', 'gemspec', 'podspec', 'thor', 'irb'], keywords: RUBY_KEYWORDS, illegal: /\/\*/, contains: COMMENT_MODES.concat(IRB_DEFAULT).concat(RUBY_DEFAULT_CONTAINS) }; -} +} \ No newline at end of file