29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/udb/yaml/preserving_emitter.rb', line 29
def emit(data, io = nil)
output = StringIO.new
@comment_map..each do ||
content = .content.strip
output.puts "# #{content}" unless content.empty?
end
output.puts if @comment_map..any?
emit_value(data, output, [], 0)
@comment_map..each do ||
output.puts "#{" " * .indent}# #{.content}"
end
source_locations = @comment_map.all_source_locations
if source_locations.any?
output.puts
output.puts "# ===== SOURCE MAP BEGIN ====="
output.puts "# This map tracks the original source file and line:column for each key"
output.puts "# Format: key_path -> file:line:column"
source_locations.keys.sort.each do |path_key|
location = source_locations.fetch(path_key)
output.puts "# #{path_key} -> #{location[:file]}:#{location[:line]}:#{location[:column]}"
end
output.puts "# ===== SOURCE MAP END ====="
end
result = output.string
if io
if io.is_a?(String)
File.write(io, result)
else
io.write(result)
end
end
result
end
|