coffee_trace 0.0.2
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/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +45 -0
- data/Rakefile +1 -0
- data/bin/coffee_trace +20 -0
- data/coffee_trace.gemspec +23 -0
- data/lib/coffee_trace.rb +7 -0
- data/lib/coffee_trace/cli.rb +34 -0
- data/lib/coffee_trace/insert_log_statement.rb +30 -0
- data/lib/coffee_trace/insert_logging.rb +22 -0
- data/lib/coffee_trace/version.rb +3 -0
- data/spec/cli_spec.rb +32 -0
- data/spec/insert_log_statement_spec.rb +56 -0
- data/spec/insert_logging_spec.rb +30 -0
- metadata +94 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2011 Chris Aitchison
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
Coffee Trace
|
2
|
+
============
|
3
|
+
|
4
|
+
A dead simple way to add trace logging to your coffeescript code... and then remove it when you're done.
|
5
|
+
|
6
|
+
To install
|
7
|
+
----------
|
8
|
+
|
9
|
+
gem install coffee_trace
|
10
|
+
|
11
|
+
To turn trace logging on
|
12
|
+
----------------------------------
|
13
|
+
coffee_trace on
|
14
|
+
|
15
|
+
Coffee Trace will find all .coffee files below your current directory and insert a log statement after every method it finds.
|
16
|
+
|
17
|
+
class MyCoffee
|
18
|
+
initialize: (arg1, arg2) ->
|
19
|
+
@doStuff()
|
20
|
+
|
21
|
+
doStuff: ->
|
22
|
+
alert("ok")
|
23
|
+
|
24
|
+
will become
|
25
|
+
|
26
|
+
class MyCoffee
|
27
|
+
initialize: (arg1, arg2) ->
|
28
|
+
console.log "mycoffee-initialize", arg1, arg2 #coffee_trace
|
29
|
+
@doStuff()
|
30
|
+
|
31
|
+
doStuff: ->
|
32
|
+
console.log "mycoffee-doStuff" #coffee_trace
|
33
|
+
alert("ok")
|
34
|
+
|
35
|
+
To turn trace logging off
|
36
|
+
----------------------------------
|
37
|
+
coffee_trace off
|
38
|
+
|
39
|
+
Coffee Trace will remove all log statements that it added to files below the current directory.
|
40
|
+
|
41
|
+
***
|
42
|
+
|
43
|
+
Copyright (c) 2011 Chris Aitchison. See LICENSE for details.
|
44
|
+
|
45
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/bin/coffee_trace
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require "rubygems"
|
3
|
+
require "thor"
|
4
|
+
require "coffee_trace"
|
5
|
+
|
6
|
+
class App < Thor
|
7
|
+
desc "on FILES", "Inserts trace logging into all .coffee files below the current directory"
|
8
|
+
def on
|
9
|
+
CoffeeTrace::CLI.new.insert_logging
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "off", "Removes trace logging all .coffee files below the current directory"
|
13
|
+
def off
|
14
|
+
CoffeeTrace::CLI.new.remove_logging
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
App.start
|
20
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "coffee_trace/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = "coffee_trace"
|
7
|
+
gem.authors = ["Chris Aitchison"]
|
8
|
+
gem.email = ["cmaitchison@gmail.com"]
|
9
|
+
gem.homepage = "https://github.com/cmaitchison/coffee_trace"
|
10
|
+
gem.summary = %q{Add and remove trace logging to coffeescript}
|
11
|
+
gem.description = %q{Add and remove trace logging to coffeescript}
|
12
|
+
|
13
|
+
gem.version = CoffeeTrace::VERSION
|
14
|
+
gem.platform = Gem::Platform::RUBY
|
15
|
+
|
16
|
+
gem.add_runtime_dependency("thor", "~> 0.14.6")
|
17
|
+
gem.add_development_dependency("rspec", "~> 2.6.0")
|
18
|
+
|
19
|
+
gem.files = `git ls-files`.split("\n")
|
20
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
22
|
+
gem.require_paths = ["lib"]
|
23
|
+
end
|
data/lib/coffee_trace.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
module CoffeeTrace
|
2
|
+
class CLI
|
3
|
+
|
4
|
+
def initialize insert_logging=CoffeeTrace::InsertLogging.new
|
5
|
+
@insert_logging = insert_logging
|
6
|
+
@files = Dir.glob "**/*.coffee"
|
7
|
+
end
|
8
|
+
|
9
|
+
def insert_logging
|
10
|
+
@files.each do |file|
|
11
|
+
prefix =File.basename file, ".coffee"
|
12
|
+
result = @insert_logging.into File.readlines(file), prefix
|
13
|
+
write_lines file, result
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def remove_logging
|
18
|
+
@files.each do |file|
|
19
|
+
lines = @insert_logging.into File.readlines(file)
|
20
|
+
result = lines.select do |line|
|
21
|
+
/console\.log.*#coffee_trace.*/.match(line).nil?
|
22
|
+
end
|
23
|
+
write_lines file, result
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def write_lines(path, data)
|
28
|
+
File.open(path, "wb") do |file|
|
29
|
+
file.puts data
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module CoffeeTrace
|
2
|
+
|
3
|
+
class InsertLogStatement
|
4
|
+
|
5
|
+
def for line, prefix=nil
|
6
|
+
leading_spaces, method_name, args = parse_function line
|
7
|
+
return unless leading_spaces
|
8
|
+
method_name = (prefix + "-" + method_name) if prefix
|
9
|
+
result = "#{leading_spaces} console.log '#{method_name}'"
|
10
|
+
result += ", #{args}" if args
|
11
|
+
result += " #coffee_trace"
|
12
|
+
result
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def parse_function line
|
18
|
+
no_arg_function_match = line.scan(/^( *)(\w+): * \(? *\)? *[-=]> *$/)
|
19
|
+
return parse_function_with_args(line) if no_arg_function_match.empty?
|
20
|
+
no_arg_function_match[0]
|
21
|
+
end
|
22
|
+
|
23
|
+
def parse_function_with_args line
|
24
|
+
arg_function_match = line.scan(/^( *)(\w+): *\((.*)\) *[-=]> *$/)
|
25
|
+
return if arg_function_match.empty?
|
26
|
+
return arg_function_match[0]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module CoffeeTrace
|
2
|
+
class InsertLogging
|
3
|
+
|
4
|
+
def initialize insert_log_statement=CoffeeTrace::InsertLogStatement.new
|
5
|
+
@insert_log_statement = insert_log_statement
|
6
|
+
end
|
7
|
+
|
8
|
+
def into lines, prefix=nil
|
9
|
+
result = []
|
10
|
+
lines.each do |line|
|
11
|
+
result.pop if is_coffee_trace_log?(line)
|
12
|
+
result << line
|
13
|
+
result << (@insert_log_statement.for line, prefix)
|
14
|
+
end
|
15
|
+
result.compact
|
16
|
+
end
|
17
|
+
|
18
|
+
def is_coffee_trace_log? line
|
19
|
+
return true if /#coffee_trace$/.match line
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/spec/cli_spec.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'coffee_trace'
|
2
|
+
|
3
|
+
describe CoffeeTrace::CLI do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@insert_logging = CoffeeTrace::InsertLogging.new
|
7
|
+
Dir.should_receive(:glob).with("**/*.coffee").and_return(["a.coffee","b.coffee"])
|
8
|
+
@cli = CoffeeTrace::CLI.new @insert_logging
|
9
|
+
end
|
10
|
+
|
11
|
+
it "inserts logging into each file" do
|
12
|
+
file1 = ["a","b"]
|
13
|
+
file2 = ["c","d"]
|
14
|
+
File.should_receive(:readlines).with("a.coffee").and_return(file1)
|
15
|
+
File.should_receive(:readlines).with("b.coffee").and_return(file2)
|
16
|
+
@insert_logging.should_receive(:into).with(file1,"a").and_return(["z","y"])
|
17
|
+
@insert_logging.should_receive(:into).with(file2,"b").and_return(["w","x"])
|
18
|
+
@cli.should_receive(:write_lines).with("a.coffee",["z","y"])
|
19
|
+
@cli.should_receive(:write_lines).with("b.coffee",["w","x"])
|
20
|
+
@cli.insert_logging
|
21
|
+
end
|
22
|
+
|
23
|
+
it "removes logging from each file" do
|
24
|
+
file1 = ["a","b","console.log blah #coffee_trace"]
|
25
|
+
file2 = ["c","console.log blahblah #coffee_trace", "d"]
|
26
|
+
File.should_receive(:readlines).with("a.coffee").and_return(file1)
|
27
|
+
File.should_receive(:readlines).with("b.coffee").and_return(file2)
|
28
|
+
@cli.should_receive(:write_lines).with("a.coffee",["a","b"])
|
29
|
+
@cli.should_receive(:write_lines).with("b.coffee",["c","d"])
|
30
|
+
@cli.remove_logging
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'coffee_trace'
|
2
|
+
|
3
|
+
describe CoffeeTrace::InsertLogStatement do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@insert_log_statement = CoffeeTrace::InsertLogStatement.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns nil if line is not a function" do
|
10
|
+
assert "some code", nil
|
11
|
+
assert " more code", nil
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns a log statement for a function with no arguments" do
|
15
|
+
assert " initialize: ->", " console.log 'initialize' #coffee_trace"
|
16
|
+
assert " render: ->", " console.log 'render' #coffee_trace"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns a log statement for a function with arguments" do
|
20
|
+
assert " doStuff: (arg1, arg2, arg3) ->", " console.log 'doStuff', arg1, arg2, arg3 #coffee_trace"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "returns a correct log statement for a function with an empty arguments list" do
|
24
|
+
assert " doStuff: () ->", " console.log 'doStuff' #coffee_trace"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "returns a log statement for a fat arrow function" do
|
28
|
+
assert " doStuff: (arg1, arg2, arg3) =>", " console.log 'doStuff', arg1, arg2, arg3 #coffee_trace"
|
29
|
+
assert " initialize: =>", " console.log 'initialize' #coffee_trace"
|
30
|
+
assert " placeSelectedHandler: (e, placeId) =>", " console.log 'placeSelectedHandler', e, placeId #coffee_trace"
|
31
|
+
assert " renderPoi: (poi) =>", " console.log 'renderPoi', poi #coffee_trace"
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
it "handles trailing spaces" do
|
36
|
+
assert " initialize: -> ", " console.log 'initialize' #coffee_trace"
|
37
|
+
end
|
38
|
+
|
39
|
+
it "adds a prefix if given" do
|
40
|
+
assert_with_prefix " initialize: -> ","trace_logger"," console.log 'trace_logger-initialize' #coffee_trace"
|
41
|
+
end
|
42
|
+
it "indents correctly" do
|
43
|
+
assert "a: ->", " console.log 'a' #coffee_trace"
|
44
|
+
assert " a: ->", " console.log 'a' #coffee_trace"
|
45
|
+
assert " a: ->", " console.log 'a' #coffee_trace"
|
46
|
+
assert " a: ->", " console.log 'a' #coffee_trace"
|
47
|
+
end
|
48
|
+
|
49
|
+
def assert line, expected_value
|
50
|
+
@insert_log_statement.for(line).should == expected_value
|
51
|
+
end
|
52
|
+
|
53
|
+
def assert_with_prefix line, prefix, expected_value
|
54
|
+
@insert_log_statement.for(line, prefix).should == expected_value
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'coffee_trace'
|
2
|
+
|
3
|
+
describe CoffeeTrace::InsertLogging do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@insert_log_statement = "insert_log_statement"
|
7
|
+
@insert_logging = CoffeeTrace::InsertLogging.new @insert_log_statement
|
8
|
+
@insert_log_statement.should_receive(:for).with("line1", "prefix").and_return(nil)
|
9
|
+
@insert_log_statement.should_receive(:for).with("line2", "prefix").and_return("prefix-log1")
|
10
|
+
@insert_log_statement.should_receive(:for).with("line3", "prefix").and_return(nil)
|
11
|
+
@insert_log_statement.should_receive(:for).with("line4", "prefix").and_return("prefix-log2")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "inserts a logging line after each function" do
|
15
|
+
lines = ["line1", "line2", "line3","line4"]
|
16
|
+
|
17
|
+
result = @insert_logging.into lines, "prefix"
|
18
|
+
result.should ==
|
19
|
+
["line1","line2","prefix-log1","line3","line4","prefix-log2"]
|
20
|
+
end
|
21
|
+
|
22
|
+
it "does not add a log statement for a method if it already has a coffee_trace log statement" do
|
23
|
+
lines = ["line1", "line2", "line3","line4","console.log #coffee_trace"]
|
24
|
+
@insert_log_statement.should_receive(:for).with("console.log #coffee_trace", "prefix").and_return(nil)
|
25
|
+
result = @insert_logging.into lines, "prefix"
|
26
|
+
result.should ==
|
27
|
+
["line1","line2","prefix-log1","line3","line4","console.log #coffee_trace"]
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: coffee_trace
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.2
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Chris Aitchison
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-06-12 00:00:00 +10:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: thor
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ~>
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.14.6
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ~>
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 2.6.0
|
36
|
+
type: :development
|
37
|
+
version_requirements: *id002
|
38
|
+
description: Add and remove trace logging to coffeescript
|
39
|
+
email:
|
40
|
+
- cmaitchison@gmail.com
|
41
|
+
executables:
|
42
|
+
- coffee_trace
|
43
|
+
extensions: []
|
44
|
+
|
45
|
+
extra_rdoc_files: []
|
46
|
+
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- bin/coffee_trace
|
54
|
+
- coffee_trace.gemspec
|
55
|
+
- lib/coffee_trace.rb
|
56
|
+
- lib/coffee_trace/cli.rb
|
57
|
+
- lib/coffee_trace/insert_log_statement.rb
|
58
|
+
- lib/coffee_trace/insert_logging.rb
|
59
|
+
- lib/coffee_trace/version.rb
|
60
|
+
- spec/cli_spec.rb
|
61
|
+
- spec/insert_log_statement_spec.rb
|
62
|
+
- spec/insert_logging_spec.rb
|
63
|
+
has_rdoc: true
|
64
|
+
homepage: https://github.com/cmaitchison/coffee_trace
|
65
|
+
licenses: []
|
66
|
+
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: "0"
|
84
|
+
requirements: []
|
85
|
+
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 1.6.2
|
88
|
+
signing_key:
|
89
|
+
specification_version: 3
|
90
|
+
summary: Add and remove trace logging to coffeescript
|
91
|
+
test_files:
|
92
|
+
- spec/cli_spec.rb
|
93
|
+
- spec/insert_log_statement_spec.rb
|
94
|
+
- spec/insert_logging_spec.rb
|