swift-source-kit 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/bin/swift-make-all-public.rb +108 -0
  3. metadata +44 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0a25a3185559c6dde9d643d407885eaf72135f01
4
+ data.tar.gz: 3834a8aba30389c1a8c26e32c925326586ddbf37
5
+ SHA512:
6
+ metadata.gz: 6f90b04c5adaeaeb61c738ba84fdab3b9016f674347420b74c2b532a3418bedbe9cf1f03cbe73f44426a1cf53fba53b1f22284fc634b6cd36f031231df9bb381
7
+ data.tar.gz: 2e31a44508fdeb232f4b98ec0a12f54a797267534e56ce59b83347f1a8597138f30643ace582d4e6edfd0682e45b75165cf3816ae0e9d5e50a7c28679deb17d6
@@ -0,0 +1,108 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'optparse'
4
+
5
+ filename = ''
6
+ replace = true
7
+ options = OptionParser.new do |opts|
8
+ opts.banner = "Usage: swift-make-all-public.rb [options]"
9
+
10
+ opts.on("-i", "--input-filename=NAME", "Input filename") do |name|
11
+ filename = name
12
+ end
13
+ opts.on("-n", "--not-replace", "Input filename") do |name|
14
+ replace = false
15
+ end
16
+ opts.on("-h", "--help", "Prints this help") do
17
+ puts opts
18
+ exit
19
+ end
20
+ end
21
+
22
+ options.parse!
23
+ if filename == ''
24
+ puts "Missing filename.\n---\n"
25
+ puts options
26
+ exit
27
+ end
28
+
29
+ # filename = "/Users/leo/prj/ios/LFramework2/Pod/Classes/LFoundation/LFoundation.swift"
30
+ # s = IO.read("/Users/leo/prj/ios/LFramework2/Pod/Classes/LFoundation/LFoundation.swift")
31
+ # puts s
32
+
33
+ def swift_make_all_public(filename, replace)
34
+ File.open('temp.swift', 'w') do |file|
35
+ scope = ''
36
+ is_commented = false
37
+ bracket = 0
38
+ File.open(filename, 'rb').each do |line|
39
+ # puts scope
40
+ # struct, class, static, protocol, or extension starts with whitespaces, without // or /* in front
41
+ # struct/class/extension definition
42
+ # static/class var/func
43
+
44
+ is_commented = (line.include? '/*') if !is_commented
45
+ is_commented = !(line.include? '*/') if is_commented
46
+ line_without_comment = line
47
+ line_without_comment = line.slice(0..line.index('//')) if line.include? '//'
48
+ if (line.include? '/*') && (line.include? '*/')
49
+ line_without_comment = line.slice(line.index('/*')..line.index('*/'))
50
+ elsif line.include? '/*'
51
+ line_without_comment = line.slice(0..line.index('/*'))
52
+ elsif line.include? '*/'
53
+ line_without_comment = line.slice(line.index('*/')..-1)
54
+ end
55
+
56
+ if is_commented
57
+ file.puts line
58
+ next
59
+ end
60
+
61
+ # detect scope
62
+ if line =~ /^((\s)*public(\s)+)?class/
63
+ scope = 'class'
64
+ elsif line =~ /^((\s)*public(\s)+)?protocol/
65
+ scope = 'protocol'
66
+ end
67
+ if line =~ /^(?!\/(\/|\*))(\s)*/
68
+ bracket += line.scan('{').length
69
+ bracket -= line.scan('}').length
70
+ end
71
+ scope = '' if bracket == 0
72
+ # puts scope
73
+ # puts bracket
74
+
75
+ regex = '^(?!\/(\/|\*))(\s)*((struct|class|static|protocol|extension|func|mutating|subscript|@IBOutlet|@IBAction|override|enum|required)(\s)+(?!public)|(var)(\s)+(?!public).*{'
76
+ # regex = '^(?!\/(\/|\*))(\s)*((struct|class|static|protocol|extension|func|mutating|subscript|@IBOutlet|@IBAction|override|enum|required)(\s)+(?!public)'
77
+ if scope == 'protocol'
78
+ regex = '^(\s)*protocol(\s)+(?!public)'
79
+ elsif scope == 'class' && bracket == 1
80
+ regex += '|(var|let)(\s)+(?!public))'
81
+ else
82
+ regex += ')'
83
+ end
84
+ regex = /#{regex}/
85
+ # puts regex
86
+
87
+ if line_without_comment =~ regex
88
+ s = line.strip.sub('@IBAction', '').sub('@IBOutlet', '').strip
89
+ s = line.sub(s, 'public ' + s)
90
+ file.puts s
91
+ else
92
+ file.puts line
93
+ end
94
+ end
95
+ end
96
+ `mv temp.swift #{filename}` if replace
97
+ end
98
+
99
+ if filename[-1] == ?/
100
+ filenames = Dir["#{filename}/**/*.swift"]
101
+ puts "Processing '#{filenames}'..."
102
+ filenames.each do |name|
103
+ swift_make_all_public(name, replace)
104
+ end
105
+ else
106
+ puts "Processing '#{filename}'..."
107
+ swift_make_all_public(filename, replace)
108
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: swift-source-kit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Leo L
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-08-12 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Source code helpers for Apple's Swift language.
14
+ email: leo@superarts.org
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - bin/swift-make-all-public.rb
20
+ homepage: https://github.com/superarts/swift-source-kit
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.0.14
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Swift source code helpers
44
+ test_files: []