Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ooh now this is more like it

  • Loading branch information...
commit 1df51a5e3a5080a650b834d4006e36e6d1732c7f 1 parent 98fbab9
@stefl authored
View
5 app.rb
@@ -158,8 +158,9 @@ class CostSavingExercise < Sinatra::Base
get "/:council_slug/on/:keyword" do |council_slug,keyword|
@council = DIY::Council.from_slug(council_slug)
- @articles = Directgov::Article.find_by_keyword(keyword)
- if @articles
+ @results = @council.search(keyword)
+ @subject = keyword
+ if @results
haml :on
else
flash[:errors] = "Sorry - we couldn't find anything for that"
View
12 lib/diy.rb
@@ -36,9 +36,9 @@ def self.titleize title, council
common_separators.each{|sep| separator = sep if title.include?(sep)}
if separator
items = title.split(separator)
- if(items.first.similarity(council_name) > 0.5)
+ if(items.first.include?(council_name) || items.first.similarity(council_name) > 0.5)
items.delete_at(0)
- elsif(items.last.similarity(council_name) > 0.5)
+ elsif(items.last.include?(council_name) || items.last.similarity(council_name) > 0.5)
items.delete_at(items.size - 1)
end
items.join(" | ")
@@ -341,6 +341,10 @@ def readable
end
def title
+ return @title unless @title.blank?
+ if @data["title"].blank?
+ self.load_title
+ end
@title ||= DIY.titleize(@data["title"], council)
end
@@ -389,9 +393,9 @@ def extract
end
def readable
- Readability::Document.new(Weary.get(@data["url"]).perform_sleepily.body).read
+ @readable ||= DIY.reroute_links(Readability::Document.new(Weary.get(@data["url"]).perform_sleepily.body).content, self.council)
end
-
+
def title
@title ||= DIY.titleize(@data["title"], council)
end
View
49 views/layout.html.haml
@@ -33,38 +33,7 @@
- else
%link{:href => "/css/pretty.css", :media => 'screen', :rel => 'stylesheet', :type => 'text/css'}/
- - if @council
- <script type="text/javascript"></script>
- :javascript
- var help_me_do_something;
-
- $(function() {
- $('.slideshow').cycle({ fx: 'fade' });
-
- function log(message) {
- $("<div/>").text(message).prependTo("#log");
- $("#log").attr("scrollTop", 0);
- }
- $("#spinner").hide();
- $("#something").autocomplete({
- source: "/#{@council.slug}/suggest",
- minLength: 2,
- search: function(event, ui) {
- $('#spinner').show();
- },
- open: function(event, ui) {
- $('#spinner').hide();
- },
- select: function(event, ui) {
- $('#spinner').hide();
- help_me_do_something = ui.item;
- log(ui.item ? ("Selected: " + ui.item.label + " : " + ui.item.value) : "Nothing selected, input was " + this.value);
- document.location.href = "/#{@council.slug}" + ui.item.value
- $('#spinner').show();
- this.value = ui.item.value;
- }
- });
- });
+
%body
%div#page
@@ -115,16 +84,22 @@
%section#content
- if @council
- %form#do_something{:action=>"/#{@council.slug}/page", :method=>:get, :onsubmit=>"return false;"}
+ %form#do_something{:action=>"/#{@council.slug}/page", :method=>:get, :onsubmit=>"document.location.href='/#{@council.slug}/on/' + $('#something').val(); return false;"}
%label{:for=>"url"}
%span
Show me
%input{:type=>"text",:size=>"48", :name=>"url", :id=>"something", :value=>"something I'd like to know about"}
- %img{:src=>"/ajax-loader.gif", :id=>"spinner"}
- / %button{:type=>"submit", :name=>"please"}
- / %span please
+ //%img{:src=>"/ajax-loader.gif", :id=>"spinner"}
+ %button{:type=>"submit", :name=>"please"}
+ %span please
%span#try
- Try "council tax", "libraries", "park"...
+ Try
+ %a{:href=>"/#{@council.slug}/on/council+tax"} council tax
+ ,
+ %a{:href=>"/#{@council.slug}/on/libraries"} libraries
+ ,
+ %a{:href=>"/#{@council.slug}/on/parks"} parks
+
- unless locals[:hide_page_title] == true
- if @page_title
%header
View
122 views/on.html.haml
@@ -1,2 +1,120 @@
-- @articles.each do |article|
- = haml :article, :layout=>false, :locals=>{:article=>article}
+:javascript
+ $(function () {
+
+ var msie6 = $.browser == 'msie' && $.browser.version < 7;
+
+ if (!msie6) {
+ var top = $('#suggestions').offset().top - parseFloat($('#suggestions').css('margin-top').replace(/auto/, 0));
+ $(window).scroll(function (event) {
+ // what the y position of the scroll is
+ var y = $(this).scrollTop();
+ console.log(y);
+ // whether that's below the form
+ if (y >= top) {
+ // if so, ad the fixed class
+ $('#suggestions').addClass('fixed');
+ console.log("add it");
+ } else {
+ // otherwise remove it
+ $('#suggestions').removeClass('fixed');
+ console.log("remove it");
+ }
+ });
+ }
+ });
+%nav#suggestions
+ %ul
+ %li.top
+ %a{:href=>"#top"}
+ Top
+ - count = 0
+ - @results.each do |result|
+ - count = count+1
+ %li.part
+ %a{:href=>"#part_#{count}"}
+ = result.title
+#results
+ %a{:name=>"top"}
+ #mapsearch
+ %span
+ Loading map...
+
+ :plain
+ <style type="text/css">
+ @import url("http://www.google.com/uds/css/gsearch.css");
+ </style>
+ <style type="text/css">
+ @import url("http://www.google.com/uds/solutions/mapsearch/gsmapsearch.css");
+ </style>
+
+ <style type="text/css">
+ .gsmsc-mapDiv {
+ height: 320px;
+ }
+
+ .gsmsc-idleMapDiv {
+ height: 320px;
+ }
+
+ #mapsearch {
+ width: auto;
+ margin-bottom: 10px;
+ }
+ </style>
+
+ :plain
+ <script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAa7htYtqM06zRBCnvw4H0whQ2RqH0IJk4nJYrk3wVgiCahHSxUhSZ-XIME5C5d57h_y1hobXAi8Jovg"
+ type="text/javascript"></script>
+ <script src="http://www.google.com/uds/api?file=uds.js&v=1.0&source=uds-msw&key=ABQIAAAAa7htYtqM06zRBCnvw4H0whQ2RqH0IJk4nJYrk3wVgiCahHSxUhSZ-XIME5C5d57h_y1hobXAi8Jovg"
+ type="text/javascript"></script>
+
+
+ <!-- Map Search Control and Stylesheet -->
+ <script type="text/javascript">
+ window._uds_msw_donotrepair = true;
+ </script>
+ <script src="http://www.google.com/uds/solutions/mapsearch/gsmapsearch.js?mode=new"
+ type="text/javascript"></script>
+ <script type="text/javascript">
+ var localSearch;
+ function loadSubject() {
+ = "localSearch.execute('#{@subject}');"
+ :plain
+ }
+
+ function LoadMapSearchControl() {
+ var options = {
+ zoomControl : GSmapSearchControl.ZOOM_CONTROL_ENABLE_ALL,
+ title : "DIY Council",
+ url : "http://diycouncil.com",
+ idleMapZoom : GSmapSearchControl.ACTIVE_MAP_ZOOM+1,
+ activeMapZoom : GSmapSearchControl.ACTIVE_MAP_ZOOM+1,
+ onBootComplete : loadSubject
+ }
+
+ - if session[:postcode]
+ = "var center = '#{session[:postcode]}';"
+ - else
+ = "var center = new Object();"
+ = "center.lat = #{@council["lat"]};"
+ = "center.lng = #{@council["lng"]};"
+ :plain
+ localSearch = new GSmapSearchControl(
+ document.getElementById("mapsearch"),
+ center,
+ options
+ );
+ }
+ // arrange for this function to be called during body.onload
+ // event processing
+ $(document).ready(function(){LoadMapSearchControl();
+
+ :plain
+ console.log("tried to load");
+ });
+ </script>
+ - res = 0
+ - @results.each do |item|
+ - res = res + 1
+
+ = haml :_item, :layout=>false, :locals=>{:item=>item, :jumpdown=>"part_#{res}"}
View
107 views/sass/screen.css.sass
@@ -145,76 +145,7 @@ section#content
border-bottom: 1px solid #bbb
+border-radius(10px, 10px, 10px, 10px)
- nav
- h2
- margin: 0
- padding= !line/2 !gutter
-
- font-weight: normal
- text-align: left
- text-transform: uppercase
- text-align: center
- text-shadow: 1px 1px 1px white
-
- color: #999
- +border-radius(0, 10px, 10px, 0)
-
- &.implied
- visibility: hidden
-
- li
- margin: 0 0 1px 0
-
- list-style: none
-
- background: url(/i/bbb.gif) 0 0 repeat-y #e6f3fc
- +border-radius(0, 10px, 10px, 0)
-
- button
- -webkit-appearance: none
- overflow: visible
- +box-sizing(content-box)
- width: auto
-
- margin: 0
- padding: 0
-
- background: transparent
- border: none
- +border-radius(0, 0, 0, 0)
-
- a,
- button span
- width= !unit*2-!gutter*4.5
-
- padding= !line/2 !gutter !line/2 !gutter*3.5
-
- font-size: 1em
- text-shadow: 1px 1px 1px white
- text-decoration: none
- text-align: left
-
- cursor: pointer
- color: black
- background: 10px 50% no-repeat transparent
- border: none
- +border-radius(0, 10px, 10px, 0)
-
- li
- a:hover,
- button:hover span
- color: #333
- background-color: white
-
- strong a,
- strong button span
- width= !unit*2-!gutter*2
- padding= !line/2 !gutter !line/2 !gutter*2
-
- color: black
- background-color: white
- background-image: none !important
- border-bottom: 1px solid #bbb
+
footer#credits
@@ -287,8 +218,12 @@ h2
font-size: 125%
div#postcode
position: absolute
- top: 5px
- left: 5px
+ top: 0px
+ left: 0px
+ padding: 3px
+ padding-right: 6px
+ background-color: #eee
+ +border-radius(0px, 0px, 6px, 0px)
input#postcode
width: 8em !important
#about_this_site
@@ -501,4 +436,30 @@ table
padding: 0.2em
td
border: 1px solid #f6f6f6
- padding: 0.2em
+ padding: 0.2em
+nav#suggestions
+ background-color: #eef3ee
+ +border-radius(8px, 8px, 8px, 8px)
+ padding: 8px
+ position: fixed
+ width: 20% !important
+ ul
+ margin: 0 !important
+ padding: 0 !important
+ text-indent: 0
+ li
+ background-color: transparent !important
+ padding: 0
+ margin: 0
+ text-indent: 0
+ margin-bottom: 0.5em
+ padding-bittom: 0.5em
+ display: block
+ border-bottom: 1px solid #eee
+ a
+ margin: 0
+ padding: 0
+ background-color: transparent !important
+
+div#results
+ margin-left: 320px
Please sign in to comment.
Something went wrong with that request. Please try again.