Module: TTL2HTML::Util
Instance Method Summary collapse
- #_uri_mapping_to_path(uri, param, suffix = ".html") ⇒ Object
- #make_mapping_uris_cache(param) ⇒ Object
- #safe_output_path(file) ⇒ Object
- #uri_mapping_to_path(uri, param, suffix = ".html") ⇒ Object
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 |
#safe_output_path(file) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ttl2html/util.rb', line 46 def safe_output_path(file) base = if @config[:output_dir] File.(@config[:output_dir]) else File.(".") end target = File.(file) unless target == base || target.start_with?(base + File::SEPARATOR) if @config[:output_dir] warn "Attempting to write outside of output_dir: #{file}" else warn "Attempting to write outside of current directory: #{file}" end return nil end target 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 |