Class: JsDuck::ExamplesExporter

Inherits:
Object
  • Object
show all
Defined in:
lib/jsduck/examples_exporter.rb

Overview

Exporter for inline examples.

It produces the following structure:

:type => :class,  # can also be :guide
:name => "Panel",
:examples => [
  {:code => "bla bla", :options => {},
  => "bla bla", :options => {"raw" => true},
  ...
]

}

Instance Method Summary collapse

Constructor Details

#initialize(relations, opts) ⇒ ExamplesExporter

Returns a new instance of ExamplesExporter.



20
21
22
23
24
# File 'lib/jsduck/examples_exporter.rb', line 20

def initialize(relations, opts)
  # All params ignored, they're present to be compatible with
  # other exporters.
  @inline_examples = InlineExamples.new
end

Instance Method Details

#export(cls) ⇒ Object

Returns hash of class name and inline examples



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/jsduck/examples_exporter.rb', line 27

def export(cls)
  examples = @inline_examples.extract(cls[:doc])
  if examples.length > 0
    {
      :type => :class,
      :name => cls[:name],
      :examples => examples,
    }
  else
    nil
  end
end

#export_guide(guide) ⇒ Object

Returns hash of guide name and inline examples



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/jsduck/examples_exporter.rb', line 41

def export_guide(guide)
  examples = @inline_examples.extract(guide[:html] || "")
  if examples.length > 0
    {
      :type => :guide,
      :name => guide["name"],
      :examples => examples,
    }
  else
    nil
  end
end