Class: Y::Lexical
- Inherits:
-
Object
- Object
- Y::Lexical
- Defined in:
- lib/y/rendering.rb
Overview
Y::Lexical and Y::ProseMirror are plain Ruby facades over the native renderers (Y::NativeLexical / Y::NativeProseMirror, private constants): they compile the rules config, hold the callbacks, and splice deferred segments after a render. The native handle does everything else.
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(doc, nodes: {}) {|builder| ... } ⇒ Lexical
constructor
Y::Lexical.new(doc, nodes: { "type" => rule })— see Y::RenderRules for the rule forms. -
#node_types(root = nil) ⇒ Object
What node types this document actually contains — the discovery aid for writing rules.
- #to_html(root = nil) ⇒ Object
Constructor Details
#initialize(doc, nodes: {}) {|builder| ... } ⇒ Lexical
Y::Lexical.new(doc, nodes: { "type" => rule }) — see Y::RenderRules
for the rule forms. This is core Lexical only: paragraphs, headings,
quotes, code, lists, tables, links, text formatting. Editor-specific
nodes arrive as rules — Y::Lexxy subclasses this with the Lexxy schema;
a different Lexical editor brings its own rule set the same way.
220 221 222 223 224 225 226 |
# File 'lib/y/rendering.rb', line 220 def initialize(doc, nodes: {}) builder = RenderRules::Builder.new(marks_allowed: false) yield builder if block_given? nodes = nodes.transform_keys(&:to_s).merge(builder.nodes) rules_json, @render_callbacks = RenderRules.compile(nodes, {}) @native = NativeLexical.new(doc, rules_json) end |
Instance Method Details
#node_types(root = nil) ⇒ Object
What node types this document actually contains — the discovery aid for writing rules. Facts per type: "count", "attrs" (names as stored), "children" (child node types), "text" (whether it holds text runs), and "handled" ("builtin", "rule", or nil — nil marks the types you still need a rule for). Children plus text is how you pick contains:.
240 241 242 243 |
# File 'lib/y/rendering.rb', line 240 def node_types(root = nil) json = root.nil? ? @native.node_types : @native.node_types(root) json && JSON.parse(json) end |
#to_html(root = nil) ⇒ Object
228 229 230 231 232 233 |
# File 'lib/y/rendering.rb', line 228 def to_html(root = nil) result = root.nil? ? @native.to_html : @native.to_html(root) return result unless result.is_a?(Array) RenderRules.splice(result, @render_callbacks) end |