Class: AngularSprinkles::ContentYielder

Inherits:
Object
  • Object
show all
Defined in:
lib/angular_sprinkles/content_yielder.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ ContentYielder

Returns a new instance of ContentYielder.



3
4
5
6
7
# File 'lib/angular_sprinkles/content_yielder.rb', line 3

def initialize(args)
  @context = args.fetch(:context)
  @yield_to = args.fetch(:yield_to)
  @cache = args.fetch(:cache)
end

Instance Method Details

#call(content) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/angular_sprinkles/content_yielder.rb', line 9

def call(content)
  return '' if @cache.set?(content)

  @cache.set(content)

  @context.(:script, content.to_json.html_safe).tap do |script_tag|
    @context.content_for(@yield_to, script_tag)
  end
end