kiss_shot 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 44b2489d4d45dea07eaffeb16de0fb17a91c100d
4
+ data.tar.gz: 0ec65bc9504fba2f7c16848b717099804cf406fe
5
+ SHA512:
6
+ metadata.gz: e7a6c8790d8ffb2020789749f9394ade219d32c02dead271b1dbb5eac9d6371dffb1e3c8ffa7a703d6d791115d132eef3d6c46b7ae16a352700342c7c9b66b75
7
+ data.tar.gz: 0fe7e2c0d91053ed855850419300a9d952c2f3e30494a01398fa9c0381180548ba35991ad4bd78110a8e46d830c21b731989d4229acd4e92db5fc4747f77d752
@@ -0,0 +1,7 @@
1
+ #encoding: utf-8
2
+
3
+ module KissShot::ObjC::All
4
+ include KissShot::ObjC::Macro
5
+ include KissShot::ObjC::Protocol
6
+ include KissShot::ObjC::Klass
7
+ end
@@ -0,0 +1,27 @@
1
+ #encoding: utf-8
2
+
3
+ module KissShot::ObjC::Base
4
+
5
+ # Create common <?,?,?> from array, nothing if array is empty
6
+ # @param array [Array] things to create
7
+ # @return [String] `<?,?,?>` if array not empty
8
+ def _objc_diamond_array(array)
9
+ unless array.empty?
10
+ "<#{array.join(', ')}>"
11
+ else
12
+ ""
13
+ end
14
+ end
15
+
16
+ # Create common (?,?,?) from array, nothing if array is empty
17
+ # @param array [Array] things to create
18
+ # @return [String] `(?,?,?)` if array not empty
19
+ def _objc_bracket_array(array)
20
+ unless array.empty?
21
+ "(#{array.join(', ')})"
22
+ else
23
+ ""
24
+ end
25
+ end
26
+
27
+ end
@@ -0,0 +1,100 @@
1
+ #encoding: utf-8
2
+
3
+ module KissShot::ObjC::Klass
4
+ include KissShot::ObjC::Base
5
+
6
+ # Append @class forward declaration
7
+ # @param name [String] class name
8
+ # @return self
9
+ def objc_class(name)
10
+ line "@class #{name};"
11
+ self
12
+ end
13
+
14
+ # Append @interface
15
+ #
16
+ # @param name [String] interface name
17
+ # @param superklass [String, Symbol] superclass
18
+ # @param protocols [String, Symbol, Array] protocols this interface implemented
19
+ # @return self
20
+ def objc_interface(name, superklass = "NSObject", protocols = nil)
21
+ line "@interface #{name} : #{superklass}#{_objc_diamond_array(Array.wrap(protocols))}"
22
+ yield if block_given?
23
+ line "@end"
24
+ self
25
+ end
26
+
27
+ # Append @implementation
28
+ #
29
+ # @param name [String] class name
30
+ # @return self
31
+ def objc_implementation(name)
32
+ line "@implementation #{name}"
33
+ yield if block_given?
34
+ line "@end"
35
+ end
36
+
37
+ # interface raw bracket for instance variable
38
+ # @return self
39
+ def objc_interface_bracket
40
+ line "{"
41
+ indent_up
42
+ yield if block_given?
43
+ indent_down
44
+ line "}"
45
+ self
46
+ end
47
+
48
+ # Interface instance variable
49
+ # @param name [String] name of instance variable
50
+ # @param type [String, Symbol, Array] type of instance variable
51
+ # @return self
52
+ def objc_interface_variable(name, type = 'NSInteger')
53
+ line "#{Array.wrap(type).join(" ")} #{name};"
54
+ end
55
+
56
+ # Append @property
57
+ #
58
+ # @param name [String] property name
59
+ # @param type [String, Array] property type, joined with ` `
60
+ # @param options [String, Array] array of options, such as `nonatomic`, joined with ','
61
+ # @return self
62
+ def objc_property(name, type, options = ['nonatomic', 'strong'])
63
+ line "@property #{_objc_bracket_array(Array.wrap(options))} #{Array.wrap(type).join(" ")} #{name};"
64
+ self
65
+ end
66
+
67
+ # Append method
68
+ #
69
+ # @param static [true, false] if is a static(class) method
70
+ # @param return_type [String, Symbol, Array] return type
71
+ # @param components remaining components
72
+ def objc_method(*args)
73
+ sign = args.shift ? "+" : "-"
74
+ type = args.shift
75
+ raw "#{sign} (#{Array.wrap(type).join(" ")})", true
76
+ if args.count == 1
77
+ raw " "
78
+ raw "#{args.shift}"
79
+ else
80
+ raise "Bad args for #objc_method" unless args.count % 3 == 0
81
+ args.each_slice(3) do |slice|
82
+ raw " "
83
+ raw slice[0]
84
+ raw ":"
85
+ raw "(#{Array.wrap(slice[1]).join(" ")})"
86
+ raw slice[2]
87
+ end
88
+ end
89
+ if block_given?
90
+ raw " {\n"
91
+ indent_up
92
+ yield
93
+ indent_down
94
+ line "}"
95
+ else
96
+ raw ";\n"
97
+ end
98
+ self
99
+ end
100
+ end
@@ -0,0 +1,43 @@
1
+ #encoding: utf-8
2
+
3
+ module KissShot::ObjC::Macro
4
+ include KissShot::ObjC::Base
5
+
6
+ # Add // comment
7
+ # @param input [String] comment
8
+ # @return self
9
+ def objc_comment(input)
10
+ line "// #{input}"
11
+ end
12
+
13
+ # Add /**/ comment
14
+ # @return self
15
+ def objc_block_comment
16
+ line "/*"
17
+ push_line_prefix " * "
18
+ yield if block_given?
19
+ pop_line_prefix " * "
20
+ line " */"
21
+ end
22
+
23
+ # For `#import <???>`, d is for diamond
24
+ # @param input [String] things in `#import <???>`
25
+ # @return self
26
+ def objc_import_d(input)
27
+ objc_import "<#{input}>"
28
+ end
29
+
30
+ # For `#import "???"`, q is for quotes
31
+ # @param input [String] header to import
32
+ # @return self
33
+ def objc_import_q(input)
34
+ objc_import "\"#{input}\""
35
+ end
36
+
37
+ # For `#import ???`
38
+ # @param input [String] header to import
39
+ # @return self
40
+ def objc_import(input)
41
+ line "#import #{input}"
42
+ end
43
+ end
@@ -0,0 +1,48 @@
1
+ #encoding: utf-8
2
+
3
+ module KissShot::ObjC::Protocol
4
+ include KissShot::ObjC::Base
5
+
6
+ # Add line for @required
7
+ # @return self
8
+ def objc_protocol_required
9
+ line
10
+ line "@required"
11
+ self
12
+ end
13
+
14
+ # Add line for @optional
15
+ # @return self
16
+ def objc_protocol_optional
17
+ line
18
+ line "@optional"
19
+ self
20
+ end
21
+
22
+ # For @protocol
23
+ # @param name [String] protocol name
24
+ # @param supers [Array, String] super protocols, default to ['NSObject']
25
+ # @return self
26
+ def objc_protocol(name, supers = ["NSObject"])
27
+ # Add new line
28
+ line
29
+ # Declare
30
+ raw "@protocol #{name}"
31
+ if block_given?
32
+ # If block given, add supers, and yield
33
+ if supers.count
34
+ raw " #{_objc_diamond_array(Array.wrap(supers))}"
35
+ end
36
+ # new line, no indent
37
+ raw "\n"
38
+ # yield
39
+ yield
40
+ # add @end
41
+ line "@end"
42
+ else
43
+ # if no block given, just close line with ;
44
+ raw ";\n"
45
+ end
46
+ self
47
+ end
48
+ end
@@ -0,0 +1,9 @@
1
+ #encoding: utf-8
2
+
3
+ module KissShot::ObjC
4
+ autoload :Base, 'kiss_shot/objc/base'
5
+ autoload :All, 'kiss_shot/objc/all'
6
+ autoload :Macro, 'kiss_shot/objc/macro'
7
+ autoload :Protocol, 'kiss_shot/objc/protocol'
8
+ autoload :Klass, 'kiss_shot/objc/klass'
9
+ end
@@ -0,0 +1,98 @@
1
+ #encoding: utf-8
2
+
3
+ # This is the main class for code generation
4
+ #
5
+ class KissShot::Spec
6
+
7
+ # @return [Hash] metadata
8
+ attr_accessor :metadata
9
+ # @return [String] content
10
+ attr_accessor :content
11
+ # @return [String] line prefix, such as indent, comment etc.
12
+ attr_accessor :line_prefix
13
+
14
+ # Create a instance of anonymous subclass, and eval instance
15
+ # @param metadata [Hash] metadata
16
+ # @param script [String] script to run
17
+ # @param block [Block] block to invoke
18
+ def self.run(metadata = {}, script = nil, &block)
19
+ spec = Class.new(self).new(metadata)
20
+ spec.instance_eval(script) unless script.nil?
21
+ spec.instance_eval(&block) unless block.nil?
22
+ spec.content
23
+ end
24
+
25
+ # Create a new Spec
26
+ #
27
+ # @param metadata [Hash] metadata
28
+ # @return [KissShot::Spec] instance
29
+ def initialize(metadata = {})
30
+ self.metadata = metadata
31
+ self.content = ""
32
+ self.line_prefix = ""
33
+ end
34
+
35
+ # Use a module, alias for `Class#extend`
36
+ #
37
+ # @param mod [Module] module to extend
38
+ # @return [KissShot::Spec] self
39
+ def use(mod)
40
+ self.extend mod
41
+ self
42
+ end
43
+
44
+ # Push line prefix
45
+ #
46
+ # @param prefix [String] line prefix to push
47
+ # @return self
48
+ def push_line_prefix(prefix)
49
+ self.line_prefix += prefix
50
+ self
51
+ end
52
+
53
+ # Pop line prefix
54
+ #
55
+ # @param prefix [String] line prefix to pop
56
+ # @return self
57
+ def pop_line_prefix(prefix)
58
+ if self.line_prefix.end_with? prefix
59
+ self.line_prefix = self.line_prefix[0, self.line_prefix.length - prefix.length]
60
+ end
61
+ self
62
+ end
63
+
64
+ # Indent right 2 whitespaces
65
+ #
66
+ # @return [KissShot::Spec] self
67
+ def indent_up
68
+ push_line_prefix " "
69
+ end
70
+
71
+ # Indent left 2 whitespaces
72
+ #
73
+ # @return [KissShot::Spec] self
74
+ def indent_down
75
+ pop_line_prefix " "
76
+ end
77
+
78
+ # Append raw string to content
79
+ #
80
+ # @param input [String] content to append
81
+ # @param use_line_prefix [true, false] whether prepend indent
82
+ # @return [KissShot::Spec] self
83
+ def raw(input = "", use_line_prefix = false)
84
+ return unless input.length > 0
85
+ self.content += self.line_prefix if use_line_prefix
86
+ self.content += input.to_s
87
+ self
88
+ end
89
+
90
+ # Apend line to content, indent prepended
91
+ #
92
+ # @param input [String] content to append
93
+ # @return [KissShot::Spec] self
94
+ def line(input = "")
95
+ raw input, true
96
+ raw "\n"
97
+ end
98
+ end
@@ -0,0 +1,5 @@
1
+ #encoding: utf-8
2
+
3
+ module KissShot
4
+ VERSION= "0.1.0"
5
+ end
data/lib/kiss_shot.rb ADDED
@@ -0,0 +1,10 @@
1
+ #encoding: utf-8
2
+
3
+ require 'active_support/core_ext/array'
4
+
5
+ class KissShot
6
+ autoload :VERSION, 'kiss_shot/version'
7
+
8
+ autoload :Spec, 'kiss_shot/spec'
9
+ autoload :ObjC, 'kiss_shot/objc'
10
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kiss_shot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yanke Guo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ description: KissShot is a simple Objective-C code generator
28
+ email: guoyk@1mxian.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/kiss_shot/objc/all.rb
34
+ - lib/kiss_shot/objc/base.rb
35
+ - lib/kiss_shot/objc/klass.rb
36
+ - lib/kiss_shot/objc/macro.rb
37
+ - lib/kiss_shot/objc/protocol.rb
38
+ - lib/kiss_shot/objc.rb
39
+ - lib/kiss_shot/spec.rb
40
+ - lib/kiss_shot/version.rb
41
+ - lib/kiss_shot.rb
42
+ homepage: http://rubygems.org/gems/kiss_shot
43
+ licenses:
44
+ - MIT
45
+ metadata: {}
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 2.0.14
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: KissShot is a simple Objective-C code generator
66
+ test_files: []
67
+ has_rdoc: