Sha256: 928658f1433f20ab06e22779733f1a3efc17cf56178d4c2817fb41e70ff7cb79
Contents?: true
Size: 1.65 KB
Versions: 4
Compression:
Stored size: 1.65 KB
Contents
txt[ Sometimes you may need to access some data that will not be available until the entire document has been fully parsed and analyzed. For example, in order to be able to validate internal links, it is necessary to know in advance if the bookmark ID referenced in the link exists or not, either before (that's easy) or even _after_ the link. Here's the source code of the %>[link]: ] highlight[=ruby| macro :link do min_parameters 1 max_parameters 2 target = param 0 title = param 1 if target.match /^#/ then @node[:document].links << target anchor = target.gsub /^#/, '' bmk = bookmark? anchor if !bmk then placeholder do \|document\| bmk = document.bookmark?(anchor) macro_error "Bookmark '#{anchor}' does not exist" unless bmk bmk_title = title bmk_title = bmk.title if bmk_title.blank? @data[:target] = bmk.link(@source_file) @data[:title] = bmk_title render end else bmk_title = title bmk_title = bmk.title if bmk_title.blank? @data[:target] = bmk.link(@source_file) @data[:title] = bmk_title render end else # Code omitted... end end =] txt[ If there's already a bookmark stored in the current document, then it is possible to retrieve its title and use it as link text. Otherwise, it is necessary to wait until the entire document has been fully processed and then check if the bookmark exists. To do so, use the @placeholder@ method. When called, this method returns an unique placeholder, which is then substituted with the value of the block, right before the document is finalized. Within the @placeholder@ block, the @document@ parameter is, by all means, the fully analyzed document. ]
Version data entries
4 entries across 4 versions & 1 rubygems