xcodesnippets 0.2.0 → 0.2.1

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.
data/README.md CHANGED
@@ -16,6 +16,18 @@ If you aren't familiar with RubyGems, fire up a Terminal and run the following c
16
16
 
17
17
  If you are using a tool like [RVM](https://rvm.beginrescueend.com/), the `sudo` will probably be unnecessary.
18
18
 
19
+ ## Migrating your existing snippets
20
+
21
+ If you already have some snippets in `~/Library/Developer/Xcode/UserData/CodeSnippets/` you will want to bring these under `xcodesnippets` control before you do anything else.
22
+
23
+ Fortunately, `xcodesnippets` will do this for you; not only that, but it will rename each snippet file to use a more meaningful title (the one you gave it within Xcode).
24
+
25
+ To migrate your exiting snippets, run:
26
+
27
+ $ xcodesnippets migrate
28
+
29
+ A list of your existing snippets will be displayed and with your confirmation, they will be copied into the default `xcodesnippet` bundle, removed from the Xcode snippets directory, then re-linked back to the `xcodesnippet` versions (see "How xcodesnippets works" for more).
30
+
19
31
  ## Installing a code snippet
20
32
 
21
33
  Code snippets are distributed as property list files with a `.codesnippet` extension. If you have created any custom code snippets in Xcode 4, you will find them in your home directory, under `~/Library/Developer/Xcode/UserData/CodeSnippets/`. The files are named using GUIDs. Any `codesnippet` file created from within Xcode 4, or manually if you are comfortable editing the files yourself (they are just plists) are installable using `xcodesnippets`.
@@ -39,6 +51,7 @@ For a full list of commands and options, run `xcodesnippets --help`.
39
51
  ## TODO
40
52
 
41
53
  * Installing snippets and bundles directly from a URL
54
+ * Activating snippets from outside the managed directory - great for using your own snippets from their local source repos.
42
55
  * Generating snippet bundles from a folder of snippets ready for distribution
43
56
  * Commands for listing installed bundles and their contents
44
57
  * Commands for activating and de-activating individual bundles/snippets
@@ -56,7 +56,10 @@ Warning: this will move #{snippets_to_migrate.count} code snippets under xcodesn
56
56
 
57
57
  Continue? (y/n)
58
58
  }
59
- agree(prompt) unless skip_confirm?
59
+ if skip_confirm?
60
+ return true
61
+ end
62
+ agree(prompt)
60
63
  end
61
64
  end
62
65
 
@@ -51,8 +51,13 @@ module XcodeSnippets
51
51
  @data[snippet.key]
52
52
  end
53
53
 
54
- def generate_new_symlink
55
- File.join(@xcode_snippets_install_path, "#{@uuid_generator.generate}.codesnippet")
54
+ def generate_symlink_for_snippet(snippet)
55
+ snippet.set_guid!(generate_guid)
56
+ File.join(@xcode_snippets_install_path, "#{snippet.guid}.codesnippet")
57
+ end
58
+
59
+ def generate_guid
60
+ @uuid_generator.generate
56
61
  end
57
62
 
58
63
  private
@@ -7,13 +7,18 @@ module XcodeSnippets
7
7
  @bundle = bundle
8
8
  end
9
9
 
10
+ def set_guid!(new_guid)
11
+ metadata.guid = new_guid
12
+ metadata.save_to(path)
13
+ end
14
+
10
15
  def copy_to_bundle(bundle)
11
16
  FileUtils.cp(path, bundle.path)
12
17
  self.class.new(File.join(bundle.path, name), bundle)
13
18
  end
14
19
 
15
20
  def activate(manifest)
16
- @symlink = manifest.generate_new_symlink
21
+ @symlink = manifest.generate_symlink_for_snippet(self)
17
22
  FileUtils.symlink(path, symlink)
18
23
  manifest.add_snippet(self)
19
24
  end
@@ -30,6 +35,10 @@ module XcodeSnippets
30
35
  File.basename(@path)
31
36
  end
32
37
 
38
+ def guid
39
+ metadata.guid
40
+ end
41
+
33
42
  def metadata
34
43
  @metadata ||= MetaData.from_file(path)
35
44
  end
@@ -59,6 +68,20 @@ module XcodeSnippets
59
68
  def title
60
69
  @data["IDECodeSnippetTitle"]
61
70
  end
