CoffeeTags 0.0.1.8 → 0.0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +2 -0
- data/Gemfile +1 -1
- data/lib/CoffeeTags/parser.rb +14 -10
- data/lib/CoffeeTags/version.rb +1 -1
- data/lib/CoffeeTags.rb +45 -31
- data/spec/coffeetags_spec.rb +7 -5
- data/spec/fixtures/class_with_dot.coffee +2 -0
- data/spec/fixtures/out.test-two.ctags +2 -1
- data/spec/fixtures/out.test.ctags +2 -1
- data/spec/fixtures/test.coffee +3 -0
- data/spec/fixtures/test_tree.yaml +7 -0
- data/spec/fixtures/tree.yaml +9 -0
- data/spec/formatter_spec.rb +1 -2
- data/spec/parser_spec.rb +16 -3
- data/spec/spec_helper.rb +2 -0
- metadata +10 -5
data/.rspec
ADDED
data/Gemfile
CHANGED
data/lib/CoffeeTags/parser.rb
CHANGED
@@ -12,7 +12,7 @@ module Coffeetags
|
|
12
12
|
|
13
13
|
# regexes
|
14
14
|
@block = /^\s*(if|unless|switch|loop|do)/
|
15
|
-
@class_regex = /^\s*class\s*(\w*)/
|
15
|
+
@class_regex = /^\s*class\s*([\w\.]*)/
|
16
16
|
@proto_meths = /^\s*([A-Za-z]*)::([@a-zA-Z0-9_]*)/
|
17
17
|
@var_regex = /([@a-zA-Z0-9_]*)\s*[=:]{1}\s*$/
|
18
18
|
@token_regex = /([@a-zA-Z0-9_]*)\s*[:=]{1}/
|
@@ -49,8 +49,12 @@ module Coffeetags
|
|
49
49
|
line_n += 1
|
50
50
|
level = line_level line
|
51
51
|
|
52
|
-
|
53
|
-
|
52
|
+
# ignore comments!
|
53
|
+
next if line =~ /^\s*#/
|
54
|
+
|
55
|
+
# FIXME this could be DRYied
|
56
|
+
if (_class = line.match @class_regex)
|
57
|
+
@tree << { :name => _class[1], :level => level }
|
54
58
|
end
|
55
59
|
|
56
60
|
if(_proto = line.match @proto_meths)
|
@@ -70,19 +74,19 @@ module Coffeetags
|
|
70
74
|
|
71
75
|
if not token.nil?
|
72
76
|
o = {
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
77
|
+
:name => token[1],
|
78
|
+
:level => level,
|
79
|
+
:parent => '',
|
80
|
+
:source => line.chomp,
|
81
|
+
:line => line_n
|
78
82
|
}
|
79
83
|
|
80
84
|
# remove edge cases for now
|
81
85
|
# - if a line containes a line like: element.getElement('type=[checkbox]').lol()
|
82
86
|
is_in_string = line =~ /.*['"].*#{token[1]}.*=.*["'].*/
|
83
87
|
|
84
|
-
|
85
|
-
|
88
|
+
# - scope access and comparison in if x == 'lol'
|
89
|
+
is_in_comparison = line =~ /::|==/
|
86
90
|
|
87
91
|
# - objects with blank parent (parser bug?)
|
88
92
|
has_blank_parent = o[:parent] =~ /\.$/
|
data/lib/CoffeeTags/version.rb
CHANGED
data/lib/CoffeeTags.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
require "CoffeeTags/version"
|
3
3
|
require "CoffeeTags/parser"
|
4
4
|
require "CoffeeTags/formatter"
|
5
|
+
require 'optparse'
|
5
6
|
|
6
7
|
class Object
|
7
8
|
def blank?
|
@@ -18,22 +19,10 @@ module Coffeetags
|
|
18
19
|
NAME = "CoffeeTags"
|
19
20
|
URL = "https://github.com/lukaszkorecki/CoffeeTags"
|
20
21
|
|
21
|
-
STRINGS = {
|
22
|
-
'version' => "#{NAME} #{Coffeetags::VERSION} by #{AUTHOR} ( #{URL} )",
|
23
|
-
'help' => <<-HELP
|
24
|
-
-R - process current directory recursively and look for all *.coffee files
|
25
|
-
--f <file> - save tags to <file>, if <file> == '-' tags get print out to STDOUT (jscatgs style)
|
26
|
-
--version - coffeetags version
|
27
|
-
--vim-conf - print out tagbar config for vim
|
28
|
-
--include-vars - include objects/variables in generated tags
|
29
|
-
combine --vim-conf and --include-vars to create a config which adds '--include-vars' option
|
30
|
-
HELP
|
31
|
-
}
|
32
22
|
class Utils
|
33
23
|
def self.tagbar_conf include_vars
|
34
24
|
<<-CONF
|
35
25
|
" Add this type definition to your vimrc
|
36
|
-
" or do
|
37
26
|
" coffeetags --vim-conf >> <PATH TO YOUR VIMRC>
|
38
27
|
" if you want your tags to include vars/objects do:
|
39
28
|
" coffeetags --vim-conf --include-vars
|
@@ -54,36 +43,59 @@ HELP
|
|
54
43
|
end
|
55
44
|
|
56
45
|
def self.option_parser args
|
57
|
-
args
|
46
|
+
args << '-h' if args.empty?
|
47
|
+
options = {}
|
48
|
+
optparse = OptionParser.new do |opts|
|
58
49
|
|
59
|
-
|
60
|
-
|
50
|
+
opts.banner = (<<-BAN
|
51
|
+
#{NAME} #{Coffeetags::VERSION}
|
52
|
+
by #{AUTHOR} ( #{URL} )
|
53
|
+
Usage:
|
54
|
+
coffeetags [OPTIONS] <list of files>
|
55
|
+
BAN
|
56
|
+
).gsub(/^\s*/,'')
|
61
57
|
|
62
|
-
|
58
|
+
opts.on('-i', '--include-vars', "Include variables in generated tags") do |o|
|
59
|
+
options[:include_vars] = true
|
60
|
+
end
|
61
|
+
|
62
|
+
opts.on('-f', '--file FILE', 'Write tags to FILE (use - for std out)') do |o|
|
63
|
+
options[:output] = o unless o == '-'
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
opts.on('-R', '--recursive', 'Process current directory recursively') do |o|
|
68
|
+
options[:recur] = true
|
69
|
+
end
|
70
|
+
|
71
|
+
opts.on('-v', '--version', 'Current version') do
|
72
|
+
puts Coffeetags::VERSION
|
73
|
+
exit
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
opts.on('-h','--help','HALP') do
|
78
|
+
puts opts
|
79
|
+
exit
|
80
|
+
end
|
63
81
|
|
64
|
-
unless args.index( '-f').nil?
|
65
|
-
output = args[ args.index('-f') + 1]
|
66
|
-
args.delete '-f'
|
67
|
-
args.delete output
|
68
|
-
output = nil if output == '-'
|
69
82
|
end
|
70
83
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
( to_print << tagbar_conf(include_vars) ) unless args.delete('--vim-conf').nil?
|
84
|
+
optparse.parse! args
|
85
|
+
|
86
|
+
options[:files] = args.to_a
|
87
|
+
options[:files] += Dir['./**/*.coffee', './**/Cakefile'] if options[:recur]
|
76
88
|
|
77
|
-
|
89
|
+
[
|
90
|
+
options[:output],
|
91
|
+
options[:include_vars],
|
92
|
+
options[:files]
|
93
|
+
]
|
78
94
|
|
79
|
-
args += Dir['./**/*.coffee', './**/Cakefile'] if recursive
|
80
|
-
[output, include_vars, args] unless args.empty?
|
81
95
|
end
|
82
96
|
|
83
97
|
|
84
98
|
def self.run output, include_vars, files
|
85
|
-
|
86
|
-
files = [files] if files.is_a? String
|
87
99
|
__out = if output.nil?
|
88
100
|
STDOUT
|
89
101
|
else
|
@@ -92,6 +104,8 @@ HELP
|
|
92
104
|
|
93
105
|
__out << Coffeetags::Formatter.header
|
94
106
|
|
107
|
+
files = [ files] if files.is_a? String
|
108
|
+
|
95
109
|
files.reject { |f| f =~ /^-/}.each do |file|
|
96
110
|
sc = File.read file
|
97
111
|
parser = Coffeetags::Parser.new sc, include_vars
|
data/spec/coffeetags_spec.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
include Coffeetags
|
3
3
|
describe Utils do
|
4
4
|
context 'Argument parsing' do
|
5
5
|
it "returns nil when nothing is passed" do
|
6
|
-
|
6
|
+
expect {
|
7
|
+
Utils.option_parser( [])
|
8
|
+
}.to raise_error SystemExit
|
9
|
+
|
7
10
|
end
|
8
11
|
|
9
12
|
it "returns files list" do
|
10
|
-
Utils.option_parser(
|
13
|
+
Utils.option_parser([ 'lol.coffee']).should == [ nil, nil, ['lol.coffee']]
|
11
14
|
end
|
12
15
|
|
13
16
|
it "parses --include-vars option" do
|
@@ -15,7 +18,7 @@ describe Utils do
|
|
15
18
|
end
|
16
19
|
|
17
20
|
it "parses -f <file> option" do
|
18
|
-
Utils.option_parser( [ '-f','tags' ,'lol.coffee']).should == [ 'tags',
|
21
|
+
Utils.option_parser( [ '-f','tags' ,'lol.coffee']).should == [ 'tags', nil, ['lol.coffee']]
|
19
22
|
end
|
20
23
|
|
21
24
|
end
|
@@ -85,7 +88,6 @@ FF
|
|
85
88
|
|
86
89
|
end
|
87
90
|
after :each do
|
88
|
-
STDERR << "DELETING!"
|
89
91
|
`rm test.out`
|
90
92
|
end
|
91
93
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
!_TAG_PROGRAM_AUTHOR Łukasz Korecki /lukasz@coffeesounds.com/
|
4
4
|
!_TAG_PROGRAM_NAME CoffeeTags //
|
5
5
|
!_TAG_PROGRAM_URL https://github.com/lukaszkorecki/CoffeeTags /GitHub repository/
|
6
|
-
!_TAG_PROGRAM_VERSION 0.0.1.
|
6
|
+
!_TAG_PROGRAM_VERSION 0.0.1.8 //
|
7
7
|
bump spec/fixtures/test.coffee /bump/;" f lineno:1 object:window type:function
|
8
8
|
ho spec/fixtures/test.coffee /ho/;" f lineno:5 object:Wat type:function
|
9
9
|
bump spec/fixtures/test.coffee /bump/;" f lineno:10 object:Wat.ho.@lolWat type:function
|
@@ -11,6 +11,7 @@ bump_up spec/fixtures/test.coffee /bump_up/;" f lineno:12 object:Wat.ho.@lolWat
|
|
11
11
|
@filter spec/fixtures/test.coffee /@filter/;" f lineno:14 object:Wat.ho type:function
|
12
12
|
_loop spec/fixtures/test.coffee /_loop/;" f lineno:19 object:window type:function
|
13
13
|
bound_func spec/fixtures/test.coffee /bound_func/;" f lineno:41 object:window type:function
|
14
|
+
beam_magnum spec/fixtures/test.coffee /beam_magnum/;" f lineno:44 object:window type:function
|
14
15
|
constructor spec/fixtures/campfire.coffee /constructor/;" f lineno:8 object:Campfire type:function
|
15
16
|
handlers spec/fixtures/campfire.coffee /handlers/;" f lineno:14 object:Campfire type:function
|
16
17
|
onSuccess spec/fixtures/campfire.coffee /onSuccess/;" f lineno:16 object:Campfire.handlers.resp type:function
|
@@ -3,7 +3,7 @@
|
|
3
3
|
!_TAG_PROGRAM_AUTHOR Łukasz Korecki /lukasz@coffeesounds.com/
|
4
4
|
!_TAG_PROGRAM_NAME CoffeeTags //
|
5
5
|
!_TAG_PROGRAM_URL https://github.com/lukaszkorecki/CoffeeTags /GitHub repository/
|
6
|
-
!_TAG_PROGRAM_VERSION 0.0.1.
|
6
|
+
!_TAG_PROGRAM_VERSION 0.0.1.8 //
|
7
7
|
bump spec/fixtures/test.coffee /bump/;" f lineno:1 object:window type:function
|
8
8
|
ho spec/fixtures/test.coffee /ho/;" f lineno:5 object:Wat type:function
|
9
9
|
bump spec/fixtures/test.coffee /bump/;" f lineno:10 object:Wat.ho.@lolWat type:function
|
@@ -11,3 +11,4 @@ bump_up spec/fixtures/test.coffee /bump_up/;" f lineno:12 object:Wat.ho.@lolWat
|
|
11
11
|
@filter spec/fixtures/test.coffee /@filter/;" f lineno:14 object:Wat.ho type:function
|
12
12
|
_loop spec/fixtures/test.coffee /_loop/;" f lineno:19 object:window type:function
|
13
13
|
bound_func spec/fixtures/test.coffee /bound_func/;" f lineno:41 object:window type:function
|
14
|
+
beam_magnum spec/fixtures/test.coffee /beam_magnum/;" f lineno:44 object:window type:function
|
data/spec/fixtures/test.coffee
CHANGED
data/spec/fixtures/tree.yaml
CHANGED
data/spec/formatter_spec.rb
CHANGED
data/spec/parser_spec.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
describe 'CoffeeTags::Parser' do
|
3
3
|
before :all do
|
4
4
|
@campfire_class = File.read File.expand_path('./spec/fixtures/campfire.coffee')
|
5
|
+
@class_with_dot = File.read File.expand_path('./spec/fixtures/class_with_dot.coffee')
|
5
6
|
@test_file = File.read File.expand_path('./spec/fixtures/test.coffee')
|
6
7
|
|
7
8
|
@cf_tree = YAML::load_file File.expand_path('./spec/fixtures/tree.yaml')
|
@@ -76,6 +77,14 @@ describe 'CoffeeTags::Parser' do
|
|
76
77
|
c.should == @cf_tree.find {|i| i[:name] == 'Test'}
|
77
78
|
end
|
78
79
|
|
80
|
+
it "parses the class with dot in name" do
|
81
|
+
@coffee_parser = Coffeetags::Parser.new @class_with_dot, true
|
82
|
+
@coffee_parser.execute!
|
83
|
+
|
84
|
+
c = @coffee_parser.tree.find { |i| i[:name] == 'App.Campfire'}
|
85
|
+
c.should == @cf_tree.find {|i| i[:name] == 'App.Campfire'}
|
86
|
+
end
|
87
|
+
|
79
88
|
it "parses the instance variable" do
|
80
89
|
c =@coffee_parser.tree.find { |i| i[:name] == '@url'}
|
81
90
|
c.should == @cf_tree.find {|i| i[:name] == '@url'}
|
@@ -122,11 +131,10 @@ describe 'CoffeeTags::Parser' do
|
|
122
131
|
|
123
132
|
end
|
124
133
|
it "detects a fat arrow function" do
|
125
|
-
c
|
134
|
+
c = @parser_test.tree.find { |i| i[:name] == 'bound_func'}
|
126
135
|
c.should == @test_tree.find {|i| i[:name] == 'bound_func'}
|
127
136
|
|
128
137
|
end
|
129
|
-
|
130
138
|
it "extracts a method defined in a prototype" do
|
131
139
|
pending 'methods defined on prototype needs implementing'
|
132
140
|
pro = @parser_test.tree.find { |i| i[:name] == '_loop'}
|
@@ -135,6 +143,11 @@ describe 'CoffeeTags::Parser' do
|
|
135
143
|
pro.should == exp
|
136
144
|
end
|
137
145
|
|
146
|
+
it 'Ignores #TODO: -> (and any other comment line)' do
|
147
|
+
@parser_test.tree.find { |i| i[:name] == 'TODO' }.should be_nil
|
148
|
+
|
149
|
+
end
|
150
|
+
|
138
151
|
context 'for loop' do
|
139
152
|
subject {
|
140
153
|
@parser_test = Coffeetags::Parser.new @test_file, true
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: CoffeeTags
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 71
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
-
|
11
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
- 0
|
11
|
+
version: 0.0.2.0
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- "\xC5\x81ukasz Korecki"
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2012-
|
19
|
+
date: 2012-02-28 00:00:00 +00:00
|
20
20
|
default_executable:
|
21
21
|
dependencies: []
|
22
22
|
|
@@ -31,6 +31,7 @@ extra_rdoc_files: []
|
|
31
31
|
|
32
32
|
files:
|
33
33
|
- .gitignore
|
34
|
+
- .rspec
|
34
35
|
- .rvmrc
|
35
36
|
- .travis.yml
|
36
37
|
- CoffeeTags.gemspec
|
@@ -47,6 +48,7 @@ files:
|
|
47
48
|
- spec/fixtures/campfire.coffee
|
48
49
|
- spec/fixtures/campfire.js
|
49
50
|
- spec/fixtures/campfire.js.tags
|
51
|
+
- spec/fixtures/class_with_dot.coffee
|
50
52
|
- spec/fixtures/out.test-two.ctags
|
51
53
|
- spec/fixtures/out.test.ctags
|
52
54
|
- spec/fixtures/test.coffee
|
@@ -54,6 +56,7 @@ files:
|
|
54
56
|
- spec/fixtures/tree.yaml
|
55
57
|
- spec/formatter_spec.rb
|
56
58
|
- spec/parser_spec.rb
|
59
|
+
- spec/spec_helper.rb
|
57
60
|
- test.rb
|
58
61
|
has_rdoc: true
|
59
62
|
homepage: http://github.com/lukaszkorecki/CoffeeTags
|
@@ -94,6 +97,7 @@ test_files:
|
|
94
97
|
- spec/fixtures/campfire.coffee
|
95
98
|
- spec/fixtures/campfire.js
|
96
99
|
- spec/fixtures/campfire.js.tags
|
100
|
+
- spec/fixtures/class_with_dot.coffee
|
97
101
|
- spec/fixtures/out.test-two.ctags
|
98
102
|
- spec/fixtures/out.test.ctags
|
99
103
|
- spec/fixtures/test.coffee
|
@@ -101,3 +105,4 @@ test_files:
|
|
101
105
|
- spec/fixtures/tree.yaml
|
102
106
|
- spec/formatter_spec.rb
|
103
107
|
- spec/parser_spec.rb
|
108
|
+
- spec/spec_helper.rb
|