asciidoctor-templates-compiler 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2bb8bf4e21a7c0da30e0862a44aa6d44bb7b848454e7709586e1d500849de30e
|
4
|
+
data.tar.gz: 1793750752bdcfb66b5193de00e0a51d962c941b41b642c17f8c3129fab0b4d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 958552ef2e142a7792272b4713997129946bc39325c7325f7cf5e49e37d9d98f211f27efe3e453a2de443a24965d1da4d1de3f0e7b279e0495bd4668d02c8a78
|
7
|
+
data.tar.gz: 237265848e2094213d2387cd8c4e2f23d6296409199e8b9223949c9493a23ff81de74625f1db396bdc8bc8d4ffdb5e7bef036cc01d66ddb8f9cc4b5f444d2a8f
|
data/README.adoc
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
:source-language: ruby
|
3
3
|
// custom
|
4
4
|
:gem-name: asciidoctor-templates-compiler
|
5
|
-
:gem-version: 0.
|
5
|
+
:gem-version: 0.5.0
|
6
6
|
:gh-name: jirutka/{gem-name}
|
7
7
|
:gh-branch: master
|
8
8
|
:codacy-id: b23b8c6503474ea5b13537eaef0c73d5
|
@@ -57,6 +57,10 @@ delegate_backend::
|
|
57
57
|
engine_opts::
|
58
58
|
A Hash of options to pass into the templating engine that compiles templates into Ruby code.
|
59
59
|
|
60
|
+
ignore_convert_opts::
|
61
|
+
Ignore (i.e. do not set as local variables) options passed to the `#convert` method (i.e. to the templates).
|
62
|
+
This is needed only for Opal.
|
63
|
+
|
60
64
|
output::
|
61
65
|
An output stream (`IO` object like opened file, `$stdout`, …) to write the generated converter into.
|
62
66
|
Default is `StringIO.new` (it’s the return value of `#compile_converter`).
|
@@ -152,6 +156,46 @@ end
|
|
152
156
|
You can also look into https://github.com/jirutka/asciidoctor-html5s/[asciidoctor-html5s] for a real-world example including integration with https://github.com/asciidoctor/asciidoctor-doctest/[Asciidoctor::DocTest].
|
153
157
|
|
154
158
|
|
159
|
+
=== Opal Caveats
|
160
|
+
|
161
|
+
The generated converter code can be transpiled into JavaScript using Opal.
|
162
|
+
However, there’s one feature that is known to not work: passing options to the `#convert` method.
|
163
|
+
|
164
|
+
Consider the following example:
|
165
|
+
|
166
|
+
[source, slim]
|
167
|
+
.toc.html.slim:
|
168
|
+
nav id='toc'
|
169
|
+
= converter.convert document, 'outline', toclevels: 5
|
170
|
+
|
171
|
+
[source, slim]
|
172
|
+
.outline.html.slim:
|
173
|
+
- toclevels ||= document.attr('toclevels').to_i
|
174
|
+
|
175
|
+
Variable `toclevels` in `outline.html.slim` should be initialized to `5` when this template is called from the `toc.html.slim` template.
|
176
|
+
This is implemented using `Kernel#binding` and `Binding#local_variable_set` which is not supported by Opal.
|
177
|
+
In such case you get exception like this:
|
178
|
+
|
179
|
+
....
|
180
|
+
RuntimeError: node_modules/opal-runtime/src/opal.js
|
181
|
+
throw exception;
|
182
|
+
^
|
183
|
+
|
184
|
+
binding: undefined method `binding` for [some Asciidoctor class]
|
185
|
+
....
|
186
|
+
|
187
|
+
Unfortunately I don’t know how to implement this feature without using `Binding`, but you can use the following workaround.
|
188
|
+
|
189
|
+
Enable `ignore_convert_opts` (see <<Usage>>) to remove the code calling `Kernel#binding` from the converter.
|
190
|
+
The options will be still passed, but not binded to the template local variables.
|
191
|
+
If you examine the generated code, you can see that the options are passed to the convert methods via argument named `opts`.
|
192
|
+
You can exploit this fact and do something like:
|
193
|
+
|
194
|
+
[source, slim]
|
195
|
+
.outline.html.slim:
|
196
|
+
- toclevels = opts[:toclevels] || document.attr('toclevels').to_i
|
197
|
+
|
198
|
+
|
155
199
|
== License
|
156
200
|
|
157
201
|
This project is licensed under http://opensource.org/licenses/MIT/[MIT License].
|
@@ -40,17 +40,21 @@ module Asciidoctor::TemplatesCompiler
|
|
40
40
|
# @param delegate_backend [String, nil] name of the backend (converter) to use as a fallback
|
41
41
|
# for AST nodes not supported by the generated converter. If not specified, no fallback will
|
42
42
|
# be used and converter will raise +NoMethodError+ when it try to convert unsupported node.
|
43
|
+
# @param ignore_convert_opts [Boolean] ignore (i.e. do not set as local variables) options
|
44
|
+
# passed to the +#convert+ method (i.e. to the templates). This is needed only for Opal.
|
43
45
|
#
|
44
46
|
# @raise [ArgumentError] if _helpers_code_ is not blank and does not contain module +Helpers+.
|
45
47
|
#
|
46
48
|
def initialize(class_name:, transforms_code:, helpers_code: nil,
|
47
|
-
register_for: [], backend_info: {}, delegate_backend: nil,
|
49
|
+
register_for: [], backend_info: {}, delegate_backend: nil,
|
50
|
+
ignore_convert_opts: false, **)
|
48
51
|
@class_name = class_name
|
49
52
|
@transforms_code = transforms_code
|
50
53
|
@helpers_code = helpers_code
|
51
54
|
@register_for = Array(register_for)
|
52
55
|
@backend_info = backend_info
|
53
56
|
@delegate_backend = delegate_backend
|
57
|
+
@ignore_convert_opts = ignore_convert_opts
|
54
58
|
|
55
59
|
if !helpers_code.blank? && helpers_code !~ /\bmodule Helpers[\s#]/
|
56
60
|
raise ArgumentError, 'The helpers_code does not contain module Helpers'
|
@@ -166,6 +170,8 @@ module Asciidoctor::TemplatesCompiler
|
|
166
170
|
end
|
167
171
|
|
168
172
|
def support_methods_code
|
173
|
+
return '' if @ignore_convert_opts
|
174
|
+
|
169
175
|
<<-EOF.reindent(2)
|
170
176
|
def set_local_variables(binding, vars)
|
171
177
|
vars.each do |key, val|
|
@@ -183,7 +189,7 @@ module Asciidoctor::TemplatesCompiler
|
|
183
189
|
out << " def #{name}(node, opts = {})\n"
|
184
190
|
out << " node.extend(Helpers)\n" unless @helpers_code.blank?
|
185
191
|
out << " node.instance_eval do\n"
|
186
|
-
out << " converter.set_local_variables(binding, opts) unless opts.empty?\n"
|
192
|
+
out << " converter.set_local_variables(binding, opts) unless opts.empty?\n" unless @ignore_convert_opts # rubocop:disable LineLength
|
187
193
|
out << code.indent(6, ' ') << "\n"
|
188
194
|
out << " end\n"
|
189
195
|
out << " end\n"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asciidoctor-templates-compiler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jakub Jirutka
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|