Module: Coradoc::Mirror::MirrorJsonFormat
- Defined in:
- lib/coradoc/mirror/mirror_json_format.rb
Overview
Format module for mirror JSON output.
Registers with Coradoc so the CLI can discover it:
Coradoc.convert(text, from: :asciidoc, to: :mirror_json)
coradoc convert doc.adoc -t mirror_json
Class Method Summary collapse
- .handles_model?(_model) ⇒ Boolean
-
.parse_to_core(_input, _options = {}) ⇒ Object
Output-only format — parsing from mirror JSON is not supported via the format registry.
-
.serialize(document, options = {}) ⇒ Object
Accept CoreModel, serialize to Mirror JSON.
- .serialize? ⇒ Boolean
Class Method Details
.handles_model?(_model) ⇒ Boolean
33 34 35 |
# File 'lib/coradoc/mirror/mirror_json_format.rb', line 33 def handles_model?(_model) false end |
.parse_to_core(_input, _options = {}) ⇒ Object
Output-only format — parsing from mirror JSON is not supported via the format registry. Use Mirror::Node.from_hash directly.
16 17 18 19 20 |
# File 'lib/coradoc/mirror/mirror_json_format.rb', line 16 def parse_to_core(_input, = {}) raise Coradoc::UnsupportedFormatError, 'Parsing from mirror JSON is not supported via the format registry. ' \ 'Use Coradoc::Mirror::Node.from_hash(JSON.parse(input)) directly.' end |
.serialize(document, options = {}) ⇒ Object
Accept CoreModel, serialize to Mirror JSON.
23 24 25 26 27 |
# File 'lib/coradoc/mirror/mirror_json_format.rb', line 23 def serialize(document, = {}) pretty = [:pretty] != false node = Coradoc::Mirror.transform(document) pretty ? JSON.pretty_generate(node.to_hash) : JSON.generate(node.to_hash) end |
.serialize? ⇒ Boolean
29 30 31 |
# File 'lib/coradoc/mirror/mirror_json_format.rb', line 29 def serialize? true end |