Class: Fdoc::JsonPresenter
- Inherits:
-
Object
- Object
- Fdoc::JsonPresenter
- Defined in:
- lib/fdoc/presenters/json_presenter.rb
Instance Attribute Summary collapse
-
#json ⇒ Object
readonly
Returns the value of attribute json.
Instance Method Summary collapse
-
#initialize(json) ⇒ JsonPresenter
constructor
A new instance of JsonPresenter.
- #to_html ⇒ Object
- #to_markdown ⇒ Object
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
#json ⇒ Object (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_html ⇒ Object
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>"%s"</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_markdown ⇒ Object
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 |