Przeglądaj źródła

Add CSV downloads

main
Adrian Short 6 lat temu
rodzic
commit
891a910e6f
3 zmienionych plików z 29 dodań i 0 usunięć
  1. +17
    -0
      bin/build
  2. +7
    -0
      public/style.css
  3. +5
    -0
      views/authority.haml

+ 17
- 0
bin/build Wyświetl plik

@@ -4,6 +4,7 @@ require 'scraperwiki'
require 'haml'
require 'pp'
require 'logger'
require 'csv'
require_relative '../lib/helpers'

OUTPUT_DIR = '_site'
@@ -28,6 +29,15 @@ def write_page(path_items, template, locals = {})
# https://support.google.com/webmasters/answer/183668?hl=en&ref_topic=4581190
end

def write_csv(path_items, filename, data)
dir = File.join(OUTPUT_DIR, path_items)
FileUtils.mkdir_p(dir)
@log.debug dir
fn = File.join(dir, filename + '.csv')
File.write(fn, data)
@log.info fn
end

def create_output_dir
# Recursively delete working directory to ensure no redundant files are left behind from previous builds.
# FileUtils.rm_rf(@working_dir)
@@ -56,6 +66,13 @@ def gen_authorities
")
apps = ScraperWiki.select("* from applications where authority_name='#{auth['authority_name']}' order by date_received")
write_page(['authorities', slug(auth['authority_name'])], 'authority', { apps: apps, auth: auth, summary: summary })

csv_string = CSV.generate do |csv|
csv << apps.first.keys # header row
apps.each { |app| csv << app.values }
end

write_csv(['authorities', slug(auth['authority_name'])], slug(auth['authority_name']), csv_string)
end
end



+ 7
- 0
public/style.css Wyświetl plik

@@ -162,6 +162,13 @@ nav
padding: 10px 20px;
}

.button, .button a, .button a:visited {
background-color: green;
color: white;
padding: 5px 10px;
margin: 10px 0;
}

.menu {
margin: 0;
padding: 0;


+ 5
- 0
views/authority.haml Wyświetl plik

@@ -21,6 +21,11 @@

%h2 Applications

%p
- csv_fn = slug(auth['authority_name']) + '.csv'
%a.button{ :href => csv_fn, :download => csv_fn }
Download CSV data

%table
%thead
%tr


Ładowanie…
Anuluj
Zapisz