nurugger07 / calliope

An elixir haml parser
Apache License 2.0
198 stars 37 forks source link

Phoenix static_path/2 call in attribute values #45

Closed Stavrus closed 8 years ago

Stavrus commented 9 years ago

Just following up to an issue I mentioned in chrismccord/phoenix_haml#14.

I was trying to convert phoenix's default web/templates/layout/application.html.eex:

<link href="<%= static_path(@conn, "/css/app.css") %>" rel="stylesheet" >

Which renders out to something similar to this:

<link href="/css/app.css?vsn=12AB1212" rel="stylesheet">

HAML equivalent:

%link{href: "#{static_path(@conn, "/css/app.css")}" rel: "stylesheet"}

will give the following when I attempt to run it under phoenix 0.13.1:

== Compilation error on file web/views/layout_view.ex ==
** (ArgumentError) cannot set attribute @conn inside function/macro
    (elixir) lib/kernel.ex:2025: Kernel.do_at/4
    (elixir) expanding macro: Kernel.@/1
    (test) web/views/layout_view.ex:1: Test.LayoutView."application.html"/1
    (phoenix) ~/.../web/views/layout_view.ex:1: Phoenix.Template.__before_compile__/1

This was my workaround:

- item = static_path(@conn, "/js/app.js")
      %script{src: "#{item}"}

Should I be using a different syntax to make that call?

nurugger07 commented 9 years ago

Thanks for reporting this issue. I believe that it is similar to https://github.com/nurugger07/calliope/issues/44 but I will keep it open for now.

smpallen99 commented 8 years ago

Working now when using string interpolation

brianflanagan commented 8 years ago

Apologies for resurrecting this: I'm still getting (ArgumentError) cannot set attribute @conn inside function/macro when I use %link{href: "#{ static_path(@conn, "/css/app.css") }", rel: "stylesheet"}.

smpallen99 commented 8 years ago

@brianflanagan What version of calliope are you using? This should be working in master.

brianflanagan commented 8 years ago

You're right. Ignore me!