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
- ODNkZDAzYzkzMmVmNjg3MmFhNjNkNWY1MWFjZjYxNmRiMjY1ODAwZA==
4
+ MzJhZmY2NTQ5ZmEzYjY5NjYzZTNiOTkwNDRkMDEyYjUwYzRmMTBlZA==
5
5
  data.tar.gz: !binary |-
6
- ZGVkODczNTJmZTg4MjM2MDcwNzk3YWZmMDQ0YTU4ZDllMjdjZGViZQ==
6
+ MDc0ZTNlMDc5OTM4NjU3MmNiOTg5NmQzODE5OTYyYTZiYmM4ZDE4MA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- Y2NlOTgwMWQ5MWQ3NTMzNmRmN2I4NzdkNjgxNWRlNzhiOTVhMWIzYmNkMzlk
10
- MzM2NGQ3ZGM0MjhiZTg4ODM1ZGIyMWRlNDAxNGU3YjkyMTliOGJkYzcwMzAy
11
- ZWRiODdjMjdhMGM2MTczNGQzNTJmNTI5MjEwNzZlODBiOTY1ZTQ=
9
+ MWZjYWE2Y2YwZTNjNjFlZTExN2EzZGJhMTU5ZTg2YTQ1YmYwNDE0ODMxMTJk
10
+ N2Q1MDUwMDM1MmU5NWZmZGM1ZWUxODY0OTFhYjMzZmQ0YTU4NGMzMDk5MzQy
11
+ Mzg3YWI5MmUyZDQ2YThjN2E2OWFkNDYxNzRiZWU0OTliODhiMGE=
12
12
  data.tar.gz: !binary |-
13
- YTgyMzNmNThlYTE5NjNmNGU1MmZkN2Q4ODc4YmJhMzU1OGJiOTE1MjMzMmRk
14
- NWQ1OGMxY2I4NWRjZTU4NDdjZjMzOGVmNDlmMTYwNWI5MjNjOGI2Yzc4NDA1
15
- MzgwMTAzNWYwYWEwOTczYWMzZmMyNzUwZDRkNzI1NDk0NGMwNGU=
13
+ Njk1MDYwMDYzN2Y4MjMwYzRmY2Q2NzI1YmE1ZTk0OTI5ZmUwOWFkMDllYjlh
14
+ ZTE5M2MxZDlmZDEwZDVjNzZhYTVlODI5ZDgxNTE2NzU2Y2ZlN2NjZGJmYzBm
15
+ YTVmMTFkOTQ3ZmU2MWY4YmM2NjExY2EwYjVhYmZhOTllNThhZTY=
@@ -10,8 +10,8 @@ require 'giteaucrat/formatters/ruby_formatter'
10
10
  module Giteaucrat
11
11
  module Formatters
12
12
  class CoffeeFormatter < RubyFormatter
13
- def include_encoding?
14
- false
13
+ def encoding
14
+ nil
15
15
  end
16
16
 
17
17
  def add_copyright!
@@ -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*utf-8\s*\n+)?/
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 = "# coding: utf-8\n\n#{copyright}" if include_encoding?
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, '') if include_encoding?
33
- end
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
@@ -6,5 +6,5 @@
6
6
  ################################################
7
7
 
8
8
  module Giteaucrat
9
- VERSION = '0.0.4'
9
+ VERSION = '0.0.5'
10
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: giteaucrat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Semyonov