Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

ooh now this is more like it

  • Loading branch information...
commit 1df51a5e3a5080a650b834d4006e36e6d1732c7f 1 parent 98fbab9
Stef Lewandowski authored
5 app.rb
@@ -158,8 +158,9 @@ class CostSavingExercise < Sinatra::Base
158 158
159 159 get "/:council_slug/on/:keyword" do |council_slug,keyword|
160 160 @council = DIY::Council.from_slug(council_slug)
161   - @articles = Directgov::Article.find_by_keyword(keyword)
162   - if @articles
  161 + @results = @council.search(keyword)
  162 + @subject = keyword
  163 + if @results
163 164 haml :on
164 165 else
165 166 flash[:errors] = "Sorry - we couldn't find anything for that"
12 lib/diy.rb
@@ -36,9 +36,9 @@ def self.titleize title, council
36 36 common_separators.each{|sep| separator = sep if title.include?(sep)}
37 37 if separator
38 38 items = title.split(separator)
39   - if(items.first.similarity(council_name) > 0.5)
  39 + if(items.first.include?(council_name) || items.first.similarity(council_name) > 0.5)
40 40 items.delete_at(0)
41   - elsif(items.last.similarity(council_name) > 0.5)
  41 + elsif(items.last.include?(council_name) || items.last.similarity(council_name) > 0.5)
42 42 items.delete_at(items.size - 1)
43 43 end
44 44 items.join(" | ")
@@ -341,6 +341,10 @@ def readable
341 341 end
342 342
343 343 def title
  344 + return @title unless @title.blank?
  345 + if @data["title"].blank?
  346 + self.load_title
  347 + end
344 348 @title ||= DIY.titleize(@data["title"], council)
345 349 end
346 350
@@ -389,9 +393,9 @@ def extract
389 393 end
390 394
391 395 def readable
392   - Readability::Document.new(Weary.get(@data["url"]).perform_sleepily.body).read
  396 + @readable ||= DIY.reroute_links(Readability::Document.new(Weary.get(@data["url"]).perform_sleepily.body).content, self.council)
393 397 end
394   -
  398 +
395 399 def title
396 400 @title ||= DIY.titleize(@data["title"], council)
397 401 end
49 views/layout.html.haml
@@ -33,38 +33,7 @@
33 33 - else
34 34 %link{:href => "/css/pretty.css", :media => 'screen', :rel => 'stylesheet', :type => 'text/css'}/
35 35
36   - - if @council
37   - <script type="text/javascript"></script>
38   - :javascript
39   - var help_me_do_something;
40   -
41   - $(function() {
42   - $('.slideshow').cycle({ fx: 'fade' });
43   -
44   - function log(message) {
45   - $("<div/>").text(message).prependTo("#log");
46   - $("#log").attr("scrollTop", 0);
47   - }
48   - $("#spinner").hide();
49   - $("#something").autocomplete({
50   - source: "/#{@council.slug}/suggest",
51   - minLength: 2,
52   - search: function(event, ui) {
53   - $('#spinner').show();
54   - },
55   - open: function(event, ui) {
56   - $('#spinner').hide();
57   - },
58   - select: function(event, ui) {
59   - $('#spinner').hide();
60   - help_me_do_something = ui.item;
61   - log(ui.item ? ("Selected: " + ui.item.label + " : " + ui.item.value) : "Nothing selected, input was " + this.value);
62   - document.location.href = "/#{@council.slug}" + ui.item.value
63   - $('#spinner').show();
64   - this.value = ui.item.value;
65   - }
66   - });
67   - });
  36 +
68 37
69 38 %body
70 39 %div#page
@@ -115,16 +84,22 @@
115 84 %section#content
116 85
117 86 - if @council
118   - %form#do_something{:action=>"/#{@council.slug}/page", :method=>:get, :onsubmit=>"return false;"}
  87 + %form#do_something{:action=>"/#{@council.slug}/page", :method=>:get, :onsubmit=>"document.location.href='/#{@council.slug}/on/' + $('#something').val(); return false;"}
119 88 %label{:for=>"url"}
120 89 %span
121 90 Show me
122 91 %input{:type=>"text",:size=>"48", :name=>"url", :id=>"something", :value=>"something I'd like to know about"}
123   - %img{:src=>"/ajax-loader.gif", :id=>"spinner"}
124   - / %button{:type=>"submit", :name=>"please"}
125   - / %span please
  92 + //%img{:src=>"/ajax-loader.gif", :id=>"spinner"}
  93 + %button{:type=>"submit", :name=>"please"}
  94 + %span please
