Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Js embed modern frameworks #219

Merged
merged 13 commits into from
Nov 5, 2018
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require 'thread_safe'
require 'tilt'

CONVERTER_FILE = 'lib/asciidoctor-revealjs/converter.rb'
JS_FILE = 'build/asciidoctor-reveal.js'
TEMPLATES_DIR = 'templates'

file CONVERTER_FILE => FileList["#{TEMPLATES_DIR}/*"] do
Expand All @@ -25,6 +26,24 @@ namespace :build do
task 'converter:opal' => 'clean' do
build_converter :opal
end

desc "Transcompile to JavaScript and generate #{JS_FILE}"
task :js => 'converter:opal' do
require 'opal'

builder = Opal::Builder.new(compiler_options: {
dynamic_require_severity: :error,
})
builder.append_paths 'lib'
builder.build 'asciidoctor-revealjs'

mkdir_p File.dirname(JS_FILE)
File.open(JS_FILE, 'w') do |file|
template = File.read('src/asciidoctor-revealjs.tmpl.js')
file << template.sub('//OPAL-GENERATED-CODE//', builder.to_s)
end
File.binwrite "#{JS_FILE}.map", builder.source_map
end
end

task :build => 'build:converter'
Expand Down
1 change: 1 addition & 0 deletions asciidoctor-revealjs.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ Gem::Specification.new do |s|
s.add_development_dependency 'asciidoctor-templates-compiler', '~> 0.3.0'
s.add_development_dependency 'slim', '~> 3.0.6'
s.add_development_dependency 'slim-htag', '~> 0.1.0'
s.add_development_dependency 'opal', '~> 0.11.1'
end
1 change: 1 addition & 0 deletions lib/asciidoctor-revealjs.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
if RUBY_ENGINE == 'opal'
require 'asciidoctor-revealjs/converter'
require 'asciidoctor-revealjs/version'
obilodeau marked this conversation as resolved.
Show resolved Hide resolved
else
require 'asciidoctor' unless defined? Asciidoctor::Converter
require_relative 'asciidoctor-revealjs/converter'
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@
},
"homepage": "https://github.com/asciidoctor/asciidoctor-reveal.js",
"dependencies": {
"asciidoctor.js": "1.5.6-rc.1",
"asciidoctor.js": "1.5.6",
"reveal.js": "3.6.0"
},
"devDependencies": {
"bestikk-fs": "0.1.0",
"bestikk-log": "0.1.0",
"expect.js": "0.3.1",
"opal-compiler": "1.0.2"
"opal-compiler": "1.0.3"
},
"readme": "# Reveal.js converter for Asciidoctor\n\n[Asciidoctor reveal.js](https://github.com/asciidoctor/asciidoctor-reveal.js) is a converter for [Asciidoctor](https://github.com/asciidoctor/asciidoctor) and [Asciidoctor.js](https://github.com/asciidoctor/asciidoctor.js) that transforms an AsciiDoc document into an HTML5 presentation designed to be executed by the [reveal.js](http://lab.hakim.se/reveal-js/) presentation framework.\n\nThis is the npm module. For setup instructions and the AsciiDoc syntax to use to write a presentation see the module's documentation at [https://github.com/asciidoctor/asciidoctor-reveal.js](https://github.com/asciidoctor/asciidoctor-reveal.js).\n"
}
46 changes: 46 additions & 0 deletions src/asciidoctor-revealjs.tmpl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
(function (Opal) {
function initialize (Opal) {
//OPAL-GENERATED-CODE//
}

var mainModule

function resolveModule () {
if (!mainModule) {
checkAsciidoctor()
initialize(Opal)
mainModule = Opal.const_get_qualified(Opal.Asciidoctor, 'Revealjs')
}
return mainModule
}

function checkAsciidoctor () {
if (typeof Opal.Asciidoctor === 'undefined') {
throw new TypeError('Asciidoctor.js is not loaded')
}
}

/**
* @return {string} Version of this extension.
*/
function getVersion () {
return resolveModule().$$const.VERSION.toString()
}

/**
* Registers the reveal.js converter.
*/
function register () {
return resolveModule()
obilodeau marked this conversation as resolved.
Show resolved Hide resolved
}

var facade = {
getVersion: getVersion,
register: register,
}

if (typeof module !== 'undefined' && module.exports) {
module.exports = facade
}
return facade
})(Opal);
2 changes: 2 additions & 0 deletions test/js-babel/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
dist/*.js
29 changes: 29 additions & 0 deletions test/js-babel/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
= Asciidoctor Reveal.js integration with Babel

== Usage

Install the dependencies:

$ npm install

Optional: To install a development version of Asciidoctor-reveal.js (1.1.4 for example):

1. Build npm package (see instructions in `HACKING.adoc` to do so)
2. Install devel npm package with:
+
$ npm i --save ../../asciidoctor-reveal.js-1.1.4-dev.tgz

Test the project:

$ npm test

[IMPORTANT]
====
obilodeau marked this conversation as resolved.
Show resolved Hide resolved
An exception will be thrown at runtime:

```
Converter: uninitialized constant Asciidoctor::Converter
```

For more details, see https://github.com/asciidoctor/asciidoctor-reveal.js/issues/205.
====
Empty file added test/js-babel/dist/.gitkeep
Empty file.
19 changes: 19 additions & 0 deletions test/js-babel/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Asciidoctor from 'asciidoctor.js'
const asciidoctor = Asciidoctor()

// Babel will move the import statement at the top of the file.
// As a consequence, the reveal.js converter will be loaded before the initialization of Asciidoctor.js.
import 'asciidoctor-reveal.js'
// If we replace the import statement by a require statement then it's working.
// Another way to fix this issue is to lazily load the reveal.js converter.
//require('asciidoctor-reveal.js')

const attributes = { revealjsdir: 'node_modules/reveal.js@' }
const options = {
safe: 'safe',
backend: 'revealjs',
attributes: attributes,
header_footer: true
}

console.log(asciidoctor.convert('Hello *Babel*', options))
Loading