diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/alaveteli_file_types.rb | 2 | ||||
-rw-r--r-- | lib/languages.rb | 5 | ||||
-rw-r--r-- | lib/public_body_categories.rb | 2 | ||||
-rw-r--r-- | lib/quiet_opener.rb | 36 | ||||
-rw-r--r-- | lib/routing_filters.rb | 17 | ||||
-rw-r--r-- | lib/tasks/gettext.rake | 4 | ||||
-rw-r--r-- | lib/tasks/rspec.rake | 19 | ||||
-rw-r--r-- | lib/world_foi_websites.rb | 33 |
8 files changed, 95 insertions, 23 deletions
diff --git a/lib/alaveteli_file_types.rb b/lib/alaveteli_file_types.rb index 076f8ffe8..e89bc0c78 100644 --- a/lib/alaveteli_file_types.rb +++ b/lib/alaveteli_file_types.rb @@ -1,5 +1,3 @@ -require 'mahoro' - class AlaveteliFileTypes # To add an image, create a file with appropriate name corresponding to the # mime type in public/images e.g. icon_image_tiff_large.png diff --git a/lib/languages.rb b/lib/languages.rb index 474c0e0cb..42231ef56 100644 --- a/lib/languages.rb +++ b/lib/languages.rb @@ -187,8 +187,9 @@ class LanguageNames 'za' => 'Saɯ cueŋƅ', 'zu' => 'isiZulu' } - - return language_names[locale] + locale = locale.sub("_", "-") # normalize + main_part = I18n::Locale::Tag::Simple.tag(locale).subtags[0] + return language_names[main_part] end end diff --git a/lib/public_body_categories.rb b/lib/public_body_categories.rb index 796b1d53d..b8058bf9e 100644 --- a/lib/public_body_categories.rb +++ b/lib/public_body_categories.rb @@ -16,7 +16,7 @@ class PublicBodyCategories @with_description = @with_headings.select() { |a| a.instance_of?(Array) } @tags = @with_description.map() { |a| a[0] } @by_tag = Hash[*@with_description.map() { |a| a[0..1] }.flatten] - @singular_by_tag = Hash[*@with_description.map() { |a| [a[0],a[2]] }.flatten] + @singular_by_tag = Hash[*@with_description.map() { |a| [a[0],a[2]] }.flatten] end def PublicBodyCategories.get diff --git a/lib/quiet_opener.rb b/lib/quiet_opener.rb new file mode 100644 index 000000000..cb8cf0619 --- /dev/null +++ b/lib/quiet_opener.rb @@ -0,0 +1,36 @@ +require 'open-uri' +require 'net-purge' + +def quietly_try_to_open(url) + begin + result = open(url).read.strip + rescue OpenURI::HTTPError, SocketError, Errno::ETIMEDOUT, Errno::ECONNREFUSED, Errno::EHOSTUNREACH + Rails.logger.warn("Unable to open third-party URL #{url}") + result = "" + end + return result +end + +def quietly_try_to_purge(host, url) + begin + result = "" + result_body = "" + Net::HTTP.bind '127.0.0.1' do + Net::HTTP.start(host) {|http| + request = Net::HTTP::Purge.new(url) + response = http.request(request) + result = response.code + result_body = response.body + } + end + rescue OpenURI::HTTPError, SocketError, Errno::ETIMEDOUT, Errno::ECONNREFUSED, Errno::EHOSTUNREACH + Rails.logger.warn("PURGE: Unable to reach host #{host}") + end + if result == "200" + Rails.logger.debug("PURGE: Purged URL #{url} at #{host}: #{result}") + else + Rails.logger.warn("PURGE: Unable to purge URL #{url} at #{host}: status #{result}") + end + return result +end + diff --git a/lib/routing_filters.rb b/lib/routing_filters.rb index cdb58e7c1..32dafc651 100644 --- a/lib/routing_filters.rb +++ b/lib/routing_filters.rb @@ -5,5 +5,22 @@ module RoutingFilter def prepend_locale?(locale) locale && I18n.available_locales.length > 1 && (self.class.include_default_locale? || !default_locale?(locale)) end + # And override the generation logic to use FastGettext.locale + # rather than I18n.locale (the latter is what rails uses + # internally and may look like `en_US`, whereas the latter is + # was FastGettext and other POSIX-based systems use, and will + # look like `en_US` + def around_generate(*args, &block) + params = args.extract_options! # this is because we might get a call like forum_topics_path(forum, topic, :locale => :en) + + locale = params.delete(:locale) # extract the passed :locale option + locale = FastGettext.locale if locale.nil? # default to I18n.locale when locale is nil (could also be false) + locale = nil unless valid_locale?(locale) # reset to no locale when locale is not valid + args << params + + yield.tap do |result| + prepend_segment!(result, locale) if prepend_locale?(locale) + end + end end end diff --git a/lib/tasks/gettext.rake b/lib/tasks/gettext.rake index 56e9f6df6..787b4029f 100644 --- a/lib/tasks/gettext.rake +++ b/lib/tasks/gettext.rake @@ -1,3 +1,7 @@ +# Rails won't automatically load rakefiles from gems - see +# http://stackoverflow.com/questions/1878640/including-rake-tasks-in-gems +Dir["#{Gem.searcher.find('gettext_i18n_rails').full_gem_path}/lib/tasks/**/*.rake"].each { |ext| load ext } + namespace :gettext do desc "Update pot file only, without fuzzy guesses (these are done by Transifex)" diff --git a/lib/tasks/rspec.rake b/lib/tasks/rspec.rake index 4024a6a6d..1eee74aee 100644 --- a/lib/tasks/rspec.rake +++ b/lib/tasks/rspec.rake @@ -1,7 +1,6 @@ -gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9 rspec_gem_dir = nil -Dir["#{RAILS_ROOT}/vendor/gems/*"].each do |subdir| - rspec_gem_dir = subdir if subdir.gsub("#{RAILS_ROOT}/vendor/gems/","") =~ /^(\w+-)?rspec-(\d+)/ && File.exist?("#{subdir}/lib/spec/rake/spectask.rb") +Dir["#{Rails.root}/vendor/gems/*"].each do |subdir| + rspec_gem_dir = subdir if subdir.gsub("#{Rails.root}/vendor/gems/","") =~ /^(\w+-)?rspec-(\d+)/ && File.exist?("#{subdir}/lib/spec/rake/spectask.rb") end rspec_plugin_dir = File.expand_path(File.dirname(__FILE__) + '/../../vendor/plugins/rspec') @@ -47,7 +46,7 @@ end Rake.application.instance_variable_get('@tasks').delete('default') -spec_prereq = File.exist?(File.join(RAILS_ROOT, 'config', 'database.yml')) ? "db:test:prepare" : :noop +spec_prereq = File.exist?(File.join(Rails.root, 'config', 'database.yml')) ? "db:test:prepare" : :noop task :noop do end @@ -60,18 +59,18 @@ task :cruise => ['spec'] desc "Run all specs in spec directory (excluding plugin specs)" Spec::Rake::SpecTask.new(:spec => spec_prereq) do |t| - t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] + t.spec_opts = ['--options', "\"#{Rails.root}/spec/spec.opts\""] t.spec_files = FileList['spec/**/*_spec.rb'] end namespace :spec do desc "Run all specs in spec directory with RCov (excluding plugin specs)" Spec::Rake::SpecTask.new(:rcov) do |t| - t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] + t.spec_opts = ['--options', "\"#{Rails.root}/spec/spec.opts\""] t.spec_files = FileList['spec/**/*_spec.rb'] t.rcov = true t.rcov_opts = lambda do - IO.readlines("#{RAILS_ROOT}/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten + IO.readlines("#{Rails.root}/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten end end @@ -90,21 +89,21 @@ namespace :spec do [:models, :controllers, :views, :helpers, :lib, :integration].each do |sub| desc "Run the code examples in spec/#{sub}" Spec::Rake::SpecTask.new(sub => spec_prereq) do |t| - t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] + t.spec_opts = ['--options', "\"#{Rails.root}/spec/spec.opts\""] t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"] end end desc "Run the code examples in vendor/plugins (except RSpec's own)" Spec::Rake::SpecTask.new(:plugins => spec_prereq) do |t| - t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] + t.spec_opts = ['--options', "\"#{Rails.root}/spec/spec.opts\""] t.spec_files = FileList['vendor/plugins/**/spec/**/*_spec.rb'].exclude('vendor/plugins/rspec/*').exclude("vendor/plugins/rspec-rails/*") end namespace :plugins do desc "Runs the examples for rspec_on_rails" Spec::Rake::SpecTask.new(:rspec_on_rails) do |t| - t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] + t.spec_opts = ['--options', "\"#{Rails.root}/spec/spec.opts\""] t.spec_files = FileList['vendor/plugins/rspec-rails/spec/**/*_spec.rb'] end end diff --git a/lib/world_foi_websites.rb b/lib/world_foi_websites.rb index 24845437a..fec40ed64 100644 --- a/lib/world_foi_websites.rb +++ b/lib/world_foi_websites.rb @@ -1,32 +1,49 @@ +# -*- coding: utf-8 -*- class WorldFOIWebsites def self.world_foi_websites world_foi_websites = [ - {:name => "WhatDoTheyKnow?", - :country_name => _("United Kingdom"), + {:name => "WhatDoTheyKnow", + :country_name => "United Kingdom", :country_iso_code => "GB", :url => "http://www.whatdotheyknow.com"}, {:name => "Informata Zyrtare", - :country_name => _("Kosovo"), + :country_name => "Kosova", :country_iso_code => "XK", :url => "http://informatazyrtare.org"}, {:name => "Ask The EU", - :country_name => _("European Union"), + :country_name => "European Union", :country_iso_code => "", :url => "http://asktheu.org"}, {:name => "MuckRock.com", - :country_name => _("United States of America"), + :country_name => "United States of America", :country_iso_code => "US", :url => "http://www.muckrock.com"}, {:name => "FYI", - :country_name => _("New Zealand"), + :country_name => "New Zealand", :country_iso_code => "NZ", :url => "http://fyi.org.nz"}, {:name => "Frag den Staat", - :country_name => _("Germany"), + :country_name => "Deutschland", :country_iso_code => "DE", :url => "http://fragdenstaat.de"}, + {:name => "tu derecho a saber", + :country_name => "España", + :country_iso_code => "ES", + :url => "http://tuderechoasaber.es"}, + {:name => "Queremos Saber", + :country_name => "Brasil", + :country_iso_code => "BR", + :url => "http://queremossaber.org.br"}, + {:name => "Ki Mit Tud", + :country_name => "Magyarország", + :country_iso_code => "HU", + :url => "http://kimittud.atlatszo.hu/"}, + {:name => "PravoDaSznam", + :country_name => "Bosna i Hercegovina", + :country_iso_code => "BA", + :url => "http://www.pravodaznam.ba/"}, {:name => "Acceso Intelligente", - :country_name => _("Chile"), + :country_name => "Chile", :country_iso_code => "CL", :url => "accesointeligente.org"}] return world_foi_websites |