parliament-utils 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.hound.yml +4 -0
  4. data/.rspec +2 -0
  5. data/.rubocop.yml +55 -0
  6. data/.ruby-version +1 -0
  7. data/.travis.yml +5 -0
  8. data/CODE_OF_CONDUCT.md +74 -0
  9. data/Gemfile +7 -0
  10. data/Instructions - Steps to include in app.md +95 -0
  11. data/LICENSE +7 -0
  12. data/Makefile +16 -0
  13. data/README.md +177 -0
  14. data/Rakefile +6 -0
  15. data/bin/console +14 -0
  16. data/bin/setup +8 -0
  17. data/config/locales/en.yml +387 -0
  18. data/config/puma.rb +20 -0
  19. data/lib/parliament/utils/config/initializers/airbrake.rb +76 -0
  20. data/lib/parliament/utils/config/initializers/assets.rb +11 -0
  21. data/lib/parliament/utils/config/initializers/backtrace_silencers.rb +7 -0
  22. data/lib/parliament/utils/config/initializers/bandiera.rb +3 -0
  23. data/lib/parliament/utils/config/initializers/cookies_serializer.rb +3 -0
  24. data/lib/parliament/utils/config/initializers/filter_parameter_logging.rb +4 -0
  25. data/lib/parliament/utils/config/initializers/inflections.rb +16 -0
  26. data/lib/parliament/utils/config/initializers/mime_types.rb +7 -0
  27. data/lib/parliament/utils/config/initializers/session_store.rb +3 -0
  28. data/lib/parliament/utils/config/initializers/timeout.rb +1 -0
  29. data/lib/parliament/utils/config/initializers/wrap_parameters.rb +9 -0
  30. data/lib/parliament/utils/config/initializers.rb +16 -0
  31. data/lib/parliament/utils/helpers/application_helper.rb +68 -0
  32. data/lib/parliament/utils/helpers/flag_helper.rb +29 -0
  33. data/lib/parliament/utils/helpers/format_helper.rb +18 -0
  34. data/lib/parliament/utils/helpers/houses_helper.rb +80 -0
  35. data/lib/parliament/utils/helpers/parliament_helper.rb +22 -0
  36. data/lib/parliament/utils/helpers/postcode_helper.rb +72 -0
  37. data/lib/parliament/utils/helpers/request_helper.rb +30 -0
  38. data/lib/parliament/utils/helpers/translation_helper.rb +12 -0
  39. data/lib/parliament/utils/helpers/v_card_helper.rb +57 -0
  40. data/lib/parliament/utils/helpers.rb +18 -0
  41. data/lib/parliament/utils/railtie.rb +12 -0
  42. data/lib/parliament/utils/test_helpers/bandiera_helper.rb +19 -0
  43. data/lib/parliament/utils/test_helpers/rails_helper.rb +42 -0
  44. data/lib/parliament/utils/test_helpers/rspec_helper.rb +76 -0
  45. data/lib/parliament/utils/test_helpers/simplecov_helper.rb +20 -0
  46. data/lib/parliament/utils/test_helpers/vcr_helper.rb +83 -0
  47. data/lib/parliament/utils/test_helpers/webmock_helper.rb +13 -0
  48. data/lib/parliament/utils/test_helpers.rb +19 -0
  49. data/lib/parliament/utils/version.rb +5 -0
  50. data/lib/parliament/utils.rb +10 -0
  51. data/log/test.log +0 -0
  52. data/parliament-utils.gemspec +41 -0
  53. metadata +318 -0
