oreilly-snippets 0.0.6 → 0.0.7
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 +4 -4
- data/lib/oreilly/snippets.rb +26 -12
- data/lib/oreilly/snippets/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 699d24e1d89e9d93b3d5dd37feda9ee4c74dd868
|
4
|
+
data.tar.gz: 9039ca84bd421dc8a8c7d51554dfe4fc715cb53e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7d2d7e190256cf14cb906686d6b3f184bece1217d4778730e380cff0f8e2f576b2a23daf86b4728ee1833c295617b6d22e40c0f585830c9e4fa534dd7b2b1e0
|
7
|
+
data.tar.gz: fb09be7dcd0200acfa0f8d76208731c97d1c0d36455390b49d286f9197f36ef4a45a12202439b8f391aadc0c235dcbe1ff5e435061f166cf33f36948e97b7f79
|
data/lib/oreilly/snippets.rb
CHANGED
@@ -6,12 +6,6 @@ COMMENTS = {
|
|
6
6
|
:python => "#"
|
7
7
|
}
|
8
8
|
|
9
|
-
class String
|
10
|
-
def unindent
|
11
|
-
gsub(/^#{scan(/^\s*/).min_by{|l|l.length}}/, "")
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
9
|
module Oreilly
|
16
10
|
module Snippets
|
17
11
|
|
@@ -36,11 +30,10 @@ module Oreilly
|
|
36
30
|
contents = "PLACEHOLDER TEXT, UPDATE WITH CORRECT SHA HASH"
|
37
31
|
else
|
38
32
|
# Use the filename to change into the directory and use git-show
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
33
|
+
spec = "." unless spec
|
34
|
+
Dir.chdir spec do
|
35
|
+
contents = `git show #{sha}`
|
36
|
+
error = true unless contents
|
44
37
|
end
|
45
38
|
end
|
46
39
|
else
|
@@ -63,7 +56,7 @@ module Oreilly
|
|
63
56
|
end
|
64
57
|
|
65
58
|
if flatten or @@_config[:flatten]
|
66
|
-
rv = rv
|
59
|
+
rv = flatten_it( rv )
|
67
60
|
end
|
68
61
|
|
69
62
|
rv = "INVALID SNIPPET, WARNING" if error
|
@@ -71,6 +64,27 @@ module Oreilly
|
|
71
64
|
rv
|
72
65
|
end
|
73
66
|
|
67
|
+
def self.flatten_it( content )
|
68
|
+
# find the smallest indent level, and then strip that off the beginning of all lines
|
69
|
+
smallest = nil
|
70
|
+
lines = content.split "\n"
|
71
|
+
lines.each do |l|
|
72
|
+
if l =~ /^(\s+)/
|
73
|
+
if smallest
|
74
|
+
if $1.length < smallest.length
|
75
|
+
smallest = $1
|
76
|
+
end
|
77
|
+
else
|
78
|
+
smallest = $1
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
replaced = content.gsub( /^#{smallest}/, '' )
|
84
|
+
replaced
|
85
|
+
end
|
86
|
+
|
87
|
+
|
74
88
|
def self.scrub_other_identifiers( s, comments )
|
75
89
|
puts s
|
76
90
|
re = /#{comments} BEGIN \S+\n(.*)\n#{comments} END \S+\n/m
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oreilly-snippets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Dawson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|