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 11 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
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ script:
- bundle exec rake doctest
- bundle exec rake examples:convert
- npm install
- bundle exec rake build:converter:opal
- npm run build
- bundle exec rake build:js
- npm run examples
- npm test

Expand Down
19 changes: 9 additions & 10 deletions HACKING.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,7 @@ Makes triaging easier.

In order to test the Node package, you first need to build the converter into Javascript and create a tarball of the project.

$ bundle exec rake build:converter:opal
$ npm run build
$ bundle exec rake build:js
$ npm pack

That last command will produce a file named `asciidoctor-reveal.js-<version>.tgz` in the working directory.
Expand All @@ -232,11 +231,11 @@ Then proceed as documented in the `README.adoc`.

=== Upgrade Asciidoctor.js version

WARNING: It is important to track `Asciidoctor.js` and `bestikk-opal-compiler` versions together.
The `opal-compiler` used to compile our node package must match `asciidoctor.js` `opal-runtime`.
The former is explicitly installed by users on install and the later is specified in our `package.json`.
WARNING: It is important to track `Asciidoctor.js` and `opal` versions together.
The `opal` used to compile our node package must match `asciidoctor.js`'s `opal` requirement.
The former is specified in our `package.json` and the latter in the `asciidoctor-revealjs.gemspec`.
When you update one remember to update the other.
Versions known to work together can be found here, just replace <tag> with the `asciidoctor.js` release you are interested in: https://github.com/asciidoctor/asciidoctor.js/blob/<tag>/package.json
Versions known to work together can be found by looking at the Asciidoctor.js release notes, just replace <tag> with the `asciidoctor.js` release you are interested in: https://github.com/asciidoctor/asciidoctor.js/releases/tag/<tag>.

== RubyGem package

Expand Down Expand Up @@ -278,13 +277,13 @@ Then run:
$ gem push asciidoctor-revealjs-X.Y.Z.gem

. Check that the new version is available on https://rubygems.org/gems/asciidoctor-revealjs[rubygems.org]
. Generate a compatible version of the Ruby converter (using opal mode)
. Generate the javascript version of the Ruby converter
+
$ bundle exec rake build:converter:opal
$ bundle exec rake build:js

. Build the node package (make sure you have `devDependencies` installed with: `npm install`):
. Test the node package (make sure you have `devDependencies` installed with: `npm install`):
+
$ npm run build
$ npm run test

. Publish the node package on npm:
+
Expand Down
3 changes: 2 additions & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ Here we are converting a file named `presentation.adoc` into a reveal.js present
----
// Load asciidoctor.js and asciidoctor-reveal.js
var asciidoctor = require('asciidoctor.js')();
require('asciidoctor-reveal.js');
var asciidoctorRevealjs = require('asciidoctor-reveal.js');
asciidoctorRevealjs.register()

// Convert the document 'presentation.adoc' using the reveal.js converter
var attributes = {'revealjsdir': 'node_modules/reveal.js@'};
Expand Down
22 changes: 22 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ require 'thread_safe'
require 'tilt'

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

file CONVERTER_FILE => FileList["#{TEMPLATES_DIR}/*"] do
Expand All @@ -25,6 +27,26 @@ 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.dirname(DIST_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

cp JS_FILE, DIST_FILE, :verbose => true
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
39 changes: 0 additions & 39 deletions npm/build.js

This file was deleted.

15 changes: 0 additions & 15 deletions npm/compiler.js

This file was deleted.

5 changes: 4 additions & 1 deletion npm/examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ log.task('examples');

// Load asciidoctor.js and local asciidoctor-reveal.js
const asciidoctor = require('asciidoctor.js')();
require('../build/asciidoctor-reveal.js');
const asciidoctorRevealjs = require('../build/asciidoctor-reveal.js');

// Register the reveal.js converter
asciidoctorRevealjs.register()

// Convert *a* document using the reveal.js converter
var attributes = {'revealjsdir': 'node_modules/reveal.js@'};
Expand Down
Loading