winton / stasis

Static sites made powerful
http://stasis.me
MIT License
677 stars 56 forks source link

Ignore causes doc to be rendered without layout #19

Closed trisulnsm closed 13 years ago

trisulnsm commented 13 years ago

I ran into something that might be a bug or maybe I am using it wrong. Please take a look at this.

The problem happens when you render an 'ignored' document from one that is not ignored. If this happens, the doc that is not ignored is rendered without a layout.

Lets say you have this setup

Directory

features/
      controller.rb
      features.textile
      index.html.haml

Contents of file

index.html.haml

= render  "features.textile"

features.textile

h1.  Hi from features

controller.rb

ignore /textile/

Running stasis on this causes the index.html.haml to be rendered without a layout. Removing the ignore /textile/ code causes it to render correctly.

I dug down into the code found this


    # This event triggers before each file renders through Stasis. It sets the `action`
    # layout from the matching layout for `path`.
    def before_render
      @stasis.action._layout = nil
      matches = _match_key?(@layouts, @stasis.path)
      matches.each do |(within, layout)|
        @stasis.action._layout = layout if _within?(within)
      end
    end

Changing the

@stasis.action._layout = nil statement to @stasis.action._layout ||= nil seems to solve the problem.

This works for me but I would like to hear from you if this looks like a good enough fix.

Regards,

Vivek - thankful user of stasis

winton commented 13 years ago

Hello. I am having trouble reproducing this issue. In your example above, I do not see a layout file. Could you post your complete controller.rb file? Also please tell me your Ruby version.

trisulnsm commented 13 years ago

Thanks for looking into this.

Git issues doesnt seem to allow me to attach my sample project, so I created a gist with the 5 files.

https://gist.github.com/1274736

The files are

/controller.rb /layouts/layout.html.haml /releases/index.html.haml /releases/body.textile /releases/controller.rb

Unfortunately GIST doesnt allow subdirectories, so I used an underscore to name the files.

Basically I want to ignore the body.textile file because it is intended to be assembled by the haml files. Running stasis without the fix causes public/releases/index.html to render without the layout. WIth the fix it renders correctly.

Thanks,

winton commented 13 years ago

I downloaded your example and renamed to the directories you outlined. The layout was present in the index.html file that was generated.

What version of Ruby are you running?

trisulnsm commented 13 years ago

Sorry , I didnt notice you asked this earlier -

The ruby version is

ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]

It is weird because it works fine when run under rdebug !!

winton commented 13 years ago

Vivek, so sorry to have taken so long on this. Hopefully I haven't lost you :)

I believe I have fixed this in the latest release (1.1.14). Thanks for your patience.

trisulnsm commented 13 years ago

Winton,

Havent lost me at all. Stasis is fantastic, I used it in conjunction with Twitter bootstrap to build this site (trisul.org) I am going to write up a detailed blog on how other folks can use this powerful combination.

As far as the problem, I worked around it by specifying layout for each file.

So instead of

layout /textile/ => '/layouts/docsection.html.haml'

I did

before /textile/ do layout '/layouts/docsection.html.haml' end

I will give the new build a spin and report back.