Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mojavelinux/b51cb25867dfa64b1b9e9bc649bed11a to your computer and use it in GitHub Desktop.
Save mojavelinux/b51cb25867dfa64b1b9e9bc649bed11a to your computer and use it in GitHub Desktop.
An Asciidoctor treeprocessor that wraps text content in Angular's localize filter.
#!/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