Class: ExternalRenderer

Inherits:
Erector::Widget show all
Defined in:
lib/erector/widgets/external_renderer.rb

Instance Method Summary collapse

Methods included from Erector::Sass

#sass

Methods included from Erector::AfterInitialize

included, #initialize

Methods included from Erector::JQuery

#jquery, #jquery_load, #jquery_ready

Methods included from Erector::Convenience

#css, #dom_id, #join, #to_pretty, #to_text, #url

Methods included from Erector::Externals

included, #render_externals, #render_with_externals

Methods included from Erector::Needs

included, #initialize

Methods included from Erector::HTML

#character, #close_tag, #comment, #element, #element!, #empty_element, #h, included, #instruct, #javascript, #nbsp, #open_tag, #raw, #text, #text!

Methods inherited from Erector::AbstractWidget

#call_block, #capture, #initialize, inline, prettyprint_default, #prettyprint_default, prettyprint_default=, #to_a, #to_html, #to_s, #widget

Instance Method Details

#contentObject



5
6
7
8
9
10
# File 'lib/erector/widgets/external_renderer.rb', line 5

def content
  included_stylesheets if @included_stylesheets
  inline_styles if @inline_styles
  included_scripts if @included_scripts
  inline_scripts if @inline_scripts
end

#included_scriptsObject



18
19
20
21
22
# File 'lib/erector/widgets/external_renderer.rb', line 18

def included_scripts
  rendered_externals(:js).each do |external|
    script({:type => "text/javascript", :src => external.text}.merge(external.options))
  end
end

#included_stylesheetsObject



24
25
26
27
28
# File 'lib/erector/widgets/external_renderer.rb', line 24

def included_stylesheets
  rendered_externals(:css).each do |external|
    link({:rel => "stylesheet", :href => external.text, :type => "text/css", :media => "all"}.merge(external.options))
  end
end

#inline_scriptsObject



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/erector/widgets/external_renderer.rb', line 38

def inline_scripts
  rendered_externals(:script).each do |external|
    javascript external.options do
      rawtext external.text
    end
  end
  # todo: allow :load or :ready per external script
  rendered_externals(:jquery).each do |external|
    jquery :load, external.text, external.options
  end
end

#inline_stylesObject



30
31
32
33
34
35
36
# File 'lib/erector/widgets/external_renderer.rb', line 30

def inline_styles
  rendered_externals(:style).each do |external|
    style({:type => "text/css", 'xml:space' => 'preserve'}.merge(external.options)) do
      rawtext external.text
    end
  end
end

#rendered_externals(type) ⇒ Object



12
13
14
15
16
# File 'lib/erector/widgets/external_renderer.rb', line 12

def rendered_externals(type)
  @classes.map do |klass|
    klass.dependencies(type)
  end.flatten.uniq
end