Class: BinnacleGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/binnacle/binnacle_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_initializer_fileObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/generators/binnacle/binnacle_generator.rb', line 13

def create_initializer_file

  initializer "binnacle.rb" do
    YAML::load(<<-EOM)
    |
    # #{'=' * 78}
    # Binnacle Configuration
    # #{'=' * 78}
    # Available parameters (preferably configure via ENV):
    # #{'=' * 78}
    # - url:         The Binnacle Endpoint URL (BINNACLE_URL)
    # - logging_channel: The application logger Binnacle Channel (BINNACLE_APP_LOG_CHANNEL)
    # - error_channel:   The application error Binnacle Channel (BINNACLE_APP_ERR_CHANNEL)
    # - api_key:     An approved publisher API key for the App (BINNACLE_API_KEY)
    # - api_secret:  The API secret for the given API key (BINNACLE_API_SECRET)
    # - intercept_rails_logging: Redirect rails logging to logging_channel (BINNACLE_RAILS_LOG)
    # - report_exceptions: Trap exceptions are log them to error_channel (BINNACLE_REPORT_EXCEPTIONS)
    # #{'=' * 78}
    Binnacle.configure do |config|
      config.intercept_rails_logging = false
      config.report_exceptions = false
    end
    EOM
  end
end

#create_web_app_manifest_for_firebaseObject



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