Module: Erector::Externals

Included in:
Widget
Defined in:
lib/erector/externals.rb

Overview

Externals are a mechanism by which a widget can declare page-level resources upon which it depends. They are not emitted during the widget’s normal emiting process. Rather, the Erector::Widget::Page keeps track of all the widgets it emits, then goes back and inserts the proper tags for all the externals inside its HEAD element.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



9
10
11
# File 'lib/erector/externals.rb', line 9

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#render_externals(options_to_external_emiter = {}) ⇒ Object



96
97
98
99
100
101
102
# File 'lib/erector/externals.rb', line 96

def render_externals(options_to_external_emiter = {})
  output_for_externals = Erector::Output.new
  nested_widgets = output.widgets
  externalizer = ExternalRenderer.new({:classes => nested_widgets}.merge(options_to_external_emiter))
  externalizer._emit(:output => output_for_externals)
  output_for_externals.to_a
end

#render_with_externals(options_to_external_emiter = {}) ⇒ Object



86
87
88
89
90
91
92
93
94
# File 'lib/erector/externals.rb', line 86

def render_with_externals(options_to_external_emiter = {})
  output = Erector::Output.new
  self.to_a(:output => output) # emit all the externals onto this new output buffer
  nested_widgets = output.widgets.to_a
  options_to_external_emiter = {:classes => nested_widgets}.merge(options_to_external_emiter)
  emiter = ExternalRenderer.new(options_to_external_emiter)
  externals = emiter.to_a(:output => output)
  output.to_a
end