Angular

23 views
Skip to first unread message

Jon Stevens

unread,
Sep 25, 2013, 11:04:32 PM9/25/13
to cambridge...@googlegroups.com
I'm trying to use Angular with Cambridge and it is failing with a parse error on the empty attributes on an html element. Specifically the 'ng-app' attribute.

<div class="widget-content" ng-app>

What can we do to make this work? If I set it to ng-app="ng-app", that parses, but isn't the Angular way of doing things since it is expecting a module name there.

Some helpful docs: http://docs.angularjs.org/guide/bootstrap

I'm using master of Cambridge.

thanks,

jon

Erdinc Yilmazel

unread,
Sep 26, 2013, 9:34:49 AM9/26/13
to cambridge...@googlegroups.com
This is surprising to me. I'll take a look as soon as I can.




--
You received this message because you are subscribed to the Google Groups "Cambridge Template Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cambridgetempla...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Jon Stevens

unread,
Sep 26, 2013, 10:17:29 AM9/26/13
to cambridge...@googlegroups.com
Sitting in the debugger, I can see the issue, but I'm not entirely sure of the fix. What's happening is that the 'element' variable is not being created because line 376 of TemplateParser.java is a switch statement where textContent gets appended, but element is never set, so things blow up on line 447, per the stack trace below...

Caused by: Error parsing template file. Unterminated tag? - On line: 5, column: 29 (Line: 5, Col: 29)
   at cambridge.parser.TemplateParser.tag(TemplateParser.java:447)
   at cambridge.parser.TemplateParser.getNode(TemplateParser.java:212)
   at cambridge.parser.TemplateParser.parse(TemplateParser.java:171)
   at cambridge.AbstractTemplateLoader.parseTemplate(AbstractTemplateLoader.java:49)

jon

Erdinc Yilmazel

unread,
Sep 26, 2013, 10:36:52 AM9/26/13
to cambridge...@googlegroups.com
Yeah, I just reproduced the issue. I'll try to fix soon.

Jon Stevens

unread,
Sep 26, 2013, 10:45:50 AM9/26/13
to cambridge...@googlegroups.com
Great, thanks Erdinc! =)

Also note that I sent a pull request to update the mvn pom files to simplify them a bit and add building of the source files. I've recently become more of an expert in it, sigh. I'm using mvn 3.1.0.

jon

Tom Carchrae

unread,
Sep 26, 2013, 11:15:30 AM9/26/13
to cambridge...@googlegroups.com
Sorry this is off topic, but...

On Thu, Sep 26, 2013 at 7:45 AM, Jon Stevens <latc...@gmail.com> wrote:

I've recently become more of an expert in it, sigh. I'm using mvn 3.1.0.

Knowing what you know now, was it worth the investment in becoming an expert?  I realize that you must succumb to the maven way or die (if you use it), but I still feel it is tremendously cumbersome as a build tool every time I give it a day or so of my life (and often rip it out after a day or two)

Tom

 

Jeff Schnitzer

unread,
Sep 26, 2013, 11:26:24 AM9/26/13
to cambridge...@googlegroups.com
Jon can chime in further, but speaking from our experience... yes, but only marginally.

It's actually pretty good for fairly simple projects, especially with modern eclipse integration. Managing dependencies this way beats doing it by hand by far.  Unfortunately it breaks down pretty quickly when you have a complicated project (we have multiple projects with multiple modules, one of which is packaged as an ear and deployed to GAE). The end result is better than the old way (countless jars in WEB-INF/lib) but it has taken countless hours of Jon's time to get it working. Part of this has been the immaturity of GAE's maven plugins, though. But that's part of the problem - any deviation from the rigid maven process requires complicated plugins.

It's just depressing because there were a number of really bad design decisions taken with Maven; it's not hard to imagine a build tool dramatically better but we don't want to invest the massive time required to produce it. BTW, Gradle is no better - actually worse in most ways. We used Ivy for a while too before going with Maven.

So yeah... I'd make the switch, but reluctantly.

Jeff


--

Tom Carchrae

unread,
Sep 26, 2013, 11:59:55 AM9/26/13
to cambridge...@googlegroups.com
Thanks Jeff.  Yeah, from a dependency management point of view, Maven is great and it is great to have a standard.  Although Ivy + Ant and you can have the same.  Or gradle, which I'll agree seems like Maven for people who hate XML (but love Groovy?!).  I recently learned that Mojo actually stands for Maven Pojo - I had always presumed it was the Screaming Jay kind of Mojo.

For the most part, I use Eclipse and love how JDT can swap in bytecode without recompiles.  I guess that might be possible with the Eclipse Maven plugin, but I've never seen that work.  Aside from fighting with dependencies and builds, that part really kills it for me, but I've always wondered if it was because I was doing it wrong.


Jon Stevens

