[IDEA] console/REPL for Scalate templates?

20 views
Skip to first unread message

James Strachan

unread,
Mar 4, 2010, 2:41:24 PM3/4/10
to sca...@googlegroups.com
One very handy feature when hacking rails is being able to boot up a
ruby REPL shell with all the server side variables & state all
initialised so you can tinker with your view/domain/controller
objects. I find myself using the Scala REPL more and more.

Now one of the design goals behind Scalate was that the templates are
statically typed; so that IDE's (once they support scalate** !) should
be able to completely smart complete and then warn at edit time (like
any other bit of scala code) any typeos in method/field/variable names
etc. So you'd know at edit time if a template was valid or not and
using correct expressions. (Sure it might not render quite how you
imagined but thats a different issue :)

However sometimes its easy to forget how to navigate domain objects;
you often want to browse & tinker with them in a REPL kinda way &
inspect them a little.

In some ways the rapid feedback loop of

1. edit template
2. hit reload in browser
3. view results
4. goto 1

is a pretty good alternative to a REPL shell; but sometimes REPL just
helps you tinker & explore first before trying to render things
nicely. e.g. rather than just writing some class in Scala, I'll often
experiment a little in REPL first before writing code or tests.

So I was wondering about having a little icon in your default layout
in your Scalate app (in development mode only) where when you click on
it you get a little popup window (maybe a little GWT app) which gives
you a little REPL shell where you can list variables in scope; see
what methods are implicitly imported (e.g. the imported fields/methods
on the view class), navigate them graphically or via text/tab
completion and then let you invoke arbitrary expression on the objects
available to help you figure out what expressions to use in your
templates.

e.g. imagine a typical day using (say Jersey/Play/someOtherFramework +
Scalate)...

* you add a new controller / resource / DTO called Foo
* you view it in a web page; since its got no view yet, maybe the
default scalate view for a scala.Product.index.ssp renders (or
java.Object.index.ssp maybe which might just show properties using
reflection or something) - i.e. we could have a default view (in
development mode only maybe)
* you decide you wanna change the default view, so you click 'create
custom view' on the little console thingy
* since there's not one available yet, Foo.index.ssp|scaml is
auto-generated for you with a simple view of the key/value pairs of
the object (using the generic introspection/Product rendering)
* there's maybe a link - like in Play - to open the new template file
in TextMate (or rather like webbytest we could open in IDEA/eclipse
using the Atlassian Connector plugin)
http://github.com/jstrachan/webbytest depending on your personal
settings
* now you've got the generated page you start hacking it in your IDE -
as you edit you just hit reload on the browser
* but you might want to pop back into the browser and play with the
controller/resource/DTO in the REPL to figure out how to navigate it
properly to create the view


I'm not saying all of the above must be in scalate BTW; various MVC
frameworks have some kind of console already, so we'd just plugin the
new scalatish bits really - am just talking generically here whichever
MVC framework you used with Scalate.

I guess there's 2 totally separate things really in this ramble

* having some kind of introspector / REPL based on the context in
which the templates execute (since we know for a template exactly what
variables are in scope thats easy to do generically)
* being able to add create/edit template links (which is much simpler
to do BTW :) to more easily build up and edit your templates
iteratively

I guess another alternative BTW is to keep the REPL purely separate;
rather like running "mvn scala:console" or "sbt console" - we could
just have framework specific consoles to boot up Jersey/Play at a
specific URI so that the controller/resource/DTO is all in scope -
then get scalate to construct its bindings - then you're just in the
regular command line scala REPL which has smart completion etc. Maybe
adding functions like "go(url: String)" so you can kinda be a browser
in the REPL switching contexts to get different sets of objects in
scope etc

So maybe all we'd have in the web console would be a little thing for
creating/editing/viewing templates easily and maybe a little
introspector for walking the data/objects available? (I'm not sure yet
how easy it'd be to embed a little REPL in a scalate view ;-)

Maybe I'm thinking a bit too far ahead of ourselves (particularly as
we need to get Scalate 1.0 out first really :), but I just figure we
could add a really useful console fairly easily to folks using any
framework (servlets / Jersey / Play / whatever) since once we get to
the scalate view layer we have a pretty good idea of what the context
is and what bindings are available etc.

Thoughts? Too wacky? :)

** also since SSP uses very similar syntax to JSP; IDEs should be able
to hack up SSP support quickly as its mostly just the basics of JSP
syntax with Scala instead of Java/EL and without all the other JSP
stuff :)

--
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://fusesource.com/

Reply all
Reply to author
Forward
0 new messages