oreilly-snippets 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 67d27cdaa420bb60920b3d025fbf2fd1d1801d74
4
- data.tar.gz: 3598b75bc1051bca2581724e64cf894c66c6f3bb
3
+ metadata.gz: 699d24e1d89e9d93b3d5dd37feda9ee4c74dd868
4
+ data.tar.gz: 9039ca84bd421dc8a8c7d51554dfe4fc715cb53e
5
5
  SHA512:
6
- metadata.gz: cb4578a7500000a4711f9cd15c6957f781a8d0c809a2bb2f83bedb77723d19b06ced9b9852ad723e186f3bfccf0dbb2c9e952fe190a112ce990ec4eec91fe662
7
- data.tar.gz: 0d0adae1b813dbcf5d02efd72ad3202203e498fc577ee8b1120a521155e0adfe1128d10bdb45d3246fb750736d080a6d75ac17c3157b1be684e57a6770366c13
6
+ metadata.gz: d7d2d7e190256cf14cb906686d6b3f184bece1217d4778730e380cff0f8e2f576b2a23daf86b4728ee1833c295617b6d22e40c0f585830c9e4fa534dd7b2b1e0
7
+ data.tar.gz: fb09be7dcd0200acfa0f8d76208731c97d1c0d36455390b49d286f9197f36ef4a45a12202439b8f391aadc0c235dcbe1ff5e435061f166cf33f36948e97b7f79
@@ -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
- if spec
40
- Dir.chdir spec do
41
- contents = `git show #{sha}`
42
- error = true unless contents
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.unindent()
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
@@ -1,5 +1,5 @@
1
1
  module Oreilly
2
2
  module Snippets
3
- VERSION = "0.0.6"
3
+ VERSION = "0.0.7"
4
4
  end
5
5
  end
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.6
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-21 00:00:00.000000000 Z
11
+ date: 2015-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler