pdd 0.12 → 0.13
Sign up to get free protection for your applications and to get access to all the features.
- data/assets/puzzles.xsd +15 -0
- data/lib/pdd/source.rb +23 -1
- data/lib/pdd/version.rb +1 -1
- data/test/test_pdd.rb +28 -0
- data/test/test_source.rb +24 -0
- metadata +2 -2
data/assets/puzzles.xsd
CHANGED
@@ -66,6 +66,21 @@
|
|
66
66
|
</xs:restriction>
|
67
67
|
</xs:simpleType>
|
68
68
|
</xs:element>
|
69
|
+
<xs:element name="author" minOccurs="0">
|
70
|
+
<xs:simpleType>
|
71
|
+
<xs:restriction base="xs:string">
|
72
|
+
<xs:pattern value=".+"/>
|
73
|
+
</xs:restriction>
|
74
|
+
</xs:simpleType>
|
75
|
+
</xs:element>
|
76
|
+
<xs:element name="email" minOccurs="0">
|
77
|
+
<xs:simpleType>
|
78
|
+
<xs:restriction base="xs:string">
|
79
|
+
<xs:pattern value=".+"/>
|
80
|
+
</xs:restriction>
|
81
|
+
</xs:simpleType>
|
82
|
+
</xs:element>
|
83
|
+
<xs:element name="time" minOccurs="0" type="xs:dateTime"/>
|
69
84
|
</xs:all>
|
70
85
|
</xs:complexType>
|
71
86
|
<xs:element name="puzzles">
|
data/lib/pdd/source.rb
CHANGED
@@ -81,7 +81,7 @@ module PDD
|
|
81
81
|
lines: "#{idx + 1}-#{idx + tail.size + 1}",
|
82
82
|
body: body,
|
83
83
|
file: @path
|
84
|
-
)
|
84
|
+
).merge(git(idx + 1))
|
85
85
|
)
|
86
86
|
end
|
87
87
|
|
@@ -95,6 +95,28 @@ module PDD
|
|
95
95
|
.each { |txt| fail Error, 'Too many spaces' if txt =~ /^\s{2,}/ }
|
96
96
|
.map { |txt| txt[1, txt.length] }
|
97
97
|
end
|
98
|
+
|
99
|
+
# Git information at the line
|
100
|
+
def git(pos)
|
101
|
+
cmd = [
|
102
|
+
"cd #{File.dirname(@file)}",
|
103
|
+
"git blame -L #{pos},#{pos} --porcelain #{File.basename(@file)}"
|
104
|
+
].join(' && ')
|
105
|
+
Hash[
|
106
|
+
`#{cmd}`.split("\n").map do |line|
|
107
|
+
if line =~ /^author /
|
108
|
+
[:author, line.sub(/^author /, '')]
|
109
|
+
elsif line =~ /^author-mail /
|
110
|
+
[:email, line.sub(/^author-mail <(.+)>$/, '\1')]
|
111
|
+
elsif line =~ /^author-time /
|
112
|
+
[
|
113
|
+
:time,
|
114
|
+
Time.at(line.sub(/^author-time ([0-9]+)$/, '\1').to_i).iso8601
|
115
|
+
]
|
116
|
+
end
|
117
|
+
end.compact
|
118
|
+
]
|
119
|
+
end
|
98
120
|
end
|
99
121
|
|
100
122
|
# Verbose Source.
|
data/lib/pdd/version.rb
CHANGED
data/test/test_pdd.rb
CHANGED
@@ -59,6 +59,34 @@ class TestPDD < Minitest::Test
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
+
def test_git_repo
|
63
|
+
Dir.mktmpdir 'test' do |dir|
|
64
|
+
opts = opts(['-v', '-s', dir])
|
65
|
+
fail unless system("
|
66
|
+
set -e
|
67
|
+
cd '#{dir}'
|
68
|
+
git init .
|
69
|
+
git config user.email test@teamed.io
|
70
|
+
git config user.name 'Mr. Tester'
|
71
|
+
echo '@todo #1 this is the puzzle' > x.txt
|
72
|
+
git add x.txt
|
73
|
+
git commit -am 'first version'
|
74
|
+
")
|
75
|
+
matches(
|
76
|
+
Nokogiri::XML(PDD::Base.new(opts).xml),
|
77
|
+
[
|
78
|
+
'/puzzles[count(puzzle)=1]',
|
79
|
+
'/puzzles/puzzle[file="x.txt"]',
|
80
|
+
'/puzzles/puzzle[author="Mr. Tester"]',
|
81
|
+
'/puzzles/puzzle[email="test@teamed.io"]',
|
82
|
+
'/puzzles/puzzle[time]'
|
83
|
+
]
|
84
|
+
)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
89
|
+
|
62
90
|
def opts(args)
|
63
91
|
Slop.parse args do
|
64
92
|
on 'v', 'verbose'
|
data/test/test_source.rb
CHANGED
@@ -69,4 +69,28 @@ class TestSources < Minitest::Test
|
|
69
69
|
assert !error.message.index('Space expected').nil?
|
70
70
|
end
|
71
71
|
end
|
72
|
+
|
73
|
+
def test_reads_git_author
|
74
|
+
Dir.mktmpdir 'test' do |dir|
|
75
|
+
fail unless system("
|
76
|
+
set -e
|
77
|
+
cd '#{dir}'
|
78
|
+
git init .
|
79
|
+
git config user.email test@teamed.io
|
80
|
+
git config user.name test
|
81
|
+
echo '@todo #1 this is the puzzle' > a.txt
|
82
|
+
git add a.txt
|
83
|
+
git commit -am 'first version'
|
84
|
+
git blame a.txt
|
85
|
+
")
|
86
|
+
list = PDD::Source.new(File.join(dir, 'a.txt'), '').puzzles
|
87
|
+
assert_equal 1, list.size
|
88
|
+
puzzle = list.first
|
89
|
+
assert_equal '1-1', puzzle.props[:lines]
|
90
|
+
assert_equal 'this is the puzzle', puzzle.props[:body]
|
91
|
+
assert_equal 'test', puzzle.props[:author]
|
92
|
+
assert_equal 'test@teamed.io', puzzle.props[:email]
|
93
|
+
assert !puzzle.props[:time].nil?
|
94
|
+
end
|
95
|
+
end
|
72
96
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pdd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.13'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-01-
|
12
|
+
date: 2015-01-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|