Module: TTL2HTML::Util

Included in:
App, Template
Defined in:
lib/ttl2html/util.rb

Instance Method Summary collapse

Instance Method Details

#uri_mapping_to_path(uri, param, suffix = ".html") ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ttl2html/util.rb', line 3

def uri_mapping_to_path(uri, param, suffix = ".html")
  path = nil
  if param[:uri_mappings]
    param[:uri_mappings].each do |mapping|
      local_file = uri.sub(param[:base_uri], "")
      if mapping["regexp"] =~ local_file
        path = local_file.sub(mapping["regexp"], mapping["path"])
      end
    end
  end
  if path.nil?
    if suffix == ".html"
      if @data.keys.find{|e| e.start_with?(uri + "/") }
        path = uri + "/index"
      elsif uri.end_with?("/")
        path = uri + "index"
      else
        path = uri
      end
    else
      path = uri
    end
  end
  path = path.sub(param[:base_uri], "")
  path << suffix
  #p [uri, path]
  path
end