codetip 0.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA512:
3
+ metadata.gz: 932c7adb27dfce4b897e89aa2f9cceb52f53b0b63081097b503e59e24dce949d10fa3ea6d6309f0722d7625ebd4f493e2330d2423c8a4c09d64e26febd838511
4
+ data.tar.gz: 137dc195207ec6f2d7aa1f37934eaf5ceb7687cc6bc87fdc117158ec111dbd3f5b144db995f4dd5b9130680ec5787e247b2ec1fc87145b3c360d5fc1164c2090
5
+ SHA1:
6
+ metadata.gz: ce4611e3690f82ba65441a14886b869e3c8906d2
7
+ data.tar.gz: 504664439222ee8c48b3f01042cefd5fc1d01e41
data/bin/codetip ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # for testing from bin
4
+ def fallback_load_path(path)
5
+ retried = false
6
+ begin
7
+ yield
8
+ rescue LoadError
9
+ unless retried
10
+ $: << path
11
+ retried = true
12
+ retry
13
+ end
14
+ raise
15
+ end
16
+ end
17
+ fallback_load_path(File.join(File.dirname(__FILE__), '..', 'lib')) do
18
+ require 'codetip/app/commander'
19
+ end
20
+
21
+ com = Codetip::Commander.new
22
+ com.run(ARGV);
@@ -0,0 +1,32 @@
1
+ module Codetip
2
+ class App
3
+ def parse(path, restrict = '*', user = nil)
4
+ result = {}
5
+ Dir.glob(path + '/**/' + restrict) do |filename|
6
+ if File.file?(filename)
7
+ comments = {}
8
+ lineNumber = 1
9
+ File.readlines(filename).each do |line|
10
+ if line.match(/\[(todo|warning|review)\](\s*[:-]+\s*(.+))$/i)
11
+ type = $1.downcase
12
+ message = $3
13
+ next if (!user.nil? && !line.downcase.match(Regexp.new('@('+user.downcase + '|all)')))
14
+ (comments[type] ||= []) << {
15
+ :line => lineNumber,
16
+ :message => message
17
+ }
18
+ end
19
+ lineNumber += 1
20
+ end
21
+ if (comments.count > 0)
22
+ result[filename] = comments
23
+ end
24
+ end
25
+ end
26
+ return result
27
+ end
28
+ end
29
+ end
30
+
31
+
32
+
@@ -0,0 +1,87 @@
1
+ require 'codetip/app'
2
+
3
+ class String
4
+ def black; "\033[30m#{self}\033[0m" end
5
+ def red; "\033[31m#{self}\033[0m" end
6
+ def green; "\033[32m#{self}\033[0m" end
7
+ def blue; "\033[34m#{self}\033[0m" end
8
+ def gray; "\033[37m#{self}\033[0m" end
9
+ def bold; "\033[1m#{self}\033[22m" end
10
+ def highlightMessage
11
+ self.gsub(/(@\w+)/, '\1'.bold)
12
+ end
13
+ end
14
+
15
+ module Codetip
16
+ class Commander < App
17
+ def run(argv = ARGV)
18
+ begin
19
+ opts = {}
20
+ if argv.length > 0
21
+ loop {
22
+ case argv[0]
23
+ # -h or --help
24
+ when /^-(h|-help)$/i then
25
+ argv.shift
26
+
27
+ puts "Usage: codetip [options] <location>"
28
+ puts
29
+ puts "Options:"
30
+ puts "\t-h, --help\tDisplays what you are looking at"
31
+ puts "\t-r, --restrict\tRestrict file search. e.g, '.js' or '*.{js,cpp}'"
32
+ puts "\t-u, --username\tOnly display comments mentioning username"
33
+ puts
34
+ puts "Example:"
35
+ puts "\tcodetip --user='kurt_wagner' -r '*.{js,pl}' ~/path/to/project"
36
+ puts
37
+
38
+ return
39
+
40
+ # -r or --restrict
41
+ when /^-(r|-opts[:restrict])(=(.+))?$/i then
42
+ if !$3.nil?
43
+ opts[:restrict] = $3
44
+ argv.shift
45
+ else
46
+ argv.shift
47
+ opts[:restrict] = argv.shift
48
+ end
49
+ # -u or --username
50
+ when /^-(u|-username)(=(.+))?$/i then
51
+ if !$3.nil?
52
+ opts[:username] = $3
53
+ argv.shift
54
+ else
55
+ argv.shift
56
+ opts[:username] = argv.shift
57
+ end
58
+ # other unknown options
59
+ when /^-/ then
60
+ puts "Unknown option: #{argv.shift}"
61
+ else
62
+ # remove any trailing forward slashes from directory
63
+ directory = argv.shift
64
+ opts[:path] = directory.gsub(/\/+$/, '') if !directory.nil?
65
+ break
66
+ end
67
+ }
68
+ end
69
+
70
+ parse(opts[:path] || '.', opts[:restrict] || "*", opts[:username]).each do |filename, types|
71
+ puts filename.red.bold;
72
+ types.each do |type, comments|
73
+ if comments.count > 0
74
+ puts "[ #{type.upcase} ]".blue.bold
75
+ comments.each do |comment|
76
+ puts " Line #{comment[:line]} - ".gray + comment[:message].highlightMessage
77
+ end
78
+ puts
79
+ end
80
+ end
81
+ end
82
+ rescue Exception => e
83
+ puts e.message
84
+ end
85
+ end
86
+ end
87
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: codetip
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kurt Wagner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2013-11-24 00:00:00 Z
13
+ dependencies: []
14
+
15
+ description: Generate a summary of a projects comments.
16
+ email: krw521@uowmail.edu.au
17
+ executables:
18
+ - codetip
19
+ extensions: []
20
+
21
+ extra_rdoc_files: []
22
+
23
+ files:
24
+ - lib/codetip/app.rb
25
+ - lib/codetip/app/commander.rb
26
+ - bin/codetip
27
+ homepage: http://rubygems.org/gems/codetip
28
+ licenses:
29
+ - GPL-2
30
+ metadata: {}
31
+
32
+ post_install_message:
33
+ rdoc_options: []
34
+
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - &id001
40
+ - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: "0"
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - *id001
46
+ requirements: []
47
+
48
+ rubyforge_project:
49
+ rubygems_version: 2.0.3
50
+ signing_key:
51
+ specification_version: 4
52
+ summary: Code Summary Generator
53
+ test_files: []
54
+