Class: Fdoc::JsonPresenter

Inherits:
Object
  • Object
show all
Defined in:
lib/fdoc/presenters/json_presenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ JsonPresenter

Returns a new instance of JsonPresenter.



6
7
8
# File 'lib/fdoc/presenters/json_presenter.rb', line 6

def initialize(json)
  @json = json
end

Instance Attribute Details

#jsonObject (readonly)

Returns the value of attribute json.



4
5
6
# File 'lib/fdoc/presenters/json_presenter.rb', line 4

def json
  @json
end

Instance Method Details

#to_htmlObject



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/fdoc/presenters/json_presenter.rb', line 10

def to_html
  if json.kind_of? String
    '<tt>&quot;%s&quot;</tt>' % json.gsub(/\"/, 'quot;')
  elsif json.kind_of?(Numeric) ||
        json.kind_of?(TrueClass) ||
        json.kind_of?(FalseClass)
    '<tt>%s</tt>' % json
  elsif json.kind_of?(Hash) ||
        json.kind_of?(Array)
    '<pre><code>%s</code></pre>' % JSON.pretty_generate(json)
  end
end

#to_markdownObject



23
24
25
26
27
28
29
30
# File 'lib/fdoc/presenters/json_presenter.rb', line 23

def to_markdown
  if json.kind_of?(Hash) ||
     json.kind_of?(Array)
    JSON.pretty_generate(json)
  else
    json
  end
end