71
+
72
+ def guid
73
+ @data["IDECodeSnippetIdentifier"]
74
+ end
75
+
76
+ def guid=(new_guid)
77
+ @data["IDECodeSnippetIdentifier"] = new_guid
78
+ end
79
+
80
+ def save_to(path)
81
+ File.open(path, "w") do |io|
82
+ io.write @data.to_plist
83
+ end
84
+ end
62
85
  end
63
86
  end
64
87
  end
@@ -2,7 +2,7 @@ module XcodeSnippets
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- TINY = 0
5
+ TINY = 1
6
6
 
7
7
  def self.to_s
8
8
  "#{MAJOR}.#{MINOR}.#{TINY}"
@@ -24,7 +24,11 @@ describe "SnippetManager" do
24
24
  File.exist?(expected_path).should be_true
25
25
  end
26
26
 
27
- it "creates a GUID symlink to the installed snippet in the Xcode snippets directory" do
27
+ it "generates a new GUID identifier for the snippet" do
28
+ @snippet.guid.should_not be_nil
29
+ end
30
+
31
+ it "creates a symlink to the installed snippet in the Xcode snippets directory based on the snippet's generated GUID" do
28
32
  symlink = @manager.manifest.symlink_for_snippet(@snippet)
29
33
  File.exist?(symlink).should be_true
30
34
  end
@@ -33,6 +37,10 @@ describe "SnippetManager" do
33
37
  @manager.manifest.should have_snippet(@snippet)
34
38
  end
35
39
 
40
+ it "updates the snippet's metadata to reflect it's generated GUID" do
41
+ @snippet.metadata.guid.should == @snippet.guid
42
+ end
43
+
36
44
  end
37
45
 
38
46
  describe "#install_snippets_from_paths" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xcodesnippets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: clamp
17
- requirement: &2156053140 !ruby/object:Gem::Requirement
17
+ requirement: &2164421420 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 0.2.1
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2156053140
25
+ version_requirements: *2164421420
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: uuidtools
28
- requirement: &2156045060 !ruby/object:Gem::Requirement
28
+ requirement: &2164419300 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 2.1.2
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *2156045060
36
+ version_requirements: *2164419300
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: plist
39
- requirement: &2156044380 !ruby/object:Gem::Requirement
39
+ requirement: &2164412280 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,21 @@ dependencies:
44
44
  version: 3.1.0
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *2156044380
47
+ version_requirements: *2164412280
48
+ - !ruby/object:Gem::Dependency
49
+ name: highline
50
+ requirement: &2164409580 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: 1.6.2
56
+ type: :runtime
57
+ prerelease: false
58
+ version_requirements: *2164409580
48
59
  - !ruby/object:Gem::Dependency
49
60
  name: rspec
50
- requirement: &2156043980 !ruby/object:Gem::Requirement
61
+ requirement: &2164408180 !ruby/object:Gem::Requirement
51
62
  none: false
52
63
  requirements:
53
64
  - - ! '>='
@@ -55,10 +66,10 @@ dependencies:
55
66
  version: '0'
56
67
  type: :development
57
68
  prerelease: false
58
- version_requirements: *2156043980
69
+ version_requirements: *2164408180
59
70
  - !ruby/object:Gem::Dependency
60
71
  name: cucumber
61
- requirement: &2156043300 !ruby/object:Gem::Requirement
72
+ requirement: &2164407640 !ruby/object:Gem::Requirement
62
73
  none: false
63
74
  requirements:
64
75
  - - ! '>='
@@ -66,10 +77,10 @@ dependencies:
66
77
  version: '0'
67
78
  type: :development
68
79
  prerelease: false
69
- version_requirements: *2156043300
80
+ version_requirements: *2164407640
70
81
  - !ruby/object:Gem::Dependency
71
82
  name: ruby-debug19
72
- requirement: &2156042600 !ruby/object:Gem::Requirement
83
+ requirement: &2164407080 !ruby/object:Gem::Requirement
73
84
  none: false
74
85
  requirements:
75
86
  - - ! '>='
@@ -77,7 +88,7 @@ dependencies:
77
88
  version: '0'
78
89
  type: :development
79
90
  prerelease: false
80
- version_requirements: *2156042600
91
+ version_requirements: *2164407080
81
92
  description:
82
93
  email: luke@lukeredpath.co.uk
83
94
  executables: