chrismccord / phoenix_haml

Phoenix Template Engine for Haml
MIT License
158 stars 42 forks source link

function error/0 undefined #14

Closed slavad closed 9 years ago

slavad commented 9 years ago

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

Stavrus commented 9 years ago

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.

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")
nurugger07 commented 9 years ago

@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

Stavrus commented 9 years ago

@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.

nurugger07 commented 9 years ago

@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 :)

slavad commented 9 years ago

@Stavrus, thanks for the workaround

chrismccord commented 9 years ago

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

nurugger07 commented 9 years ago

@chrismccord sounds good. This one is definitely on me & I'm working the issue https://github.com/nurugger07/calliope/issues/45