39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/generators/binnacle/binnacle_generator.rb', line 39
def create_web_app_manifest_for_firebase
if options.firebase?
create_file "app/assets/javascripts/manifest.json", { gcm_sender_id: "103953800507" }.to_json
app_layout = find_application_layout
manifest_include = ActionController::Base.helpers.tag(:link, rel: 'manifest', href: "/manifest.json")
if app_layout
inject_into_file app_layout, before: "</head>\n" do
manifest_include
end
else
warn " #{'warning:'.red} couldn't find application layout. add manifest declaration manually to your layout's <head> section:"
warn " #{manifest_include}"
end
append_to_file "config/initializers/assets.rb", "Rails.application.config.assets.precompile += %w( manifest.json firebase-messaging-sw.js )\n"
inject_into_file "config/application.rb", %[ config.assets.paths << Rails.root.join("app", "assets", "service_workers")\n], :after => "Rails::Application\n"
template "firebase-messaging-sw.js.erb", "app/assets/service_workers/firebase-messaging-sw.js.erb"
routes = <<-ROUTES
get 'manifest.json', to: redirect(ActionController::Base.helpers.asset_path('manifest.json'))
get 'firebase-messaging-sw.js', to: -> (env) do
[200, { 'Content-Type' => 'application/javascript' }, [Rails.application.assets_manifest.find_sources('firebase-messaging-sw.js').first]]
end
ROUTES
inject_into_file "config/routes.rb", routes, :before => /^end/
end
end
|