Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing the menu highliting #19

Merged
merged 2 commits into from Mar 30, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion template.rb
Expand Up @@ -6,7 +6,8 @@ def initialize(view)
end

def render(locals={})
Haml::Engine.new(File.read("views/layout.html.haml")).render do
locals.merge! page: @view
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory, this should really be something like

locals = locals.dup.merge! page: @view

So that you don't mutate the hash that was passed in. That said, I don't think it really matters here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the Feedback Steve!
What would the general concern with mutating the Hash here be? (just curious, only answer if you got time).

Plus: couldn't I just do locals = locals.merge page: @view, or is there something very different about #dup ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would be the general concern

It's not polite to mutate things in Ruby unless it's expected. That's why there's merge and merge! in the first place, no?

Plus: couldn't I just do

yes, that'd work too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep gotta work on immutability and specifically my functional programming. Thanks for elaborating!

Haml::Engine.new(File.read("views/layout.html.haml")).render(Object.new, locals) do
Haml::Engine.new(File.read("views/#{@view}.html.haml")).render(Object.new, locals)
end
end
Expand Down
12 changes: 6 additions & 6 deletions views/layout.html.haml
Expand Up @@ -38,17 +38,17 @@
%a.brand{:href => "/"} Shoes
.nav-collapse
%ul.nav
%li.active
%li{ :class => ('active' if page == :index) }
%a{:href => "/"} Home
%li
%li{ :class => ('active' if page == :downloads) }
%a{:href => "/downloads"} Downloads
%li
%li{ :class => ('active' if page == :tutorials) }
%a{:href => "/tutorials"} Tutorials
%li
%li{ :class => ('active' if page == :blog) }
%a{:href => "/blog"} Blog
%li
%li{ :class => ('active' if page == :contribute) }
%a{:href => "/contribute"} Contribute
%li
%li{ :class => ('active' if page == :about) }
%a{:href => "/about"} About
/ /.nav-collapse
.container
Expand Down