add smarty mode
This commit is contained in:
parent
31e1a2d1f3
commit
99f49fdc49
6 changed files with 203 additions and 1 deletions
7
demo/kitchen-sink/docs/smarty.smarty
Normal file
7
demo/kitchen-sink/docs/smarty.smarty
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
{foreach $foo as $bar}
|
||||
<a href="{$bar.zig}">{$bar.zag}</a>
|
||||
<a href="{$bar.zig2}">{$bar.zag2}</a>
|
||||
<a href="{$bar.zig3}">{$bar.zag3}</a>
|
||||
{foreachelse}
|
||||
There were no rows found.
|
||||
{/foreach}
|
||||
|
|
@ -123,6 +123,7 @@ var supportedModes = {
|
|||
SASS: ["sass"],
|
||||
SCAD: ["scad"],
|
||||
Scala: ["scala"],
|
||||
Smarty: ["smarty|tpl"],
|
||||
Scheme: ["scm|rkt"],
|
||||
SCSS: ["scss"],
|
||||
SH: ["sh|bash|^.bashrc"],
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ define(function(require, exports, module) {
|
|||
var oop = require("../lib/oop");
|
||||
var TextMode = require("./text").Mode;
|
||||
var Tokenizer = require("../tokenizer").Tokenizer;
|
||||
var MushCodeRules = require("./mushcode_high_rules").MushCodeRules;
|
||||
var MushCodeRules = require("./mushcode_highlight_rules").MushCodeRules;
|
||||
var PythonFoldMode = require("./folding/pythonic").FoldMode;
|
||||
var Range = require("../range").Range;
|
||||
|
||||
|
|
|
|||
58
lib/ace/mode/smarty.js
Normal file
58
lib/ace/mode/smarty.js
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Distributed under the BSD license:
|
||||
*
|
||||
* Copyright (c) 2012, Ajax.org B.V.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of Ajax.org B.V. nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
define(function(require, exports, module) {
|
||||
"use strict";
|
||||
|
||||
var oop = require("../lib/oop");
|
||||
var HtmlMode = require("./html").Mode;
|
||||
var Tokenizer = require("../tokenizer").Tokenizer;
|
||||
var SmartyHighlightRules = require("./smarty_highlight_rules").SmartyHighlightRules;
|
||||
var HtmlBehaviour = require("./behaviour/html").HtmlBehaviour;
|
||||
var HtmlFoldMode = require("./folding/html").FoldMode;
|
||||
|
||||
var Mode = function() {
|
||||
HtmlMode.call(this);
|
||||
this.HighlightRules = SmartyHighlightRules;
|
||||
this.$behaviour = new HtmlBehaviour();
|
||||
|
||||
|
||||
this.foldingRules = new HtmlFoldMode();
|
||||
};
|
||||
|
||||
oop.inherits(Mode, HtmlMode);
|
||||
|
||||
(function() {
|
||||
|
||||
this.$id = "ace/mode/smarty";
|
||||
}).call(Mode.prototype);
|
||||
|
||||
exports.Mode = Mode;
|
||||
});
|
||||
136
lib/ace/mode/smarty_highlight_rules.js
Normal file
136
lib/ace/mode/smarty_highlight_rules.js
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Distributed under the BSD license:
|
||||
*
|
||||
* Copyright (c) 2012, Ajax.org B.V.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of Ajax.org B.V. nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/* This file was autogenerated from https://raw.github.com/amitsnyderman/sublime-smarty/master/Syntaxes/Smarty.tmLanguage (uuid: ) */
|
||||
/****************************************************************************************
|
||||
* IT MIGHT NOT BE PERFECT ...But it's a good start from an existing *.tmlanguage file. *
|
||||
* fileTypes *
|
||||
****************************************************************************************/
|
||||
|
||||
define(function(require, exports, module) {
|
||||
"use strict";
|
||||
|
||||
var oop = require("../lib/oop");
|
||||
var HtmlHighlightRules = require("./html_highlight_rules").HtmlHighlightRules;
|
||||
|
||||
var SmartyHighlightRules = function() {
|
||||
HtmlHighlightRules.call(this);
|
||||
var smartyRules = { start:
|
||||
[ { include: '#comments' },
|
||||
{ include: '#blocks' } ],
|
||||
'#blocks':
|
||||
[ { token: 'punctuation.section.embedded.begin.smarty',
|
||||
regex: '\\{%?',
|
||||
push:
|
||||
[ { token: 'punctuation.section.embedded.end.smarty',
|
||||
regex: '%?\\}',
|
||||
next: 'pop' },
|
||||
{ include: '#strings' },
|
||||
{ include: '#variables' },
|
||||
{ include: '#lang' },
|
||||
{ defaultToken: 'source.smarty' } ] } ],
|
||||
'#comments':
|
||||
[ { token:
|
||||
[ 'punctuation.definition.comment.smarty',
|
||||
'comment.block.smarty' ],
|
||||
regex: '(\\{%?)(\\*)',
|
||||
push:
|
||||
[ { token: 'comment.block.smarty', regex: '\\*%?\\}', next: 'pop' },
|
||||
{ defaultToken: 'comment.block.smarty' } ] } ],
|
||||
'#lang':
|
||||
[ { token: 'keyword.operator.smarty',
|
||||
regex: '(?:!=|!|<=|>=|<|>|===|==|%|&&|\\|\\|)|\\b(?:and|or|eq|neq|ne|gte|gt|ge|lte|lt|le|not|mod)\\b' },
|
||||
{ token: 'constant.language.smarty',
|
||||
regex: '\\b(?:TRUE|FALSE|true|false)\\b' },
|
||||
{ token: 'keyword.control.smarty',
|
||||
regex: '\\b(?:if|else|elseif|foreach|foreachelse|section|switch|case|break|default)\\b' },
|
||||
{ token: 'variable.parameter.smarty', regex: '\\b[a-zA-Z]+=' },
|
||||
{ token: 'support.function.built-in.smarty',
|
||||
regex: '\\b(?:capture|config_load|counter|cycle|debug|eval|fetch|include_php|include|insert|literal|math|strip|rdelim|ldelim|assign|constant|block|html_[a-z_]*)\\b' },
|
||||
{ token: 'support.function.variable-modifier.smarty',
|
||||
regex: '\\|(?:capitalize|cat|count_characters|count_paragraphs|count_sentences|count_words|date_format|default|escape|indent|lower|nl2br|regex_replace|replace|spacify|string_format|strip_tags|strip|truncate|upper|wordwrap)' } ],
|
||||
'#strings':
|
||||
[ { token: 'punctuation.definition.string.begin.smarty',
|
||||
regex: '\'',
|
||||
push:
|
||||
[ { token: 'punctuation.definition.string.end.smarty',
|
||||
regex: '\'',
|
||||
next: 'pop' },
|
||||
{ token: 'constant.character.escape.smarty', regex: '\\\\.' },
|
||||
{ defaultToken: 'string.quoted.single.smarty' } ] },
|
||||
{ token: 'punctuation.definition.string.begin.smarty',
|
||||
regex: '"',
|
||||
push:
|
||||
[ { token: 'punctuation.definition.string.end.smarty',
|
||||
regex: '"',
|
||||
next: 'pop' },
|
||||
{ token: 'constant.character.escape.smarty', regex: '\\\\.' },
|
||||
{ defaultToken: 'string.quoted.double.smarty' } ] } ],
|
||||
'#variables':
|
||||
[ { token:
|
||||
[ 'punctuation.definition.variable.smarty',
|
||||
'variable.other.global.smarty' ],
|
||||
regex: '\\b(\\$)(Smarty\\.)' },
|
||||
{ token:
|
||||
[ 'punctuation.definition.variable.smarty',
|
||||
'variable.other.smarty' ],
|
||||
regex: '(\\$)([a-zA-Z_][a-zA-Z0-9_]*)\\b' },
|
||||
{ token: [ 'keyword.operator.smarty', 'variable.other.property.smarty' ],
|
||||
regex: '(->)([a-zA-Z_][a-zA-Z0-9_]*)\\b' },
|
||||
{ token:
|
||||
[ 'keyword.operator.smarty',
|
||||
'meta.function-call.object.smarty',
|
||||
'punctuation.definition.variable.smarty',
|
||||
'variable.other.smarty',
|
||||
'punctuation.definition.variable.smarty' ],
|
||||
regex: '(->)([a-zA-Z_][a-zA-Z0-9_]*)(\\()(.*?)(\\))' } ] }
|
||||
|
||||
var smartyStart = smartyRules.start;
|
||||
|
||||
Object.keys(smartyRules).forEach(function(x) {
|
||||
if (x == "start")
|
||||
this.$rules[x].unshift.apply(this.$rules[x], smartyRules[x]);
|
||||
else
|
||||
this.$rules[x] = smartyRules[x];
|
||||
}, this);
|
||||
this.normalizeRules();
|
||||
};
|
||||
|
||||
SmartyHighlightRules.metaData = { fileTypes: [ 'tpl' ],
|
||||
foldingStartMarker: '\\{%?',
|
||||
foldingStopMarker: '%?\\}',
|
||||
name: 'Smarty',
|
||||
scopeName: 'text.html.smarty' }
|
||||
|
||||
|
||||
oop.inherits(SmartyHighlightRules, HtmlHighlightRules);
|
||||
|
||||
exports.SmartyHighlightRules = SmartyHighlightRules;
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue