Skip to content

Commit

Permalink
Merge pull request woople#31 from bigbangtechnology/searching
Browse files Browse the repository at this point in the history
Searching
  • Loading branch information
awd committed May 30, 2012
2 parents 0d826ee + a1eb6c9 commit f0e0dee
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/assets/stylesheets/woople-theme/index.css.less
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*= require woople-theme/grid
*= require woople-theme/buttons
*= require woople-theme/content-item
*= require woople-theme/search-results
*= require woople-theme/pagination
*= require woople-theme/modal
*= require woople-theme/legacy
Expand Down
16 changes: 16 additions & 0 deletions app/assets/stylesheets/woople-theme/search-results.css.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@import "woople-theme/variables.css.less";
@import "woople-theme/colours.css.less";

h2.results-header {
.content-title();
background-color:@highlight;
color: #fff;
display: inline-block;
margin-right: 10px;
padding: 0.5em 20px;
text-shadow:0 1px 0 rgba(0,0,0,0.5);
}

.content-item + h2 {
margin-top: 40px;
}
7 changes: 7 additions & 0 deletions app/helpers/theme_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,11 @@ def menu
model = ThemePresentation.wrap(send(WoopleTheme.configuration.menu_helper), MenuPresenter)
render 'woople-theme/menu', menu: model
end

def results_header(title, path = nil)
output = ""
output << content_tag(:h2, title, class: 'results-header')
output << content_tag(:a, I18n.t('woople_theme.search_results_more'), href: path) unless path.nil?
output.html_safe
end
end
4 changes: 2 additions & 2 deletions app/views/woople-theme/_profile.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="profile">
<form class="search">
<form class="search" action="/search">
<a href="#" class='search-page'><i class="icon-search"></i></a>
<input type="text" class="search-query" placeholder="<%=t 'woople_theme.profile.search' %>">
<input name="q" type="text" class="search-query" placeholder="<%=t 'woople_theme.profile.search' %>" value="<%= params[:q] %>">
</form>
<ul class="nav nav-pills profile-link">
<li class="dropdown">
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ en:
result_title: Result
pass: Pass
fail: Fail
search_results_more: See All >
date:
formats:
default: ! '%b %d %Y'
11 changes: 9 additions & 2 deletions spec/dummy/app/controllers/browse_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

class BrowseController < ApplicationController
layout 'theme'

helper_method :random_unit, :random_video

def video
@course = random_course
Expand All @@ -22,14 +24,19 @@ def show
10.times do
@content_items << random_course
end

end

def course
@course = random_course
end

def search
@content_items = []

helper_method :random_unit
3.times do
@content_items << random_course
end
end

private

Expand Down
9 changes: 9 additions & 0 deletions spec/dummy/app/views/browse/search.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<%= page_header(title: 'Search Results', description: "find what you're looking for") %>
<%= results_header("Courses & Channels", '#') %>
<%= content_items(@content_items) %>
<%= results_header("Videos", '#') %>
<%= outline(OpenStruct.new(videos: 10.times.collect { random_video(0, false, true, true) })) do |outline| %>
<%= outline.videos %>
<% end %>
1 change: 1 addition & 0 deletions spec/dummy/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Dummy::Application.routes.draw do
match 'browse', to: 'browse#show'
match 'search', to: 'browse#search'
match 'course', to: 'browse#course'
match 'course/video', to: 'browse#video'
match 'framework', to: 'framework#show'
Expand Down
24 changes: 24 additions & 0 deletions spec/helpers/theme_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,28 @@ class Attachment; end

end
end

describe "#results_header" do
let(:title) { "Results Header" }

it "always shows the title" do
html = helper.results_header(title)
page = Capybara::Node::Simple.new(html)
page.find('h2.results-header').should have_content(title)
end

it "does not show the more link when the path is nil" do
html = helper.results_header(title)
page = Capybara::Node::Simple.new(html)
page.should_not have_selector("a")
end

it "shows the more link when the path is not nil" do
path = "/search"
html = helper.results_header(title, path)
page = Capybara::Node::Simple.new(html)
page.find("a").should have_content(I18n.t('woople_theme.search_results_more'))
page.should have_css("a[href='#{path}']")
end
end
end

0 comments on commit f0e0dee

Please sign in to comment.