]> granicus.if.org Git - multimarkdown/commitdiff
expose singular-S type to Swift code generator
authorChristian Tietze <christian.tietze@gmail.com>
Wed, 27 Dec 2017 10:10:41 +0000 (11:10 +0100)
committerChristian Tietze <christian.tietze@gmail.com>
Wed, 27 Dec 2017 10:10:41 +0000 (11:10 +0100)
swift/cocoaconv.rb

index 064c4c3ea2e439e6f37c7446acd59b8cc5065046..e47b679139f79261026cbb8f503987d8ca38c065 100755 (executable)
@@ -93,27 +93,33 @@ class String
 end
 
 module NSEnum
-  def self.type_names(type)
+  def self.type_name(type)
     type_name = type.camelize
     # Remove plural "S"
-    type_name = if type_name == "TokenTypes"
-                  "TokenType"
-                elsif type_name == "ParserExtensions"
-                  "ParserExtension"
-                else
-                  type_name
-                end
-    return "MMD6#{type_name}", type_name
+    if type_name == "TokenTypes"
+      "TokenType"
+    elsif type_name == "ParserExtensions"
+      "ParserExtension"
+    else
+      type_name
+    end
+  end
+  
+  def type_name
+    NSEnum.type_name(type)
   end
 
   def ns_enum
-    type_name, swift_type_name = NSEnum.type_names(type)
+    base_type_name = NSEnum.type_name(type)
+    swift_type_name = base_type_name
+    objc_type_name = "MMD6#{base_type_name}"
+    
     ns_enum_cases = cases
-      .map { |line| NSEnum.case(type_name, line) }
+      .map { |line| NSEnum.case(objc_type_name, line) }
       .join("\n")
       
     return %Q{
-typedef NS_ENUM(NSUInteger, #{type_name}) {
+typedef NS_ENUM(NSUInteger, #{objc_type_name}) {
 #{ns_enum_cases}
 } NS_SWIFT_NAME(#{swift_type_name});}
   end