PageRenderTime 19ms CodeModel.GetById 11ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

Visualforce Page | 70 lines | 47 code | 23 blank | 0 comment | 0 complexity | 80c14e06b1c9a5f7e101f30c8ca6f9ec MD5 | raw file
 2title: Creating an IDE for Scalate
 3in_menu: false
 4--- name:overview
 6# How to create a Scalate IDE
 7We love awesome IDEs! :)
 9--- name:content pipeline:markdown
11# Scalate the IDE friendly template language
13We specifically designed Scalate so that it should work amazingly well in an IDE since all expressions in the templates are Scala using static typing so that when you are editing a template the IDE knows all of the attributes and their types. 
15Your IDE should be capable of great completion and error checking; plus at edit time your IDE should know if you have made any typos in any of your expressions such as maybe getting the property name wrong on a bean you are displaying. Its very easy to make typos in templates!
17## Making it easier on the IDE hacker
19Making great IDE plugins is a lot of work, but we hope we can cut some corners making great IDE plugins for Scalate because:
21* most IDEs already have a plugin to support JSP or Erb editing and dealing with the syntax of mixing HTML/XML markup with a language (Java/Ruby). So for [Ssp](documentation/ssp-reference.html) its just a case of reusing the core JSP/Erb editor with Scala language instead. JSP is pretty complex; Ssp is probably closer to the simplicity of Erb really
22* for IDEs which support HAML already it should be relatively easy to provide [Scaml](documentation/scaml-reference.html) support by just switching the language from Ruby to Scala for a very quick win (other than the change to Scala the differences are minimal).
23* both [Ssp](documentation/ssp-reference.html) and [Scaml](documentation/scaml-reference.html) have very simple surface syntaxes that are easy for IDEs to parse; plus both parsers are implemented using Scala's excellent combinator parser libraries so they should be easy to reuse if you need them. Check out the source code for [SspParser](
24  and [ScamlParser](
25* all the clever stuff in a Scalate template is done by the Scala language which already has great IDE support.
28## JSR 45 Support
30Scalate adds [JSR 45]( metadata to the template classes that it generates.  This means that, when running in Java a debugger, browsing through stack frames of generated template classes will take you to the template file instead of the generated scala file.  This feature should also allow IDE implementors to create Ssp and Scaml editors which allow you to set debugging breakpoints in the templates.
32## Types in scope for the Scala language completion
34Other than detecting when there is a Scala code block or expression in the  [Ssp](documentation/ssp-reference.html) and [Scaml](documentation/scaml-reference.html) template languages, the main thing for the IDE to do is to configure which variables are available and their types for error checking and completion. Here's a break down...
36* the RenderContext is imported so its methods are available. Typically in web applications the ServletRenderContext is imported which adds a few Servlet specific methods (like request/response/session/servletContext/servletConfig); though in some uses and frameworks just a RenderContext that is in scope.
37* each attribute declaration is available in scope (which maybe be imported too if the 'import' keyword is used)
39For example the following [Ssp](documentation/ssp-reference.html) script:
40{pygmentize:: ssp}
41<%@ val bar: String = "this is the default value" %>
42<%@ import val foo: Customer %>
43<p>hello there ${name} and ${bar}</p>
46could be considered to mean the following scala code (using **<<** to refer to rendering output)
48{pygmentize:: scala}
49def render(context: ServletRenderContext, 
50           bar: String = "this is the default value", 
51           foo: Customer): Unit = {
53  import context._
54  import foo._
56  << "<p> hello there"
57  << name
58  << " and "
59  << bar
60  << "</p>"
64The purpose of the above isn't to give a faithful representation of how output is generated (its similar to the above but you could always look at the actual generated scala code in **WEB-INF/\_scalate/src/foo.ssp.scala** to see for sure) - its more to show what variables are in context for the purpose of compiler warnings and method completion.
66So in the above the "name" expression is resoved by the foo variable's import for example.
68## We're here to help!
70If you are considering hacking an IDE plugin for Scalate we're more than happy to help you out, please [get in touch](community.html)! Many thanks!