From c18bf3106db87460ac012f8b64a28ccd6edee81c Mon Sep 17 00:00:00 2001 From: Andrew White Date: Mon, 20 Jul 2015 23:05:43 +0100 Subject: [PATCH] Move browserconfig.xml and manifest.json to actions The application manifest files need to be generated with asset urls so it's simplest to just make them into Rails actions. --- Gemfile | 1 + Gemfile.lock | 4 ++ app/controllers/pages_controller.rb | 9 ++++ app/views/pages/browserconfig.xml.builder | 14 +++++++ app/views/pages/manifest.json.jbuilder | 50 +++++++++++++++++++++++ config/routes.rb | 3 +- public/browserconfig.xml | 12 ------ public/manifest.json | 44 -------------------- 8 files changed, 80 insertions(+), 57 deletions(-) create mode 100644 app/views/pages/browserconfig.xml.builder create mode 100644 app/views/pages/manifest.json.jbuilder delete mode 100644 public/browserconfig.xml delete mode 100644 public/manifest.json diff --git a/Gemfile b/Gemfile index ac4a8b7d3..991873074 100644 --- a/Gemfile +++ b/Gemfile @@ -34,6 +34,7 @@ gem 'dalli' gem 'connection_pool' gem 'lograge' gem 'logstash-logger' +gem 'jbuilder' group :development, :test do gem 'rspec-rails' diff --git a/Gemfile.lock b/Gemfile.lock index ea1965a02..6ed5ea682 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -132,6 +132,9 @@ GEM phantomjs (>= 1.9) railties (>= 3.2.0) sprockets-rails + jbuilder (2.3.1) + activesupport (>= 3.0.0, < 5) + multi_json (~> 1.2) jmespath (1.0.2) multi_json (~> 1.0) jquery-rails (4.0.4) @@ -305,6 +308,7 @@ DEPENDENCIES faraday faraday_middleware jasmine-rails + jbuilder jquery-rails json launchy diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 7f60be185..dec27754c 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -4,4 +4,13 @@ def index def help end + + def privacy + end + + def browserconfig + end + + def manifest + end end diff --git a/app/views/pages/browserconfig.xml.builder b/app/views/pages/browserconfig.xml.builder new file mode 100644 index 000000000..c4d9f8ea1 --- /dev/null +++ b/app/views/pages/browserconfig.xml.builder @@ -0,0 +1,14 @@ +cache :browserconfig, expires_in: 5.minutes do + xml.instruct! :xml, version: "1.0" + xml.browserconfig do + xml.msapplication do + xml.tile do + xml.square70x70logo src: path_to_image('os-social/windows/tiny.png') + xml.square150x150logo src: path_to_image('os-social/windows/square.png') + xml.wide310x150logo src: path_to_image('os-social/windows/wide.png') + xml.square310x310logo src: path_to_image('os-social/windows/large.png') + xml.TileColor "#008800" + end + end + end +end diff --git a/app/views/pages/manifest.json.jbuilder b/app/views/pages/manifest.json.jbuilder new file mode 100644 index 000000000..d008fd73c --- /dev/null +++ b/app/views/pages/manifest.json.jbuilder @@ -0,0 +1,50 @@ +json.cache! :manifest, expires_in: 5.minutes do + json.name "Petitions" + json.display "standalone" + json.orientation "portrait" + json.start_url "/" + + json.icons do + json.child! do + json.src path_to_image("os-social/android/launcher-icon-0-75x.png") + json.sizes "36x36" + json.type "image/png" + json.density "0.75" + end + + json.child! do + json.src path_to_image("os-social/android/launcher-icon-1x.png") + json.sizes "48x48" + json.type "image/png" + json.density "1.0" + end + + json.child! do + json.src path_to_image("os-social/android/launcher-icon-1-5x.png") + json.sizes "72x72" + json.type "image/png" + json.density "1.5" + end + + json.child! do + json.src path_to_image("os-social/android/launcher-icon-2x.png") + json.sizes "96x96" + json.type "image/png" + json.density "2.0" + end + + json.child! do + json.src path_to_image("os-social/android/launcher-icon-3x.png") + json.sizes "144x144" + json.type "image/png" + json.density "3.0" + end + + json.child! do + json.src path_to_image("os-social/android/launcher-icon-4x.png") + json.sizes "192x192" + json.type "image/png" + json.density "4.0" + end + end +end diff --git a/config/routes.rb b/config/routes.rb index b90127669..2e0c54c91 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,7 +3,8 @@ get '/' => 'pages#index', :as => :home get 'help' => 'pages#help', :as => :help get 'privacy' => 'pages#privacy', :as => :privacy - + get 'browserconfig' => 'pages#browserconfig', format: 'xml' + get 'manifest' => 'pages#manifest', format: 'json' get 'feedback' => 'feedback#index', :as => 'feedback' get 'feedback/thanks' => 'feedback#thanks', :as => 'thanks_feedback' diff --git a/public/browserconfig.xml b/public/browserconfig.xml deleted file mode 100644 index 9abb3e357..000000000 --- a/public/browserconfig.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - #008800 - - - diff --git a/public/manifest.json b/public/manifest.json deleted file mode 100644 index a10542f5d..000000000 --- a/public/manifest.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "name": "Petitions", - "icons": [ - { - "src": "/images/os-social/android/launcher-icon-0-75x.png", - "sizes": "36x36", - "type": "image/png", - "density": "0.75" - }, - { - "src": "/images/os-social/android/launcher-icon-1x.png", - "sizes": "48x48", - "type": "image/png", - "density": "1.0" - }, - { - "src": "/images/os-social/android/launcher-icon-1-5x.png", - "sizes": "72x72", - "type": "image/png", - "density": "1.5" - }, - { - "src": "/images/os-social/android/launcher-icon-2x.png", - "sizes": "96x96", - "type": "image/png", - "density": "2.0" - }, - { - "src": "/images/os-social/android/launcher-icon-3x.png", - "sizes": "144x144", - "type": "image/png", - "density": "3.0" - }, - { - "src": "/images/os-social/android/launcher-icon-4x.png", - "sizes": "192x192", - "type": "image/png", - "density": "4.0" - } - ], - "start_url": "/index.html", - "display": "standalone", - "orientation": "portrait" -}