property_synthesize_dealloc 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +9 -2
- data/VERSION +1 -1
- data/lib/property_synthesize_dealloc.rb +36 -33
- data/pkg/property_synthesize_dealloc-0.1.2.gem +0 -0
- data/pkg/property_synthesize_dealloc-0.2.0.gem +0 -0
- data/property_synthesize_dealloc.gemspec +82 -0
- data/spec/property_synthesize_dealloc_spec.rb +0 -10
- metadata +39 -36
data/README.markdown
CHANGED
@@ -2,6 +2,13 @@
|
|
2
2
|
|
3
3
|
One of the things we do a lot of in Objective-C is outlet and variable declaration, synthesize and dealloc. Since this is a repeatable recurring event I thought I would add a little automation to the process.
|
4
4
|
|
5
|
+
# Update March 19, 2011 #
|
6
|
+
|
7
|
+
Xcode 4 no longer supports user scripts but instead uses Services.
|
8
|
+
You can create a Service with Automator.
|
9
|
+
Do the same as below except put the code in a Run Shell Script.
|
10
|
+
Set the Application to Xcode and the input as Text.
|
11
|
+
|
5
12
|
# Instructions #
|
6
13
|
|
7
14
|
Install the gem.
|
@@ -18,11 +25,11 @@ Make a user script in Xcode with the following:
|
|
18
25
|
require "property_synthesize_dealloc"
|
19
26
|
|
20
27
|
property = PropertySynthesizeDealloc.new
|
21
|
-
property.file_path = '%%%{PBXFilePath}%%%'
|
22
28
|
property.selection = STDIN.read
|
23
29
|
property.psd!
|
24
30
|
|
25
|
-
Then select the ivars you wish to make property, synthesize and dealloc declarations and execute
|
31
|
+
Then select the ivars you wish to make property, synthesize and dealloc declarations and execute using either a user script or
|
32
|
+
if using Xcode 4, a Service (as described in the Update above).
|
26
33
|
|
27
34
|
|
28
35
|
# Overriding defaults #
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -2,24 +2,26 @@ $:.unshift File.dirname(__FILE__)
|
|
2
2
|
|
3
3
|
require "rubygems"
|
4
4
|
require "appscript"; include Appscript
|
5
|
-
require 'osax'; include OSAX
|
6
5
|
require "file_checker"
|
7
6
|
require 'configuration'
|
8
7
|
require "converter"
|
9
8
|
require "content_replacer"
|
10
9
|
|
11
10
|
class PropertySynthesizeDealloc
|
12
|
-
attr_accessor :xcode, :file_path, :selection, :header_file_path, :m_file_path, :config_path
|
11
|
+
attr_accessor :xcode, :file_path, :selection, :header_file_path, :m_file_path, :config_path, :logging
|
13
12
|
|
14
13
|
def initialize(config_file_path='')
|
15
14
|
Configuration.new(config_file_path)
|
16
15
|
|
17
16
|
@sleep_time = Configuration.settings['sleep_time']
|
18
17
|
@xcode = app(Configuration.settings['xcode_app_path'])
|
19
|
-
@
|
18
|
+
@logging = false
|
19
|
+
|
20
|
+
set_file_path
|
20
21
|
end
|
21
22
|
|
22
23
|
def psd!
|
24
|
+
log "Selection:\n#{@selection}"
|
23
25
|
selection_check
|
24
26
|
file_check
|
25
27
|
|
@@ -31,6 +33,8 @@ class PropertySynthesizeDealloc
|
|
31
33
|
# Update the files!
|
32
34
|
replace_file_content(@header_file_path, header_content)
|
33
35
|
replace_file_content(@m_file_path, m_content)
|
36
|
+
save_file(@header_content)
|
37
|
+
save_file(@m_file_path)
|
34
38
|
end
|
35
39
|
|
36
40
|
def convert_selection
|
@@ -43,28 +47,31 @@ class PropertySynthesizeDealloc
|
|
43
47
|
protected
|
44
48
|
|
45
49
|
def log(msg)
|
46
|
-
File.open(File.expand_path("~/desktop/errors.txt"), 'a+') { |f| f.puts msg + "\n" }
|
50
|
+
File.open(File.expand_path("~/desktop/errors.txt"), 'a+') { |f| f.puts msg + "\n" } if @logging
|
47
51
|
end
|
48
52
|
|
49
53
|
def dialog(msg)
|
54
|
+
require 'osax'; include OSAX
|
50
55
|
osax.display_dialog(msg,
|
51
56
|
:buttons => ["Ok"],
|
52
57
|
:default_button => 1)
|
53
58
|
end
|
54
59
|
|
55
60
|
def replace_file_content(path, content)
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
61
|
+
log "Replacing: #{path}\nWith content: #{content}"
|
62
|
+
begin
|
63
|
+
if doc = @xcode.open(path)
|
64
|
+
sleep @sleep_time
|
65
|
+
save_file(path)
|
66
|
+
doc.contents.set(content)
|
67
|
+
doc.save
|
68
|
+
end
|
69
|
+
rescue => e
|
70
|
+
log "********************\nError Replacing File Content\n**********************\n#{e}"
|
62
71
|
end
|
63
|
-
return false
|
64
72
|
end
|
65
73
|
|
66
74
|
def selection_check
|
67
|
-
# exit if nothing is selected
|
68
75
|
if @selection.empty?
|
69
76
|
dialog "There is nothing selected to convert."
|
70
77
|
exit!
|
@@ -72,9 +79,8 @@ class PropertySynthesizeDealloc
|
|
72
79
|
end
|
73
80
|
|
74
81
|
def file_check
|
75
|
-
|
76
|
-
|
77
|
-
find_and_save_file
|
82
|
+
log "@file_path: #{@file_path}"
|
83
|
+
save_file
|
78
84
|
|
79
85
|
file_checker = FileChecker.new(@file_path)
|
80
86
|
file_checker.check_file_path
|
@@ -87,27 +93,24 @@ class PropertySynthesizeDealloc
|
|
87
93
|
end
|
88
94
|
end
|
89
95
|
|
90
|
-
def
|
91
|
-
|
92
|
-
|
93
|
-
|
96
|
+
def set_file_path
|
97
|
+
docs = @xcode.source_documents.get
|
98
|
+
docs.each do |doc|
|
99
|
+
start_sel, end_sel = doc.selected_character_range.get
|
100
|
+
if end_sel > 0
|
101
|
+
@file_path = doc.path.get
|
102
|
+
return
|
103
|
+
end
|
94
104
|
end
|
105
|
+
log "FilePath: #{@file_path}"
|
95
106
|
end
|
96
107
|
|
97
|
-
def
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
docs = @xcode.text_documents.get
|
103
|
-
docs.each do |doc|
|
104
|
-
path = doc.get.file_name.get
|
105
|
-
if file_path == path
|
106
|
-
doc.save
|
107
|
-
return doc
|
108
|
-
else
|
109
|
-
false
|
110
|
-
end
|
108
|
+
def save_file(path=nil)
|
109
|
+
if path.nil?
|
110
|
+
doc = @xcode.source_documents[1].get
|
111
|
+
else
|
112
|
+
doc = @xcode.source_documents[its.path.eq(path)].get.first
|
111
113
|
end
|
114
|
+
doc.save ? doc : false
|
112
115
|
end
|
113
116
|
end
|
Binary file
|
Binary file
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{property_synthesize_dealloc}
|
8
|
+
s.version = "0.2.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Craig Williams"]
|
12
|
+
s.date = %q{2011-03-19}
|
13
|
+
s.description = %q{Creates property, synthesize and dealloc statements from selected ivar declarations for the header and implementation files in an Xcode project.}
|
14
|
+
s.email = %q{cwilliams.allancraig@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.markdown"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".rvmrc",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.markdown",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"lib/config.yml",
|
28
|
+
"lib/configuration.rb",
|
29
|
+
"lib/content_replacer.rb",
|
30
|
+
"lib/converter.rb",
|
31
|
+
"lib/file_checker.rb",
|
32
|
+
"lib/property_synthesize_dealloc.rb",
|
33
|
+
"pkg/property_synthesize_dealloc-0.1.0.gem",
|
34
|
+
"pkg/property_synthesize_dealloc-0.1.1.gem",
|
35
|
+
"pkg/property_synthesize_dealloc-0.1.2.gem",
|
36
|
+
"pkg/property_synthesize_dealloc-0.2.0.gem",
|
37
|
+
"property_synthesize_dealloc.gemspec",
|
38
|
+
"spec/property_synthesize_dealloc_spec.rb",
|
39
|
+
"spec/spec_helper.rb",
|
40
|
+
"spec/test_config.yml"
|
41
|
+
]
|
42
|
+
s.homepage = %q{http://github.com/CraigWilliams/property_synthesize_dealloc}
|
43
|
+
s.licenses = ["MIT"]
|
44
|
+
s.require_paths = ["lib"]
|
45
|
+
s.rubygems_version = %q{1.5.3}
|
46
|
+
s.summary = %q{Creates property, synthesize and dealloc statements from selected ivar declarations}
|
47
|
+
s.test_files = [
|
48
|
+
"spec/property_synthesize_dealloc_spec.rb",
|
49
|
+
"spec/spec_helper.rb"
|
50
|
+
]
|
51
|
+
|
52
|
+
if s.respond_to? :specification_version then
|
53
|
+
s.specification_version = 3
|
54
|
+
|
55
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
56
|
+
s.add_runtime_dependency(%q<rb-appscript>, [">= 0.6.0"])
|
57
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
58
|
+
s.add_development_dependency(%q<yard>, [">= 0"])
|
59
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
60
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
61
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
62
|
+
s.add_runtime_dependency(%q<rb-appscript>, [">= 0.6.0"])
|
63
|
+
else
|
64
|
+
s.add_dependency(%q<rb-appscript>, [">= 0.6.0"])
|
65
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
66
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
67
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
68
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
69
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
70
|
+
s.add_dependency(%q<rb-appscript>, [">= 0.6.0"])
|
71
|
+
end
|
72
|
+
else
|
73
|
+
s.add_dependency(%q<rb-appscript>, [">= 0.6.0"])
|
74
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
75
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
76
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
77
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
78
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
79
|
+
s.add_dependency(%q<rb-appscript>, [">= 0.6.0"])
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
@@ -29,16 +29,6 @@ describe "PropertySynthesizeDealloc" do
|
|
29
29
|
p.file_path = path
|
30
30
|
p.file_path.should == path
|
31
31
|
end
|
32
|
-
|
33
|
-
it "should exit if no file path provided" do
|
34
|
-
pending "stubbing a dialog not working" do
|
35
|
-
dialog = mock('dialog').as_null_object
|
36
|
-
OSAX.osax.stub!(:display_dialog).with('"You have not supplied a file path", ({:buttons=>["Ok"], :default_button=>1}').and_return(dialog)
|
37
|
-
|
38
|
-
p.selection = "NSString *string"
|
39
|
-
p.psd!.should == dialog
|
40
|
-
end
|
41
|
-
end
|
42
32
|
|
43
33
|
it "should exit if nothing is selected" do
|
44
34
|
pending "stubbing a dialog not working" do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: property_synthesize_dealloc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 1
|
9
8
|
- 2
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Craig Williams
|
@@ -15,12 +15,13 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-03-
|
18
|
+
date: 2011-03-19 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
|
23
|
-
|
22
|
+
prerelease: false
|
23
|
+
type: :runtime
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
25
|
none: false
|
25
26
|
requirements:
|
26
27
|
- - ">="
|
@@ -31,12 +32,12 @@ dependencies:
|
|
31
32
|
- 6
|
32
33
|
- 0
|
33
34
|
version: 0.6.0
|
34
|
-
|
35
|
-
|
36
|
-
requirement: *id001
|
35
|
+
name: rb-appscript
|
36
|
+
version_requirements: *id001
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
|
-
|
39
|
-
|
38
|
+
prerelease: false
|
39
|
+
type: :development
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
41
|
none: false
|
41
42
|
requirements:
|
42
43
|
- - ">="
|
@@ -45,12 +46,12 @@ dependencies:
|
|
45
46
|
segments:
|
46
47
|
- 0
|
47
48
|
version: "0"
|
49
|
+
name: rspec
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
48
52
|
prerelease: false
|
49
53
|
type: :development
|
50
|
-
requirement:
|
51
|
-
- !ruby/object:Gem::Dependency
|
52
|
-
name: yard
|
53
|
-
version_requirements: &id003 !ruby/object:Gem::Requirement
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
55
|
none: false
|
55
56
|
requirements:
|
56
57
|
- - ">="
|
@@ -59,12 +60,12 @@ dependencies:
|
|
59
60
|
segments:
|
60
61
|
- 0
|
61
62
|
version: "0"
|
63
|
+
name: yard
|
64
|
+
version_requirements: *id003
|
65
|
+
- !ruby/object:Gem::Dependency
|
62
66
|
prerelease: false
|
63
67
|
type: :development
|
64
|
-
requirement:
|
65
|
-
- !ruby/object:Gem::Dependency
|
66
|
-
name: bundler
|
67
|
-
version_requirements: &id004 !ruby/object:Gem::Requirement
|
68
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
68
69
|
none: false
|
69
70
|
requirements:
|
70
71
|
- - ">="
|
@@ -73,12 +74,12 @@ dependencies:
|
|
73
74
|
segments:
|
74
75
|
- 0
|
75
76
|
version: "0"
|
77
|
+
name: bundler
|
78
|
+
version_requirements: *id004
|
79
|
+
- !ruby/object:Gem::Dependency
|
76
80
|
prerelease: false
|
77
81
|
type: :development
|
78
|
-
requirement:
|
79
|
-
- !ruby/object:Gem::Dependency
|
80
|
-
name: jeweler
|
81
|
-
version_requirements: &id005 !ruby/object:Gem::Requirement
|
82
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
82
83
|
none: false
|
83
84
|
requirements:
|
84
85
|
- - ">="
|
@@ -87,12 +88,12 @@ dependencies:
|
|
87
88
|
segments:
|
88
89
|
- 0
|
89
90
|
version: "0"
|
91
|
+
name: jeweler
|
92
|
+
version_requirements: *id005
|
93
|
+
- !ruby/object:Gem::Dependency
|
90
94
|
prerelease: false
|
91
95
|
type: :development
|
92
|
-
requirement:
|
93
|
-
- !ruby/object:Gem::Dependency
|
94
|
-
name: rcov
|
95
|
-
version_requirements: &id006 !ruby/object:Gem::Requirement
|
96
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
96
97
|
none: false
|
97
98
|
requirements:
|
98
99
|
- - ">="
|
@@ -101,12 +102,12 @@ dependencies:
|
|
101
102
|
segments:
|
102
103
|
- 0
|
103
104
|
version: "0"
|
104
|
-
|
105
|
-
|
106
|
-
requirement: *id006
|
105
|
+
name: rcov
|
106
|
+
version_requirements: *id006
|
107
107
|
- !ruby/object:Gem::Dependency
|
108
|
-
|
109
|
-
|
108
|
+
prerelease: false
|
109
|
+
type: :runtime
|
110
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
110
111
|
none: false
|
111
112
|
requirements:
|
112
113
|
- - ">="
|
@@ -117,9 +118,8 @@ dependencies:
|
|
117
118
|
- 6
|
118
119
|
- 0
|
119
120
|
version: 0.6.0
|
120
|
-
|
121
|
-
|
122
|
-
requirement: *id007
|
121
|
+
name: rb-appscript
|
122
|
+
version_requirements: *id007
|
123
123
|
description: Creates property, synthesize and dealloc statements from selected ivar declarations for the header and implementation files in an Xcode project.
|
124
124
|
email: cwilliams.allancraig@gmail.com
|
125
125
|
executables: []
|
@@ -145,6 +145,9 @@ files:
|
|
145
145
|
- lib/property_synthesize_dealloc.rb
|
146
146
|
- pkg/property_synthesize_dealloc-0.1.0.gem
|
147
147
|
- pkg/property_synthesize_dealloc-0.1.1.gem
|
148
|
+
- pkg/property_synthesize_dealloc-0.1.2.gem
|
149
|
+
- pkg/property_synthesize_dealloc-0.2.0.gem
|
150
|
+
- property_synthesize_dealloc.gemspec
|
148
151
|
- spec/property_synthesize_dealloc_spec.rb
|
149
152
|
- spec/spec_helper.rb
|
150
153
|
- spec/test_config.yml
|
@@ -178,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
178
181
|
requirements: []
|
179
182
|
|
180
183
|
rubyforge_project:
|
181
|
-
rubygems_version: 1.5.
|
184
|
+
rubygems_version: 1.5.3
|
182
185
|
signing_key:
|
183
186
|
specification_version: 3
|
184
187
|
summary: Creates property, synthesize and dealloc statements from selected ivar declarations
|