Skip to content

Commit

Permalink
highlight current page, highlight current category, display categorie…
Browse files Browse the repository at this point in the history
…s in main nav, add feature for it
  • Loading branch information
scottkf committed Nov 1, 2010
1 parent a9d1545 commit 3704f64
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 8 deletions.
7 changes: 2 additions & 5 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :main_categories

rescue_from CanCan::AccessDenied do |exception|
flash[:notice] = exception.message
Expand All @@ -8,13 +9,9 @@ class ApplicationController < ActionController::Base


def main_categories
Category.roots
@main_categories = Category.roots
end

#returns all direct descendants of category
def sub_categories(name)
Category.find_by_name(name).children
end


#returns an array of hashes to be used for a form
Expand Down
1 change: 1 addition & 0 deletions app/controllers/categories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def list
#get all articles belonging to category, paginated
#check if the url is a subcategory, if it is, just get subcats
else
flash[:notice] = "No articles found in category, #{@category.name}, sorry!"
redirect_to articles_path
end
end
Expand Down
9 changes: 8 additions & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
<% if can? :manage, Article %>
<li<%= is_active?("articles", "all", "edit")%>><%= link_to "manage articles", articles_all_path %></li>
<% end %>
<% if can? :manage, Category %>
<li<%= is_active?("categories", "index", "new", "edit", "show")%>><%= link_to "manage categories", categories_path %></li>
<% end %>
<% else %>
<li><%= link_to "sign in", new_user_session_path %></li>
<% end %>
Expand All @@ -45,7 +48,11 @@
<nav class="main">
<ul>
<li<%= is_active?("articles", "index")%>><%= link_to "home", articles_path %></li>
<li<%= is_active?("categories", "index", "new", "edit", "show")%>><%= link_to "categories", categories_path %></li>
<% @main_categories.each do |c| -%>
<li<%= is_active?("categories", "list") if @category and @category.id == c.id %>>
<%= link_to c.name, articles_category_path(c.url) %>
</li>
<% end -%>
<li><a href="mailto:web@487teabags.com">contact</a></li>
</ul>
</nav>
Expand Down
11 changes: 10 additions & 1 deletion features/category.feature
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ Feature: Category
Then "hello" should not be seen within select "category[parent_id]"


@navigation
Scenario: For every category, a link should exist in the main nav
Given there is a category with name "hello" and url "hello123"
And there is a category with name "hello2" and url "1234"
When I go to the homepage
Then I should see "hello" within xpath "//nav[@class='main']/ul/li/a"
And I should see "hello2" within xpath "//nav[@class='main']/ul/li/a"





# fopen to add something unique to the layout to check for it
Expand All @@ -69,7 +79,6 @@ Feature: Category
And I have an article in that category
And the layout has "<html><body><h1>UNCOMMONSHIBBOLETH</h1><%= yield %></body></html>"
When I am on the hello23 category page
And show me the page
Then I should see "UNCOMMONSHIBBOLETH" within "h1"


Expand Down
5 changes: 5 additions & 0 deletions features/step_definitions/web_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ def with_scope(locator)
end
end

Then /^I should see "([^"]*)" within xpath "([^"]*)"$/ do |text, xpath|
page.should have_xpath(xpath, :text => text)
end


Then /^"([^"]*)" should be selected for "([^"]*)"$/ do |value, field|
assert page.has_xpath?("//option[@selected = 'selected' and contains(string(), value)]")
end
Expand Down
1 change: 1 addition & 0 deletions public/stylesheets/sass/screen.scss
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ body.bp {
@include column(14, true);
ul {
li {
padding: 0em 0.5em 0em 0.5em;
float: right;
&.active {
background-color: $link-color - #222;
Expand Down
2 changes: 1 addition & 1 deletion public/stylesheets/screen.css

Large diffs are not rendered by default.

0 comments on commit 3704f64

Please sign in to comment.