fxbois / web-mode

web template editing mode for emacs
https://web-mode.org
GNU General Public License v3.0
1.64k stars 260 forks source link

Play Framework Templates with Scala, JS and HTML don't always parse correctly #131

Closed distelli-1 closed 10 years ago

distelli-1 commented 11 years ago

Here is a simple PlayFramework Template:

https://gist.github.com/distelli/7175009

Web Mode is confusing the scala bits with the JS and HTML. If you can make webmode correctly parse HTML that contains Scala Code and JS then you'll make a lot of Play Framework Devs like me happy!

Thanks for building this. Web is super cool!

fxbois commented 11 years ago

@distelli can you try to associate your scala templates with the "razor" engine

fxbois commented 11 years ago

@distelli see engine association on http://web-mode.org

jilen commented 11 years ago

@fxbois Indent seems not work properly screenshot from 2013-10-31 09 20 55

jilen commented 11 years ago

indent with case statement not work properly

@a match {
  case a => {
       <span>xxx</span>
   }
 case a => {
       <span>yyy</span>
   }
}

indent with argument declaration followed by layout declaration not work properly

@(seq: Seq[String])
@admin(title="bar") {
<span>
@for(a <- b)  {
  @a match => {
  case A => {
    <span></span>}
case B => {
  <td></td>}
}
}
</span>
}
fxbois commented 11 years ago

@jilen Parsing razor (/play) is very complicated (compared with all the other engines I ve played with)

Do you know where i can find some info about how to parse such templates (even parser source code)

What is very strange to me is how it knows inside a block that the line is a html line (only because the first char is < ?)

Moreover,

} else {

is a valid razor line. But it is also a valid js line. So we inevitably have conflicts.

It would be great for me to find some help.

Btw, I ve updated web-mode.el yesterday with patches for razor

jilen commented 11 years ago

@fxbois http://www.playframework.com/documentation/2.2.0/ScalaTemplates , there are some rules described in play framework documentation. It is really complicated, because it can embed almost any scala code into play 2.0 template, with the @ character

petro-rudenko commented 11 years ago

+1 razor association didn't help. Would be nice at least basic html features in play templates.

fxbois commented 11 years ago

Could you get the last version of web-mode on github and send me the debug info displayed when you execute the command web-mode-debug

petro-rudenko commented 11 years ago
--- WEB-MODE DEBUG BEG ---
versions: emacs(24.3) web-mode("7.0.50")
vars: engine("razor") content-type("html") file("/home/peter/work/pet/scala/hewi/app/views/config.scala.html")
system: window(x) config("x86_64-pc-linux-gnu")
colors: fg("#e4e4ef") bg("#181818") 
modes: whitespace-mode(nil) rainbow-mode(nil) idle-highlight-mode(nil)
(transient-mark-mode line-number-mode auto-compression-mode auto-encryption-mode auto-composition-mode font-lock-mode global-font-lock-mode file-name-shadow-mode menu-bar-mode mouse-wheel-mode tooltip-mode yas/global-mode recentf-mode show-paren-mode icomplete-mode linum-mode global-linum-mode global-auto-complete-mode delete-selection-mode undo-tree-mode global-undo-tree-mode rainbow-delimiters-mode global-rainbow-delimiters-mode smartparens-mode smartparens-global-mode)
--- WEB-MODE DEBUG END ---
fxbois commented 11 years ago

@petro-rudenko could you put on gist an example that does not work please

petro-rudenko commented 11 years ago

https://gist.github.com/petro-rudenko/dfbcb24bf53358861048

fxbois commented 10 years ago

@distelli @jilen @petro-rudenko I ve pushed a new version. Could you test it please ?

jilen commented 10 years ago
@for(acc <- accounts) {
  <tr>
    <td>@acc.id</td>
    <td>@acc.email</td>
    <td>
      @acc.accountType match {
         case Account.VIP => {<span class="label label-danger">VIP</span>}
      case Account.NORMAL => {<span class="label label-info">}
      }</td>
    <td>@acc.parent</td>
  </tr>

Pattern match with multi case statement seems not parsed correctly.

fxbois commented 10 years ago

@distelli @jilen @petro-rudenko the last version committed should work better

jilen commented 10 years ago

I have tried, it works for me!!! Thanks @fxbois

jilen commented 10 years ago

Some html tag not recognized when file is firstly opened. And will be recognized after edit. Look at the button element Firstly open: screenshot from 2014-01-07 11 34 58 After edit screenshot from 2014-01-07 11 36 13

fxbois commented 10 years ago

@jilen could you post this example on gist please.

Could you also update to the last version available on github et post the output of web-mode-debug

Thank you in advance

jilen commented 10 years ago

I am using the latest web-mode from elpa I post the html file and web-mode-debug output here! https://gist.github.com/jilen/8295906

fxbois commented 10 years ago

@jilen Hope the last commit fixes your issue

(for other issues, could you open new issues please)

fxbois commented 10 years ago

@jilen is it ok ... can I close the issue ?

jilen commented 10 years ago

Ok.