augment 1.0.0

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.
@@ -0,0 +1,8 @@
1
+ class Frontend
2
+ class << self
3
+ def run(file)
4
+ # TODO: deal with overlapping color ranges
5
+ Layer.read(file).inject(File.read(file)) { |text, layer| process_layer(text, layer) }
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,28 @@
1
+ class String
2
+ def html_colorize(color)
3
+ "<span style='color: #{color};'>#{self}</span>"
4
+ end
5
+
6
+ def html_colorize_range(range, color)
7
+ "#{self[0 ... range.begin]}#{self[range].html_colorize(color)}#{self[range.end .. -1]}"
8
+ end
9
+ end
10
+
11
+ class HtmlFrontend < Frontend
12
+ class << self
13
+ def run(file)
14
+ puts "<html>
15
+ <head><title>#{file} - Augment</title></head>
16
+ <body>
17
+ #{super(file).gsub("\n", "<br />").gsub(' ', '&nbsp; ')}
18
+ </body>
19
+ </html>"
20
+ end
21
+
22
+ def process_layer(text, layer)
23
+ text.html_colorize_range(layer['range'], layer['color'])
24
+ end
25
+ end
26
+ end
27
+
28
+ Augment::FRONTENDS['html'] = HtmlFrontend
@@ -0,0 +1,27 @@
1
+ require 'json'
2
+
3
+ class Layer
4
+ def initialize(range, color, message, backend)
5
+ range = (range.split('...').first.to_i ... range.split('...').last.to_i) if range.is_a? String
6
+ @attrs = { 'range' => range, 'color' => color, 'message' => message,
7
+ 'backend' => backend.to_s.downcase.gsub(/backend/, '')}
8
+ end
9
+
10
+ def self.read(original_file)
11
+ JSON.parse(File.read(Augment.augment_path(original_file))).map{ |l| Layer.new(l['range'], l['color'], l['message'], l['backend']) }.sort_by{ |l| l['range'].begin }.reverse
12
+ end
13
+
14
+ def self.line_to_char_range(file, line)
15
+ file = File.read(file).split("\n")
16
+ start = file[0 ... line - 1].join("\n").size + 2
17
+ (start ... start + file[line - 1].size)
18
+ end
19
+
20
+ def to_json
21
+ @attrs.to_json
22
+ end
23
+
24
+ def [](attr)
25
+ @attrs[attr]
26
+ end
27
+ end
@@ -0,0 +1,26 @@
1
+ $LOAD_PATH << File.dirname(__FILE__)
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Frontend, " when outputting ANSI color" do
6
+ before do
7
+ FileUtils.cd(PROJECT_ROOT)
8
+ FileUtils.rm_r('lib/.augment') rescue nil
9
+ FileUtils.rm_r('test/.augment') rescue nil
10
+
11
+ ColoringBackend.run('lib/drink.rb')
12
+ TestUnitBackend.run('test/test_drink.rb')
13
+ end
14
+
15
+ it "should color red as red" do
16
+ output = `../../../bin/augment ansi #{PROJECT_ROOT}/lib/drink.rb`
17
+ output.to_s.should include("#{'white'.colorize('white')}")
18
+ output.to_s.should include("#{'red'.colorize('red')}")
19
+ end
20
+
21
+ it "should color the test_drink" do
22
+ output = `../../../bin/augment ansi #{PROJECT_ROOT}/test/test_drink.rb`
23
+ output.to_s.should match(/\e\[#{String::COLOR_LOOKUP['red']}m *assert/)
24
+ output.to_s.should match(/\e\[#{String::COLOR_LOOKUP['yellow']}m *junk/)
25
+ end
26
+ end
@@ -0,0 +1,32 @@
1
+ $LOAD_PATH << File.dirname(__FILE__)
2
+ require 'spec_helper'
3
+
4
+ describe Backend, " when augmenting by color" do
5
+ before do
6
+ FileUtils.cd(PROJECT_ROOT)
7
+ FileUtils.rm_r('lib/.augment') rescue nil
8
+
9
+ ColoringBackend.run('lib/drink.rb')
10
+ end
11
+
12
+ it "should create .augment directory and files" do
13
+ File.should exist('lib/.augment')
14
+ File.should exist('lib/.augment/drink.rb')
15
+ end
16
+
17
+ it "should color the colors and ranges" do
18
+ layers = Layer.read('lib/drink.rb')
19
+ layers.size.should == 4
20
+
21
+ layers[0]['color'].should == 'black'
22
+ layers[1]['color'].should == 'green'
23
+ layers[2]['color'].should == 'red'
24
+ layers[3]['color'].should == 'white'
25
+
26
+ layers[0]['range'].should == (531 ... 536)
27
+ layers[1]['range'].should == (456 ... 461)
28
+ layers[2]['range'].should == (371 ... 374)
29
+ layers[3]['range'].should == (221 ... 226)
30
+ layers.map{ |l| l['backend'] }.uniq.should == ['coloring']
31
+ end
32
+ end
@@ -0,0 +1,63 @@
1
+ ;;; augment.el --- Display metadata about code
2
+
3
+ ;; Copyright (C) 2007 Phil Hagelberg
4
+
5
+ ;; Author: Phil Hagelberg <technomancy@gmail.com>
6
+ ;; Created: 19 Oct 2007
7
+ ;; Version: 0.1
8
+ ;; Keywords: augment testing metadata
9
+
10
+ ;; This file is part of the Augment system:
11
+ ;; http://augment.rubyforge.org
12
+
13
+ (require 'elunit) ;; See http://www.emacswiki.org/cgi-bin/wiki/ElUnit
14
+ (require 'augment)
15
+ (require 'flymake)
16
+
17
+ ;; in case it hasn't been properly installed
18
+ (add-to-list 'exec-path (expand-file-name "../bin"))
19
+
20
+ (elunit-clear-suites)
21
+ (defsuite augment-suite nil)
22
+
23
+ (deftest layer-from-plist augment-suite
24
+ "The layer struct should populated from a plist."
25
+ (let ((layer (augment-layer-from-plist (list :message "message" :color "color"
26
+ :range "221...226"))))
27
+ (assert-equal 221 (layer-begin layer))
28
+ (assert-equal 226 (layer-end layer))
29
+ (assert-equal "color" (layer-color layer))
30
+ (assert-equal "message" (layer-message layer))))
31
+
32
+ (deftest augment-file-path augment-suite
33
+ (assert-equal "/foo/bar/.augment/baz.rb" (augment-file-path "/foo/bar/baz.rb")))
34
+
35
+ (deftest render-layers augment-suite
36
+ "Rendering layers should create overlays in a buffer."
37
+ (with-test-buffer
38
+ ;; Fill the buffer with some garbage
39
+ (dotimes (i 5) (insert "hello world.\n"))
40
+ (augment-render-layer (augment-layer-from-plist (list :message "hello"
41
+ :color "red"
42
+ :range "0...10")))
43
+ (assert-overlay 1)
44
+ (assert-overlay 9)))
45
+
46
+ (deftest layer-message augment-suite
47
+ "Finding message at point should get the message of the layer the point is in."
48
+ (let* ((json-object-type 'plist)
49
+ (json-array-type 'list)
50
+ (layers (mapcar #'augment-layer-from-plist
51
+ (json-read-file "fixtures/layers.json"))))
52
+ (assert-equal "cons" (augment-message-at-point 5))
53
+ (assert-equal "car" (augment-message-at-point 16))
54
+ (assert-equal "cdr" (augment-message-at-point 29))))
55
+
56
+ (deftest augment-filter augment-suite
57
+ (with-test-buffer
58
+ (make-local-variable 'layers)
59
+ (dotimes (i 3) (insert "hello world\n"))
60
+ (augment-filter nil (flymake-read-file-to-string "fixtures/augment-output.txt"))
61
+ (assert-overlay 2)))
62
+
63
+ (elunit "augment-suite")
@@ -0,0 +1,3 @@
1
+ {"/home/phil/*elunit-output*":[{"message":"cons", "color":"red", "range":"1...12"},
2
+ {"message":"car", "color":"green", "range":"13...24"},
3
+ {"message":"cdr", "color":"blue", "range":"25...36"}]}
@@ -0,0 +1,15 @@
1
+ class Drink
2
+ attr_accessor :name, :proof, :color
3
+
4
+ def initialize args
5
+ @name = args[:name]
6
+ @proof = args[:proof]
7
+ @color = args[:color]
8
+ end
9
+ end
10
+
11
+ Vodka = Drink.new :name => 'Vodka', :proof => 80, :color => 'white'
12
+ Kahlua = Drink.new :name => 'Kahlua', :proof => 40, :color => 'brown'
13
+ TomatoJuice = Drink.new :name => 'Tomato Juice', :proof => 0, :color => 'red'
14
+ MikesHardLime = Drink.new :name => 'Mike\'s Hard Lime', :proof => 8, :color => 'green'
15
+ Jager = Drink.new :name => 'Jagermeister', :proof => 40, :color => 'black'
@@ -0,0 +1,19 @@
1
+ require 'test/unit'
2
+
3
+ class SampleTest < Test::Unit::TestCase
4
+ def test_might_error
5
+ junk.foo
6
+ end
7
+
8
+ def test_should_pass_longer
9
+ foo = 2 + 0
10
+ assert_equal 2, foo
11
+ assert_match /foo(.*)/, "foobarbunkle"
12
+ end
13
+
14
+ def test_will_fail
15
+ a = "hello world"
16
+ a.split(' ')
17
+ assert_equal 88, a.length, "bad length"
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ [{"message":"cons", "color":"red", "range":"1...12"},
2
+ {"message":"car", "color":"green", "range":"13...24"},
3
+ {"message":"cdr", "color":"blue", "range":"25...36"}]
@@ -0,0 +1,24 @@
1
+ $LOAD_PATH << File.dirname(__FILE__)
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Frontend, " when outputting HTML" do
6
+ before do
7
+ FileUtils.cd(PROJECT_ROOT)
8
+ FileUtils.rm_r('lib/.augment') rescue nil
9
+ ColoringBackend.run('lib/drink.rb')
10
+ end
11
+
12
+ it "should create styled spans around colors" do
13
+ output = `../../../bin/augment html #{PROJECT_ROOT}/lib/drink.rb`
14
+ output.to_s.should include("<span style='color: white;'>white</span>")
15
+ end
16
+ end
17
+
18
+ describe Layer, " when converting line range to char range" do
19
+ it "should convert properly" do
20
+ Layer.line_to_char_range('test/test_drink.rb', 10).should == (153 ... 176)
21
+ Layer.line_to_char_range('test/test_drink.rb', 3).should == (22 ... 61)
22
+ Layer.line_to_char_range('test/test_drink.rb', 17).should == (289 ... 332)
23
+ end
24
+ end
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH << File.dirname(__FILE__) + '/../lib'
2
+ require 'augment'
3
+
4
+ PROJECT_ROOT = File.expand_path(File.dirname(__FILE__) + '/fixtures/drinks/') unless defined? PROJECT_ROOT
@@ -0,0 +1,28 @@
1
+ $LOAD_PATH << File.dirname(__FILE__)
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Backend, " when augmenting test results" do
6
+ before do
7
+ FileUtils.cd(PROJECT_ROOT)
8
+ FileUtils.rm_r('test/.augment') rescue nil
9
+
10
+ TestUnitBackend.run('test/test_drink.rb')
11
+ end
12
+
13
+ it "should color failing/erroring tests" do
14
+ File.should exist(Augment.augment_path('test/test_drink.rb'))
15
+ layers = Layer.read('test/test_drink.rb')
16
+ layers.first['color'].should == 'red'
17
+ layers.last['color'].should == 'yellow'
18
+
19
+ layers.first['range'].should == (289 ... 332)
20
+ end
21
+
22
+ it "should include failure message" do
23
+ layers = Layer.read('test/test_drink.rb')
24
+ layers.first['message'].should =~ /bad length/
25
+ layers.last['message'].should =~ /undefined local variable or method/
26
+ layers.map{ |l| l['backend'] }.uniq.should == ['testunit']
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.2
3
+ specification_version: 1
4
+ name: augment
5
+ version: !ruby/object:Gem::Version
6
+ version: 1.0.0
7
+ date: 2007-10-27 00:00:00 -07:00
8
+ summary: Augment is a system for collecting and displaying code metadata.
9
+ require_paths:
10
+ - lib
11
+ email: technomancy@gmail.com
12
+ homepage: " by Phil Hagelberg (c) 2007"
13
+ rubyforge_project: augment
14
+ description: "== Usage The +augment+ executable gathers metadata in the form of layers for a given file via a backend. Some backends gather data for a file other than the original one passed in. (The test backend will store data for the test if you pass in the implementation.) Example: $ augment test lib/foo.rb # will store metadata for test/test_foo.rb"
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Phil Hagelberg
31
+ files:
32
+ - COPYING
33
+ - TODO
34
+ - History.txt
35
+ - Manifest.txt
36
+ - README.txt
37
+ - Rakefile
38
+ - bin/augment
39
+ - lib/augment.rb
40
+ - lib/layer.rb
41
+ - lib/flet.rb
42
+ - lib/backends/backend.rb
43
+ - lib/backends/coloring_backend.rb
44
+ - lib/backends/test_unit_backend.rb
45
+ - lib/frontends/frontend.rb
46
+ - lib/frontends/ansi_color_frontend.rb
47
+ - lib/frontends/html_frontend.rb
48
+ - lib/frontends/augment.el
49
+ - spec/ansi_frontend_spec.rb
50
+ - spec/color_backend_spec.rb
51
+ - spec/emacs-frontend-test.el
52
+ - spec/html_frontend_spec.rb
53
+ - spec/spec_helper.rb
54
+ - spec/test_backend_spec.rb
55
+ - spec/fixtures/augment-output.txt
56
+ - spec/fixtures/layers.json
57
+ - spec/fixtures/drinks/lib/drink.rb
58
+ - spec/fixtures/drinks/test/test_drink.rb
59
+ test_files: []
60
+
61
+ rdoc_options:
62
+ - --main
63
+ - README.txt
64
+ extra_rdoc_files:
65
+ - History.txt
66
+ - Manifest.txt
67
+ - README.txt
68
+ - spec/fixtures/augment-output.txt
69
+ executables:
70
+ - augment
71
+ extensions: []
72
+
73
+ requirements: []
74
+
75
+ dependencies:
76
+ - !ruby/object:Gem::Dependency
77
+ name: miniunit
78
+ version_requirement:
79
+ version_requirements: !ruby/object:Gem::Version::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: 1.0.1
84
+ version:
85
+ - !ruby/object:Gem::Dependency
86
+ name: json
87
+ version_requirement:
88
+ version_requirements: !ruby/object:Gem::Version::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 1.1.1
93
+ version:
94
+ - !ruby/object:Gem::Dependency
95
+ name: hoe
96
+ version_requirement:
97
+ version_requirements: !ruby/object:Gem::Version::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: 1.2.2
102
+ version: