-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add special API for JS, don't register implicitly after require
Fixes #2
- Loading branch information
Showing
5 changed files
with
113 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
require 'asciidoctor/extensions' unless RUBY_PLATFORM == 'opal' | ||
require 'asciidoctor/html5s/version' | ||
require 'asciidoctor/html5s/converter' | ||
require 'asciidoctor/html5s/attached_colist_treeprocessor' | ||
|
||
Asciidoctor::Extensions.register do | ||
treeprocessor Asciidoctor::Html5s::AttachedColistTreeprocessor | ||
unless RUBY_PLATFORM == 'opal' | ||
require 'asciidoctor/extensions' | ||
|
||
Asciidoctor::Extensions.register do | ||
treeprocessor Asciidoctor::Html5s::AttachedColistTreeprocessor | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
module Asciidoctor | ||
module Html5s | ||
VERSION = '0.1.0.beta.6'.freeze | ||
VERSION = '0.1.0.beta.6' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
(function (Opal) { | ||
function initialize (Opal) { | ||
//OPAL-GENERATED-CODE// | ||
} | ||
|
||
var mainModule | ||
|
||
function resolveModule (name) { | ||
if (!mainModule) { | ||
checkAsciidoctor() | ||
initialize(Opal) | ||
mainModule = Opal.const_get_qualified(Opal.Asciidoctor, 'Html5s') | ||
} | ||
if (!name) { | ||
return mainModule | ||
} | ||
return Opal.const_get_qualified(mainModule, name) | ||
} | ||
|
||
function checkAsciidoctor () { | ||
if (typeof Opal.Asciidoctor === 'undefined') { | ||
throw new TypeError('Asciidoctor.js is not loaded') | ||
} | ||
} | ||
|
||
/** | ||
* @return A new instance of `Asciidoctor::Html5s::AttachedColistTreeprocessor`. | ||
*/ | ||
function AttachedColistTreeprocessor () { | ||
var processor = resolveModule('AttachedColistTreeprocessor').$new() | ||
processor.process = processor.$process | ||
|
||
return processor | ||
} | ||
|
||
/** | ||
* @param {string} backend The backend name. | ||
* @param {Object} opts The converter options. | ||
* @return A new instance of `Asciidoctor::Html5s::Converter`. | ||
*/ | ||
function Converter (backend, opts) { | ||
var converter = resolveModule('Converter').$new(backend, Opal.hash(opts || {})) | ||
|
||
converter.convert = function (node, transform, opts) { | ||
return this.$convert(node, transform, Opal.hash(opts || {})) | ||
} | ||
return converter | ||
} | ||
|
||
/** | ||
* @return {string} Version of this extension. | ||
*/ | ||
function getVersion () { | ||
return resolveModule().$$const.VERSION.toString() | ||
} | ||
|
||
/** | ||
* Registers the HTML5s converter and the supporting extension into Asciidoctor. | ||
* | ||
* @param registry The Asciidoctor extensions registry to register the | ||
* extension into. Defaults to the global Asciidoctor registry. | ||
* @throws {TypeError} if the *registry* is invalid or Asciidoctor.js is not loaded. | ||
*/ | ||
function register (registry) { | ||
if (!registry) { | ||
checkAsciidoctor() | ||
registry = Opal.Asciidoctor.Extensions | ||
} | ||
var processor = AttachedColistTreeprocessor() | ||
|
||
// global registry | ||
if (typeof registry.register === 'function') { | ||
registry.register(function () { | ||
this.treeProcessor(processor) | ||
}) | ||
// custom registry | ||
} else if (typeof registry.block === 'function') { | ||
registry.treeProcessor(processor) | ||
} else { | ||
throw new TypeError('Invalid registry object') | ||
} | ||
} | ||
|
||
var facade = { | ||
AttachedColistTreeprocessor: AttachedColistTreeprocessor, | ||
Converter: Converter, | ||
getVersion: getVersion, | ||
register: register, | ||
} | ||
|
||
if (typeof module !== 'undefined' && module.exports) { | ||
module.exports = facade | ||
} | ||
return facade | ||
})(Opal); |