Module: MarkupExtensionMethods
- Included in:
- MarkupExtensions::MString
- Defined in:
- lib/markup_methods/logo.rb,
lib/markup_methods/ahttp.rb,
lib/markup_methods/checklist.rb
Instance Method Summary collapse
-
#ahttp ⇒ Object
This sample extension replaces URL strings in the form: “http://…” with links: “<a href=”http://…“.
-
#checklist ⇒ Object
This sample extension allows list elements to act as a checklist.
-
#logo ⇒ Object
This sample extension inserts a company logo.
Instance Method Details
#ahttp ⇒ Object
This sample extension replaces URL strings in the form:
"http://..."
with links:
"<a href="http://..."
Strings that are already part of
<a href= ...> or <img src= ...>
or inside
<code> or <pre>
tags will remain unchanged
(This extension can be used for any markup language.)
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/markup_methods/ahttp.rb', line 16 def ahttp gsub( /http:\/\/[^\s><"']+/ ) { match = $&; before = $`; after = $' before !~ /\s+(href|src|)\s*=\s*['"]*$/ && after !~ /^[^<]*<\/a>/ && before !~ /(<code>|<pre>).*$/ ? %Q~<a href="#{match}">#{match}</a>~ : match } end |
#checklist ⇒ Object
This sample extension allows list elements to act as a checklist. If the markup list indicator is followed by a disposition character and a space, this method will make checklist substitutions.
For example, when this method sees this in a Markdown list:
'- x item one'
or this in a Textile list:
'* x item one"
it will substitute:
'<li <strong>(x)</strong> item one'.
This method recognizes these disposition characters.
x - item completed
0 - item dropped
d - item deferred
@ - item in progress
(this extension can be used for any markup language.)
22 23 24 25 26 27 28 |
# File 'lib/markup_methods/checklist.rb', line 22 def checklist gsub(/<li>([x0d@]) (\S)/) { m1 = $1;m2 = $2 m1 = ">" if m1 == "d" "<li><strong>(#{m1.upcase}) </strong>#{m2}" } end |
#logo ⇒ Object
This sample extension inserts a company logo. If Markdown contains:
"[logo](home)"
or Textile contains:
"logo":home
The generated HTML contains the company logo and links to the home page.
(This extension can be used for any markup language)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/markup_methods/logo.rb', line 12 def logo gsub( /<a href="home">logo<\/a>/ ) { match = $&; before = $` if before !~ /(<code>|<pre>).*$/ %Q~<a href="http://www.google.com">\n~ + %Q~<img id="logo" alt="Google"~ + %Q~ src="http://www.google.com/images/logos/google_logo.gif"~ + %Q~ style="border: 0 none;">\n~ + %Q~</a>\n~ else match end } end |