I’d like to write a syntax definition for a JS template compiler I wrote. It emulates Razor syntax, and is called Vash. It’s available: https://github.com/kirbysayshi/vash
As an example, this is what a snippet of Vash (Razor code in JS) would look like:
<table>
@model.blank_order_items.forEach(function(item){
<tr>
<td class="item-color">@item.color[0].long_value</td>
<td class="item-size">@item.size[0].long_value</td>
<td class="item-type">@item.type[0].long_value</td>
<td class="item-quantity">
@if( item.status !== 'consumed' ){
<input name="item-quantity-@item.id" type="text" value="@item.quantity" maxlength="5" size="6" />
} else {
@item.quantity
}
</td>
<td class="item-price">$@item.unit_price</td>
<td class="item-status">@(item.status === 'consumed' ? 'In Inventory' : 'Outstanding')</td>
</tr>
})
</table>
As you can see, it’s main trigger character is the @ symbol, and then is just a combination of HTML and JS.
I’d like to make a syntax definition for it to enable syntax highlighting, but have never done so for Sublime or Textmate. Typically JS templates are separate files, but often they are included inside of HTML source, contained within script tags, like so:
<script type="text/tpl-vash">
<input type="hidden" name="order-id" value="@model.id" />
<div class="row-fluid">
<div class="span4">
<h3 class="order-id">ORDER #: @model.id</h3>
</div>
</div>
</script>
So the question is, how do you create a syntax file that can be active on a buffer, but only for a portion? I wouldn’t want to have to make several syntax files, one for each language you could have this embedded in… for example: HTML (Vash), PHP (Vash), etc. Would this be handled by something like the ‘include’ directive as explained here: http://sublimetext.info/docs/en/extensibility/syntaxdefs.html?
Is this something that can be done, or will the user have to explicitely set their buffer syntax to HTML (Vash) etc?