126 95 %span#try
127   - Try "council tax", "libraries", "park"...
  96 + Try
  97 + %a{:href=>"/#{@council.slug}/on/council+tax"} council tax
  98 + ,
  99 + %a{:href=>"/#{@council.slug}/on/libraries"} libraries
  100 + ,
  101 + %a{:href=>"/#{@council.slug}/on/parks"} parks
  102 +
128 103 - unless locals[:hide_page_title] == true
129 104 - if @page_title
130 105 %header
122 views/on.html.haml
... ... @@ -1,2 +1,120 @@
1   -- @articles.each do |article|
2   - = haml :article, :layout=>false, :locals=>{:article=>article}
  1 +:javascript
  2 + $(function () {
  3 +
  4 + var msie6 = $.browser == 'msie' && $.browser.version < 7;
  5 +
  6 + if (!msie6) {
  7 + var top = $('#suggestions').offset().top - parseFloat($('#suggestions').css('margin-top').replace(/auto/, 0));
  8 + $(window).scroll(function (event) {
  9 + // what the y position of the scroll is
  10 + var y = $(this).scrollTop();
  11 + console.log(y);
  12 + // whether that's below the form
  13 + if (y >= top) {
  14 + // if so, ad the fixed class
  15 + $('#suggestions').addClass('fixed');
  16 + console.log("add it");
  17 + } else {
  18 + // otherwise remove it
  19 + $('#suggestions').removeClass('fixed');
  20 + console.log("remove it");
  21 + }
  22 + });
  23 + }
  24 + });
  25 +%nav#suggestions
  26 + %ul
  27 + %li.top
  28 + %a{:href=>"#top"}
  29 + Top
  30 + - count = 0
  31 + - @results.each do |result|
  32 + - count = count+1
  33 + %li.part
  34 + %a{:href=>"#part_#{count}"}
  35 + = result.title
  36 +#results
  37 + %a{:name=>"top"}
  38 + #mapsearch
  39 + %span
  40 + Loading map...
  41 +
  42 + :plain
  43 + <style type="text/css">
  44 + @import url("http://www.google.com/uds/css/gsearch.css");
  45 + </style>
  46 + <style type="text/css">
  47 + @import url("http://www.google.com/uds/solutions/mapsearch/gsmapsearch.css");
  48 + </style>
  49 +
  50 + <style type="text/css">
  51 + .gsmsc-mapDiv {
  52 + height: 320px;
  53 + }
  54 +
  55 + .gsmsc-idleMapDiv {
  56 + height: 320px;
  57 + }
  58 +
  59 + #mapsearch {
  60 + width: auto;
  61 + margin-bottom: 10px;
  62 + }
  63 + </style>
  64 +
  65 + :plain
  66 + <script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAa7htYtqM06zRBCnvw4H0whQ2RqH0IJk4nJYrk3wVgiCahHSxUhSZ-XIME5C5d57h_y1hobXAi8Jovg"
  67 + type="text/javascript"></script>
  68 + <script src="http://www.google.com/uds/api?file=uds.js&v=1.0&source=uds-msw&key=ABQIAAAAa7htYtqM06zRBCnvw4H0whQ2RqH0IJk4nJYrk3wVgiCahHSxUhSZ-XIME5C5d57h_y1hobXAi8Jovg"
  69 + type="text/javascript"></script>
  70 +
  71 +
  72 + <!-- Map Search Control and Stylesheet -->
  73 + <script type="text/javascript">
  74 + window._uds_msw_donotrepair = true;
  75 + </script>
  76 + <script src="http://www.google.com/uds/solutions/mapsearch/gsmapsearch.js?mode=new"
  77 + type="text/javascript"></script>
  78 + <script type="text/javascript">
  79 + var localSearch;
  80 + function loadSubject() {
  81 + = "localSearch.execute('#{@subject}');"
  82 + :plain
  83 + }
  84 +
  85 + function LoadMapSearchControl() {
  86 + var options = {
  87 + zoomControl : GSmapSearchControl.ZOOM_CONTROL_ENABLE_ALL,
  88 + title : "DIY Council",
  89 + url : "http://diycouncil.com",
  90 + idleMapZoom : GSmapSearchControl.ACTIVE_MAP_ZOOM+1,
  91 + activeMapZoom : GSmapSearchControl.ACTIVE_MAP_ZOOM+1,
  92 + onBootComplete : loadSubject
  93 + }
  94 +
  95 + - if session[:postcode]
  96 + = "var center = '#{session[:postcode]}';"
  97 + - else
  98 + = "var center = new Object();"
  99 + = "center.lat = #{@council["lat"]};"
  100 + = "center.lng = #{@council["lng"]};"
  101 + :plain
  102 + localSearch = new GSmapSearchControl(
  103 + document.getElementById("mapsearch"),
  104 + center,
  105 + options
  106 + );
  107 + }
  108 + // arrange for this function to be called during body.onload
  109 + // event processing
  110 + $(document).ready(function(){LoadMapSearchControl();
  111 +
  112 + :plain
  113 + console.log("tried to load");
  114 + });
  115 + </script>
  116 + - res = 0
  117 + - @results.each do |item|
  118 + - res = res + 1
  119 +
  120 + = haml :_item, :layout=>false, :locals=>{:item=>item, :jumpdown=>"part_#{res}"}
