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

/scalate-website/src/creating-ide.page

http://github.com/scalate/scalate
Visualforce Page | 70 lines | 47 code | 23 blank | 0 comment | 0 complexity | 80c14e06b1c9a5f7e101f30c8ca6f9ec MD5 | raw file
 1---
 2title: Creating an IDE for Scalate
 3in_menu: false
 4--- name:overview
 5
 6# How to create a Scalate IDE
 7We love awesome IDEs! :)
 8
 9--- name:content pipeline:markdown
10
11# Scalate the IDE friendly template language
12
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. 
14
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!
16
17## Making it easier on the IDE hacker
18
19Making great IDE plugins is a lot of work, but we hope we can cut some corners making great IDE plugins for Scalate because:
20
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](http://github.com/scalate/scalate/blob/master/scalate-core/src/main/scala/org/fusesource/scalate/ssp/SspParser.scala)
24  and [ScamlParser](http://github.com/scalate/scalate/blob/master/scalate-core/src/main/scala/org/fusesource/scalate/scaml/ScamlParser.scala)
25* all the clever stuff in a Scalate template is done by the Scala language which already has great IDE support.
26
27
28## JSR 45 Support
29
30Scalate adds [JSR 45](http://jcp.org/aboutJava/communityprocess/final/jsr045/index.html) 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.
31
32## Types in scope for the Scala language completion
33
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...
35
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)
38
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>
44{pygmentize}
45
46could be considered to mean the following scala code (using **<<** to refer to rendering output)
47
48{pygmentize:: scala}
49def render(context: ServletRenderContext, 
50           bar: String = "this is the default value", 
51           foo: Customer): Unit = {
52
53  import context._
54  import foo._
55  
56  << "<p> hello there"
57  << name
58  << " and "
59  << bar
60  << "</p>"
61} 
62{pygmentize}
63
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.
65
66So in the above the "name" expression is resoved by the foo variable's import for example.
67
68## We're here to help!
69
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!