3 require 'yard/serializers/file_system_serializer'
8 # Subclass required to get correct filename for the top level namespace.
10 class WikiSerializer < FileSystemSerializer
11 # Post-process the data before serializing.
12 # Strip unnecessary whitespace.
13 # Convert stuff into more wiki-friendly stuff.
15 def serialize(object, data)
16 data = data.encode("UTF-8")
17 if object == "Sidebar.wiki"
18 data = data.gsub(/^#sidebar Sidebar\n/, "")
20 data = data.gsub(/\n\s*\n/, "\n")
21 # ASCII/UTF-8 erb error work-around.
22 data = data.gsub(/--/, "—")
23 data = data.gsub(/——/, "----")
24 data = data.gsub(/----\n----/, "----")
25 # HACK! Google Code Wiki treats <code> blocks like <pre> blocks.
26 data = data.gsub(/\<code\>(.+)\<\/code\>/, "`\\1`")
30 def serialized_path(object)
31 return object if object.is_a?(String)
33 if object.is_a?(CodeObjects::ExtraFileObject)
34 fspath = ['file.' + object.name + (extension.empty? ? '' : ".#{extension}")]
36 # This line is the only change of significance.
37 # Changed from 'top-level-namespace' to 'TopLevelNamespace' to
38 # conform to wiki word page naming convention.
39 objname = object != YARD::Registry.root ? object.name.to_s : "TopLevelNamespace"
40 objname += '_' + object.scope.to_s[0,1] if object.is_a?(CodeObjects::MethodObject)
41 fspath = [objname + (extension.empty? ? '' : ".#{extension}")]
42 if object.namespace && object.namespace.path != ""
43 fspath.unshift(*object.namespace.path.split(CodeObjects::NSEP))
47 # Don't change the filenames, it just makes it more complicated
48 # to figure out the original name.
50 # p.gsub(/([a-z])([A-Z])/, '\1_\2').downcase
53 # Remove special chars from filenames.
54 # Windows disallows \ / : * ? " < > | but we will just remove any
55 # non alphanumeric (plus period, underscore and dash).
57 p.gsub(/[^\w\.-]/) do |x|
60 x.each_byte { |b| encoded << ("%X" % b) }