CoffeeTags 0.0.1.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/.gitignore +4 -0
- data/CoffeeTags.gemspec +20 -0
- data/Gemfile +18 -0
- data/Guardfile +6 -0
- data/README.md +15 -0
- data/Rakefile +1 -0
- data/bin/coffeetags +4 -0
- data/lib/CoffeeTags.rb +73 -0
- data/lib/CoffeeTags/formatter.rb +63 -0
- data/lib/CoffeeTags/parser.rb +77 -0
- data/lib/CoffeeTags/version.rb +4 -0
- data/spec/fixtures/campfire.coffee +45 -0
- data/spec/fixtures/campfire.js +49 -0
- data/spec/fixtures/campfire.js.tags +13 -0
- data/spec/fixtures/test.coffee +13 -0
- data/spec/fixtures/test_tree.yaml +35 -0
- data/spec/fixtures/tree.yaml +55 -0
- data/spec/formatter_spec.rb +26 -0
- data/spec/parser_spec.rb +86 -0
- data/test.rb +4 -0
- metadata +80 -0
data/.gitignore
ADDED
data/CoffeeTags.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "CoffeeTags/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "CoffeeTags"
|
7
|
+
s.version = Coffeetags::VERSION
|
8
|
+
s.authors = ["Łukasz Korecki"]
|
9
|
+
s.email = ["lukasz@coffeesounds.com"]
|
10
|
+
s.homepage = "http://github.com/lukaszkorecki/CoffeeTags"
|
11
|
+
s.summary = %q{Simple tags generator for CoffeeScript}
|
12
|
+
s.description = %q{CoffeeTags generates tag file for use with TagBar.vim}
|
13
|
+
|
14
|
+
s.rubyforge_project = "CoffeeTags"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
end
|
data/Gemfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem 'rake'
|
4
|
+
# Specify your gem's dependencies in CoffeeTags.gemspec
|
5
|
+
gemspec
|
6
|
+
|
7
|
+
group :development do
|
8
|
+
gem 'guard'
|
9
|
+
gem 'growl'
|
10
|
+
gem 'guard-rspec'
|
11
|
+
|
12
|
+
# osx
|
13
|
+
gem 'rb-fsevent'
|
14
|
+
end
|
15
|
+
|
16
|
+
group :test do
|
17
|
+
gem 'rspec', '~> 2.6.0'
|
18
|
+
end
|
data/Guardfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# CoffeeTags
|
2
|
+
|
3
|
+
A tiny, simple tool for generating tags (Ctags compatible ) for use with Vim + [TagBar plugin](https://github.com/majutsushi/tagbar)
|
4
|
+
|
5
|
+
It might work with other plugins/editors which can use Ctags (such as Emacs or
|
6
|
+
TagList for Vim).
|
7
|
+
|
8
|
+
|
9
|
+
# Installation
|
10
|
+
|
11
|
+
`gem install CoffeeTags` (when it's released :-))
|
12
|
+
|
13
|
+
# TODO
|
14
|
+
|
15
|
+
- squash all bugs
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/bin/coffeetags
ADDED
data/lib/CoffeeTags.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "CoffeeTags/version"
|
3
|
+
require "CoffeeTags/parser"
|
4
|
+
require "CoffeeTags/formatter"
|
5
|
+
|
6
|
+
class Object
|
7
|
+
def blank?
|
8
|
+
if self.respond_to? :"empty?"
|
9
|
+
self.nil? or self.empty?
|
10
|
+
else
|
11
|
+
self.nil?
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module Coffeetags
|
17
|
+
AUTHOR = "Łukasz Korecki /lukasz@coffeesounds.com/"
|
18
|
+
NAME = "CoffeeTags"
|
19
|
+
URL = "https://github.com/lukaszkorecki/CoffeeTags"
|
20
|
+
TAGBAR_COFFEE_CONF = <<-CONF
|
21
|
+
let g:tagbar_type_coffee = {
|
22
|
+
\\ 'kinds' : [
|
23
|
+
\\ 'f:functions',
|
24
|
+
\\ 'o:object'
|
25
|
+
\\ ],
|
26
|
+
\\ 'kind2scope' : {
|
27
|
+
\\ 'f' : 'object',
|
28
|
+
\\ 'o' : 'object'
|
29
|
+
\\},
|
30
|
+
\\ 'sro' : ".",
|
31
|
+
\\ 'ctagsbin' : 'coffeetags',
|
32
|
+
\\ 'ctagsargs' : '',
|
33
|
+
\\}
|
34
|
+
CONF
|
35
|
+
|
36
|
+
class Utils
|
37
|
+
|
38
|
+
def self.option_parser args
|
39
|
+
puts "no args!" and return if args.empty?
|
40
|
+
case args.first
|
41
|
+
when /version/
|
42
|
+
STDOUT << Coffeetags::VERSION
|
43
|
+
when 'help'
|
44
|
+
STDOUT << 'coffeetags [version|vim_conf] or path to a coffeescript file'
|
45
|
+
when /vim_conf/
|
46
|
+
puts <<-HELP
|
47
|
+
" Add this type definition to your vimrc
|
48
|
+
" or do
|
49
|
+
" coffeetags vim_conf >> <PATH TO YOUR VIMRC>
|
50
|
+
HELP
|
51
|
+
puts Coffeetags::TAGBAR_COFFEE_CONF
|
52
|
+
else
|
53
|
+
self.run args
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.run files
|
59
|
+
files.each do |file|
|
60
|
+
sc = File.read file
|
61
|
+
|
62
|
+
parser = Coffeetags::Parser.new sc
|
63
|
+
parser.execute!
|
64
|
+
|
65
|
+
formatter = Coffeetags::Formatter.new file, parser.tree
|
66
|
+
|
67
|
+
formatter.parse_tree
|
68
|
+
|
69
|
+
STDOUT << formatter.to_file
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Coffeetags
|
2
|
+
class Formatter
|
3
|
+
def initialize file, tree =[]
|
4
|
+
@file = file
|
5
|
+
@tree = tree
|
6
|
+
|
7
|
+
@header = [
|
8
|
+
"!_TAG_FILE_FORMAT 2 /extended format/",
|
9
|
+
"!_TAG_FILE_SORTED 0 /0=unsorted, 1=sorted, 2=foldcase/",
|
10
|
+
"!_TAG_PROGRAM_AUTHOR #{Coffeetags::AUTHOR}",
|
11
|
+
"!_TAG_PROGRAM_NAME #{Coffeetags::NAME} //",
|
12
|
+
"!_TAG_PROGRAM_URL #{Coffeetags::URL} /GitHub repository/",
|
13
|
+
"!_TAG_PROGRAM_VERSION #{Coffeetags::VERSION} //"
|
14
|
+
]
|
15
|
+
|
16
|
+
@types = {
|
17
|
+
'f' => 'type:function',
|
18
|
+
'c' => 'type:class',
|
19
|
+
'v' => 'type:var'
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def regex_line line
|
24
|
+
"/^#{line}$/;\""
|
25
|
+
end
|
26
|
+
|
27
|
+
def line_to_string entry
|
28
|
+
namespace = (entry[:parent].blank?) ? entry[:name]: entry[:parent]
|
29
|
+
namespace = namespace == entry[:name] ? '' : "object:#{namespace}"
|
30
|
+
|
31
|
+
[
|
32
|
+
entry[:name],
|
33
|
+
@file,
|
34
|
+
regex_line(entry[:source]),
|
35
|
+
entry[:kind],
|
36
|
+
"lineno:#{entry[:line]}",
|
37
|
+
namespace,
|
38
|
+
@types[entry[:kind]]
|
39
|
+
].join("\t")
|
40
|
+
end
|
41
|
+
|
42
|
+
def parse_tree
|
43
|
+
@lines = @tree.map do | content|
|
44
|
+
line_to_string content if content[:kind] == 'f'
|
45
|
+
end.reject{|l| l.nil? }
|
46
|
+
end
|
47
|
+
|
48
|
+
def to_file
|
49
|
+
str = ""
|
50
|
+
@header.each do |header|
|
51
|
+
str << header
|
52
|
+
str << "\n"
|
53
|
+
end
|
54
|
+
|
55
|
+
@lines.each do |line|
|
56
|
+
str << line
|
57
|
+
str << "\n"
|
58
|
+
end
|
59
|
+
|
60
|
+
str
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
module Coffeetags
|
3
|
+
class Parser
|
4
|
+
attr_reader :tree
|
5
|
+
def initialize source
|
6
|
+
@source = source
|
7
|
+
|
8
|
+
# tree maps the ... tree :-)
|
9
|
+
@tree = []
|
10
|
+
|
11
|
+
# regexes
|
12
|
+
@class_regex = /^[ \t]*class\s*(\w*)/
|
13
|
+
@var_regex = /([@a-zA-Z0-9_]*)[ \t]*[=:][ \t]*$/
|
14
|
+
@token_regex = /[ \t]*([@a-zA-Z0-9_]*)[ \t]*[:=]/
|
15
|
+
end
|
16
|
+
|
17
|
+
def line_level line
|
18
|
+
line.match(/^[ \t]*/)[0].gsub("\t", " ").split('').length
|
19
|
+
end
|
20
|
+
|
21
|
+
def scope_path _el = nil, _tree = nil
|
22
|
+
bf = []
|
23
|
+
tree = (_tree || @tree)
|
24
|
+
element = (_el || tree.last)
|
25
|
+
idx = tree.index(element) || -1
|
26
|
+
|
27
|
+
current_level = element[:level]
|
28
|
+
tree[0..idx].reverse.each do |_el|
|
29
|
+
# uhmmmmmm
|
30
|
+
if _el[:level] != current_level and _el[:level] < current_level
|
31
|
+
bf << _el[:name]
|
32
|
+
current_level = _el[:level]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
bf.uniq.reverse.join('.')
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
def execute!
|
40
|
+
line_n = 0
|
41
|
+
level = 0
|
42
|
+
sc = '__top__'
|
43
|
+
# indentify scopes
|
44
|
+
@source.each_line do |line|
|
45
|
+
line_n += 1
|
46
|
+
level = line_level line
|
47
|
+
|
48
|
+
if (_class = line.match @class_regex)
|
49
|
+
@tree << {
|
50
|
+
:name => _class[1], :level => level
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
if(var = line.match @var_regex)
|
55
|
+
@tree << {
|
56
|
+
:name => var[1], :level => level
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
token = line.match @token_regex
|
61
|
+
if not token.nil? and line =~ /-\>/
|
62
|
+
o = {
|
63
|
+
:name => token[1],
|
64
|
+
:level => level,
|
65
|
+
:parent => '',
|
66
|
+
:source => line.chomp,
|
67
|
+
:kind => 'f',
|
68
|
+
:line => line_n
|
69
|
+
}
|
70
|
+
o[:parent] = scope_path o
|
71
|
+
@tree << o
|
72
|
+
end
|
73
|
+
@tree.uniq!
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# this example is not complete, but shows how to
|
2
|
+
# implement an API client using Request class
|
3
|
+
class Campfire
|
4
|
+
|
5
|
+
# @api_key - Campfire API keys
|
6
|
+
# @host - your campifre host, for example if you're using trololo.campfirenow.com, then host is 'trololo
|
7
|
+
constructor: (api_key, host) ->
|
8
|
+
@url = "https://#{host}.campfirenow.com/"
|
9
|
+
@auth = { 'username' : api_key, 'password' : 'X'}
|
10
|
+
@headers = { 'Content-Type' : 'application/json' }
|
11
|
+
|
12
|
+
# private function used for parsing JSON responses
|
13
|
+
handlers: (callbacks) ->
|
14
|
+
resp =
|
15
|
+
onSuccess : (response) ->
|
16
|
+
try
|
17
|
+
obj = JSON.parse(response.responseText)
|
18
|
+
catch error
|
19
|
+
console.dir(error)
|
20
|
+
callbacks.onFailure(error)
|
21
|
+
callbacks.onSuccess(obj)
|
22
|
+
|
23
|
+
onFailure: (response) ->
|
24
|
+
console.dir(response)
|
25
|
+
callbacks.onFailure(response)
|
26
|
+
|
27
|
+
# get list of rooms
|
28
|
+
rooms: (callbacks) ->
|
29
|
+
new Request(@url, @headers, @auth).get 'rooms.json', this.handlers(callbacks)
|
30
|
+
|
31
|
+
# get information about a room
|
32
|
+
# @id - room id
|
33
|
+
roomInfo: (id, callbacks) ->
|
34
|
+
new Request(@url, @headers, @auth).get "room/#{id}.json", this.handlers(callbacks)
|
35
|
+
|
36
|
+
# get latest messages and events from a room
|
37
|
+
# @id - room id
|
38
|
+
# @since - optional since id parameter
|
39
|
+
recent: (id, since, callbacks) ->
|
40
|
+
url = "room/#{id}/recent.json"
|
41
|
+
url += "?since_message_id=#{since}" if since
|
42
|
+
new Request(@url, @headers, @auth).get url, this.handlers(callbacks)
|
43
|
+
|
44
|
+
class Test
|
45
|
+
bump : ->
|
@@ -0,0 +1,49 @@
|
|
1
|
+
(function() {
|
2
|
+
var Campfire;
|
3
|
+
window.Campfire = Campfire = (function() {
|
4
|
+
function Campfire(api_key, host) {
|
5
|
+
this.url = "https://" + host + ".campfirenow.com/";
|
6
|
+
this.auth = {
|
7
|
+
'username': api_key,
|
8
|
+
'password': 'X'
|
9
|
+
};
|
10
|
+
this.headers = {
|
11
|
+
'Content-Type': 'application/json'
|
12
|
+
};
|
13
|
+
}
|
14
|
+
Campfire.prototype.handlers = function(callbacks) {
|
15
|
+
var resp;
|
16
|
+
return resp = {
|
17
|
+
onSuccess: function(response) {
|
18
|
+
var obj;
|
19
|
+
try {
|
20
|
+
obj = JSON.parse(response.responseText);
|
21
|
+
} catch (error) {
|
22
|
+
console.dir(error);
|
23
|
+
callbacks.onFailure(error);
|
24
|
+
}
|
25
|
+
return callbacks.onSuccess(obj);
|
26
|
+
},
|
27
|
+
onFailure: function(response) {
|
28
|
+
console.dir(response);
|
29
|
+
return callbacks.onFailure(response);
|
30
|
+
}
|
31
|
+
};
|
32
|
+
};
|
33
|
+
Campfire.prototype.rooms = function(callbacks) {
|
34
|
+
return new Request(this.url, this.headers, this.auth).get('rooms.json', this.handlers(callbacks));
|
35
|
+
};
|
36
|
+
Campfire.prototype.roomInfo = function(id, callbacks) {
|
37
|
+
return new Request(this.url, this.headers, this.auth).get("room/" + id + ".json", this.handlers(callbacks));
|
38
|
+
};
|
39
|
+
Campfire.prototype.recent = function(id, since, callbacks) {
|
40
|
+
var url;
|
41
|
+
url = "room/" + id + "/recent.json";
|
42
|
+
if (since) {
|
43
|
+
url += "?since_message_id=" + since;
|
44
|
+
}
|
45
|
+
return new Request(this.url, this.headers, this.auth).get(url, this.handlers(callbacks));
|
46
|
+
};
|
47
|
+
return Campfire;
|
48
|
+
})();
|
49
|
+
}).call(this);
|
@@ -0,0 +1,13 @@
|
|
1
|
+
!_TAG_FILE_FORMAT 2 /extended format/
|
2
|
+
!_TAG_FILE_SORTED 0 /0=unsorted, 1=sorted, 2=foldcase/
|
3
|
+
!_TAG_PROGRAM_AUTHOR Patrick Walton /pwalton@mozilla.com/
|
4
|
+
!_TAG_PROGRAM_NAME jsctags //
|
5
|
+
!_TAG_PROGRAM_URL http://github.com/pcwalton/jsctags /GitHub repository/
|
6
|
+
!_TAG_PROGRAM_VERSION 0.1 //
|
7
|
+
Campfire examples/campfire.js /^ function Campfire(api_key, host) {$/;" f lineno:4 type:void function(any, any)
|
8
|
+
constructor examples/campfire.js /^ function Campfire(api_key, host) {$/;" f lineno:4 namespace:Campfire.prototype type:void function(any, any)
|
9
|
+
handlers examples/campfire.js /^ Campfire.prototype.handlers = function(callbacks) {$/;" f lineno:14 namespace:Campfire.prototype type:Object function(any)
|
10
|
+
prototype examples/campfire.js /^ Campfire.prototype.handlers = function(callbacks) {$/;" v lineno:14 namespace:Campfire type:Campfire
|
11
|
+
rooms examples/campfire.js /^ Campfire.prototype.rooms = function(callbacks) {$/;" f lineno:33 namespace:Campfire.prototype type:any function(any)
|
12
|
+
roomInfo examples/campfire.js /^ Campfire.prototype.roomInfo = function(id, callbacks) {$/;" f lineno:36 namespace:Campfire.prototype type:any function(any, any)
|
13
|
+
recent examples/campfire.js /^ Campfire.prototype.recent = function(id, since, callbacks) {$/;" f lineno:39 namespace:Campfire.prototype type:any function(any, any, any)
|
@@ -0,0 +1,35 @@
|
|
1
|
+
---
|
2
|
+
- :source: bump = (wat) ->
|
3
|
+
:parent: ""
|
4
|
+
:kind: f
|
5
|
+
:name: bump
|
6
|
+
:line: 1
|
7
|
+
:level: 0
|
8
|
+
- :name: Wat
|
9
|
+
:level: 0
|
10
|
+
- :source: " ho : (x) ->"
|
11
|
+
:parent: Wat
|
12
|
+
:kind: f
|
13
|
+
:name: ho
|
14
|
+
:line: 5
|
15
|
+
:level: 2
|
16
|
+
- :name: '@lolWat'
|
17
|
+
:level: 4
|
18
|
+
- :source: " bump : ->"
|
19
|
+
:parent: 'Wat.ho.@lolWat'
|
20
|
+
:kind: f
|
21
|
+
:name: bump
|
22
|
+
:line: 9
|
23
|
+
:level: 6
|
24
|
+
- :source: " bump_up : ->"
|
25
|
+
:parent: 'Wat.ho.@lolWat'
|
26
|
+
:kind: f
|
27
|
+
:name: bump_up
|
28
|
+
:line: 11
|
29
|
+
:level: 6
|
30
|
+
- :source: " @BOOO__up = -> z()"
|
31
|
+
:parent: Wat.ho
|
32
|
+
:kind: f
|
33
|
+
:name: '@BOOO__up'
|
34
|
+
:line: 13
|
35
|
+
:level: 4
|
@@ -0,0 +1,55 @@
|
|
1
|
+
---
|
2
|
+
- :name: Campfire
|
3
|
+
:level: 0
|
4
|
+
- :parent: Campfire
|
5
|
+
:name: constructor
|
6
|
+
:line: 7
|
7
|
+
:kind: f
|
8
|
+
:source: " constructor: (api_key, host) ->"
|
9
|
+
:level: 2
|
10
|
+
- :parent: Campfire
|
11
|
+
:name: handlers
|
12
|
+
:line: 13
|
13
|
+
:kind: f
|
14
|
+
:source: ' handlers: (callbacks) ->'
|
15
|
+
:level: 2
|
16
|
+
- :name: resp
|
17
|
+
:level: 4
|
18
|
+
- :parent: Campfire.handlers.resp
|
19
|
+
:name: onSuccess
|
20
|
+
:line: 15
|
21
|
+
:kind: f
|
22
|
+
:source: ' onSuccess : (response) ->'
|
23
|
+
:level: 6
|
24
|
+
- :parent: Campfire.handlers.resp
|
25
|
+
:name: onFailure
|
26
|
+
:line: 23
|
27
|
+
:kind: f
|
28
|
+
:source: ' onFailure: (response) ->'
|
29
|
+
:level: 6
|
30
|
+
- :parent: Campfire
|
31
|
+
:name: rooms
|
32
|
+
:line: 28
|
33
|
+
:kind: f
|
34
|
+
:source: ' rooms: (callbacks) ->'
|
35
|
+
:level: 2
|
36
|
+
- :parent: Campfire
|
37
|
+
:name: roomInfo
|
38
|
+
:line: 33
|
39
|
+
:kind: f
|
40
|
+
:source: ' roomInfo: (id, callbacks) ->'
|
41
|
+
:level: 2
|
42
|
+
- :parent: Campfire
|
43
|
+
:name: recent
|
44
|
+
:line: 39
|
45
|
+
:kind: f
|
46
|
+
:source: ' recent: (id, since, callbacks) ->'
|
47
|
+
:level: 2
|
48
|
+
- :name: Test
|
49
|
+
:level: 0
|
50
|
+
- :parent: Test
|
51
|
+
:name: bump
|
52
|
+
:line: 45
|
53
|
+
:kind: f
|
54
|
+
:source: ' bump : ->'
|
55
|
+
:level: 2
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require './lib/CoffeeTags'
|
2
|
+
|
3
|
+
describe 'CoffeeTags::Formatter' do
|
4
|
+
before :each do
|
5
|
+
@tree = YAML::load_file './spec/fixtures/tree.yaml'
|
6
|
+
end
|
7
|
+
|
8
|
+
it "works!" do
|
9
|
+
lambda { Coffeetags::Formatter.new 'lol.coffee' }.should_not raise_exception
|
10
|
+
end
|
11
|
+
|
12
|
+
before :each do
|
13
|
+
@instance = Coffeetags::Formatter.new 'test.coffee', @tree
|
14
|
+
end
|
15
|
+
|
16
|
+
it "generates a line for method definition" do
|
17
|
+
exp = 'constructor test.coffee /^ constructor: (api_key, host) ->$/;" f lineno:7 object:Campfire type:function'
|
18
|
+
@instance.parse_tree.first.should == exp
|
19
|
+
end
|
20
|
+
|
21
|
+
it "generates line for second class" do
|
22
|
+
exp = 'bump test.coffee /^ bump : ->$/;" f lineno:45 object:Test type:function'
|
23
|
+
@instance.parse_tree.last.should == exp
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
data/spec/parser_spec.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require './lib/CoffeeTags'
|
2
|
+
describe 'CoffeeTags::Parser' do
|
3
|
+
before :all do
|
4
|
+
@campfire_class = File.read File.expand_path('./spec/fixtures/campfire.coffee')
|
5
|
+
@test_file = File.read File.expand_path('./spec/fixtures/test.coffee')
|
6
|
+
@test_tree = YAML::load_file File.expand_path('./spec/fixtures/test_tree.yaml')
|
7
|
+
@cf_tree = YAML::load_file File.expand_path('./spec/fixtures/tree.yaml')
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should work" do
|
12
|
+
lambda { Coffeetags::Parser.new "\n" }.should_not raise_exception
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
context 'detect item level' do
|
17
|
+
before :each do
|
18
|
+
@parser = Coffeetags::Parser.new ''
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'gets level from a string with no indent' do
|
22
|
+
@parser.line_level("zooo").should == 0
|
23
|
+
end
|
24
|
+
|
25
|
+
it "gets level from spaces" do
|
26
|
+
@parser.line_level(" def lol").should == 4
|
27
|
+
end
|
28
|
+
|
29
|
+
it "gets level from tabs" do
|
30
|
+
@parser.line_level("\t\t\tdef lol").should == 3
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
context "Creating scope path" do
|
36
|
+
before(:each) do
|
37
|
+
@parser = Coffeetags::Parser.new ''
|
38
|
+
end
|
39
|
+
it 'gets the scope path for first function' do
|
40
|
+
@parser.scope_path(@cf_tree[1], @cf_tree[0...1] ).should == 'Campfire'
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'gets the scope path for second function' do
|
44
|
+
@parser.scope_path(@cf_tree[2], @cf_tree[0..1] ).should == 'Campfire'
|
45
|
+
end
|
46
|
+
|
47
|
+
it "gets the scope for nested function" do
|
48
|
+
@parser.scope_path(@cf_tree[4], @cf_tree[0..3]).should == 'Campfire.handlers.resp'
|
49
|
+
end
|
50
|
+
|
51
|
+
it "gets the scope of a function which comes after nested function" do
|
52
|
+
|
53
|
+
@parser.scope_path(@cf_tree[6], @cf_tree[0..5]).should == 'Campfire'
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'gets scope for last method defined in diff class' do
|
57
|
+
@parser.scope_path(@cf_tree.last, @cf_tree).should == 'Test'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'Parsing' do
|
62
|
+
context 'Scoping' do
|
63
|
+
before(:each) do
|
64
|
+
@coffee_parser = Coffeetags::Parser.new @campfire_class
|
65
|
+
@test_parser = Coffeetags::Parser.new @test_file
|
66
|
+
end
|
67
|
+
|
68
|
+
it "generates the scope list" do
|
69
|
+
@coffee_parser.execute!
|
70
|
+
@coffee_parser.tree.should == @cf_tree
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'Test.coffee parsing' do
|
76
|
+
before(:each) do
|
77
|
+
@parser_test = Coffeetags::Parser.new @test_file
|
78
|
+
@parser_test.execute!
|
79
|
+
end
|
80
|
+
|
81
|
+
it "generates the tree for test.coffee" do
|
82
|
+
@parser_test.tree.should == @test_tree
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
end
|
data/test.rb
ADDED
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: CoffeeTags
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Łukasz Korecki
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-09-22 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: CoffeeTags generates tag file for use with TagBar.vim
|
15
|
+
email:
|
16
|
+
- lukasz@coffeesounds.com
|
17
|
+
executables:
|
18
|
+
- coffeetags
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- .gitignore
|
23
|
+
- CoffeeTags.gemspec
|
24
|
+
- Gemfile
|
25
|
+
- Guardfile
|
26
|
+
- README.md
|
27
|
+
- Rakefile
|
28
|
+
- bin/coffeetags
|
29
|
+
- lib/CoffeeTags.rb
|
30
|
+
- lib/CoffeeTags/formatter.rb
|
31
|
+
- lib/CoffeeTags/parser.rb
|
32
|
+
- lib/CoffeeTags/version.rb
|
33
|
+
- spec/fixtures/campfire.coffee
|
34
|
+
- spec/fixtures/campfire.js
|
35
|
+
- spec/fixtures/campfire.js.tags
|
36
|
+
- spec/fixtures/test.coffee
|
37
|
+
- spec/fixtures/test_tree.yaml
|
38
|
+
- spec/fixtures/tree.yaml
|
39
|
+
- spec/formatter_spec.rb
|
40
|
+
- spec/parser_spec.rb
|
41
|
+
- test.rb
|
42
|
+
homepage: http://github.com/lukaszkorecki/CoffeeTags
|
43
|
+
licenses: []
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
hash: 2103132400043761592
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
hash: 2103132400043761592
|
66
|
+
requirements: []
|
67
|
+
rubyforge_project: CoffeeTags
|
68
|
+
rubygems_version: 1.8.10
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: Simple tags generator for CoffeeScript
|
72
|
+
test_files:
|
73
|
+
- spec/fixtures/campfire.coffee
|
74
|
+
- spec/fixtures/campfire.js
|
75
|
+
- spec/fixtures/campfire.js.tags
|
76
|
+
- spec/fixtures/test.coffee
|
77
|
+
- spec/fixtures/test_tree.yaml
|
78
|
+
- spec/fixtures/tree.yaml
|
79
|
+
- spec/formatter_spec.rb
|
80
|
+
- spec/parser_spec.rb
|