Class: ExternalRenderer

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

Instance Method Summary collapse

Methods inherited from Erector::Widget

#to_html, #to_s

Methods included from Erector::Sass

#sass, #scss

Methods included from Erector::JQuery

#jquery, #jquery_load, #jquery_ready

Methods included from Erector::Convenience

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

Methods included from Erector::Externals

included, #render_externals, #render_with_externals

Methods included from Erector::Caching

#cache, included, #should_cache?

Methods included from Erector::Needs

included, #initialize

Methods inherited from Erector::HTMLWidget

#to_html, #to_s

Methods inherited from Erector::XMLWidget

#comment, full_tags, #instruct, #newliney?, self_closing_tags, tag, tag_named

Methods inherited from Erector::AbstractWidget

#call_block, #capture_content, #emit, hyphenize_underscores, hyphenize_underscores=, #initialize, inline, prettyprint_default, #prettyprint_default, prettyprint_default=, #to_a, #to_s, #widget

Methods included from Erector::AfterInitialize

included, #initialize

Methods included from Erector::Text

#character, #h, #nbsp, #raw, #text, #text!

Methods included from Erector::Attributes

#format_attributes, #format_sorted, #sort_attributes

Methods included from Erector::Element

#_element, #_empty_element, #element, #empty_element

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



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/erector/widgets/external_renderer.rb', line 46

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
37
38
39
40
41
42
43
44
# 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

  if Object.const_defined?(:Sass)
    rendered_externals(:scss).each do |external|
      style({:type => "text/css", 'xml:space' => 'preserve'}.merge(external.options)) do
        rawtext Sass.compile(external.text)
      end
    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