-
-
Save mojavelinux/b51cb25867dfa64b1b9e9bc649bed11a to your computer and use it in GitHub Desktop.
An Asciidoctor treeprocessor that wraps text content in Angular's localize filter.
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
#!/usr/bin/env ruby | |
require 'asciidoctor/extensions' | |
class AngularLocalizerTreeprocessor < Asciidoctor::Extensions::Treeprocessor | |
def process document | |
document.blocks? ? (localize_blocks document) : nil | |
end | |
def localize_blocks node | |
node.find_by do |b| | |
case b.context | |
when :paragraph | |
b.lines.replace [localize_text(b.lines * ' ')] | |
when :list_item | |
b.instance_variable_set :@text, (localize_text b.instance_variable_get :@text) | |
end | |
true | |
end | |
nil | |
end | |
def localize_text text | |
%({{#{text} | localize}}) | |
end | |
end | |
Asciidoctor::Extensions.register do | |
treeprocessor AngularLocalizerTreeprocessor | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment