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

Compiling slim templates into pure ruby (simplifies Javascript maintenance) #131

Merged
merged 6 commits into from
Sep 26, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@
# test stuff
/examples/*.html
/examples/reveal.js/
/test/doctest/reveal.js/

# node stuff
node_modules/
npm-debug.log
build/
/dist/main.js

# ruby stuff
/.bundle/
/Gemfile.lock

# the compiled slim template
/lib/asciidoctor-revealjs/converter.rb
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ git:
# use depth 2 just in case two refs get pushed at once (like a tag)
depth: 2
language: ruby
node_js: lts/*
rvm:
- 2.4
- 2.3
Expand All @@ -17,7 +18,11 @@ env:
# use system libraries to speed up installation of nokogiri
- NOKOGIRI_USE_SYSTEM_LIBRARIES=true
script:
- bundle exec rake build
- bundle exec rake doctest
- bundle exec rake examples:convert
- npm install
- npm run build

notifications:
email: false
22 changes: 21 additions & 1 deletion HACKING.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ done with `bundler`:

bundle config --local github.https true
bundle --path=.bundle/gems --binstubs=.bundle/.bin
bundle exec rake build

Go to `test/output/slim/` folder and install `reveal.js`:

Expand Down Expand Up @@ -207,14 +208,32 @@ In order to test the Node package, you need to create a test project adjacent to

Now, install the dependencies:

$ npm i --save asciidoctor.js@1.5.5-3
$ npm i --save asciidoctor.js@1.5.6-preview.3
$ npm i --save ../asciidoctor-reveal.js

NOTE: The relative portion of the last command is where you are installing the local `asciidoctor-reveal.js` version from.

Then proceed as documented in the `README.adoc`.


== RubyGem package

=== Test a local asciidoctor-revealjs version

Compile the converter:

$ bundle exec rake build

In a clean directory besides the `asciidoctor-reveal.js` repository, create the following `Gemspec` file:

source 'https://rubygems.org'
gem 'asciidoctor-revealjs', :path => '../asciidoctor-reveal.js'

Then run:

$ bundle --path=.bundle/gems --binstubs=.bundle/.bin


== Release process

. Update the version in `lib/asciidoctor-revealjs/version.rb` and `package.json`
Expand All @@ -232,6 +251,7 @@ Then proceed as documented in the `README.adoc`.
. Make a release on github (from changelog and copy from previous releases)
. Pushing the gem on rubygems.org:
+
$ bundle exec rake build
$ gem build asciidoctor-revealjs.gemspec
$ gem push asciidoctor-revealjs-X.Y.Z.gem

Expand Down
9 changes: 3 additions & 6 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ NOTE: These instructions should be repeated for every presentation project.
source 'https://rubygems.org'

gem 'asciidoctor-revealjs' # latest released version
#gem 'asciidoctor-revealjs', github: 'asciidoctor/asciidoctor-reveal.js' # github master branch
----
+
NOTE: For some reason, when you use the system Ruby on Fedora, you also have to add the json gem to the Gemfile.
Expand Down Expand Up @@ -133,14 +132,12 @@ 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')();
var Asciidoctor = asciidoctor.Asciidoctor();

require('asciidoctor-reveal.js');

// Convert the document 'presentation.adoc' using the reveal.js converter
var attributes = 'revealjsdir=node_modules/reveal.js@';
var attributes = {'revealjsdir': 'node_modules/reveal.js@'};
var options = {safe: 'safe', backend: 'revealjs', attributes: attributes};
Asciidoctor.convertFile('presentation.adoc', options); // <1>
asciidoctor.convertFile('presentation.adoc', options); // <1>
----
<1> Creates a file named `presentation.html` (in the directory where command is run)

Expand All @@ -162,7 +159,7 @@ Asciidoctor.convertFile('presentation.adoc', options); // <1>

To render the slides, run:

node asciidoctor-reveal.js
node asciidoctor-revealjs.js

You can open the `presentation.html` file in your browser and enjoy!

Expand Down
77 changes: 74 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,83 @@
#!/usr/bin/env rake

require 'asciidoctor'
require 'asciidoctor/doctest'
require 'colorize'
require 'thread_safe'
require 'tilt'

CONVERTER_FILE = 'lib/asciidoctor-revealjs/converter.rb'
TEMPLATES_DIR = 'templates'

namespace :build do
require 'asciidoctor-templates-compiler'
require 'slim-htag'

generator = if :mode == :opal
Temple::Generators::ArrayBuffer.new(freeze_static: false)
else
Temple::Generators::StringBuffer
end

file CONVERTER_FILE, [:mode] => FileList["#{TEMPLATES_DIR}/*"] do |t, args|
#require 'asciidoctor-templates-compiler'
require_relative 'lib/asciidoctor-templates-compiler'
require 'slim-htag'

File.open(CONVERTER_FILE, 'w') do |file|
$stderr.puts "Generating #{file.path}."
Asciidoctor::TemplatesCompiler::RevealjsSlim.compile_converter(
templates_dir: TEMPLATES_DIR,
class_name: 'Asciidoctor::Revealjs::Converter',
register_for: ['revealjs'],
backend_info: {
basebackend: 'html',
outfilesuffix: '.html',
filetype: 'html',
},
delegate_backend: 'html5',
engine_opts: {
generator: generator,
},
pretty: (args[:mode] == :pretty),
output: file)
end
end

namespace :converter do
desc 'Compile Slim templates and generate converter.rb (pretty mode)'
task :pretty do
Rake::Task[CONVERTER_FILE].invoke(:pretty)
end

desc 'Compile Slim templates and generate converter.rb (fast mode)'
task :fast do
Rake::Task[CONVERTER_FILE].invoke
end
end

task :converter => 'converter:pretty'
end

task :build => 'build:converter:pretty'

task :clean do
rm_rf CONVERTER_FILE
end

DocTest::RakeTasks.new do |t|
t.output_examples :html, path: 'test/output/slim'
t.output_examples :html, path: 'test/doctest'
t.input_examples :asciidoc, path: [ *DocTest.examples_path, 'examples' ]
t.converter = DocTest::HTML::Converter
t.converter_opts = { template_dirs: 'templates/slim' }
t.converter_opts = { backend_name: 'revealjs' }
end

task 'prepare-converter' do
# Run as an external process to ensure that it will not affect tests
# environment with extra loaded modules (especially slim).
`bundle exec rake build:converter:fast`

require_relative 'lib/asciidoctor-revealjs'
end

namespace :examples do
Expand All @@ -21,7 +90,7 @@ namespace :examples do
:safe => 'safe',
:backend => 'revealjs',
:base_dir => 'examples',
:template_dir => 'templates/slim'
:template_dir => 'templates'
if out.instance_of? Asciidoctor::Document
puts "✔️".green
else
Expand All @@ -31,5 +100,7 @@ namespace :examples do
end
end

task 'doctest:test' => 'prepare-converter'
task 'doctest:generate' => 'prepare-converter'
# When no task specified, run test.
task :default => :doctest
4 changes: 3 additions & 1 deletion asciidoctor-revealjs.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ Gem::Specification.new do |s|
s.require_paths = ['lib']

s.add_runtime_dependency 'asciidoctor', '~> 1.5.6'
s.add_runtime_dependency 'slim', '~> 3.0.6'
s.add_runtime_dependency 'thread_safe', '~> 0.3.5'

s.add_development_dependency 'rake', '~> 10.4.2'
s.add_development_dependency 'asciidoctor-doctest', '= 2.0.0.beta.4'
s.add_development_dependency 'pry', '~> 0.10.4'
s.add_development_dependency 'colorize'
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'
end
64 changes: 0 additions & 64 deletions dist/main.js

This file was deleted.

1 change: 0 additions & 1 deletion lib/asciidoctor-revealjs.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
if RUBY_ENGINE == 'opal'
require 'asciidoctor-revealjs/converter'
`require('asciidoctor-template.js')`
else
require 'asciidoctor' unless defined? Asciidoctor::Converter
require_relative 'asciidoctor-revealjs/converter'
Expand Down
38 changes: 0 additions & 38 deletions lib/asciidoctor-revealjs/converter.rb

This file was deleted.

11 changes: 11 additions & 0 deletions lib/asciidoctor-templates-compiler.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'asciidoctor-templates-compiler'

module Asciidoctor::TemplatesCompiler
class RevealjsSlim < Asciidoctor::TemplatesCompiler::Slim
def engine_options
::Asciidoctor::Converter::TemplateConverter::DEFAULT_ENGINE_OPTIONS[:slim].merge(
generator: Temple::Generators::ArrayBuffer.new(capture_generator: 'ArrayBuffer')
)
end
end
end
3 changes: 2 additions & 1 deletion npm/builder.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = Builder;

var fs = require('fs');
var async = require('async');
var log = require('bestikk-log');
var bfs = require('bestikk-fs');
Expand Down Expand Up @@ -49,7 +50,7 @@ Builder.prototype.compile = function (callback) {
var opalCompiler = new OpalCompiler({dynamicRequireLevel: 'ignore'});
opalCompiler.compile('asciidoctor-revealjs', 'build/asciidoctor-revealjs.js', ['lib']);
typeof callback === 'function' && callback();
}
};

Builder.prototype.copyToDist = function (callback) {
var builder = this;
Expand Down
Loading