oss_xcodesnippet 0.0.3

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 92e0fe6766191be24d9355ed56eba4166138f383
4
+ data.tar.gz: 29f706b05515390bfdcd58408fc9d30a1161ba9c
5
+ SHA512:
6
+ metadata.gz: 1ad8907e478693713842cc5a415e8bae7613c4dea6322e1cd691699fb4d5e28308b87e29696a34e81c647ae477f2a4cf55e4ae1e6efb248f64afb314dc912c35
7
+ data.tar.gz: a2ffb93d4aa44f778e4dbc22c0af2ed08d54eafd962fc61f06ae3f6a60f2f511e17eb448106bb54d9180b8ad48005adc871971239e25fcd2d1d061436efda206
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,27 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ oss_xcodesnippet (0.0.2)
5
+ commander (~> 4.1)
6
+ plist
7
+ yaml-front-matter
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ commander (4.4.3)
13
+ highline (~> 1.7.2)
14
+ highline (1.7.8)
15
+ plist (3.2.0)
16
+ rake (10.1.0)
17
+ yaml-front-matter (0.0.1)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ oss_xcodesnippet!
24
+ rake
25
+
26
+ BUNDLED WITH
27
+ 1.14.6
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2015 Mattt Thompson (http://mattt.me/)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # xcodesnippet
2
+ *A command-line interface for installing Xcode Snippets*
3
+
4
+ ## Installation
5
+
6
+ ```
7
+ $ gem install oss_xcodesnippet
8
+ ```
9
+
10
+ ## Usage
11
+
12
+ #### Sourcefile.swift
13
+
14
+ ```swift
15
+ ---
16
+ title: "Hello, World!"
17
+ summary: "Prints 'Hello World'"
18
+ completion-scope: Function or Method
19
+ ---
20
+
21
+ println("Hello, World!")
22
+ ```
23
+
24
+ #### Terminal Command
25
+
26
+ ```
27
+ $ oss_xcodesnippet install path/to/source.m
28
+ ```
29
+
30
+ ---
31
+
32
+ ## Creator
33
+
34
+ Andy Cui
35
+
36
+ Original Author:
37
+
38
+ Mattt Thompson ([@mattt](https://twitter.com/mattt))
39
+
40
+ ## License
41
+
42
+ xcodesnippet is released under an MIT license. See LICENSE for more information.
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/setup"
2
+
3
+ gemspec = eval(File.read("oss_xcodesnippet.gemspec"))
4
+
5
+ task :build => "#{gemspec.full_name}.gem"
6
+
7
+ file "#{gemspec.full_name}.gem" => gemspec.files + ["oss_xcodesnippet.gemspec"] do
8
+ system "gem build oss_xcodesnippet.gemspec"
9
+ end
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'commander/import'
4
+
5
+ $:.push File.expand_path("../../lib", __FILE__)
6
+ require 'oss_xcodesnippet'
7
+
8
+ HighLine.track_eof = false # Fix for built-in Ruby
9
+ Signal.trap("INT") {} # Suppress backtrace when exiting command
10
+
11
+ program :version, OSSXcodeSnippet::VERSION
12
+ program :description, 'A command-line interface for installing Xcode Snippets'
13
+
14
+ program :help, 'Author', 'Andy Cui'
15
+ program :help, 'Website', 'https://github.com/andy380743909/xcodesnippet'
16
+ program :help_formatter, :compact
17
+
18
+ default_command :help
19
+
20
+ require 'oss_xcodesnippet/commands'
@@ -0,0 +1,2 @@
1
+ require 'oss_xcodesnippet/snippet'
2
+ require 'oss_xcodesnippet/version'
@@ -0,0 +1,3 @@
1
+ $:.push File.expand_path('../', __FILE__)
2
+
3
+ require 'commands/install'
@@ -0,0 +1,73 @@
1
+ require 'yaml'
2
+ require 'yaml/front-matter'
3
+ require 'fileutils'
4
+ require 'securerandom'
5
+
6
+ USER_XCODE_SNIPPETS_DIRECTORY = File.expand_path("~/Library/Developer/Xcode/UserData/CodeSnippets/")
7
+
8
+ command :install do |c|
9
+ c.syntax = 'codesnippet install [SNIPPET]'
10
+ c.summary = 'Create and Install an Xcode Snippet'
11
+ c.description = 'Creates and installs an Xcode .codesnippet file from an source file annotated with YAML front matter.'
12
+
13
+ c.example 'description', 'codesnippet install /path/to/code.source'
14
+
15
+ c.action do |args, options|
16
+ say_error "Input file required" and abort unless @input_filepath = args.first
17
+ say_error "Input file does not exist" and abort unless File.exist?(@input_filepath)
18
+
19
+ @content = File.read(@input_filepath)
20
+ say_error "Input file is empty" and abort if @content.empty?
21
+
22
+ extract_front_matter!
23
+
24
+ # UUID+basename is better than single UUID
25
+ # @output_filepath = File.join(USER_XCODE_SNIPPETS_DIRECTORY, @snippet.identifier + ".codesnippet")
26
+ file_basename = File.basename(@input_filepath, File.extname(@input_filepath))
27
+ @output_filepath = File.join(USER_XCODE_SNIPPETS_DIRECTORY, file_basename + @snippet.identifier + ".codesnippet")
28
+
29
+ begin
30
+ FileUtils.mkdir_p(USER_XCODE_SNIPPETS_DIRECTORY)
31
+ # test if file name conflicts
32
+
33
+ # if conflicts backup oldfile
34
+
35
+ # else write to file
36
+ File.open(@output_filepath, 'w') do |f|
37
+ f.write @snippet.to_plist
38
+ end
39
+ rescue => error
40
+ say_error "Error: #{error.message}" and abort
41
+ end
42
+
43
+ say_ok "Installed Code Snippet"
44
+ puts @output_filepath
45
+ end
46
+ end
47
+
48
+ private
49
+
50
+ def extract_front_matter!
51
+ @snippet = OSSXcodeSnippet::Snippet.new
52
+
53
+ front_matter, contents = YAML::FrontMatter.extract(@content)
54
+
55
+ if front_matter.empty?
56
+ say_error "No YAML Front Matter Detected" and abort
57
+ else
58
+ @snippet.contents = contents.strip
59
+ @snippet.completion_prefix = File.basename(@input_filepath, File.extname(@input_filepath))
60
+ @snippet.language = case File.extname(@input_filepath)
61
+ when ".swift" then "Xcode.SourceCodeLanguage.Swift"
62
+ when ".m" then "Xcode.SourceCodeLanguage.Objective-C"
63
+ when ".mm" then "Xcode.SourceCodeLanguage.Objective-C++"
64
+ else ""
65
+ end
66
+ @snippet.title = front_matter["title"] || ""
67
+ @snippet.summary = front_matter["summary"] || ""
68
+ @snippet.completion_scopes = [front_matter["completion-scope"]] || front_matter["completion-scopes"] || "All"
69
+ @snippet.identifier = SecureRandom.uuid().upcase
70
+ @snippet.is_user_snippet = true
71
+ @snippet.version = 0
72
+ end
73
+ end
@@ -0,0 +1,29 @@
1
+ require 'plist'
2
+
3
+ module OSSXcodeSnippet
4
+ class Snippet
5
+ attr_accessor :completion_prefix
6
+ attr_accessor :completion_scopes
7
+ attr_accessor :contents
8
+ attr_accessor :identifier
9
+ attr_accessor :is_user_snippet
10
+ attr_accessor :language
11
+ attr_accessor :summary
12
+ attr_accessor :title
13
+ attr_accessor :version
14
+
15
+ def to_plist
16
+ {
17
+ "IDECodeSnippetCompletionPrefix" => @completion_prefix,
18
+ "IDECodeSnippetCompletionScopes" => @completion_scopes,
19
+ "IDECodeSnippetContents" => @contents,
20
+ "IDECodeSnippetIdentifier" => @identifier,
21
+ "IDECodeSnippetLanguage" => @language,
22
+ "IDECodeSnippetSummary" => @summary,
23
+ "IDECodeSnippetTitle" => @title,
24
+ "IDECodeSnippetUserSnippet" => @is_user_snippet,
25
+ "IDECodeSnippetVersion" => @version
26
+ }.to_plist
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module OSSXcodeSnippet
2
+ VERSION = "0.0.3"
3
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ require "oss_xcodesnippet/version"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "oss_xcodesnippet"
8
+ s.authors = ["Andy Cui"]
9
+ s.email = "andy380743909@gmail.com"
10
+ s.license = "MIT"
11
+ s.homepage = "https://github.com/andy380743909/xcodesnippet"
12
+ s.version = OSSXcodeSnippet::VERSION
13
+ s.platform = Gem::Platform::RUBY
14
+ s.summary = "dianping overseas xcodesnippet"
15
+ s.description = "A command-line interface for installing Xcode Snippets."
16
+
17
+ s.add_dependency "yaml-front-matter"
18
+ s.add_dependency "plist"
19
+ s.add_dependency "commander", "~> 4.1"
20
+
21
+ s.add_development_dependency "rake"
22
+
23
+ s.files = Dir["./**/*"].reject { |file| file =~ /\.\/(bin|log|pkg|script|spec|test|vendor)/ }
24
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
25
+ s.executables = `git ls-files -- bin/`.split("\n").map{ |f| File.basename(f) }
26
+ s.require_paths = ["lib"]
27
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oss_xcodesnippet
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Andy Cui
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-05-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: yaml-front-matter
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: plist
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: commander
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: A command-line interface for installing Xcode Snippets.
70
+ email: andy380743909@gmail.com
71
+ executables:
72
+ - oss_xcodesnippet
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - "./Gemfile"
77
+ - "./Gemfile.lock"
78
+ - "./LICENSE"
79
+ - "./README.md"
80
+ - "./Rakefile"
81
+ - "./lib/oss_xcodesnippet.rb"
82
+ - "./lib/oss_xcodesnippet/commands.rb"
83
+ - "./lib/oss_xcodesnippet/commands/install.rb"
84
+ - "./lib/oss_xcodesnippet/snippet.rb"
85
+ - "./lib/oss_xcodesnippet/version.rb"
86
+ - "./oss_xcodesnippet.gemspec"
87
+ - bin/oss_xcodesnippet
88
+ homepage: https://github.com/andy380743909/xcodesnippet
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.4.8
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: dianping overseas xcodesnippet
112
+ test_files: []