Home Download Buy Blog Forum Support

I want to create syntax highlighting for Silverstripe CMS

I want to create syntax highlighting for Silverstripe CMS

Postby mrsteveheyes on Tue Mar 27, 2012 8:20 pm

Hi, my names Steve. I am new here, so if I am posting in the wrong section please forgive me and let me know!

I use a CMS called SilverStipe - http://www.silverstripe.org/ - and I think it's great. You should check it out, especially the new version 3 beta! Looks great!

However, it uses it's own templating language and file extension which is .ss . The theme I am using at the moment (Solarized) doesn't do a very good job so I wanted to created whatever is needed to get it right. It will be very similar to how PHP is in HTML so I don't think it will be very difficult.

Could someone help me with what I will need to do to do this for happen?

Cheers,
Steve
mrsteveheyes
 
Posts: 4
Joined: Tue Mar 27, 2012 7:36 pm

Re: I want to create syntax highlighting for Silverstripe CMS

Postby nick. on Tue Mar 27, 2012 10:18 pm

If you're a developer yourself, creating a syntax is not difficult. Basically it's just a lot of regex's and an understanding of the scope taxonomy. The SilverStripe templating docs will be useful. Here is documentation on syntax in Sublime, and this is the corresponding page for Textmate (from which Sublime derives it's syntax features).

For a templating system, it shouldn't be too difficult. I'm in the process of building a Perl syntax from scratch, and that's a bit more complex. :)
nick.
 
Posts: 266
Joined: Wed Jan 18, 2012 3:45 am

Re: I want to create syntax highlighting for Silverstripe CMS

Postby mrsteveheyes on Wed Mar 28, 2012 1:27 pm

Thanks, thats a real help!

I have started to create one but I'm not worrying about the patterns and snippets yet. Just wanted it to look the same as HTML to start with (including colour of the tags etc) so made a real simple one. Below is the JSON and the buiult XML tmLanguage code for what I have so far:

Code: Select all
{ "name": "SilverStripe Templates",
  "scopeName": "text.html.ss",
  "fileTypes": ["ss"],
  "patterns": [
  ],
  "uuid": "461239ff-321d-4b44-bc63-6f8a7d6bce4a"
}


and the built XML:

Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
   <key>fileTypes</key>
   <array>
      <string>ss</string>
   </array>
   <key>name</key>
   <string>SilverStripe Templates</string>
   <key>patterns</key>
   <array>
   </array>
   <key>scopeName</key>
   <string>text.html.ss</string>
   <key>uuid</key>
   <string>461239ff-321d-4b44-bc63-6f8a7d6bce4a</string>
</dict>
</plist>


However, when I restart SublimeText 2 and make a new .ss file it doesn't use any of the same colouring and HTML. Am I missing something, or misunderstanding scopes?
mrsteveheyes
 
Posts: 4
Joined: Tue Mar 27, 2012 7:36 pm

Re: I want to create syntax highlighting for Silverstripe CMS

Postby nick. on Wed Mar 28, 2012 1:49 pm

You haven't defined any scopes of value. "text.html" is like a last-resort scope, and most schemes probably won't define it (except to define "text" or "source"). A better way would be to include the HTML syntax:

Code: Select all
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
       <key>fileTypes</key>
       <array>
          <string>ss</string>
       </array>
       <key>name</key>
       <string>SilverStripe Templates</string>
       <key>patterns</key>
       <array>
              <dict>
                     <key>include</key>
                     <string>text.html</string>
              </dict>
       </array>
       <key>scopeName</key>
       <string>source.ss</string>
       <key>uuid</key>
       <string>461239ff-321d-4b44-bc63-6f8a7d6bce4a</string>
    </dict>
    </plist>

That way you get all the scopes defined by the HTML.tmLanguage file.

But what you really should be doing is an edit to the HTML.tmLanguage file to include SilverStripe specific syntax. So you might add:
Code: Select all
<dict>
       <key>contentName</key>
       <string>embedded.source.ss</string>
       <key>begin</key>
       <string>&lt;%</string>
       <key>end</string>
       <string>%&gt;</string>
       <key>patterns</key>
       <array>
              <dict>
                     <key>include</key>
                     <string>source.ss</string>
              </dict>
       </array>
</dict>


Then in the SilverStripe.tmLanguage, you only have to worry about the SilverStripe syntax.
nick.
 
Posts: 266
Joined: Wed Jan 18, 2012 3:45 am

Re: I want to create syntax highlighting for Silverstripe CMS

Postby mrsteveheyes on Wed Mar 28, 2012 3:53 pm

Thanks again nick.

I've copied your code into my file and it doesn't work. Also added it the the JSON and re built it but that didn't work. I've been following what is in the docs:

Select Json to tmLanguage in Tools | Build System
Press F7
A .tmLanguage file will be generated for you in the same folder as your .JSON-tmLanguage file
Restart Sublime Text so all your changes can take effect


Also, what you suggested goes against what the TextMate docs seem to be saying:

But if you are specializing an existing type, you probably want to derive the name from the type you are specializing. For example Markdown is text.html.markdown and Ruby on Rails (rhtml files) is text.html.rails.


I can't find anything in the docs about "include" though

Any ideas?

Cheers
mrsteveheyes
 
Posts: 4
Joined: Tue Mar 27, 2012 7:36 pm

Re: I want to create syntax highlighting for Silverstripe CMS

Postby nick. on Wed Mar 28, 2012 7:02 pm

In the code I provided, change "text.html" to "text.html.basic" . My mistake.

The include key is documented better on the Textmate resouce. Basically it allows you to pull in another syntax, items from the repository of the current syntax, or the entire current syntax itself. It's really powerful.

As to scope naming, if you look in the default HTML.tmLanguage file, you'll see that php is included as "source.php" . That is pulling in the full PHP language, so it's a bit different than SS's templating language. I assumed that it was possible to insert arbitrary PHP alongside the SS template, which may not be correct. In any case, I think you'll be fine naming the scope either "text.html.ss" or "source.ss" . I do think my previous post's latter suggestion is the way to go though, since this we're dealing with an HTML file with embedded PHP, not the other way around.*

* Okay, it actually is the other way around since it will be handled server side by PHP. But it LOOKS like an HTML file for the most part, so I think it's easier to treat it as such.
nick.
 
Posts: 266
Joined: Wed Jan 18, 2012 3:45 am

Re: I want to create syntax highlighting for Silverstripe CMS

Postby mrsteveheyes on Thu Mar 29, 2012 9:30 am

Thats brilliant! Got it working a treat!

It also seems that most of the stuff is already working, such as the <% %> stuff which is great!

Bellow is the code for anyone to use:

Code: Select all
{ "name": "SilverStripe Templates",
    "scopeName": "source.ss",
    "fileTypes": ["ss"],
    "patterns": [{
        "include": "text.html.basic"
    }],
    "uuid": "461239ff-321d-4b44-bc63-6f8a7d6bce4a"
}


Thanks nick, You've been a real help
mrsteveheyes
 
Posts: 4
Joined: Tue Mar 27, 2012 7:36 pm

Re: I want to create syntax highlighting for Silverstripe CMS

Postby benjamin-smith on Wed Dec 19, 2012 2:52 pm

For those stumbling in from Google, I've created a ST2 package for SilverStripe templates, with syntax highlighting and snippets. Install via Package Control or via the github repo: http://bit.ly/UueqnL
benjamin-smith
 
Posts: 1
Joined: Wed Dec 19, 2012 2:50 pm


Return to Technical Support

Who is online

Users browsing this forum: Exabot [Bot], Google [Bot], Majestic-12 [Bot] and 31 guests