sublime_sunippetter 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sublime_sunippetter.gemspec
4
+ gemspec
5
+ gem "rspec", "~> 2.14.1"
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 tbpgr
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,94 @@
1
+ # SublimeSunippetter
2
+
3
+ SublimeSunippetter is generate Sublime Text2 simple sunippet from Sunippetfile DSL.
4
+
5
+ 2013/11/20 ver 0.01 is still simple. Only single line space separating sunippet is supported.
6
+
7
+ ## Purpose
8
+
9
+ SublimeSunippetter can use following situations.
10
+
11
+ * You create dsl for team.
12
+
13
+ * You create some library for team.
14
+
15
+ * You create some open-source library.
16
+
17
+ If you provide sunippets for your users, they appreciate your kindness ...maybe.
18
+
19
+ ## Installation
20
+
21
+ Add this line to your application's Gemfile:
22
+
23
+ gem 'sublime_sunippetter'
24
+
25
+ And then execute:
26
+
27
+ $ bundle
28
+
29
+ Or install it yourself as:
30
+
31
+ $ gem install sublime_sunippetter
32
+
33
+ ## Usage
34
+ ### Generate
35
+ First, you create Sunippetfile manually or following command.
36
+
37
+ suni init
38
+
39
+ Second, you have to edit Sunippetfile.
40
+
41
+ # encoding: utf-8
42
+
43
+ # set output path. default=current directory
44
+ output_path 'C:/Users/user_name/AppData/Roaming/Sublime Text 2/Packages/User'
45
+
46
+ # set sunippet scope. default=source.ruby
47
+ scope "source.ruby"
48
+
49
+ # if two args method
50
+ add :hoge, :args1, :args2
51
+ # if no args method
52
+ add :hige
53
+
54
+ Third, you have to do is execute command suni.
55
+
56
+ suni
57
+
58
+ Result => generate hoge.sublime-snippet, hige.sublime-snippet
59
+
60
+ This Sample Sunppet Contens are ...
61
+
62
+ <snippet>
63
+ <content><![CDATA[
64
+ hoge ${1:args1}, ${2:args2}
65
+ ]]></content>
66
+ <tabTrigger>hoge</tabTrigger>
67
+ <scope>source.ruby</scope>
68
+ <description>hoge method</description>
69
+ </snippet>
70
+
71
+ And
72
+
73
+ <snippet>
74
+ <content><![CDATA[
75
+ hige
76
+ ]]></content>
77
+ <tabTrigger>hige</tabTrigger>
78
+ <scope>source.ruby</scope>
79
+ <description>hige method</description>
80
+ </snippet>
81
+
82
+ in 'C:/Users/user_name/AppData/Roaming/Sublime Text 2/Packages/User' directory.
83
+
84
+ ## Use Generated Sunippet
85
+
86
+ <img src="./doc_image/sublime_sunippetter.gif" />
87
+
88
+ ## Contributing
89
+
90
+ 1. Fork it
91
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
92
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
93
+ 4. Push to the branch (`git push origin my-new-feature`)
94
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/suni ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'sublime_sunippetter'
4
+ SublimeSunippetter::Core.new.execute
Binary file
@@ -0,0 +1,3 @@
1
+ module SublimeSunippetter
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,144 @@
1
+ require "sublime_sunippetter/version"
2
+ require "erb"
3
+
4
+ module SublimeSunippetter
5
+ #= SublimeSunippetter Core
6
+ class Core
7
+ #== Sunippetdefine file name.
8
+ DEFINE_FILE = "Sunippetdefine"
9
+
10
+ #== Sunippetdefine file template
11
+ DEFINE_FILE_TEMPLATE =<<-EOS
12
+ # encoding: utf-8
13
+
14
+ # set output path. default=current directory
15
+ # output_path 'C:/Users/user_name/AppData/Roaming/Sublime Text 2/Packages/User'
16
+
17
+ # set sunippet scope. default=source.ruby
18
+ # scope "source.ruby"
19
+
20
+ # if two args method
21
+ # add :hoge, :args1, :args2
22
+ # if no args method
23
+ # add :hige
24
+ EOS
25
+
26
+ #== sublime sunippet template
27
+ SUNIPPET_TEMPLATE =<<-EOS
28
+ <snippet>
29
+ <content><![CDATA[
30
+ <%= method_name %><%= args_names %>
31
+ ]]></content>
32
+ <tabTrigger><%= method_name %></tabTrigger>
33
+ <scope><%= scope%></scope>
34
+ <description><%= method_name %> method</description>
35
+ </snippet>
36
+ EOS
37
+
38
+ #== generate Sunippetdefine to current directory.
39
+ def init
40
+ File.open("./#{DEFINE_FILE}", "w") {|f|f.puts DEFINE_FILE_TEMPLATE}
41
+ end
42
+
43
+ #== generate sublime text2 sunippets from Sunippetdefine
44
+ def generate_sunippets
45
+ sunippet_define = read_sunippetdefine
46
+ dsl = Dsl.new
47
+ dsl.instance_eval sunippet_define
48
+ dsl.target_methods.each do |m|
49
+ snippet = get_snippet(m.method_name , get_args_names(m) , dsl._scope)
50
+ File.open("#{dsl._output_path}/#{m.method_name}.sublime-snippet", "w") {|f|f.puts snippet}
51
+ end
52
+ end
53
+
54
+ #== for command prompt.
55
+ # if you execute suni(no-option), generate sublime text2 sunippet.
56
+ #
57
+ # if you execute suni init, generate Sunippetdefine.
58
+ def execute
59
+ sunippet = SublimeSunippetter::Core.new
60
+
61
+ if $*[0] == "init"
62
+ sunippet.init
63
+ else
64
+ sunippet.generate_sunippets
65
+ end
66
+ end
67
+
68
+ private
69
+ def read_sunippetdefine
70
+ unless File.exists? "./#{DEFINE_FILE}"
71
+ raise SunippetterError.new("you must create #{DEFINE_FILE}. manual or 'suni init' command")
72
+ end
73
+
74
+ File.open("./#{DEFINE_FILE}") {|f|f.read}
75
+ end
76
+
77
+ def get_snippet(method_name, args_names, scope)
78
+ erb = ERB.new(SUNIPPET_TEMPLATE)
79
+ snippet = erb.result(binding)
80
+ snippet
81
+ end
82
+
83
+ def get_args_names(_method)
84
+ args = _method.args
85
+ args_names = " "
86
+ args.each_with_index do |a, i|
87
+ args_names << "${#{i + 1}:#{a}}, "
88
+ end
89
+ args_names.chop!.chop! unless args.empty?
90
+ end
91
+ end
92
+
93
+ #= TargetMethod. this is method information container
94
+ class TargetMethod
95
+ attr_accessor :method_name, :args
96
+
97
+ #== generate sublime text2 sunippets from Sunippetdefine
98
+ def initialize(&block)
99
+ instance_eval do
100
+ block.call(self)
101
+ end
102
+ end
103
+ end
104
+
105
+ #= Dsl. this is dsl for Sunippetdefine.
106
+ class Dsl
107
+ attr_accessor :target_methods, :_scope, :_output_path
108
+
109
+ #== init default values
110
+ def initialize
111
+ @target_methods = []
112
+ @_scope = "source.ruby"
113
+ @_output_path = "./"
114
+ end
115
+
116
+ #== add sunippet information
117
+ def add(method_name, *args)
118
+ return if method_name.nil?
119
+ return if method_name.empty?
120
+ return if args.each.include?(nil)
121
+ return if args.each.include?("")
122
+ @target_methods << TargetMethod.new do |t|
123
+ t.method_name = method_name
124
+ t.args = args
125
+ end
126
+ end
127
+
128
+ #== set sunippet scope
129
+ def scope(_scope)
130
+ return if _scope.nil?
131
+ return if _scope.empty?
132
+ @_scope = _scope
133
+ end
134
+
135
+ #== set sunippet output path
136
+ def output_path(_output_path)
137
+ return if _output_path.nil?
138
+ return if _output_path.empty?
139
+ @_output_path = _output_path
140
+ end
141
+ end
142
+
143
+ class SunippetterError < StandardError;end
144
+ end
@@ -0,0 +1,17 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+ end
@@ -0,0 +1,130 @@
1
+ # encoding: utf-8
2
+ require_relative "../lib/sublime_sunippetter"
3
+ require "spec_helper"
4
+
5
+ describe SublimeSunippetter::Dsl do
6
+ cases_add = [
7
+ {
8
+ case_no: 1,
9
+ method_names: :hoge,
10
+ params: [:hoge, :hige, :hage],
11
+ expecteds: SublimeSunippetter::TargetMethod.new do |t|
12
+ t.method_name = :hoge
13
+ t.args = [:hoge, :hige, :hage]
14
+ end
15
+ },
16
+ {
17
+ case_no: 2,
18
+ method_names:nil,
19
+ params: [:hoge, :hige, :hage],
20
+ expecteds: nil,
21
+ invalid?: true
22
+ },
23
+ {
24
+ case_no: 3,
25
+ method_names:"",
26
+ params: [:hoge, :hige, :hage],
27
+ expecteds: "",
28
+ invalid?: true
29
+ },
30
+ {
31
+ case_no: 4,
32
+ method_names: :hoge,
33
+ params: [:hoge, nil, :hage],
34
+ expecteds: "",
35
+ invalid?: true
36
+ },
37
+ {
38
+ case_no: 5,
39
+ method_names: :hoge,
40
+ params: [:hoge, "", :hage],
41
+ expecteds: "",
42
+ invalid?: true
43
+ },
44
+ ]
45
+
46
+ cases_add.each do |c|
47
+ it "#add case_no=#{c[:case_no]} add method_names=#{c[:method_names]}, params=#{c[:params]}" do
48
+ # given
49
+ dsl = SublimeSunippetter::Dsl.new
50
+
51
+ # when
52
+ if c[:params].nil?
53
+ dsl.add c[:method_names]
54
+ else
55
+ dsl.add c[:method_names], *c[:params]
56
+ end
57
+ actual = dsl.target_methods.first
58
+
59
+ # then
60
+ if c[:invalid?]
61
+ expect(actual).to be nil
62
+ else
63
+ expect(actual.method_name).to eq(c[:expecteds].method_name)
64
+ expect(actual.args).to eq(c[:expecteds].args)
65
+ end
66
+ end
67
+ end
68
+
69
+ cases_scope = [
70
+ {
71
+ case_no: 1,
72
+ scope:"source.java",
73
+ expected: "source.java"
74
+ },
75
+ {
76
+ case_no: 2,
77
+ scope:nil,
78
+ expected: "source.ruby"
79
+ },
80
+ {
81
+ case_no: 3,
82
+ scope:"",
83
+ expected: "source.ruby"
84
+ },
85
+ ]
86
+
87
+ cases_scope.each do |c|
88
+ it "#scope case_no=#{c[:case_no]} add scope=#{c[:scope]}" do
89
+ # given
90
+ dsl = SublimeSunippetter::Dsl.new
91
+
92
+ # when
93
+ dsl.scope c[:scope]
94
+
95
+ # then
96
+ expect(dsl._scope).to eq(c[:expected])
97
+ end
98
+ end
99
+
100
+ cases_output_path = [
101
+ {
102
+ case_no: 1,
103
+ output_path:"C:\\",
104
+ expected: "C:\\"
105
+ },
106
+ {
107
+ case_no: 2,
108
+ output_path:nil,
109
+ expected: "./"
110
+ },
111
+ {
112
+ case_no: 3,
113
+ output_path:"",
114
+ expected: "./"
115
+ },
116
+ ]
117
+
118
+ cases_output_path.each do |c|
119
+ it "#output_path case_no=#{c[:case_no]} add output_path=#{c[:output_path]}" do
120
+ # given
121
+ dsl = SublimeSunippetter::Dsl.new
122
+
123
+ # when
124
+ dsl.output_path c[:output_path]
125
+
126
+ # then
127
+ expect(dsl._output_path).to eq(c[:expected])
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,68 @@
1
+ # encoding: utf-8
2
+ require_relative "../lib/sublime_sunippetter"
3
+ require "spec_helper"
4
+
5
+ describe SublimeSunippetter::Core do
6
+ cases_init = [
7
+ {
8
+ case_no: 1,
9
+ expected: SublimeSunippetter::Core::DEFINE_FILE_TEMPLATE
10
+ },
11
+ ]
12
+
13
+ cases_init.each do |c|
14
+ it "#init case_no=#{c[:case_no]} generate #{SublimeSunippetter::Core::DEFINE_FILE}" do
15
+ # given
16
+ sunippet = SublimeSunippetter::Core.new
17
+
18
+ # when
19
+ sunippet.init
20
+
21
+ # then
22
+ actual = File.open("#{SublimeSunippetter::Core::DEFINE_FILE}") {|f|f.read}
23
+ expect(actual).to eq(c[:expected])
24
+ end
25
+ end
26
+
27
+ GENERATE_SUNIPPETS_CASE =<<-EOS
28
+ output_path "#{File.absolute_path('.')}"
29
+ scope "source.java"
30
+ add :hoge, :args1, :args2
31
+ add :hige
32
+ EOS
33
+
34
+ cases_generate_sunippets = [
35
+ {
36
+ case_no: 1,
37
+ sunippetdefine: GENERATE_SUNIPPETS_CASE,
38
+ output_file_names: ["hoge.sublime-snippet", "hige.sublime-snippet"],
39
+ }
40
+ ]
41
+
42
+ context do
43
+ before do
44
+ File.open("./#{SublimeSunippetter::Core::DEFINE_FILE}", "w") {|f|f.puts GENERATE_SUNIPPETS_CASE}
45
+ end
46
+
47
+ cases_generate_sunippets.each do |c|
48
+
49
+ it "#generate_sunippets case_no=#{c[:case_no]}" do
50
+ # given
51
+ sunippet = SublimeSunippetter::Core.new
52
+
53
+ # when
54
+ sunippet.generate_sunippets
55
+
56
+ # then
57
+ c[:output_file_names].each do |f|
58
+ FileTest.exist?("./#{f}").should be_true
59
+ File.delete("./#{f}")
60
+ end
61
+ end
62
+ end
63
+ end
64
+
65
+ after(:each) do
66
+ File.delete("#{SublimeSunippetter::Core::DEFINE_FILE}") if File.exists?("#{SublimeSunippetter::Core::DEFINE_FILE}")
67
+ end
68
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sublime_sunippetter/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sublime_sunippetter"
8
+ spec.version = SublimeSunippetter::VERSION
9
+ spec.authors = ["tbpgr"]
10
+ spec.email = ["tbpgr@tbpgr.jp"]
11
+ spec.description = %q{SublimeSunippetter is generate Sublime Text2 simple sunippet from Sunippetfile DSL.}
12
+ spec.summary = %q{SublimeSunippetter is generate Sublime Text2 simple sunippet from Sunippetfile DSL.}
13
+ spec.homepage = "https://github.com/tbpgr/sublime_sunippetter"
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_development_dependency "rspec", "~> 2.14.1"
24
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sublime_sunippetter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - tbpgr
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-11-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: &26779920 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *26779920
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &26783976 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *26783976
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &26729028 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 2.14.1
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *26729028
47
+ description: SublimeSunippetter is generate Sublime Text2 simple sunippet from Sunippetfile
48
+ DSL.
49
+ email:
50
+ - tbpgr@tbpgr.jp
51
+ executables:
52
+ - suni
53
+ extensions: []
54
+ extra_rdoc_files: []
55
+ files:
56
+ - .gitignore
57
+ - .rspec
58
+ - Gemfile
59
+ - LICENSE.txt
60
+ - README.md
61
+ - Rakefile
62
+ - bin/suni
63
+ - doc_image/sublime_sunippetter.gif
64
+ - lib/sublime_sunippetter.rb
65
+ - lib/sublime_sunippetter/version.rb
66
+ - spec/spec_helper.rb
67
+ - spec/sublime_sunippetter_dsl_spec.rb
68
+ - spec/sublime_sunippetter_spec.rb
69
+ - sublime_sunippetter.gemspec
70
+ homepage: https://github.com/tbpgr/sublime_sunippetter
71
+ licenses:
72
+ - MIT
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 1.8.11
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: SublimeSunippetter is generate Sublime Text2 simple sunippet from Sunippetfile
95
+ DSL.
96
+ test_files:
97
+ - spec/spec_helper.rb
98
+ - spec/sublime_sunippetter_dsl_spec.rb
99
+ - spec/sublime_sunippetter_spec.rb
100
+ has_rdoc: