aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/alaveteli_external_command.rb19
-rw-r--r--lib/i18n_fixes.rb4
-rw-r--r--lib/patches/fixtures_constraint_disabling.rb21
-rw-r--r--lib/public_body_categories.rb7
-rw-r--r--lib/public_body_categories_en.rb94
-rw-r--r--lib/tasks/gettext.rake20
-rw-r--r--lib/tmail_extensions.rb2
-rw-r--r--lib/willpaginate_extension.rb59
-rw-r--r--lib/willpaginate_hack.rb14
9 files changed, 137 insertions, 103 deletions
diff --git a/lib/alaveteli_external_command.rb b/lib/alaveteli_external_command.rb
index b967c89b5..b1d4f17d1 100644
--- a/lib/alaveteli_external_command.rb
+++ b/lib/alaveteli_external_command.rb
@@ -11,11 +11,26 @@ module AlaveteliExternalCommand
opts = args.pop
end
- xc = ExternalCommand.new(program_name, *args)
+ if program_name =~ %r(^/)
+ program_path = program_name
+ else
+ utility_search_path = MySociety::Config.get("UTILITY_SEARCH_PATH", ["/usr/bin", "/usr/local/bin"])
+ found = false
+ utility_search_path.each do |d|
+ program_path = File.join(d, program_name)
+ if File.file? program_path and File.executable? program_path
+ found = true
+ break
+ end
+ end
+ raise "Could not find #{program_name} in any of #{utility_search_path.join(', ')}" if !found
+ end
+
+ xc = ExternalCommand.new(program_path, *args)
if opts.has_key? :append_to
xc.out = opts[:append_to]
end
- xc.run()
+ xc.run(opts[:stdin_string], opts[:env] || {})
if xc.status != 0
# Error
$stderr.puts("Error from #{program_name} #{args.join(' ')}:")
diff --git a/lib/i18n_fixes.rb b/lib/i18n_fixes.rb
index fad258a72..6e684d44a 100644
--- a/lib/i18n_fixes.rb
+++ b/lib/i18n_fixes.rb
@@ -22,9 +22,9 @@ def gettext_interpolate(string, values)
if escaped
pattern
elsif INTERPOLATION_RESERVED_KEYS.include?(pattern)
- raise ReservedInterpolationKey.new(pattern, string)
+ raise I18n::ReservedInterpolationKey.new(pattern, string)
elsif !values.include?(key)
- raise MissingInterpolationArgument.new(pattern, string)
+ raise I18n::MissingInterpolationArgument.new(pattern, string)
else
values[key].to_s
end
diff --git a/lib/patches/fixtures_constraint_disabling.rb b/lib/patches/fixtures_constraint_disabling.rb
new file mode 100644
index 000000000..7d97e81f7
--- /dev/null
+++ b/lib/patches/fixtures_constraint_disabling.rb
@@ -0,0 +1,21 @@
+# An alternative way of disabling foreign keys in fixture loading in Postgres and
+# does not require superuser permissions
+# http://kopongo.com/2008/7/25/postgres-ri_constrainttrigger-error
+require 'active_record/connection_adapters/postgresql_adapter'
+module ActiveRecord
+ module ConnectionAdapters
+ class PostgreSQLAdapter < AbstractAdapter
+ def disable_referential_integrity(&block)
+ transaction {
+ begin
+ execute "SET CONSTRAINTS ALL DEFERRED"
+ yield
+ ensure
+ execute "SET CONSTRAINTS ALL IMMEDIATE"
+ end
+ }
+ end
+ end
+ end
+end
+
diff --git a/lib/public_body_categories.rb b/lib/public_body_categories.rb
index 21a021d39..796b1d53d 100644
--- a/lib/public_body_categories.rb
+++ b/lib/public_body_categories.rb
@@ -20,7 +20,7 @@ class PublicBodyCategories
end
def PublicBodyCategories.get
- load_categories() if @@CATEGORIES.nil?
+ load_categories if @@CATEGORIES.empty?
@@CATEGORIES[I18n.locale.to_s] || @@CATEGORIES[I18n.default_locale.to_s] || PublicBodyCategories.new([])
end
@@ -30,10 +30,9 @@ class PublicBodyCategories
end
private
- @@CATEGORIES = nil
+ @@CATEGORIES = {}
def PublicBodyCategories.load_categories()
- @@CATEGORIES = {} if @@CATEGORIES.nil?
I18n.available_locales.each do |locale|
begin
load "public_body_categories_#{locale}.rb"
@@ -41,4 +40,4 @@ class PublicBodyCategories
end
end
end
-end \ No newline at end of file
+end
diff --git a/lib/public_body_categories_en.rb b/lib/public_body_categories_en.rb
index 5fe762357..95eed750b 100644
--- a/lib/public_body_categories_en.rb
+++ b/lib/public_body_categories_en.rb
@@ -1,83 +1,19 @@
-# lib/public_body_categories.rb:
-# Categorisations of public bodies.
+# The PublicBodyCategories structure works like this:
+# [
+# "Main category name",
+# [ "tag_to_use_as_category", "Sub category title", "sentence that can describes things in this subcategory" ],
+# [ "another_tag", "Second sub category title", "another descriptive sentence for things in this subcategory"],
+# "Another main category name",
+# [ "another_tag_2", "Another sub category title", "another descriptive sentence"]
+# ])
#
-# Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved.
-# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
-#
-# $Id: public_body_categories.rb,v 1.1 2009-09-14 14:45:48 francis Exp $
+# DO NOT EDIT THIS FILE! It should be overridden in a custom theme.
+# See doc/THEMES.md for more info
PublicBodyCategories.add(:en, [
- "Miscellaneous",
- [ "other", "Miscellaneous", "miscellaneous" ],
- "Central government",
- [ "department", "Ministerial departments", "a ministerial department" ],
- [ "non_ministerial_department", "Non-ministerial departments", "a non-ministerial department" ],
- [ "executive_agency", "Executive agencies", "an executive agency" ],
- [ "government_office", "Government offices for the regions", "a government office for the regions" ],
- [ "advisory_committee", "Advisory committees", "an advisory committee" ],
- [ "awc", "Agricultural wages committees", "an agriculatural wages committee" ],
- [ "adhac", "Agricultural dwelling house advisory committees", "an agriculatural dwelling house advisory committee" ],
- [ "newdeal", "New Deal for Communities partnership", "a New Deal for Communities partnership" ],
- "Local and regional",
- [ "local_council", "Local councils", "a local council" ],
- [ "parish_council", "Town and Parish councils", "a town or parish council"],
- [ "housing_association", "Housing associations", "a housing association"],
- [ "almo", "Housing ALMOs", "a housing ALMO"],
- [ "municipal_bank", "Municipal bank", "a municipal bank"],
- [ "nsbody", "North/south bodies", "a north/south body"],
- [ "pbo", "Professional buying organisations", "a professional buying organisation"],
- [ "regional_assembly", "Regional assemblies", "a regional assembly"],
- [ "rda", "Regional development agencies", "a regional development agency" ],
- "Education",
- [ "university", "Universities", "a university" ],
- [ "university_college", "University colleges", "a university college" ],
- [ "cambridge_college", "Cambridge colleges", "a Cambridge college" ],
- [ "durham_college", "Durham colleges", "a Durham college" ],
- [ "oxford_college", "Oxford colleges", "an Oxford college or permanent private hall" ],
- [ "york_college", "York colleges", "a college of the University of York" ],
- [ "university_owned_company", "University owned companies", "a university owned company" ],
- [ "hei", "Higher education institutions", "a higher educational institution" ],
- [ "fei", "Further education institutions", "a further educational institution" ],
- [ "school", "Schools", "a school" ],
- [ "research_council", "Research councils", "a research council" ],
- [ "lib_board", "Education and library boards", "an education and library board" ],
- [ "rbc", "Regional Broadband Consortia", "a Regional Broadband Consortium" ],
- "Environment",
- [ "npa", "National park authorities", "a national park authority" ],
- [ "rpa", "Regional park authorities", "a regional park authority" ],
- [ "sea_fishery_committee", "Sea fisheries committees", "a sea fisheries committee" ],
- [ "watercompanies", "Water companies", "a water company" ],
- [ "idb", "Internal drainage boards", "an internal drainage board" ],
- [ "rfdc", "Regional flood defence committees", "a regional flood defence committee" ],
- [ "wda", "Waste disposal authorities", "a waste disposal authority" ],
- [ "zoo", "Zoos", "a zoo" ],
- "Health",
- [ "nhstrust", "NHS trusts", "an NHS trust" ],
- [ "pct", "Primary care trusts", "a primary care trust" ],
- [ "nhswales", "NHS in Wales", "part of the NHS in Wales" ],
- [ "nhsni", "NHS in Northern Ireland", "part of the NHS in Northern Ireland" ],
- [ "hscr", "Health / social care", "Relating to health / social care" ],
- [ "pha", "Port health authorities", "a port health authority"],
- [ "sha", "Strategic health authorities", "a strategic health authority" ],
- [ "specialha", "Special health authorities", "a special health authority" ],
- "Media and culture",
- [ "media", "Media", "a media organisation" ],
- [ "rcc", "Cultural consortia", "a cultural consortium"],
- [ "museum", "Museums and galleries", "a museum or gallery" ],
- "Military and security services",
- [ "military_college", "Military colleges", "a military college" ],
- [ "security_services", "Security services", "a security services body" ],
- "Emergency services and the courts",
- [ "police", "Police forces", "a police force" ],
- [ "police_authority", "Police authorities", "a police authority" ],
- [ "dpp", "District policing partnerships", "a district policing partnership" ],
- [ "fire_service", "Fire and rescue services", "a fire and rescue service" ],
- [ "prob_board", "Probation boards", "a probation board" ],
- [ "rules_committee", "Rules commitees", "a rules committee" ],
- [ "tribunal", "Tribunals", "a tribunal"],
- "Transport",
- [ "npte", "Passenger transport executives", "a passenger transport executive" ],
- [ "port_authority", "Port authorities", "a port authority" ],
- [ "scp", "Safety Camera Partnerships", "a safety camera partnership" ],
- [ "srp", "Safer Roads Partnership", "a safer roads partnership" ]
+ "Silly ministries",
+ [ "useless_agency", "Useless ministries", "a useless ministry" ],
+ [ "lonely_agency", "Lonely agencies", "a lonely agency"],
+ "Popular agencies",
+ [ "popular_agency", "Popular agencies", "a lonely agency"]
])
diff --git a/lib/tasks/gettext.rake b/lib/tasks/gettext.rake
index 017e7c837..8ffd5ce1b 100644
--- a/lib/tasks/gettext.rake
+++ b/lib/tasks/gettext.rake
@@ -1,5 +1,23 @@
namespace :gettext do
+
+ desc "Update pot file only, without fuzzy guesses (these are done by Transifex)"
+ task :findpot => :environment do
+ load_gettext
+ $LOAD_PATH << File.join(File.dirname(__FILE__),'..','..','lib')
+ require 'gettext_i18n_rails/haml_parser'
+ files = files_to_translate
+
+ #write found messages to tmp.pot
+ temp_pot = "tmp.pot"
+ GetText::rgettext(files, temp_pot)
+
+ #merge tmp.pot and existing pot
+ FileUtils.mkdir_p('locale')
+ GetText::msgmerge("locale/app.pot", temp_pot, "version 0.0.1", :po_root => 'locale', :msgmerge=>[ :no_fuzzy_matching, :sort_output ])
+ File.delete(temp_pot)
+ end
+
def files_to_translate
Dir.glob("{app,lib,config,locale}/**/*.{rb,erb,haml,rhtml}")
end
-end \ No newline at end of file
+end
diff --git a/lib/tmail_extensions.rb b/lib/tmail_extensions.rb
index 6a5044cdb..f35565352 100644
--- a/lib/tmail_extensions.rb
+++ b/lib/tmail_extensions.rb
@@ -30,7 +30,7 @@ module TMail
# Monkeypatch! Return the name part of from address, or nil if there isn't one
def from_name_if_present
if self.from && self.from_addrs[0].name
- return self.from_addrs[0].name
+ return TMail::Unquoter.unquote_and_convert_to(self.from_addrs[0].name, "utf-8")
else
return nil
end
diff --git a/lib/willpaginate_extension.rb b/lib/willpaginate_extension.rb
new file mode 100644
index 000000000..3cdb0ae60
--- /dev/null
+++ b/lib/willpaginate_extension.rb
@@ -0,0 +1,59 @@
+# this extension is loaded in environment.rb
+module WillPaginateExtension
+ class LinkRenderer < WillPaginate::LinkRenderer
+ def page_link(page, text, attributes = {})
+ # Hack for admin pages, when proxied via https on mySociety servers, they
+ # need a relative URL.
+ url = url_for(page)
+ if url.match(/\/admin.*(\?.*)/)
+ url = $1
+ end
+ # Hack around our type-ahead search magic
+ if url.match(/\/body\/search_ahead/)
+ url.sub!("/body/search_ahead", "/select_authority")
+ end
+ @template.link_to text, url, attributes
+ end
+
+ # Returns URL params for +page_link_or_span+, taking the current GET params
+ # and <tt>:params</tt> option into account.
+ def url_for(page)
+ page_one = page == 1
+ unless @url_string and !page_one
+ @url_params = {}
+ # page links should preserve GET parameters
+ stringified_merge @url_params, @template.params if @template.request.get?
+ stringified_merge @url_params, @options[:params] if @options[:params]
+ if complex = param_name.index(/[^\w-]/)
+ page_param = parse_query_parameters("#{param_name}=#{page}")
+
+ stringified_merge @url_params, page_param
+ else
+ @url_params[param_name] = page_one ? 1 : 2
+ end
+ # the following line makes pagination work on our specially munged search page
+ combined = @template.request.path_parameters["combined"]
+ @url_params["combined"] = combined if !combined.nil?
+ url = @template.url_for(@url_params)
+ return url if page_one
+
+ if complex
+ @url_string = url.sub(%r!((?:\?|&amp;)#{CGI.escape param_name}=)#{page}!, "\\1\0")
+ return url
+ else
+ @url_string = url
+ @url_params[param_name] = 3
+ @template.url_for(@url_params).split(//).each_with_index do |char, i|
+ if char == '3' and url[i, 1] == '2'
+ @url_string[i] = "\0"
+ break
+ end
+ end
+ end
+ end
+ # finally!
+ @url_string.sub "\0", page.to_s
+ end
+
+ end
+end
diff --git a/lib/willpaginate_hack.rb b/lib/willpaginate_hack.rb
deleted file mode 100644
index 084329e82..000000000
--- a/lib/willpaginate_hack.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-# Monkeypatch! Hack for admin pages, when proxied via https on mySociety servers, they
-# need a relative URL.
-module WillPaginate
- class LinkRenderer
- def page_link(page, text, attributes = {})
- url = url_for(page)
- if url.match(/^\/admin.*(\?.*)/)
- url = $1
- end
- @template.link_to text, url, attributes
- end
- end
-end
-