@@ -0,0 +1,387 @@
1
+ # Files in the config/locales directory are used for internationalization
2
+ # and are automatically loaded by Rails. If you want to use locales other
3
+ # than English, add the necessary files in this directory.
4
+ #
5
+ # To use the locales, use `I18n.t`:
6
+ #
7
+ # I18n.t 'hello'
8
+ #
9
+ # In views, this is aliased to just `t`:
10
+ #
11
+ # <%= t('hello') %>
12
+ #
13
+ # To use a different locale, set it with `I18n.locale`:
14
+ #
15
+ # I18n.locale = :es
16
+ #
17
+ # This would use the information in config/locales/es.yml.
18
+ #
19
+ # To learn more, please read the Rails Internationalization guide
20
+ # available at http://guides.rubyonrails.org/i18n.html.
21
+
22
+ en:
23
+ # global people translations
24
+ mp: 'MP'
25
+ mp_plural: 'MPs'
26
+ lord: 'Lord'
27
+ lord_plural: 'Lords'
28
+ mps_and_lords: 'MPs and Lords'
29
+ mp_count:
30
+ zero: 'MPs'
31
+ one: 'MP'
32
+ other: 'MPs'
33
+ lord_count:
34
+ zero: 'Lords'
35
+ one: 'Lord'
36
+ other: 'Lords'
37
+ house_of_commons_speaker: 'The Speaker of the House of Commons'
38
+ # global constituency translations
39
+ constituency: 'constituency'
40
+ constituency_plural: 'constituencies'
41
+ # global party translations
42
+ party: 'party'
43
+ party_plural: 'parties'
44
+ parties_and_groups: 'parties and groups'
45
+ member: 'member'
46
+ member_plural: 'members'
47
+ # global house translations
48
+ house: 'house'
49
+ house_plural: 'houses'
50
+ house_of_commons: 'House of Commons'
51
+ house_of_lords: 'House of Lords'
52
+ commons: 'Commons'
53
+ lords: 'Lords'
54
+ # global parliaments translations
55
+ parliament: 'parliament'
56
+ parliament_plural: 'parliaments'
57
+ # global generic translations
58
+ view_all: 'view all'
59
+ all: 'all'
60
+ find: 'find'
61
+ current: 'current'
62
+ former: 'former'
63
+ current_and_former: 'current and former'
64
+ to_present: 'to present'
65
+ to: 'to'
66
+ from: 'from'
67
+ of_the: 'of the'
68
+ in_the: 'in the'
69
+ search: 'search'
70
+ find_results: 'Find results from current parliament.uk websites.'
71
+ does_not_search_beta: "This search doesn't search beta.parliament.uk"
72
+ open_new_window: "website opens in a new window"
73
+ # global a-z navigation translations
74
+ a_to_z:
75
+ select_letter: 'select a letter'
76
+ aria_label: 'Paged navigation'
77
+ # global time format translations
78
+ time:
79
+ formats:
80
+ default: '%-d %b %Y'
81
+ # global error message translations
82
+ error:
83
+ no_constituency: "we couldn't find the postcode you entered."
84
+ lookup_unavailable: 'postcode check is currently unavailable.'
85
+ postcode_invalid: "we couldn't find the postcode you entered."
86
+ no_mp: "We couldn't find an MP for that postcode. Your constituency is"
87
+ # people translations
88
+ people:
89
+ index:
90
+ title: '%{current_and_former} %{mps_and_lords}'
91
+ a_to_z:
92
+ title: # needs title
93
+ letters:
94
+ title: '%{current_and_former} %{mps_and_lords}'
95
+ lookup_by_letters:
96
+ title: '%{current_and_former} %{mps_and_lords}'
97
+ members:
98
+ index:
99
+ title: '%{current_and_former} %{mps_and_lords}'
100
+ a_to_z:
101
+ title: # needs title
102
+ letters:
103
+ title: '%{current_and_former} %{mps_and_lords}'
104
+ current:
105
+ title: '%{current} %{mps_and_lords}'
106
+ current_letters:
107
+ title: '%{current} %{mps_and_lords}'
108
+ show:
109
+ mp_for: 'MP for'
110
+ contact: 'contact'
111
+ membership_history: 'membership history'
112
+ election_history: 'election history'
113
+ roles: 'roles'
114
+ check_mp: 'Check if %{name} is your MP'
115
+ check_mp_alternative: 'Check if this is your MP'
116
+ correct_mp: '%{name} is the MP for the postcode entered.'
117
+ incorrect_mp: '%{name} is not the MP for the postcode entered. Your MP is '
118
+ constituencies:
119
+ index:
120
+ title: '%{current_and_former} %{constituency_plural}'
121
+ current:
122
+ title: '%{current} %{constituency}'
123
+ contact_points:
124
+ index:
125
+ houses:
126
+ index:
127
+ title: '%{current_and_former} %{house_plural}'
128
+ current:
129
+ title: '%{current} %{house}'
130
+ parties:
131
+ index:
132
+ title: '%{current_and_former} %{parties_and_groups}'
133
+ current:
134
+ title: '%{current} %{party}'
135
+ # contact points translations
136
+ contact_points:
137
+ index:
138
+ web-title: 'contact points'
139
+ page-title: 'contact details'
140
+ email: 'email'
141
+ phone: 'phone'
142
+ fax: 'fax'
143
+ address: 'address'
144
+ download: 'download'
145
+ add_address_book: 'add to address book'
146
+ # constituencies translations
147
+ constituencies:
148
+ index:
149
+ title: '%{current_and_former} %{constituency_plural}'
150
+ a_to_z:
151
+ title: # needs title
152
+ letters:
153
+ title: '%{current_and_former} %{constituency_plural}'
154
+ lookup_by_letters:
155
+ title: '%{current_and_former} %{constituency_plural}'
156
+ current:
157
+ title: '%{current} %{constituency}'
158
+ a_to_z_current:
159
+ title: # needs title
160
+ show:
161
+ title: # title does not require translation
162
+ members:
163
+ index:
164
+ title: '%{current_and_former} %{mp_plural}'
165
+ current:
166
+ title: '%{current} %{mp}'
167
+ current_letters:
168
+ title: '%{current} %{constituency_plural}'
169
+ map:
170
+ title: # title does not require translation
171
+ contact_points:
172
+ index:
173
+ title: # title does not require translation
174
+ shared_translations:
175
+ vacant: 'Vacant'
176
+ constituency:
177
+ title: # title does not require translation
178
+ correct_constituency: "this is the constituency for your postcode"
179
+ incorrect_constituency: 'this is not your constituency.'
180
+ constituency_for_postcode: 'is the constituency for'
181
+ check_constituency: 'check if this is your constituency'
182
+ former_constituency: 'This is a former constituency. %{current_constituencies_link}.'
183
+ current_constituencies_link: 'view current constituencies'
184
+ constituency_map_fallback: 'Map of constituency is unavailable.'
185
+ # parties translations
186
+ parties:
187
+ index:
188
+ title: '%{current_and_former} %{parties_and_groups}'
189
+ a_to_z:
190
+ title: # needs title
191
+ letters:
192
+ title: '%{current_and_former} %{parties_and_groups}'
193
+ lookup_by_letters:
194
+ title: '%{current_and_former} %{parties_and_groups}'
195
+ current:
196
+ title: '%{current} %{parties_and_groups}'
197
+ show:
198
+ title: # title does not require translation
199
+ party_no_current_members: 'There are no MPs or Lords in this party.'
200
+ members:
201
+ index:
202
+ title: '%{current_and_former} %{member_plural}'
203
+ a_to_z:
204
+ title: # needs title
205
+ letters:
206
+ title: '%{current_and_former} %{member_plural}'
207
+ current:
208
+ title: '%{current} %{member_plural}'
209
+ a_to_z_current:
210
+ title: # needs title
211
+ current_letters:
212
+ title: '%{current} %{member_plural}'
213
+ # houses translations
214
+ houses:
215
+ index:
216
+ title: '%{house_plural}'
217
+ all_mps_info: 'MPs, parties and constituencies in the House of Commons'
218
+ all_lords_info: 'Lords, parties and groups in the House of Lords'
219
+ show:
220
+ title: # title does not require translation
221
+ area_they_represent: 'by the area they represent'
222
+ members:
223
+ index:
224
+ title: '%{current_and_former} %{member_type}'
225
+ a_to_z:
226
+ title: # needs title
227
+ letters:
228
+ title: '%{current_and_former} %{member_type}'
229
+ current:
230
+ title: '%{current} %{member_type}'
231
+ a_to_z_current:
232
+ title: # needs title
233
+ current_letters:
234
+ title: '%{current} %{member_type}'
235
+ parties:
236
+ index:
237
+ title: '%{current_and_former} %{parties_and_groups}'
238
+ current:
239
+ title: '%{current} %{parties_and_groups}'
240
+ show:
241
+ title: # title does not require translation
242
+ house_no_current_party_members: 'There are currently no members of this party in this House.'
243
+ members:
244
+ index:
245
+ title: '%{current_and_former} %{member_type}'
246
+ a_to_z:
247
+ title: # needs title
248
+ letters:
249
+ title: '%{current_and_former} %{member_type}'
250
+ current:
251
+ title: '%{current} %{member_type}'
252
+ a_to_z_current:
253
+ title: # needs title
254
+ current_letters:
255
+ title: '%{current} %{member_type}'
256
+ # postcodes translations
257
+ postcodes:
258
+ find_mp_constituency: 'Find your MP and constituency'
259
+ index:
260
+ title: 'find your constituency'
261
+ show:
262
+ title: # title does not require translation
263
+ check_different_postcode: 'Check for a different postcode'
264
+ no_mp: 'There is currently no MP for your constituency.'
265
+ results_for: 'Results for'
266
+ postcode_lookup:
267
+ title: # title does not require translation
268
+ search_by_postcode: 'Enter your full postcode, for example SW1A 0AA.'
269
+ do_not_know_postcode: "Don't know your postcode? Find it on the %{link}."
270
+ do_not_know_postcode_link: 'Royal Mail postcode finder'
271
+
272
+ # parliament translations
273
+ parliaments:
274
+ find_mp_a_to_z: 'Find an MP by A-Z list'
275
+ find_mp_area: 'Find an MP by the area they represented'
276
+ find_party_a_to_z: 'Find a party by A-Z list'
277
+ a_to_z: 'A to Z'
278
+ showing_results: 'showing results for'
279
+ index:
280
+ show:
281
+ find_mp_house: 'Find an MP by house'
282
+ constituencies:
283
+ find_constituency_a_to_z: 'Find a constituency by A-Z list'
284
+ # no content translations
285
+ no_content:
286
+ empty_list:
287
+ constituencies:
288
+ description: "Sorry there are no results for '%{letter}'"
289
+ houses:
290
+ description: "Sorry there are no results for '%{letter}'"
291
+ parties:
292
+ description: "Sorry there are no results for '%{letter}'"
293
+ no_mp: 'There is currently no MP for your constituency.'
294
+ # shared partial translations
295
+ shared:
296
+ dissolution_message:
297
+ description_text: 'There are currently no MPs because Parliament has been dissolved before the general election on 8 June.'
298
+ description_link: 'Find your constituency'
299
+ description_text_2: 'to find your constituency and its former MPs.'
300
+ dissolution_singular:
301
+ description_text: 'There is currently no MP because Parliament has been dissolved before the general election on 8 June.'
302
+ election_message:
303
+ description_singular: 'There is currently no MP. Vote today in the general election to choose yours.'
304
+ description_text: 'There are currently no MPs. Vote today in the general election to choose yours.'
305
+ post_election_message:
306
+ description_text: "As new MPs are announced following the general election, we're updating our pages."
307
+ # homepage translations
308
+ home:
309
+ index:
310
+ title: 'Welcome to the UK Parliament test website'
311
+ new_website: 'We’re building a %{link}. These pages are being tested and improved – they may be inaccurate or misleading.'
312
+ new_website_link: 'new website for Parliament'
313
+ old_website: 'Test pages are separate from the current %{link} website.'
314
+ old_website_link: 'parliament.uk'
315
+ feedback:
316
+ title: 'Give feedback'
317
+ provide: 'We want your feedback to %{link} further.'
318
+ provide_link: 'help us improve these pages'
319
+ whats_on:
320
+ title: "What's on our test website"
321
+ members_info:
322
+ title: 'MPs and Lords information'
323
+ current_mps: 'View all current members of the House of Commons.'
324
+ current_lords: 'View all current members of the House of Lords.'
325
+ current_constituencies: 'Find current MPs by the area they represent.'
326
+ current_parties: 'Find current MPs and Lords by their party or group.'
327
+ latest_members:
328
+ blog: 'Read the %{link}.'
329
+ blog_link: 'MPs and Lords information blog post'
330
+ search:
331
+ blog: 'Read the %{link}.'
332
+ blog_link: 'Search blog post'
333
+ follow_progress:
334
+ title: 'Follow our progress'
335
+ blog: 'Follow all %{link}.'
336
+ blog_link: 'new website developments on our blog'
337
+ mps:
338
+ find_mp: 'Find your MP'
339
+ a_z_surname: 'A - Z by surname'
340
+ view_list_constituencies: 'View list of constituencies'
341
+ find_mp_party: 'Find an MP by party.'
342
+ find_mp_date_range: 'Find a former MP by date range'
343
+ speaker_link: 'The Speaker'
344
+ speaker_clarification: '%{speaker_link} is not a member of a party.'
345
+ # meta information translations
346
+ meta:
347
+ index:
348
+ title: 'Meta information'
349
+ cookie_policy:
350
+ title: 'Cookies on beta.parliament.uk'
351
+ subtitle:
352
+ ga: 'Google Analytics cookies'
353
+ hj: 'HotJar cookies'
354
+ which_cookies: 'Which cookies do we use?'
355
+ cookie:
356
+ definition: 'Cookies are small files put on your device to let us know how you use our website.'
357
+ explanations:
358
+ ga: 'We use Google Analytics cookies to collect information about how you use our services. This helps us meet your needs and improve our website.'
359
+ hj: 'We use HotJar to find out how you use our website to improve your experience.'
360
+ anonymous_statement: 'All the information we collect is anonymous.'
361
+ cookie_table:
362
+ meta:
363
+ name: 'Name'
364
+ purpose: 'Purpose'
365
+ expires: 'Expires'
366
+ expiration:
367
+ minutes:
368
+ one: 'After 1 minute.'
369
+ other: 'After %{count} minutes.'
370
+ years:
371
+ one: 'After 1 year.'
372
+ other: 'After %{count} years.'
373
+ explanations:
374
+ ga: 'This helps us know how many people have visited beta.parliament.uk by telling us if you’ve visited before.'
375
+ gat: 'This helps us know how long you spend on a page.'
376
+ hjdonepolls: 'This ensures a poll will not reappear once you have completed it.'
377
+ hjminimizedpolls: 'This ensures a poll remains minimised when you move through our site.'
378
+ hjdonetesterswidgets: 'This ensures a form does not reappear once you have completed it.'
379
+ hjminimizedtesterswidgets: 'This ensures a form remains minimised when you move through our site.'
380
+ hjincludedinsample: 'This informs Hotjar whether your visit is included in their sample set.'
381
+ managing_cookies:
382
+ title: 'How to manage your cookies'
383
+ subtitle: 'Most web browsers allow you to control cookies through browser settings.'
384
+ find_out: "Find out how to %{link}."
385
+ find_out_link: "manage and delete cookies"
386
+ opt_out: "You can %{link}."
387
+ opt_out_link: "opt out of %{service} cookies"
data/config/puma.rb ADDED
@@ -0,0 +1,20 @@
1
+ worker_count = ENV['WEB_CONCURRENCY']
2
+ worker_count ||= Rails.env.development? ? 1 : 2
3
+
4
+ thread_count = ENV['RAILS_MAX_THREADS']
5
+ thread_count ||= Rails.env.development? ? 1 : 5
6
+
7
+ workers Integer(worker_count)
8
+ threads Integer(thread_count), Integer(thread_count)
9
+
10
+ preload_app!
11
+
12
+ rackup DefaultRackup
13
+ port ENV['PORT'] || 3000
14
+ environment ENV['RACK_ENV'] || 'development'
15
+
16
+ on_worker_boot do
17
+ # Worker specific setup for Rails 4.1+
18
+ # See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot
19
+ # ActiveRecord::Base.establish_connection
20
+ end
@@ -0,0 +1,76 @@
1
+ if ENV['AIRBRAKE_PROJECT_ID'].present? && ENV['AIRBRAKE_PROJECT_KEY'].present?
2
+ # Airbrake is an online tool that provides robust exception tracking in your Rails
3
+ # applications. In doing so, it allows you to easily review errors, tie an error
4
+ # to an individual piece of code, and trace the cause back to recent
5
+ # changes. Airbrake enables for easy categorization, searching, and prioritization
6
+ # of exceptions so that when errors occur, your team can quickly determine the
7
+ # root cause.
8
+ #
9
+ # Configuration details:
10
+ # https://github.com/airbrake/airbrake-ruby#configuration
11
+ Airbrake.configure do |c|
12
+ # You must set both project_id & project_key. To find your project_id and
13
+ # project_key navigate to your project's General Settings and copy the values
14
+ # from the right sidebar.
15
+ # https://github.com/airbrake/airbrake-ruby#project_id--project_key
16
+ c.project_id = ENV['AIRBRAKE_PROJECT_ID']
17
+ c.project_key = ENV['AIRBRAKE_PROJECT_KEY']
18
+
19
+ # Configures the root directory of your project. Expects a String or a
20
+ # Pathname, which represents the path to your project. Providing this option
21
+ # helps us to filter out repetitive data from backtrace frames and link to
22
+ # GitHub files from our dashboard.
23
+ # https://github.com/airbrake/airbrake-ruby#root_directory
24
+ c.root_directory = Rails.root
25
+
26
+ # By default, Airbrake Ruby outputs to STDOUT. In Rails apps it makes sense to
27
+ # use the Rails' logger.
28
+ # https://github.com/airbrake/airbrake-ruby#logger
29
+ c.logger = Rails.logger
30
+
31
+ # Configures the environment the application is running in. Helps the Airbrake
32
+ # dashboard to distinguish between exceptions occurring in different
33
+ # environments.
34
+ # NOTE: This option must be set in order to make the 'ignore_environments'
35
+ # option work.
36
+ # https://github.com/airbrake/airbrake-ruby#environment
37
+ c.environment = Rails.env
38
+
39
+ # Setting this option allows Airbrake to filter exceptions occurring in
40
+ # unwanted environments such as :test.
41
+ # NOTE: This option *does not* work if you don't set the 'environment' option.
42
+ # https://github.com/airbrake/airbrake-ruby#ignore_environments
43
+ c.ignore_environments = %w[test]
44
+
45
+ # A list of parameters that should be filtered out of what is sent to
46
+ # Airbrake. By default, all "password" attributes will have their contents
47
+ # replaced.
48
+ # https://github.com/airbrake/airbrake-ruby#blacklist_keys
49
+ c.blacklist_keys = [/password/i, /authorization/i]
50
+
51
+ # Alternatively, you can integrate with Rails' filter_parameters.
52
+ # Read more: https://goo.gl/gqQ1xS
53
+ # c.blacklist_keys = Rails.application.config.filter_parameters
54
+ end
55
+
56
+ # A filter that collects request body information. Enable it if you are sure you
57
+ # don't send sensitive information to Airbrake in your body (such as passwords).
58
+ # https://github.com/airbrake/airbrake#requestbodyfilter
59
+ # Airbrake.add_filter(Airbrake::Rack::RequestBodyFilter.new)
60
+
61
+ # A filter method that chooses which errors to ignore before sending them to
62
+ # Airbrake. This can be based on type, message, file, region or any other part
63
+ # of the error's JSON
64
+ Airbrake.add_filter do |notice|
65
+ if notice[:errors].any? { |error| error[:type] == 'ActionController::RoutingError' }
66
+ notice.ignore!
67
+ end
68
+ end
69
+
70
+ # If you want to convert your log messages to Airbrake errors, we offer an
71
+ # integration with the Logger class from stdlib.
72
+ # https://github.com/airbrake/airbrake#logger
73
+ # Rails.logger = Airbrake::AirbrakeLogger.new(Rails.logger)
74
+ else
75
+ puts 'WARNING: Airbrake environment variables are not set - no Airbrake logging will occur.'
76
+ end
@@ -0,0 +1,11 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Version of your assets, change this if you want to expire all your assets.
4
+ Rails.application.config.assets.version = '1.0'
5
+
6
+ # Add additional assets to the asset load path
7
+ # Rails.application.config.assets.paths << Emoji.images_path
8
+
9
+ # Precompile additional assets.
10
+ # application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
11
+ # Rails.application.config.assets.precompile += %w( search.js )
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
+ # Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,3 @@
1
+ require 'bandiera/client'
2
+
3
+ BANDIERA_CLIENT = Bandiera::Client.new(ENV['BANDIERA_URL'].dup)
@@ -0,0 +1,3 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Rails.application.config.action_dispatch.cookies_serializer = :json
@@ -0,0 +1,4 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Configure sensitive parameters which will be filtered from the log file.
4
+ Rails.application.config.filter_parameters += [:password]
@@ -0,0 +1,16 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format. Inflections
4
+ # are locale specific, and you may define rules for as many different
5
+ # locales as you wish. All of these examples are active by default:
6
+ # ActiveSupport::Inflector.inflections(:en) do |inflect|
7
+ # inflect.plural /^(ox)$/i, '\1en'
8
+ # inflect.singular /^(ox)en/i, '\1'
9
+ # inflect.irregular 'person', 'people'
10
+ # inflect.uncountable %w( fish sheep )
11
+ # end
12
+
13
+ # These inflection rules are supported but not enabled by default:
14
+ # ActiveSupport::Inflector.inflections(:en) do |inflect|
15
+ # inflect.acronym 'RESTful'
16
+ # end
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+
6
+ Mime::Type.register 'text/turtle', :ttl
7
+ Mime::Type.register 'application/rdf+json', :rdfjson
@@ -0,0 +1,3 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Rails.application.config.session_store :cookie_store, key: '_beta_parliament_session'
@@ -0,0 +1 @@
1
+ Rack::Timeout.timeout = 20
@@ -0,0 +1,9 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # This file contains settings for ActionController::ParamsWrapper which
4
+ # is enabled by default.
5
+
6
+ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
+ ActiveSupport.on_load(:action_controller) do
8
+ wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
9
+ end
@@ -0,0 +1,16 @@
1
+ # Dir["parliament/utils/initializers/*.rb"].each {|file| require file }
2
+ # Dir["parliament-utils/lib/parliament/utils/config/initializers/*.rb"].each { |f| require f }
3
+ # Dir[File.expand_path "lib/parliament/utils/config/initializers/*.rb"].each{|f| require_relative f}
4
+ # Dir[File.join(File.dirname(__FILE__), '../parliament/utils/config/initializers', '*.rb')].each { |file| require file }
5
+
6
+ require 'parliament/utils/config/initializers/airbrake'
7
+ require 'parliament/utils/config/initializers/assets'
8
+ require 'parliament/utils/config/initializers/backtrace_silencers'
9
+ require 'parliament/utils/config/initializers/bandiera'
10
+ require 'parliament/utils/config/initializers/cookies_serializer'
11
+ require 'parliament/utils/config/initializers/filter_parameter_logging'
12
+ require 'parliament/utils/config/initializers/inflections'
13
+ require 'parliament/utils/config/initializers/mime_types'
14
+ require 'parliament/utils/config/initializers/session_store'
15
+ require 'parliament/utils/config/initializers/timeout'
16
+ require 'parliament/utils/config/initializers/wrap_parameters'
@@ -0,0 +1,68 @@
1
+ module Parliament
2
+ module Utils
3
+ module Helpers
4
+ module ApplicationHelper
5
+ # Sets the title for a page.
6
+ #
7
+ # @param [String] page_title the title of the page.
8
+ # @return [String] the title of the page.
9
+ def title(page_title)
10
+ content_for(:title) { page_title }
11
+ page_title
12
+ end
13
+ # Before every request that provides data, see if the user is requesting a format that can be served by the data API.
14
+ # If they are, transparently redirect them with a '302: Found' status code
15
+ def data_check
16
+ # Check format to see if it is available from the data API
17
+ return if !Parliament::Utils::Helpers::FormatHelper::DATA_FORMATS.include?(request.formats.first) || (params[:controller] == 'constituencies' && params[:action] == 'map')
18
+
19
+ # Find the current controller/action's API url
20
+ @data_url = data_url
21
+
22
+ # Catch potential nil values
23
+ raise StandardError, 'Data URL does not exist' if @data_url.nil?
24
+
25
+ response.headers['Accept'] = request.formats.first
26
+ redirect_to(@data_url.call(params).query_url) && return
27
+ end
28
+
29
+ # Get the data URL for our current controller and action OR raise a StandardError
30
+ #
31
+ # @raises [StandardError] if there is no Proc available for a controller and action pair, we raise a StandardError
32
+ #
33
+ # @return [Proc] a Proc which can be called to generate a data URL
34
+ def data_url
35
+ self.class::ROUTE_MAP[params[:action].to_sym] || raise(StandardError, "You must provide a ROUTE_MAP proc for #{params[:controller]}##{params[:action]}")
36
+ end
37
+
38
+ # Populates @request with a data url which can be used within controllers.
39
+ def build_request
40
+ @request = data_url.call(params)
41
+
42
+ populate_alternates(@request.query_url)
43
+ end
44
+
45
+ # Populates Pugin.alternates with a list of data formats and corresponding urls
46
+ #
47
+ # @param [String] url the url where alternatives can be found
48
+ def populate_alternates(url)
49
+ alternates = []
50
+
51
+ Parliament::Utils::Helpers::FormatHelper::DATA_FORMATS.each do |format|
52
+ alternates << { type: format, href: url }
53
+ end
54
+
55
+ Pugin.alternates = alternates
56
+ end
57
+
58
+ private
59
+
60
+ # Before every request, reset Pugin's list of alternates to prevent showing rel-alternate tags on pages without data
61
+ def reset_alternates
62
+ Pugin.alternates = []
63
+ end
64
+
65
+ end
66
+ end
67
+ end
68
+ end