107 views/sass/screen.css.sass
@@ -145,76 +145,7 @@ section#content
145 145 border-bottom: 1px solid #bbb
146 146 +border-radius(10px, 10px, 10px, 10px)
147 147
148   - nav
149   - h2
150   - margin: 0
151   - padding= !line/2 !gutter
152   -
153   - font-weight: normal
154   - text-align: left
155   - text-transform: uppercase
156   - text-align: center
157   - text-shadow: 1px 1px 1px white
158   -
159   - color: #999
160   - +border-radius(0, 10px, 10px, 0)
161   -
162   - &.implied
163   - visibility: hidden
164   -
165   - li
166   - margin: 0 0 1px 0
167   -
168   - list-style: none
169   -
170   - background: url(/i/bbb.gif) 0 0 repeat-y #e6f3fc
171   - +border-radius(0, 10px, 10px, 0)
172   -
173   - button
174   - -webkit-appearance: none
175   - overflow: visible
176   - +box-sizing(content-box)
177   - width: auto
178   -
179   - margin: 0
180   - padding: 0
181   -
182   - background: transparent
183   - border: none
184   - +border-radius(0, 0, 0, 0)
185   -
186   - a,
187   - button span
188   - width= !unit*2-!gutter*4.5
189   -
190   - padding= !line/2 !gutter !line/2 !gutter*3.5
191   -
192   - font-size: 1em
193   - text-shadow: 1px 1px 1px white
194   - text-decoration: none
195   - text-align: left
196   -
197   - cursor: pointer
198   - color: black
199   - background: 10px 50% no-repeat transparent
200   - border: none
201   - +border-radius(0, 10px, 10px, 0)
202   -
203   - li
204   - a:hover,
205   - button:hover span
206   - color: #333
207   - background-color: white
208   -
209   - strong a,
210   - strong button span
211   - width= !unit*2-!gutter*2
212   - padding= !line/2 !gutter !line/2 !gutter*2
213   -
214   - color: black
215   - background-color: white
216   - background-image: none !important
217   - border-bottom: 1px solid #bbb
  148 +
218 149
219 150
220 151 footer#credits
@@ -287,8 +218,12 @@ h2
287 218 font-size: 125%
288 219 div#postcode
289 220 position: absolute
290   - top: 5px
291   - left: 5px
  221 + top: 0px
  222 + left: 0px
  223 + padding: 3px
  224 + padding-right: 6px
  225 + background-color: #eee
  226 + +border-radius(0px, 0px, 6px, 0px)
292 227 input#postcode
293 228 width: 8em !important
294 229 #about_this_site
@@ -501,4 +436,30 @@ table
501 436 padding: 0.2em
502 437 td
503 438 border: 1px solid #f6f6f6
504   - padding: 0.2em
  439 + padding: 0.2em
  440 +nav#suggestions
  441 + background-color: #eef3ee
  442 + +border-radius(8px, 8px, 8px, 8px)
  443 + padding: 8px
  444 + position: fixed
  445 + width: 20% !important
  446 + ul
  447 + margin: 0 !important
  448 + padding: 0 !important
  449 + text-indent: 0
  450 + li
  451 + background-color: transparent !important
  452 + padding: 0
  453 + margin: 0
  454 + text-indent: 0
  455 + margin-bottom: 0.5em
  456 + padding-bittom: 0.5em
  457 + display: block
  458 + border-bottom: 1px solid #eee
  459 + a
  460 + margin: 0
  461 + padding: 0
  462 + background-color: transparent !important
  463 +
  464 +div#results
  465 + margin-left: 320px

0 comments on commit 1df51a5

Please sign in to comment.
Something went wrong with that request. Please try again.