macaw 0.0.40 → 0.0.41

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: 06dfef52346c5bafb0f0fc2ee6ffa2f95298cd1a
4
- data.tar.gz: 1f11bf5f437fb1c5665385cad0d91541613716e9
3
+ metadata.gz: 3d5a9f79f978035965ae9ed533cbd5148d927684
4
+ data.tar.gz: 165d7dcd5d67b483d95ad5b086bd7f4b7e31bb02
5
5
  SHA512:
6
- metadata.gz: 6861e834380c57a5a354178c533ebfe9cdc084d765a5d063f5ac73c0c7e82c5476aae0e85f0788f1165f015ad72cb7c0d12527e0053ef3355762680d96a7a0a0
7
- data.tar.gz: dd05f1a8f17e67eb2f2506010e5fce59688597fc63683c2d5d2589c8e21ab8c1d070f450fe1b04aa3178724b26bb1226cca6193c11ee76704730d6a9a3f19618
6
+ metadata.gz: 0b24477694fe597e30eafdbf8539d5f72d5af965b3bea11a98c38fd7e1dbdb5e9f27aa7d39cc51aac77992919b8260fbcb5d5a32835f0cc4ed51a4e65db02ed3
7
+ data.tar.gz: df4e9accab5048946bf08d1685e99cd28717a5beac9f71bc47dc3083cd31a6d2989b8a12ec4889f09fe5c94e5ba3c83f40d92c787d68ead5975a10e47f5840ae
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- macaw (0.0.40)
4
+ macaw (0.0.41)
5
5
  i18n
6
6
  json_pure
7
7
  os
data/bin/macaw CHANGED
@@ -275,19 +275,23 @@ class Macaw
275
275
  @@log.write(line) if @@log
276
276
  end
277
277
 
278
- def self.system(cmd, onfail=:exit)
278
+ def self.system(cmd, options={})
279
+ onfail = options.delete(:onfail) || :exit
280
+ returntype = options.delete(:return) || :string
281
+ error "Unhandled system option #{options.inspect}" unless options.size == 0
282
+
279
283
  throw "errormode can only be #{ERRORMODES.inspect}" unless ERRORMODES.include?(onfail)
280
284
 
281
285
  cmd = cmd.compact.join(' ') if cmd.is_a?(Array)
282
286
  log(cmd)
283
287
 
284
- output = ''
288
+ output = []
285
289
  begin
286
290
  Timeout::timeout(@@options.timeout || 0) {
287
291
  Open3.popen2e(cmd) do |stdin, stdout_err, wait_thr|
288
292
  while line = stdout_err.gets
289
293
  self.log(line)
290
- output += line + "\n"
294
+ output << line
291
295
  end
292
296
 
293
297
  exit_status = wait_thr.value
@@ -297,7 +301,12 @@ class Macaw
297
301
  rescue Timeout::Error
298
302
  error "#{cmd}: timed out after #{@@options.timeout} seconds" if failonerror
299
303
  end
300
- return output
304
+
305
+ return case returntype
306
+ when :string then output.join("\n")
307
+ when :array then output
308
+ else error "Unexpected return type #{returntype} from system"
309
+ end
301
310
  end
302
311
 
303
312
  def self.load_rules
@@ -1,9 +1,40 @@
1
+ require 'i18n'
2
+
1
3
  # texcount rule for arara
2
4
  # author: Francesco Endrici
3
5
  # requires arara 3.0
4
6
  class Macaw
5
7
  # this probably needs to be a lot fancier, but I can't be arsed about it right now.
6
- def texcount(parameters)
7
- Macaw.system ['texcount'] + parameters
8
+ def texcount(includes=nil)
9
+
10
+ count = {}
11
+ Macaw.system(['texcount', ~@file], return: :array).each{|line|
12
+ Macaw.log(line)
13
+
14
+ case line
15
+ when /^Words in text:\s*([0-9]+)/
16
+ count[:all] = Integer($1)
17
+ when /\s([0-9]+)\+[0-9]+\+[0-9]\s+\([0-9]+\/[0-9]+\/[0-9]+\/[0-9]+\)\s+Section:\s*([^}]+)/
18
+ count[$2.strip] = Integer($1)
19
+ end
20
+ }
21
+
22
+ cleanfile = lambda{|f|
23
+ dir = File.dirname(f)
24
+ file = File.basename(f)
25
+
26
+ file = I18n.transliterate(file) # fold diacritics where possible
27
+ file.gsub!(/[^!-~]/, '') # remove non-ascii characters
28
+ file.gsub!(/#<\$\+%>!`&\*'\|{\?"=}\/:\\@/, '') # remove problematic characters
29
+ File.join(dir, file)
30
+ }
31
+
32
+ if includes
33
+ Dir["#{@base}*.count.txt"].each{|f| File.unlink(f) }
34
+ count.each_pair{|k, v|
35
+ f = cleanfile.call(@base + (k == :all ? '' : ".#{k}") + ".count.txt")
36
+ File.open(f, 'w') {|f| f.write(v)}
37
+ }
38
+ end
8
39
  end
9
40
  end
@@ -1,3 +1,3 @@
1
1
  class Macaw
2
- VERSION = "0.0.40"
2
+ VERSION = "0.0.41"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: macaw
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.40
4
+ version: 0.0.41
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emiliano Heyns
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-26 00:00:00.000000000 Z
11
+ date: 2014-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler