Skip to content

Commit

Permalink
feat(docs): Creates Asciidoctor constant extension (#148)
Browse files Browse the repository at this point in the history
* feat(docs): Creates Asciidoctor constant extension

* chore: rename extension directory
  • Loading branch information
lordofthejars authored and bartoszmajsak committed Sep 14, 2017
1 parent 38b406a commit ae0edb3
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .asciidoctor/lib/const-inline-macro.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
RUBY_ENGINE == 'opal' ? (require 'const-inline-macro/extension') : (require_relative 'const-inline-macro/extension')

Extensions.register do
inline_macro ConstBlockMacro
end
53 changes: 53 additions & 0 deletions .asciidoctor/lib/const-inline-macro/extension.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
require 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal'

include ::Asciidoctor

# A block macro that embeds a Constant into the output document
#
# Usage
#
# const::src/main/java/org/superbiz/Color.java[name="DEFAULT_COLOR"]
# public static final String DEFAULT_COLOR = "blue";
#
# const::src/main/java/org/superbiz/Color.java[tag="DEFAULT_COLOR"]
# // const::DEFAULT_COLOR[]
# public static final STRING MY_DEFAULT_COLOR = "blue";
#
class ConstBlockMacro < Extensions::InlineMacroProcessor
use_dsl
named :const

def process parent, target, attrs

data_path = parent.normalize_asset_path(target, 'target')
const_value = nil

if attrs.has_key? 'name'
const_name = attrs['name']

File.open(data_path).each do |line|
if (line[const_name])
# Gets content between double quotes
const_value = line.scan(/"([^"]*)"/)
break;
end
end
else
if attrs.has_key? 'tag'
const_tag = %(const::#{attrs['tag']})
found_tag = false
File.open(data_path).each do |line|
if found_tag
# Gets content between double quotes
const_value = line.scan(/"([^"]*)"/)
break;
end
if (line[const_tag])
found_tag = true
end
end
end
end
return const_value[0][0].chomp
end
end
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ env:
script:
- ./mvnw clean verify -P travis -DJAVA_OPTS="-XX:-UseLoopPredicate"
- 'if [ $FORCE_DOC_GEN == 0 ] || [ $GENERATE_DOC == 0 ]; then
docker run -v $TRAVIS_BUILD_DIR:/docs/ --name adoc-to-html rochdev/alpine-asciidoctor:mini asciidoctor /docs/README.adoc -a generated-doc=true -a asciidoctor-source=/docs/docs -o /docs/gh-pages/index.html;
docker run -v $TRAVIS_BUILD_DIR:/docs/ --name adoc-to-html rochdev/alpine-asciidoctor:mini asciidoctor -r /docs/asciidoctor/lib/const-inline-macro.rb /docs/README.adoc -a generated-doc=true -a asciidoctor-source=/docs/docs -o /docs/gh-pages/index.html;
fi'

after_success:
Expand Down

0 comments on commit ae0edb3

Please sign in to comment.