diff options
Diffstat (limited to 'lib/tasks')
-rw-r--r-- | lib/tasks/temp.rake | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/lib/tasks/temp.rake b/lib/tasks/temp.rake index 67fa10174..094bf4492 100644 --- a/lib/tasks/temp.rake +++ b/lib/tasks/temp.rake @@ -1,5 +1,39 @@ +# -*- coding: utf-8 -*- namespace :temp do + desc 'Rewrite cached HTML attachment headers to use responsive CSS' + task :responsive_attachments => :environment do + example = 'rake responsive_attachments PATTERN="./cache/views/request/*/*/response/*/attach/html/*/*.html"' + check_for_env_vars(['PATTERN'],example) + pattern = ENV['PATTERN'] + replacement_head_content = <<-EOF +<!--[if LTE IE 7]> +<link href="/assets/responsive/application-lte-ie7.css" media="all" rel="stylesheet" title="Main" type="text/css" /> +<![endif]--> + +<!--[if IE 8]> +<link href="/assets/responsive/application-ie8.css" media="all" rel="stylesheet" title="Main" type="text/css" /> +<![endif]--> + +<!--[if GT IE 8]><!--> +<link href="/assets/responsive/application.css" media="all" rel="stylesheet" title="Main" type="text/css" /> +<!--<![endif]--> + +<script type="text/javascript" src="//use.typekit.net/csi1ugd.js"></script> +<script type="text/javascript">try{Typekit.load();}catch(e){}</script> +EOF + + + Dir.glob(pattern) do |cached_html_file| + puts cached_html_file + text = File.read(cached_html_file) + text.sub!(/<link [^>]*href="(\/assets\/application.css|\/stylesheets\/main.css|https?:\/\/www.whatdotheyknow.com\/stylesheets\/main.css)[^>]*>/, replacement_head_content) + text.sub!(/<\/div>(\s*This is an HTML version of an attachment to the Freedom of Information request.*?)<\/div>/m, '</div><p class="view_html_description">\1</p></div>') + text.sub!(/<iframe src='http:\/\/docs.google.com\/viewer/, "<iframe src='https://docs.google.com/viewer") + text.sub!(/<\/head>/, '<meta name="viewport" content="width=device-width, initial-scale=1.0" /></head>') + File.open(cached_html_file, 'w') { |file| file.write(text) } + end + end desc 'Analyse rails log specified by LOG_FILE to produce a list of request volume' task :request_volume => :environment do @@ -37,4 +71,38 @@ namespace :temp do end + desc 'Look for broken UTF-8 text in IncomingMessage cached_attachment_text_clipped' + task :find_broken_cached_utf8 => :environment do + PublicBody.find_each do |public_body| + begin + public_body.name.split(' ') + rescue + puts "Bad encoding in public_body #{public_body.id} #{public_body.name}" + public_body.name = public_body.name.force_encoding("cp1252").encode('UTF-8').gsub('’', "'") + public_body.last_edit_editor = 'system' + public_body.last_edit_comment = 'Broken utf-8 encoding fixed by temp:find_broken_cached_utf8' + public_body.save! + public_body.name.split(' ') + puts "Fixed #{public_body.id}" + end + end + + IncomingMessage.find_each do |incoming_message| + begin + incoming_message.get_attachment_text_full.split(' ') + incoming_message.get_attachment_text_clipped.split(' ') + incoming_message.get_main_body_text_folded.split(' ') + incoming_message.get_main_body_text_unfolded.split(' ') + rescue ArgumentError => e + puts "Bad encoding in incoming message #{incoming_message.id}" + incoming_message.clear_in_database_caches! + incoming_message.get_attachment_text_full.split(' ') + incoming_message.get_attachment_text_clipped.split(' ') + incoming_message.get_main_body_text_folded.split(' ') + incoming_message.get_main_body_text_unfolded.split(' ') + puts "Fixed #{incoming_message.id}" + end + end + + end end |