Class: Swift::Playground::DocumentationSection

Inherits:
Section
  • Object
show all
Defined in:
lib/swift/playground/sections/documentation_section.rb

Instance Attribute Summary collapse

Attributes inherited from Section

#content

Instance Method Summary collapse

Methods inherited from Section

#filename, #path, #xcplayground_node

Methods included from Util::PathOrContent

#derived_filename, #path_or_content_as_io

Constructor Details

#initialize(content) ⇒ DocumentationSection

Returns a new instance of DocumentationSection.



12
13
14
15
16
17
18
19
20
21
# File 'lib/swift/playground/sections/documentation_section.rb', line 12

def initialize(content)
  super(content)

  if @content =~ /(<html|<head|<body)[\s>]/
    raise 'Please provide an HTML fragment only. ' +
          'Do not include an <html>, <head> or <body> tag.'
  end

  extract_assets
end

Instance Attribute Details

#assetsObject (readonly)

Returns the value of attribute assets.



10
11
12
# File 'lib/swift/playground/sections/documentation_section.rb', line 10

def assets
  @assets
end

Instance Method Details

#render(number, playground) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/swift/playground/sections/documentation_section.rb', line 23

def render(number, playground)
  pipeline = Util::Pipeline.new
  if playground.convert_emoji?
    pipeline.filters << Util::Pipeline::EmojiFilter
  end

  if playground.syntax_highlighting
    if Util::SyntaxHighlighting.available?
      pipeline.filters << Util::Pipeline::SyntaxHighlightFilter
    else
      $stderr.puts "WARNING: Unable to highlight syntax for section " +
                   "#{number}, please make sure that github-linguist " +
                   "and pygments.rb gems are installed."
    end
  end

  if pipeline.has_filters?
    processed = pipeline.call(content)
    super(number, playground, processed[:output].inner_html)
  else
    super(number, playground)
  end
end