lib/yard-api/serializer.rb in yard-api-0.3.4 vs lib/yard-api/serializer.rb in yard-api-0.3.5
- old
+ new
@@ -2,10 +2,23 @@
class Serializer < ::YARD::Serializers::FileSystemSerializer
USNSEP = '__' # url-safe namespace separator
FSSEP = '/'
def self.topicize(str)
- str.lines.first.gsub(/\W+/, '_').downcase
+ self.str_underscore(str.lines.first.gsub(/\W+/, '_'))
+ end
+
+ # Stolen from rails 4.2, see:
+ #
+ # http://apidock.com/rails/v4.2.1/ActiveSupport/Inflector/underscore
+ def self.str_underscore(camel_cased_word)
+ return camel_cased_word unless camel_cased_word =~ /[A-Z-]|::/
+ word = camel_cased_word.to_s.gsub(/::/, '/')
+ word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
+ word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
+ word.tr!("-", "_")
+ word.downcase!
+ word
end
def serialize(object, data)
path = File.join(basepath, serialized_path(object))
File.open!(path, "wb") {|f| f.write data }
\ No newline at end of file