This repository has been archived by the owner on Apr 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6956bae
commit f725050
Showing
16 changed files
with
656 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules/ | ||
build/ | ||
npm-debug.log |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Generic template backend for Asciidoctor.js | ||
Guillaume Grossetie <https://github.com/mogztter[@mogztter]> |
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,2 @@ | ||
require 'asciidoctor/core_ext/factory' | ||
require 'asciidoctor/core_ext/template' |
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,50 @@ | ||
# encoding: UTF-8 | ||
module Asciidoctor | ||
# Monkey patch the create method to add JavaScript slide converters | ||
module Converter | ||
class Factory | ||
def create backend, opts = {} | ||
if (converter = resolve backend) | ||
if converter.is_a? ::Class | ||
return converter.new backend, opts | ||
else | ||
return converter | ||
end | ||
end | ||
|
||
base_converter = case backend | ||
when 'html5' | ||
unless defined? ::Asciidoctor::Converter::Html5Converter | ||
require 'asciidoctor/converter/html5'.to_s | ||
end | ||
Html5Converter.new backend, opts | ||
when 'docbook5' | ||
unless defined? ::Asciidoctor::Converter::DocBook5Converter | ||
require 'asciidoctor/converter/docbook5'.to_s | ||
end | ||
DocBook5Converter.new backend, opts | ||
when 'docbook45' | ||
unless defined? ::Asciidoctor::Converter::DocBook45Converter | ||
require 'asciidoctor/converter/docbook45'.to_s | ||
end | ||
DocBook45Converter.new backend, opts | ||
when 'manpage' | ||
unless defined? ::Asciidoctor::Converter::ManPageConverter | ||
require 'asciidoctor/converter/manpage'.to_s | ||
end | ||
ManPageConverter.new backend, opts | ||
end | ||
|
||
return base_converter unless opts.key? :template_dirs | ||
|
||
unless defined? ::Asciidoctor::Converter::TemplateConverter | ||
require 'asciidoctor/converter/template'.to_s | ||
end | ||
unless defined? ::Asciidoctor::Converter::CompositeConverter | ||
require 'asciidoctor/converter/composite'.to_s | ||
end | ||
TemplateConverter.new backend, opts[:template_dirs], opts | ||
end | ||
end | ||
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,58 @@ | ||
module Asciidoctor | ||
|
||
class Converter::TemplateConverter < Converter::Base | ||
def initialize backend, template_dirs, opts = {} | ||
@backend = backend | ||
@engine = 'jade' # Only Jade/Pug templates are supported for now | ||
if template_dirs.kind_of?(String) | ||
@template_dirs = [template_dirs] | ||
else | ||
@template_dirs = template_dirs | ||
end | ||
end | ||
|
||
def resolve_template name | ||
path_resolver = PathResolver.new | ||
backend = @backend | ||
engine = @engine | ||
@template_dirs.each do |template_dir| | ||
# FIXME need to think about safe mode restrictions here | ||
next unless ::File.directory?(template_dir = (path_resolver.system_path template_dir, nil)) | ||
|
||
# NOTE last matching template wins for template name if no engine is given | ||
if engine | ||
# example: templates/haml | ||
if ::File.directory?(engine_dir = (::File.join template_dir, engine)) | ||
template_dir = engine_dir | ||
end | ||
end | ||
|
||
# example: templates/html5 or templates/haml/html5 | ||
if ::File.directory?(backend_dir = (::File.join template_dir, backend)) | ||
template_dir = backend_dir | ||
end | ||
|
||
template = ::File.join(template_dir, name + "." + engine) | ||
return ::File.read(template) if ::File.exist?(template); | ||
end | ||
return nil | ||
end | ||
|
||
def convert node, template_name = nil, opts = {} | ||
template_name ||= node.node_name | ||
unless (template = resolve_template template_name) | ||
raise %(Could not find a custom template to handle transform: #{template_name}) | ||
end | ||
|
||
%x( | ||
if (typeof window !== 'undefined') { | ||
var jade = jade || window.jade; | ||
} else if (typeof require !== 'undefined') { | ||
var jade = jade || require('./jade.js') || require('jade'); | ||
} | ||
var compiled = jade.compile(#{template}, {pretty: true}); | ||
return compiled({ node: #{node} }); | ||
) | ||
end | ||
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,4 @@ | ||
var Builder = require('./builder.js'); | ||
var builder = new Builder(); | ||
|
||
builder.build(); |
Oops, something went wrong.