Module: Udb::Helpers::AsciidocUtils
- Defined in:
- lib/udb_helpers/backend_helpers.rb
Class Method Summary collapse
-
.resolve_links(path_or_str) ⇒ String
The syntax “class << self” causes all methods to be treated as class methods.
Class Method Details
.resolve_links(path_or_str) ⇒ String
The syntax “class << self” causes all methods to be treated as class methods. Convert proprietary link format to legal AsciiDoc links. They are converted to AsciiDoc internal cross references (i.e., <<anchor_name,link_text>>). For example,
%%UDB_DOC_LINK%inst;add;add instruction%%
is converted to:
<<udb:inst:add,add instruction>>
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
# File 'lib/udb_helpers/backend_helpers.rb', line 303 def self.resolve_links(path_or_str) str = if path_or_str.is_a?(Pathname) path_or_str.read else path_or_str end str.gsub(/%%UDB_DOC_LINK%([^;%]+)\s*;\s*([^;%]+)\s*;\s*([^%]+)%%/) do type = Regexp.last_match[1] name = Regexp.last_match[2] link_text = Regexp.last_match[3] case type when "ext" "<<udb:doc:ext:#{name},#{link_text}>>" when "ext_param" ext_name, param_name = name.split(".") "<<udb:doc:ext_param:#{ext_name}:#{param_name},#{link_text}>>" when "inst" "<<udb:doc:inst:#{name},#{link_text}>>" when "csr" "<<udb:doc:csr:#{name},#{link_text}>>" when "csr_field" csr_name, field_name = name.split("*") "<<udb:doc:csr_field:#{csr_name}:#{field_name},#{link_text}>>" when "mmr" "<<udb:doc:mmr:#{name},#{link_text}>>" when "mmr_field" mmr_name, field_name = name.split(".") "<<udb:doc:mmr_field:#{mmr_name}:#{field_name},#{link_text}>>" when "func" "<<udb:doc:func:#{name},#{link_text}>>" else raise "Unhandled link type of '#{type}' for '#{name}' with link_text '#{link_text}'" end end.gsub(/%%UDB_DOC_COV_PT_LINK%([^;%]+)\s*;\s*([^;%]+)\s*;\s*([^%]+)%%/) do org = Regexp.last_match[1] # "sep", "combo", or "appendix" id = Regexp.last_match[2] link_text = Regexp.last_match[3] raise "Unhandled link org of '#{org}' for ID '#{id}' with link_text '#{link_text}'" unless org == "sep" || org == "combo" || org == "appendix" "<<udb:doc:cov_pt:#{org}:#{id},#{link_text}>>" end.gsub(/%%IDL_CODE_LINK%([^;%]+)\s*;\s*([^;%]+)\s*;\s*([^%]+)%%/) do type = Regexp.last_match[1] name = Regexp.last_match[2] link_text = Regexp.last_match[3] case type when "inst" inst_name, id = name.split(".") "<<idl:code:inst:#{inst_name}:#{id},#{link_text}>>" # TODO: Add csr and csr_field support else raise "Unhandled link type of '#{type}' for '#{name}' with link_text '#{link_text}'" end end end |