Module: Rote::Format::HTML

Includes:
ERB::Util
Defined in:
lib/rote/format/html.rb

Overview

HTML Formatting module for Rote. This module may be mixed in to any Page instance to provide various HTML helpers (including those from ERB::Util).

To use this module for a given page, simply place the following code somewhere applicable to that page:

extend Format::HTML

Note that include cannot be used since the page code is run via instance_eval.

Instance Method Summary collapse

Instance Method Details

#relative(href) ⇒ Object Also known as: link_rel

Make the given output-root-relative path relative to the current page’s path. This is handy when you do both local preview from some deep directory, and remote deployment to a root



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rote/format/html.rb', line 33

def relative(href)
  thr = href
  
  if thr.is_a?(String) && href[0,1] == '/'    # only interested in absolute        
    dtfn = File.dirname(template_name) + '/'
    
    count = dtfn == './' ? 0 : dtfn.split('/').length
    thr = ('../' * count) + href[1..href.length]
  end
  
  thr
end