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.



5
6
7
8
# File 'lib/js_routes/engine.rb', line 5

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

Class Method Details

.call(input) ⇒ Object



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

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



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

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



10
11
12
# File 'lib/js_routes/engine.rb', line 10

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