clips2snippets 0.0.1

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: 1b4729117bf05326a1a29ad9367cf3bae683a39b
4
+ data.tar.gz: cccb71ac4e9267c7bb59fa8bfab8642a61d09d9f
5
+ SHA512:
6
+ metadata.gz: 9fb86ba171047dc58157c7d9628f96ff27a3672cd261be3f526184015f7e0d06e95a921eb4c09574b3c354840f6d1a1423f9f14179c871e3561aadd6f4a6c501
7
+ data.tar.gz: b3ecc3fa750e63adc58ed08030c733ef3a0e12081c37eb48573d3b52f6679ba473fd3cbaa862716443b51de813f01e6fb9c2065add6f1de7989569a4392a2d39
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ /vendor/bundle
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ .DS_Store
20
+ Thumbs.db
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in clips2snippets.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2013 o_ame - http://oameya.com
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 o_ame
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # Coda Clips 2 Sublime Text Snippets
2
+
3
+ This tool help you to convert Coda Clips into Sublime Text Snippets.
4
+
5
+ # Requirements
6
+
7
+ * OSX
8
+ * Ruby 1.9.x
9
+
10
+ # Installation
11
+
12
+ ```bash
13
+ $ gem install clips2snippets
14
+ ```
15
+
16
+ # Usage
17
+
18
+ ```bash
19
+ $ clips2snippets gen HTML.clips
20
+ Found Clip: htmllayout
21
+ Finished converting all of Clips!
22
+ ```
23
+
24
+ # Contribution
25
+
26
+ If you have any improvement / new feature requests, please tell us in reply to my Twitter or writing to the box for opinions anonymously.
27
+
28
+ Pull requests are welcome!
29
+
30
+ # Credits
31
+
32
+ Maintained by o_ame - http://oameya.com
33
+ Licensed under MIT License
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'clips2snippets'
4
+
5
+ Clips2Snippets::CLI.start
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'clips2snippets/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "clips2snippets"
8
+ spec.version = Clips2snippets::VERSION
9
+ spec.authors = ["o_ame"]
10
+ spec.email = ["oame@oameya.com"]
11
+ spec.description = %q{Tools that convert Coda Clips to Sublime Text Snippets.}
12
+ spec.summary = %q{Tools that convert Coda Clips to Sublime Text Snippets.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_dependency "plist"
24
+ spec.add_dependency 'thor'
25
+ end
@@ -0,0 +1,6 @@
1
+ require "clips2snippets/version"
2
+ require "clips2snippets/cli"
3
+
4
+ module Clips2snippets
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,96 @@
1
+ # coding: utf-8
2
+
3
+ require 'clips2snippets'
4
+ require "tmpdir"
5
+ require "plist"
6
+ require 'thor'
7
+
8
+ module Clips2Snippets
9
+ class CLI < Thor
10
+ desc "gen FILE", "Convert Coda Clips to Sublime Text Snippets"
11
+ def gen(srcfile)
12
+
13
+ unless srcfile
14
+ puts "Usage: clips2snippets [filename.clips]"
15
+ exit
16
+ end
17
+
18
+ Dir.mktmpdir do |tmpdir|
19
+ clipsfile = File.join(tmpdir, 'clips')
20
+ system "plutil -convert xml1 '#{File.expand_path(srcfile)}' -o '#{clipsfile}'"
21
+ plist = Plist::parse_xml(clipsfile)
22
+
23
+ objects = plist["$objects"]
24
+ clips_title = objects[2]
25
+
26
+ indexes = []
27
+ objects.each_with_index do |e, n|
28
+ if e.class == Hash && e.keys.include?("title")
29
+ indexes << n
30
+ end
31
+ end
32
+
33
+ indexes.each_with_index do |index, n|
34
+ eor = (indexes[n+1])? indexes[n+1].to_i - 3 : objects.size
35
+
36
+ title = objects[index+1]
37
+ code = objects[index+2]
38
+ trigger = objects[index+3]
39
+ puts "Found Clip: #{title}"
40
+
41
+ # プレースホルダーの存在チェック
42
+ ranges = []
43
+ placeholders = objects[index+4, eor]
44
+ placeholders.each_with_index do |ph, i|
45
+ if ph.class == Hash && ph.has_key?("range")
46
+ range = placeholders[i+1].scan(/\{(\d+), (\d+)\}/)[0].map{|s| s.to_i}
47
+ ranges << [range, ph["type"]]
48
+ end
49
+ end
50
+
51
+ # プレースホルダーを置換
52
+ curr = ranges.size
53
+ ranges.reverse.each do |range, type|
54
+ # 1 => 日付
55
+ # 2 => ファイルネーム(*)
56
+ # 3 => 親フォルダー
57
+ # 4 => サイト名
58
+ # 5 => ローカルURL
59
+ # 6 => リモートURL
60
+ # 7 => 作者(*)
61
+ # 8 => SCMリビジョン
62
+ # 9 => 挿入ポイント(*)
63
+ # 10 => 選択されたテキスト(*)
64
+ # 11 => 直前のテキスト
65
+ # 12 => カスタム(*)
66
+ # 13 => クリップボード
67
+
68
+ case type
69
+ when 2
70
+ code[range[0], range[1]] = "${#{curr}:$TM_FILENAME}"
71
+ when 7
72
+ code[range[0], range[1]] = "${#{curr}:$TM_FULLNAME}"
73
+ when 10
74
+ code[range[0], range[1]] = "${#{curr}:$SELECTION}"
75
+ when 12
76
+ code[range[0], range[1]] = "${#{curr}:#{code[range[0], range[1]]}}"
77
+ else
78
+ code[range[0], range[1]] = "${#{curr}}"
79
+ end
80
+
81
+ curr -= 1
82
+ end
83
+
84
+ # ST2 Snippet
85
+ save_dir = "Snippets - #{clips_title}"
86
+ Dir.mkdir save_dir unless FileTest.exists? save_dir
87
+ st2_snippet = "<snippet>\n <content><![CDATA[\n%s\n]]></content>\n <tabTrigger>%s</tabTrigger>\n <description>%s</description>\n <!-- <scope>[add here]</scope> -->\n</snippet>"
88
+ snippet = st2_snippet % [code, trigger, title]
89
+ open(File.join(save_dir, "#{title}.sublime-snippet"), "w").puts snippet
90
+ end
91
+ end
92
+
93
+ say "Finished converting all of Clips!", :green
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,3 @@
1
+ module Clips2snippets
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: clips2snippets
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - o_ame
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: plist
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Tools that convert Coda Clips to Sublime Text Snippets.
70
+ email:
71
+ - oame@oameya.com
72
+ executables:
73
+ - clips2snippets
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - Gemfile
79
+ - LICENSE
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/clips2snippets
84
+ - clips2snippets.gemspec
85
+ - lib/clips2snippets.rb
86
+ - lib/clips2snippets/cli.rb
87
+ - lib/clips2snippets/version.rb
88
+ homepage: ''
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.0.3
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Tools that convert Coda Clips to Sublime Text Snippets.
112
+ test_files: []