From 71eab8f4df5bc65af8bc7df97e28e7eecf419304 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Sun, 20 Sep 2015 23:00:30 +0800 Subject: [PATCH] FEATURE: Add web manifest for Chrome users. --- app/controllers/manifest_json_controller.rb | 15 +++++++++++++++ app/views/layouts/application.html.erb | 1 + config/routes.rb | 1 + spec/controllers/manifest_json_controller_spec.rb | 12 ++++++++++++ 4 files changed, 29 insertions(+) create mode 100644 app/controllers/manifest_json_controller.rb create mode 100644 spec/controllers/manifest_json_controller_spec.rb diff --git a/app/controllers/manifest_json_controller.rb b/app/controllers/manifest_json_controller.rb new file mode 100644 index 00000000000..5462ec1fd63 --- /dev/null +++ b/app/controllers/manifest_json_controller.rb @@ -0,0 +1,15 @@ +class ManifestJsonController < ApplicationController + layout false + skip_before_filter :preload_json, :check_xhr + + def index + manifest = { + short_name: SiteSetting.title, + display: 'browser', + orientation: 'portrait', + start_url: "#{Discourse.base_uri}/" + } + + render json: manifest.to_json + end +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 8a29518367d..65cf09b5350 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -31,6 +31,7 @@ <%- end %> <%= render_google_universal_analytics_code %> + <%= yield :head %> diff --git a/config/routes.rb b/config/routes.rb index 66125570f49..75d3dcf7cc6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -533,6 +533,7 @@ Discourse::Application.routes.draw do get "favicon/proxied" => "static#favicon", format: false get "robots.txt" => "robots_txt#index" + get "manifest.json" => "manifest_json#index", as: :manifest Discourse.filters.each do |filter| root to: "list##{filter}", constraints: HomePageConstraint.new("#{filter}"), :as => "list_#{filter}" diff --git a/spec/controllers/manifest_json_controller_spec.rb b/spec/controllers/manifest_json_controller_spec.rb new file mode 100644 index 00000000000..41df4e221ca --- /dev/null +++ b/spec/controllers/manifest_json_controller_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' + +RSpec.describe ManifestJsonController do + context 'index' do + it 'returns the right output' do + title = 'MyApp' + SiteSetting.title = title + get :index + expect(response.body).to include(title) + end + end +end