Module: Docter::Template::ContextMethods
- Includes:
- HTML
- Defined in:
- lib/docter/template.rb
Instance Method Summary
collapse
Methods included from HTML
inner_text_from, regexp_attribute, regexp_element
Instance Method Details
#collect_links(content, mark = false) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/docter/template.rb', line 16
def collect_links(content, mark = false)
@links ||= []
content.gsub(regexp_element('a')) do |link|
url = $3 if link =~ regexp_attribute('href')
if url =~ /^\w+:/
unless index = @links.index(url)
index = @links.size
@links << [url, inner_text_from(link)]
end
mark ? "#{link}<sup>[#{index + 1}]</sup>" : link
else
link
end
end
end
|
#list_links(cls = nil) ⇒ Object
32
33
34
35
36
37
38
|
# File 'lib/docter/template.rb', line 32
def list_links(cls = nil)
links = @links.inject({}) { |hash, link| hash[link.first] ||= link.last ; hash }.
sort { |a,b| a.last <=> b.last }.
map { |url, text| %{<dt>#{text.capitalize}</dt><dd><a href='#{url}'>#{url}</a></dd>} }
%{<dl class='#{cls}'>#{links.join}</dl>}
end
|
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/docter/template.rb', line 40
def (html)
@footnote ||= 0
html.gsub(/<a href=['"]#fn(\d+)['"]>\1<\/a>/) {
fn = $1.to_i + @footnote
%{<a href='#fn#{fn}'>#{fn}</a>}
}.gsub(/<p id=['"]fn(\d+)['"](.*?)><sup>\1<\/sup>(.*?)<\/p>/m) {
@footnote += 1
%{<p id='fn#{@footnote}'#{$2}><sup>#{@footnote}</sup>#{$3}</p>}
}
end
|