guard-entangle 0.0.4.4 → 0.0.5.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9eb3cf5fc653251a0f86ef0ba45cde239dbd7d48
4
- data.tar.gz: 1a3ee58e2f67a89cb2536bf15efcbefdd533c381
3
+ metadata.gz: 4bd715421e7ff970ad10a17252452ab066f39516
4
+ data.tar.gz: 8418706babf13d2fdd2a3be47b5d17f450ecbce2
5
5
  SHA512:
6
- metadata.gz: 894317b5e0e8e2cc9268324aefdc30657c07ea49206362451623ab9949068cff76ed638decb4361dcdd6b8b46a8e4f6d4c8403e2656f64534de457c7ebc7ee24
7
- data.tar.gz: aa95642ca8b241a62debad635a5b4ca5d571d58f17e249dd6c990c73e61f90c4071f00af40504e581c7b82bf8ec2230a4d11511141176eae252a2c9db83113f4
6
+ metadata.gz: 0dc56b08fc7803137b446463201992df0a27f50fe9ae954ee829f2770573006a6c5ec49495c4d30192d5130027912899942fd1a80b1319d5dc4d1c817d4e5bfa
7
+ data.tar.gz: b2179c62004954e691049058363898d4d128dd9103d03379d85f662f1c4690e78e5b6a139c5430fbe1f50d23653d3fc4a04aa8426aad0c9ed1dba77938779973
@@ -66,6 +66,7 @@ module Guard
66
66
  name = file.sub '//=', ''
67
67
  stripped = name.strip
68
68
  file = "#{path}/#{stripped}"
69
+
69
70
  if File.exists?(file) && File.readable?(file)
70
71
  insert = File.open(file, 'rb')
71
72
  insert_content = insert.read
@@ -57,6 +57,15 @@ module Guard
57
57
  ::Guard::Notifier.notify(message, options)
58
58
  end
59
59
 
60
+ # Output raw string, as Guard UI adds [#XXXXXXX] memory address to string
61
+ #
62
+ # @param [String] text the text to colorize
63
+ # @param [String] color_code the color code
64
+ #
65
+ def colorize(text, color_code)
66
+ return "\e[#{color_code}m#{text}\e[0m"
67
+ end
68
+
60
69
  private
61
70
 
62
71
  # Print a info message to the console.
@@ -83,7 +83,7 @@ module Guard
83
83
  elsif paths.kind_of?(String)
84
84
  process_dir(paths)
85
85
  else
86
- ::Guard::UI.info "Paths in configuration are incorrect"
86
+ ::Guard::UI.error "Paths in configuration are incorrect"
87
87
  end
88
88
  end
89
89
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Guard
4
4
  class EntangleVersion
5
- VERSION = "0.0.4.4"
5
+ VERSION = "0.0.5.0"
6
6
  end
7
7
  end
@@ -43,6 +43,7 @@ module Guard
43
43
  else
44
44
  path.gsub! "#{cwd}/", ''
45
45
  message = "The path #{ rel } is not writable."
46
+ puts "here"
46
47
  @formatter.error(message)
47
48
  return
48
49
  end
@@ -62,7 +63,7 @@ module Guard
62
63
  if File.extname(path) == '.js'
63
64
  min = path.gsub(/\.[^.]+$/, '.min.js')
64
65
  begin
65
- if (options[:force_utf8])
66
+ if options[:force_utf8]
66
67
  content.encoding
67
68
  content.force_encoding 'utf-8'
68
69
  end
@@ -71,7 +72,12 @@ module Guard
71
72
  rescue Exception => e
72
73
  # Get a readable message
73
74
  message = e.message.split(/[\n\r]/).first
75
+ lines = error_lines(content, message)
74
76
  @formatter.error("Uglifier - #{message}")
77
+ if lines
78
+ @formatter.error("Surrounding lines:")
79
+ puts lines
80
+ end
75
81
  return nil
76
82
  end
77
83
 
@@ -84,6 +90,54 @@ module Guard
84
90
  end
85
91
  end
86
92
 
93
+ # Get the error lines for an uglifier error
94
+ #
95
+ # @param [String] content The content that is being parsed
96
+ # @param [String] message The error message from uglifier
97
+ #
98
+ # @return [mixed] error lines or false
99
+ #
100
+ def error_lines(content, message)
101
+ line = error_line_number(message)
102
+
103
+ # The line number is set, we can now get the lines from the file
104
+ if line
105
+ counter = 2
106
+ first = line - options[:error_lines]
107
+ last = line + options[:error_lines]
108
+ file_lines = []
109
+
110
+ content.each_line do |item|
111
+ if counter >= first && counter <= last
112
+ item.sub! "\n", ''
113
+ if counter == line
114
+ file_lines << @formatter.colorize("line #{counter}: #{item}", 31)
115
+ else
116
+ file_lines << @formatter.colorize("line #{counter}: #{item}", 33)
117
+ end
118
+ end
119
+ counter += 1
120
+ end
121
+
122
+ if not file_lines.empty?
123
+ return file_lines.join("\n")
124
+ end
125
+ end
126
+ end
127
+
128
+ # Get the line number for an error message
129
+ #
130
+ # @param [String] message The error message generated by Uglifier
131
+ #
132
+ # @return [String] The error line number
133
+ #
134
+ def error_line_number(message)
135
+ lines = message.match(/line:\s?(\d+),/)
136
+
137
+ if lines.kind_of?(MatchData) && lines[1]
138
+ return lines[1].to_i
139
+ end
140
+ end
87
141
 
88
142
  # Save the file
89
143
  #
@@ -17,6 +17,7 @@ module Guard
17
17
  :hide_success => false,
18
18
  :uglifier_options => {},
19
19
  :force_utf8 => false,
20
+ :error_lines => 6,
20
21
  :copy => true #save a copy of the original file
21
22
  }
22
23
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard-entangle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4.4
4
+ version: 0.0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Deshi Rahim
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-02 00:00:00.000000000 Z
11
+ date: 2014-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: guard