Class: Webring::WidgetController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/webring/widget_controller.rb

Direct Known Subclasses

CustomWidgetController

Instance Method Summary collapse

Instance Method Details

#showObject

Serve the webring navigation widget JavaScript GET /widget.js



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/webring/widget_controller.rb', line 10

def show
  respond_to do |format|
    format.js do
      response.headers['Content-Type'] = 'application/javascript; charset=utf-8'

      # Take the minified JavaScript file from the engine's assets and replace the customizable Logo SVG
      widget_js =
        Webring::Engine
        .root.join('app/assets/javascripts/webring/widget.js')
        .read
        .gsub('"<<REPLACE_ME_LOGO_SVG_FUNCTION>>"', logo_svg_function)
        .gsub('"<<REPLACE_ME_TEXT_DEFAULTS>>"', JSON.generate(text_defaults))
        .sub('<<REPLACE_ME_WIDGET_FETCH_METRICS_PATH>>', widget_fetch_metrics_path)

      render js: widget_js
    end
  end
end