unread,
Sep 27, 2013, 12:17:02 AM9/27/13
to cambridge...@googlegroups.com
Maven is great when you are just building a jar file. It falls flat on its face when you need to inject a process between two lifecycle mappings that a single plugin is handling. For example, when you want to war up your code, but you want to run a javascript minimizer first... it just isn't possible. You have to effectively create the war folder yourself first... then minimize the code into that folder (by running some sort of exec plugin) ... then maven just builds up the war from that folder. Total hack. Yes, this can be viewed as the fault of the plugin to not offer this sort of functionality, but the reality is that this is a fundamental flaw in the design of maven. lifecycles really should have before and after tasks that you can attach things to. Another huge issue is that the Java community around maven is pretty much dead (or moved onto other things I guess). Want to build a 'skinny war'? All the documentation on it died off in 2009 as evidenced by the fact that this page hasn't been updated since then and nobody has solved this problem... http://docs.codehaus.org/display/MAVENUSER/Solving+the+Skinny+Wars+problem

I could keep going... but I've resigned myself to becoming a maven 'expert' simply because I don't have the time or energy to deal with this issue any longer. =(

jon

Jon Stevens

unread,
Sep 28, 2013, 1:25:06 AM9/28/13
to cambridge...@googlegroups.com
Hey Erdinc,

Not to pressure you, but any luck on fixing the parser?

thanks,

jon

Erdinc Yilmazel

unread,
Sep 29, 2013, 10:38:52 AM9/29/13
to cambridge...@googlegroups.com
Jon, did you file a bug on github about this? I just checked in the fix for this: https://github.com/erdincyilmazel/Cambridge/commit/03b4c58a6342dedd603017001028aa81ac52b81e

Thanks for reporting the issue.

Erdinç
Template_parser_fix_to_support_attributes_with_no_values.patch

Jon Stevens

unread,
Sep 29, 2013, 1:59:31 PM9/29/13
to cambridge...@googlegroups.com
I didn't file a bug. Sorry. 

Thanks for the fix, although I'm curious about this diff... 1) you did seem to follow your own code conventions with the braces. 2) no tests?

jon

Erdinc Yilmazel

unread,
Sep 29, 2013, 6:20:32 PM9/29/13
to cambridge...@googlegroups.com

You are right about the braces, I was rushing the patch before I left home today and my ide was configured with my work conventions.  I'll get to adding tests later.

Jon Stevens

unread,
Sep 29, 2013, 7:55:10 PM9/29/13
to cambridge...@googlegroups.com
Thanks so much for getting it out quickly. I tested it today and it is working perfectly. It seems that AngularJS likes attributes with no values quite a bit and this is going to help a lot.

On a side note, I'm starting to 'get' Angular after playing with it a bit and I'm really impressed with it. As a test, I'm converting a few simple Voost pages over to it and it seems like I'll be able to delete a metric ton of my code because Angular handles, by default, most of what I am doing by hand. I like deleting code. =)

jon

Erdinc Yilmazel

unread,
Sep 29, 2013, 8:05:48 PM9/29/13
to cambridge...@googlegroups.com
Angular is great. We are using it to develop some internal tools at TripAdvisor. If we had Angular a few years back, I wouldn't probably attempt to create a server side template engine. 

Jon Stevens

unread,
Sep 29, 2013, 9:29:17 PM9/29/13
to cambridge...@googlegroups.com
I still see a need for Cambridge actually... Voost isn't a single page app at all. I still need to be able to use nested templates and Cambridge is perfect for that. =)

jon

Jeff Schnitzer

unread,
Sep 29, 2013, 9:48:24 PM9/29/13
to cambridge...@googlegroups.com
Yeah, until Google is "perfect" at indexing heavily generated pages, we are going to be dependent on server-side templates.

Jeff

Tom Carchrae

unread,
Sep 30, 2013, 12:42:18 PM9/30/13
to cambridge...@googlegroups.com
Aside from the googlebot - there are quite a few platforms that don't always behave as expected with lots of javascript.  Hello smartphones and tablets...  but there are also other things like rendering email templates as well.  

I've been working on a template system that can run on either client or server.  I get a bit worried that I'm reinventing a very old (and heavily reinvented) wheel, but I still haven't found anything that was a clear match.  Perhaps the closest thing is using phantomjs to generate pages.  

The crux of my approach is dead simple; all templates are defined using standard HTML.  In full javascript mode, all links, buttons and forms are detected/intercepted and when clicked, they turn into events.  The events run some logic that will eventually render events to update the page HTML.  In server mode, those page elements act in their traditional HTML like manner, generating a new page render - which is produced by running the same events/logic that would run in the browser.

Sure, there are limitations to this, primarily, you don't want dozens of page fetches in a short time, or small pieces of page update, and you need to keep some UI context/state on the server for each user (or somehow encode it in a cookie/URL/etc).  However, I've been surprised at how much of this has worked quite well with this pattern....  so far, anyway, I've spent less than a week making a server version out of my client code.

I'm using vertx.io (which could run javascript on the server) and GWT in the browser (which runs logic code written in Java which is translated to javascript).   I think GWT is brilliant for client-side logic but the UI components in GWT don't do it for me and lag behind other JS components.  

I once thought about porting Cambridge to GWT, which would let it run client-side, and while that is probably possible, it could be a lot of work for each expression language.  Right now I'm using dust.js - which is not without issues, but is pretty good because it has quite good template composition features - and I've sunk enough time into it that I can hack it into doing what I want.

Tom

ps, a quick google indicates people using angular and phantom for indexing: https://github.com/steeve/angular-seo





Reply all
Reply to author
Forward
0 new messages