Class: RicherText::Node
- Inherits:
-
Object
- Object
- RicherText::Node
- Includes:
- Rendering
- Defined in:
- lib/richer_text/node.rb
Direct Known Subclasses
RicherText::Nodes::AttachmentFigure, RicherText::Nodes::AttachmentGallery, RicherText::Nodes::Blockquote, RicherText::Nodes::BulletList, RicherText::Nodes::Callout, RicherText::Nodes::CodeBlock, RicherText::Nodes::Doc, RicherText::Nodes::HardBreak, RicherText::Nodes::Heading, RicherText::Nodes::HorizontalRule, RicherText::Nodes::IframelyEmbed, RicherText::Nodes::Image, RicherText::Nodes::ListItem, RicherText::Nodes::Mention, RicherText::Nodes::OrderedList, RicherText::Nodes::Paragraph, RicherText::Nodes::RicherTextEmbed, RicherText::Nodes::Table, RicherText::Nodes::TableCell, RicherText::Nodes::TableHeader, RicherText::Nodes::TableRow, RicherText::Nodes::Text
Constant Summary collapse
- STYLES =
{ "textAlign" => "text-align" }
Instance Attribute Summary collapse
-
#attrs ⇒ Object
readonly
Returns the value of attribute attrs.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#json ⇒ Object
readonly
Returns the value of attribute json.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
-
#initialize(json) ⇒ Node
constructor
A new instance of Node.
- #style ⇒ Object
Constructor Details
#initialize(json) ⇒ Node
Returns a new instance of Node.
16 17 18 19 20 21 |
# File 'lib/richer_text/node.rb', line 16 def initialize(json) @json = json @attrs = json.fetch("attrs", {}) @type = json.fetch("type", "text") @children = json.fetch("content", []).map { |child| self.class.build(child) } end |
Instance Attribute Details
#attrs ⇒ Object (readonly)
Returns the value of attribute attrs.
3 4 5 |
# File 'lib/richer_text/node.rb', line 3 def attrs @attrs end |
#children ⇒ Object (readonly)
Returns the value of attribute children.
3 4 5 |
# File 'lib/richer_text/node.rb', line 3 def children @children end |
#json ⇒ Object (readonly)
Returns the value of attribute json.
3 4 5 |
# File 'lib/richer_text/node.rb', line 3 def json @json end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/richer_text/node.rb', line 3 def type @type end |
Class Method Details
.build(json) ⇒ Object
10 11 12 13 14 |
# File 'lib/richer_text/node.rb', line 10 def self.build(json) node = json.is_a?(String) ? JSON.parse(json) : json klass = "RicherText::Nodes::#{node["type"].underscore.classify}".constantize klass.new(node) if klass end |
Instance Method Details
#accept(visitor) ⇒ Object
27 28 29 |
# File 'lib/richer_text/node.rb', line 27 def accept(visitor) visitor.send("visit_#{type.underscore}", self) end |