bdkjones / CodeKit-1-Old

146 stars 1 forks source link

Compiling Haml / Ruby Code #198

Open greenz opened 12 years ago

greenz commented 12 years ago

I'm running into an issue with the codekit app when its compiling haml / ruby embedded code. Whenever i have a command with a = in front of it it won't compile correctly even though it compiles fine when i'm not using codekit ui or have it turned off.

= render "home/media"

This is a common command in ruby to render partials inside a haml. When i insert these into my code codeui throws a fit* and will not compile.

bdkjones commented 12 years ago

Hi Greenz,

Can you give me the exact error message you see in the CodeKit log along with the files necessary to replicate the issue on my end?

greenz commented 12 years ago
Exception on line 12: undefined method `render' for #<Object:0x10d45e940>
  Use --trace for backtrace.
  Use --trace for backtrace.

https://gist.github.com/1829384 - Sample code lines 4-7 are commented out on purpose

mediarow is a partial haml text _mediarow.haml and just contains a line of code

%h2 Mediarow Example
bdkjones commented 12 years ago

Are you able to compile this file at the command line, using the HAML command line utility? Or when you say it "compiles fine" outside of CodeKit, do you mean in a Ruby environment or Rails app?

greenz commented 12 years ago

I am able to compile this fine using HAML command line. All the = is doing is passing a partial render into the haml.

http://guides.rubyonrails.org/layouts_and_rendering.html Section 3.4.1 explains this action

boretom commented 12 years ago

@greenz : I also wanted to include partials with HAML and your example did not work for me. Reading through the webpage you included the URL to I realized that it is the documentation for Rails not HAML (it writes about partials like .erb).

The easiest way to include a partial seems to be either use = Haml::Engine.new(IO.read("header.haml")).render or install the stasis gem as explained on a stackoverflow thread.

I went for the first approach and hit a feature (say: bug) of CodeKit. That is the current directory for HAML is set to root (/) instead to the project root and therefore it won't find your HAML partital. I had to manually set the directory like

- Dir.chdir("/full/path/to/my/project")
= Haml::Engine.new(IO.read("header.haml")).render