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



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ttl2html/util.rb', line 18

def _uri_mapping_to_path(uri, param, suffix = ".html")
  local_path = uri.sub(param[:base_uri], "")
  if param[:uri_mappings]
    param[:uri_mappings].each do |mapping|
      if mapping["regexp"] =~ local_path
        #p [mapping["regexp"], local_path]
        local_path = local_path.sub(mapping["regexp"], mapping["path"])
        #p [mapping["regexp"], local_path]
      end
    end
  end
  local_path
end

#make_mapping_uris_cache(param) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/ttl2html/util.rb', line 3

def make_mapping_uris_cache(param)
  @path_cache = Set.new
  data = @data || @param[:data_global] || @param[:data] || {}
  data.keys.each do |uri|
    local_path = _uri_mapping_to_path(uri, param)
    # 親パスをすべて抽出してSetに追加
    idx = 0
    while (idx = local_path.index("/", idx))
      parent = local_path[0...idx]
      @path_cache << parent unless parent.empty?
      idx += 1
    end
  end
  @path_cache
end

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



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ttl2html/util.rb', line 31

def uri_mapping_to_path(uri, param, suffix = ".html")
  path = nil
  @path_cache ||= make_mapping_uris_cache(param)
  path = _uri_mapping_to_path(uri, param, suffix)
  if suffix == ".html"
    if @path_cache.include? path
      path += "/index"
    elsif path.end_with?("/")
      path += "index"
    end
  end
  path << suffix
  #p [uri, path]
  path
end