Class: JsRoutes::SprocketsExtension

Inherits:
Object
  • Object
show all
Defined in:
lib/js_routes/engine.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, &block) ⇒ SprocketsExtension

Returns a new instance of SprocketsExtension.



3
4
5
6
# File 'lib/js_routes/engine.rb', line 3

def initialize(filename, &block)
  @filename = filename
  @source   = block.call
end

Class Method Details

.call(input) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/js_routes/engine.rb', line 20

def self.call(input)
  filename = input[:filename]
  source   = input[:data]
  context  = input[:environment].context_class.new(input)

  result = run(filename, source, context)
  context..merge(data: result)
end

.run(filename, source, context) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/js_routes/engine.rb', line 12

def self.run(filename, source, context)
  if context.logical_path == 'js-routes'
    routes = Rails.root.join('config', 'routes.rb').to_s
    context.depend_on(routes)
  end
  source
end

Instance Method Details

#render(context, empty_hash_wtf) ⇒ Object



8
9
10
# File 'lib/js_routes/engine.rb', line 8

def render(context, empty_hash_wtf)
  self.class.run(@filename, @source, context)
end