giteaucrat 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MzJhZmY2NTQ5ZmEzYjY5NjYzZTNiOTkwNDRkMDEyYjUwYzRmMTBlZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MDc0ZTNlMDc5OTM4NjU3MmNiOTg5NmQzODE5OTYyYTZiYmM4ZDE4MA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MWZjYWE2Y2YwZTNjNjFlZTExN2EzZGJhMTU5ZTg2YTQ1YmYwNDE0ODMxMTJk
|
10
|
+
N2Q1MDUwMDM1MmU5NWZmZGM1ZWUxODY0OTFhYjMzZmQ0YTU4NGMzMDk5MzQy
|
11
|
+
Mzg3YWI5MmUyZDQ2YThjN2E2OWFkNDYxNzRiZWU0OTliODhiMGE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Njk1MDYwMDYzN2Y4MjMwYzRmY2Q2NzI1YmE1ZTk0OTI5ZmUwOWFkMDllYjlh
|
14
|
+
ZTE5M2MxZDlmZDEwZDVjNzZhYTVlODI5ZDgxNTE2NzU2Y2ZlN2NjZGJmYzBm
|
15
|
+
YTVmMTFkOTQ3ZmU2MWY4YmM2NjExY2EwYjVhYmZhOTllNThhZTY=
|
@@ -11,6 +11,8 @@ require 'delegate'
|
|
11
11
|
module Giteaucrat
|
12
12
|
module Formatters
|
13
13
|
class Formatter < SimpleDelegator
|
14
|
+
HASHBANG_REGEXP = /\A(#!.*)\n/
|
15
|
+
|
14
16
|
# @return [String]
|
15
17
|
def format_copyright
|
16
18
|
first, _, last = comment_parts
|
@@ -56,6 +58,10 @@ module Giteaucrat
|
|
56
58
|
end
|
57
59
|
|
58
60
|
def remove_copyright!
|
61
|
+
if contents =~ HASHBANG_REGEXP
|
62
|
+
@hashbang = $1
|
63
|
+
contents.sub!(HASHBANG_REGEXP, '')
|
64
|
+
end
|
59
65
|
contents.sub!(self.class.const_get(:COPYRIGHT_REGEXP), '')
|
60
66
|
if $~ && $~[:comment]
|
61
67
|
parse_comment($~[:comment])
|
@@ -79,6 +85,7 @@ module Giteaucrat
|
|
79
85
|
def write_copyright!
|
80
86
|
remove_copyright!
|
81
87
|
add_copyright!
|
88
|
+
@contents = [@hashbang, contents].compact.join("\n")
|
82
89
|
write_contents(contents)
|
83
90
|
end
|
84
91
|
|
@@ -13,12 +13,12 @@ module Giteaucrat
|
|
13
13
|
COMMENT_PARTS = %w(# # #)
|
14
14
|
|
15
15
|
# @return [String]
|
16
|
-
CODING_REGEXP = /\A(#\s*.*coding:\s*
|
16
|
+
CODING_REGEXP = /\A((#\s*.*coding:\s*[^\s]+)\s*\n+)?/
|
17
17
|
COPYRIGHT_REGEXP = /(?<ruler>##+#\n)(?<copyright>(#\s*[^\s#]+.*\s#\n)+)(#\s+#?\n(?<comment>(#\s*.*#?\n)+))?\k<ruler>\n+/
|
18
18
|
|
19
19
|
def format_copyright
|
20
20
|
copyright = super
|
21
|
-
copyright = "
|
21
|
+
copyright = [encoding, copyright].compact.join("\n\n")
|
22
22
|
copyright
|
23
23
|
end
|
24
24
|
|
@@ -29,17 +29,8 @@ module Giteaucrat
|
|
29
29
|
|
30
30
|
def remove_copyright!
|
31
31
|
super
|
32
|
-
contents.sub!(CODING_REGEXP, '')
|
33
|
-
|
34
|
-
|
35
|
-
def add_copyright!
|
36
|
-
if !include_encoding? && !!(contents =~ CODING_REGEXP)
|
37
|
-
lines = contents.split(/\n/).to_a
|
38
|
-
lines.insert(1, format_copyright)
|
39
|
-
@contents = lines.join("\n")
|
40
|
-
else
|
41
|
-
super
|
42
|
-
end
|
32
|
+
contents.sub!(CODING_REGEXP, '')
|
33
|
+
@encoding = $2 if $2
|
43
34
|
end
|
44
35
|
|
45
36
|
def parse_comment(comment)
|
@@ -53,6 +44,10 @@ module Giteaucrat
|
|
53
44
|
def include_encoding?
|
54
45
|
repo.include_encoding?
|
55
46
|
end
|
47
|
+
|
48
|
+
def encoding
|
49
|
+
@encoding || (include_encoding? && '# coding: utf-8' || nil)
|
50
|
+
end
|
56
51
|
end
|
57
52
|
end
|
58
53
|
end
|
data/lib/giteaucrat/version.rb
CHANGED