chrismccord / phoenix_haml

Phoenix Template Engine for Haml

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

function error/0 undefined

slavad opened this issue · comments

I'm trying to create add haml to a new Phoenix application, but I'm getting this error

$ mix phoenix.server
==> phoenix_haml
Compiled lib/phoenix_haml.ex
Compiled lib/phoenix_haml/engine.ex
Generated phoenix_haml.app
==> hello_phoenix
Compiled lib/hello_phoenix.ex
Compiled web/web.ex
Compiled lib/hello_phoenix/repo.ex
Compiled web/router.ex
Compiled web/views/error_view.ex
Compiled web/controllers/page_controller.ex
Compiled web/views/page_view.ex

== Compilation error on file web/views/layout_view.ex ==
** (CompileError) web/templates/layout/application.html.haml:1: function error/0 undefined
    (stdlib) lists.erl:1336: :lists.foreach/2
    (stdlib) erl_eval.erl:657: :erl_eval.do_apply/6

application.html.haml looks like this:

!!!
%html{:lang => "en"}
  %head
    %meta{:charset => "utf-8"}/
    %meta{:content => "IE=edge", "http-equiv" => "X-UA-Compatible"}/
    %meta{:content => "width=device-width, initial-scale=1", :name => "viewport"}/
    %meta{:content => "", :name => "description"}/
    %meta{:content => "", :name => "author"}/
    %title Hello Phoenix!
    %link{:href => static_path(@conn, "/css/app.css"), :rel => "stylesheet"}/
  %body
    .container{:role => "main"}
      .header
        %ul.nav.nav-pills.pull-right
          %li
            %a{:href => "http://www.phoenixframework.org/docs"} Get Started
        %span.logo
      %p.alert.alert-info{:role => "alert"}= get_flash(@conn, :info)
      %p.alert.alert-danger{:role => "alert"}= get_flash(@conn, :error)
      = @inner
    / /container
    %script{:src => static_path(@conn, "/js/app.js")}
    :javascript
      require("web/static/js/app")

I use phoenix 0.13.1 and phoenix_haml 0.1.2

Is it a bug, or did I miss something? Looks very similar to #4

Hi @slavad, I ran into this issue as well, using phoenix 0.13.1 and phoenix_haml 0.1.2. I narrowed the issue down to how Calliope parses HAML. As it appears to support its own flavor of HAML, which is why you're getting compilation errors, I've marked down the differences I've found so far below that have allowed me to get a parse-able file.

  • No support for hashrockets ("=>").
  • Dashes in attributes don't require you to put the name of the attribute as a string (e.g. http-equiv: "X-UA-Compatible" is acceptable)
  • Multiple attributes do not have to be separated by commas
  • I couldn't quite figure out how to get it to support method calls within attributes (e.g. static_path/2). I found a workaround for this in the code sample below.

This code sample of application.html.haml is supported by Calliope's parser:

!!!
%html{lang: "en"}
  %head
    %meta{charset: "utf-8"}
    %meta{content: "IE=edge" http-equiv: "X-UA-Compatible"}
    %meta{content: "width=device-width, initial-scale=1" name: "viewport"}
    %meta{content: "" name:  "description"}
    %meta{content: "" name: "author"}
    %title Hello Phoenix!
    - item = static_path(@conn, "/css/app.css") 
      %link{href: "#{item}" rel: "stylesheet"}
  %body
    .container{role: "main"}
      .header
        %ul.nav.nav-pills.pull-right
          %li
            %a{href: "http://www.phoenixframework.org/docs"} Get Started
        %span.logo
      %p.alert.alert-info{role: "alert"}= get_flash(@conn, :info)
      %p.alert.alert-danger{role: "alert"}= get_flash(@conn, :error)
      = @inner
    / /container
    - item = static_path(@conn, "/js/app.js")
      %script{src: "#{item}"}
    :javascript
      require("web/static/js/app")

@Stavrus the last two issues need to be addressed in calliope. However, the first two aren't bugs as much as preferences on my part. I tried to implement the necessary haml syntax and only add support for additional syntax when requested. It's really just to keep unused syntax out.

I wonder if I should be more explicit in the README on some of the haml differences. That being said, I'm actively working on the next iteration so if you have any issues that you would like addressed please add them to the Calliope repo.

Thanks for using Calliope & I hope I can make your experience better

@nurugger07 this issue was one of the first hits on google I found when I ran into this error, so I wanted to give anyone else following in my footsteps a quick rundown of what was needed to get the default application.html template converted. Please don't take it as me knocking your project, it was just the "gotchas" I came across with that particular template that I'm hoping others can avoid in order to get up and running with the library faster.

I assumed that the last issue I mentioned was just my unfamiliarity with the library as I only just started using it (along with Elixir/Phoenix), but I'll throw up an issue just in case.

With regards to the first two, http://html2haml.herokuapp.com/ is what I assume @slavad used in generating the initial conversion. I did the same, as it's probably the easiest way to do so, but it uses that unsupported syntax which caused the problem we both ran into.

@Stavrus No, no I really appreciate you using it and thank you for helping others too! Thanks for documenting the issue in calliope. I'll be working more on it today :)

@Stavrus, thanks for the workaround

Closing for now and we can bump the calliope dep when things are handled on that end.

@chrismccord sounds good. This one is definitely on me & I'm working the issue nurugger07/calliope#45