-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(docs): Creates Asciidoctor constant extension (#148)
* feat(docs): Creates Asciidoctor constant extension * chore: rename extension directory
- Loading branch information
1 parent
38b406a
commit ae0edb3
Showing
3 changed files
with
59 additions
and
1 deletion.
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,5 @@ | ||
RUBY_ENGINE == 'opal' ? (require 'const-inline-macro/extension') : (require_relative 'const-inline-macro/extension') | ||
|
||
Extensions.register do | ||
inline_macro ConstBlockMacro | ||
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,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 |
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