Parent

Generators::HyperlinkHtml

Subclass of the SM::ToHtml class that supports looking up words in the AllReferences list. Those that are found (like AllReferences in this comment) will be hyperlinked


Subclass of the SM::ToHtml class that supports looking up words in the AllReferences list. Those that are found (like AllReferences in this comment) will be hyperlinked

Public Class Methods

new(from_path, context) click to toggle source

We need to record the html path of our caller so we can generate correct relative paths for any hyperlinks that we find

    # File lib/generators/templates/application/merb_stack/doc/rdoc/generators/merb_generator.rb, line 88
88:         def initialize(from_path, context)
89:             super()
90:             @from_path = from_path
91: 
92:             @parent_name = context.parent_name
93:             @parent_name += "::" if @parent_name
94:             @context = context
95:         end
new(from_path, context) click to toggle source

We need to record the html path of our caller so we can generate correct relative paths for any hyperlinks that we find

    # File lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb, line 88
88:         def initialize(from_path, context)
89:             super()
90:             @from_path = from_path
91: 
92:             @parent_name = context.parent_name
93:             @parent_name += "::" if @parent_name
94:             @context = context
95:         end

Public Instance Methods

gen_url(url, text) click to toggle source

Generate a hyperlink for url, labeled with text. Handle the special cases for img: and link: described under handle_special_HYPEDLINK

     # File lib/generators/templates/application/merb_stack/doc/rdoc/generators/merb_generator.rb, line 131
131:         def gen_url(url, text)
132:             if url =~ /([A-Za-z]+):(.*)/
133:                 type = $1
134:                 path = $2
135:             else
136:                 type = "http"
137:                 path = url
138:                 url  = "http://#{url}"
139:             end
140: 
141:             if type == "link"
142:                 url = path
143:             end
144: 
145:             if (type == "http" || type == "link") && url =~ /\.(gif|png|jpg|jpeg|bmp)$/
146:                 "<img src=\"#{url}\">"
147:             elsif (type == "http" || type == "link")
148:                 "<a href=\"#{url}\" target=\"_blank\">#{text}</a>"
149:             else
150:                 "<a href=\"#\" onclick=\"jsHref('#{url}');\">#{text.sub(%r{^#{type}:/*}, '')}</a>"
151: 
152:             end
153:         end
gen_url(url, text) click to toggle source

Generate a hyperlink for url, labeled with text. Handle the special cases for img: and link: described under handle_special_HYPEDLINK

     # File lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb, line 131
131:         def gen_url(url, text)
132:             if url =~ /([A-Za-z]+):(.*)/
133:                 type = $1
134:                 path = $2
135:             else
136:                 type = "http"
137:                 path = url
138:                 url  = "http://#{url}"
139:             end
140: 
141:             if type == "link"
142:                 url = path
143:             end
144: 
145:             if (type == "http" || type == "link") && url =~ /\.(gif|png|jpg|jpeg|bmp)$/
146:                 "<img src=\"#{url}\">"
147:             elsif (type == "http" || type == "link")
148:                 "<a href=\"#{url}\" target=\"_blank\">#{text}</a>"
149:             else
150:                 "<a href=\"#\" onclick=\"jsHref('#{url}');\">#{text.sub(%r{^#{type}:/*}, '')}</a>"
151: 
152:             end
153:         end
handle_special_CROSSREF(special) click to toggle source

We’re invoked when any text matches the CROSSREF pattern (defined in MarkUp). If we fine the corresponding reference, generate a hyperlink. If the name we’re looking for contains no punctuation, we look for it up the module/class chain. For

example, HyperlinkHtml is found, even without the Generators

prefix, because we look for it in module Generators first.

     # File lib/generators/templates/application/merb_stack/doc/rdoc/generators/merb_generator.rb, line 104
104:         def handle_special_CROSSREF(special)
105:             name = special.text
106:             if name[0,1] == '#'
107:                 lookup = name[1..1]
108:                 name = lookup unless Options.instance.show_hash
109:             else
110:                 lookup = name
111:             end
112: 
113:             if /([A-Z].*)[.\#](.*)/ =~ lookup
114:                 container = $1
115:                 method = $2
116:                 ref = @context.find_symbol(container, method)
117:             else
118:                 ref = @context.find_symbol(lookup)
119:             end
120: 
121:             if ref and ref.document_self
122:                 "<a href=\"index.html?a=#{ref.aref}&name=#{name}\">#{name}</a>"
123:             else
124:                 name #it does not need to be a link
125:             end
126:         end
handle_special_CROSSREF(special) click to toggle source

We’re invoked when any text matches the CROSSREF pattern (defined in MarkUp). If we fine the corresponding reference, generate a hyperlink. If the name we’re looking for contains no punctuation, we look for it up the module/class chain. For

example, HyperlinkHtml is found, even without the Generators

prefix, because we look for it in module Generators first.

     # File lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb, line 104
104:         def handle_special_CROSSREF(special)
105:             name = special.text
106:             if name[0,1] == '#'
107:                 lookup = name[1..1]
108:                 name = lookup unless Options.instance.show_hash
109:             else
110:                 lookup = name
111:             end
112: 
113:             if /([A-Z].*)[.\#](.*)/ =~ lookup
114:                 container = $1
115:                 method = $2
116:                 ref = @context.find_symbol(container, method)
117:             else
118:                 ref = @context.find_symbol(lookup)
119:             end
120: 
121:             if ref and ref.document_self
122:                 "<a href=\"index.html?a=#{ref.aref}&name=#{name}\">#{name}</a>"
123:             else
124:                 name #it does not need to be a link
125:             end
126:         end
handle_special_HYPERLINK(special) click to toggle source
handle_special_HYPERLINK(special) click to toggle source
handle_special_TIDYLINK(special) click to toggle source

HEre’s a hypedlink where the label is different to the URL

 <label>[url]
     # File lib/generators/templates/application/merb_stack/doc/rdoc/generators/merb_generator.rb, line 171
171:         def handle_special_TIDYLINK(special)
172:             text = special.text
173:             #      unless text =~ /(\S+)\[(.*?)\]/
174:             unless text =~ /\{(.*?)\}\[(.*?)\]/ or text =~ /(\S+)\[(.*?)\]/ 
175:                 return text
176:             end
177:             label = $1
178:             url   = $2
179:             gen_url(url, label)
180:         end
handle_special_TIDYLINK(special) click to toggle source

HEre’s a hypedlink where the label is different to the URL

 <label>[url]
     # File lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb, line 171
171:         def handle_special_TIDYLINK(special)
172:             text = special.text
173:             #      unless text =~ /(\S+)\[(.*?)\]/
174:             unless text =~ /\{(.*?)\}\[(.*?)\]/ or text =~ /(\S+)\[(.*?)\]/ 
175:                 return text
176:             end
177:             label = $1
178:             url   = $2
179:             gen_url(url, label)
180:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.