Module: Collab::JS

Defined in:
lib/collab/js.rb

Defined Under Namespace

Classes: JSProcess, JSRuntimeError

Class Method Summary collapse

Class Method Details

.apply_commit(document, commit, pos: nil, map_steps_through:, schema_name:) ⇒ Object



30
31
32
# File 'lib/collab/js.rb', line 30

def apply_commit(document, commit, pos: nil, map_steps_through:, schema_name:)
  call("applyCommit", {doc: document, commit: commit, mapStepsThrough: map_steps_through, pos: pos},schema_name)
end

.call(name, data = nil, schema_name = nil) ⇒ Object



24
25
26
27
28
# File 'lib/collab/js.rb', line 24

def call(name, data = nil, schema_name = nil)
  req = {name: name, data: data, schemaPackage: ::Collab.config.schema_package}
  req[:schemaName] = schema_name if schema_name
  with_js { |js| js.call(JSON.generate(req)) }
end

.document_to_html(document, schema_name:) ⇒ Object



38
39
40
# File 'lib/collab/js.rb', line 38

def document_to_html(document, schema_name:)
  call("docToHtml", document, schema_name)
end

.html_to_document(html, schema_name:) ⇒ Object



34
35
36
# File 'lib/collab/js.rb', line 34

def html_to_document(html, schema_name:)
  call("htmlToDoc", html, schema_name)
end

.map_through(steps:, pos:) ⇒ Object



42
43
44
# File 'lib/collab/js.rb', line 42

def map_through(steps:, pos:)
  call("mapThru", {steps: steps, pos: pos})
end

.queueObject



10
11
12
13
# File 'lib/collab/js.rb', line 10

def queue
  initialize_queue unless @queue_initialized
  @queue
end

.with_jsObject

Calls the block given with a JS process acquired from the queue Will block until a JS process is available



17
18
19
20
21
22
# File 'lib/collab/js.rb', line 17

def with_js
  js = queue.pop
  yield js
ensure
  queue << js
end