houcluttex 1.0.1 → 1.0.2

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
  SHA256:
3
- metadata.gz: 7c7d8c81d46c8d8a380f7a3cf3d1fa1d43478792fa2825c6556a68f50a44ad11
4
- data.tar.gz: c8b68498ba79dc4c5af70f4e70347da2d0856acecd91bc5064156486bcff7b5b
3
+ metadata.gz: 611c1ee3802bd076e4b6a0b055e9123311584ce405285de0b3e45e3cc476db5e
4
+ data.tar.gz: 66b69c57438a06bf69d8e249395e39f21a491a5a144a5f6a6aa24bbdc7d63791
5
5
  SHA512:
6
- metadata.gz: 3644ae35c0c01fc72e4f1dc3088eaa3f0eef243ff5a8040fa323d6c2a24a8bf46b7061e0e09d97be2bdeaa0d2fc0877a182028990708d78a67ac98e0daf5f46e
7
- data.tar.gz: c195e7e359de0479f30813570601014918d3cf9a92446f111c96a5b24b95f04329e1e871f58c083eea1aafb362591df6a9a7bb537a3ee5b4f34b7eb567a8c63a
6
+ metadata.gz: 11e6b07578483d287142caefda22fb38c8826667d942ecf368371fbee13b3321380292ab2aade41ddf621216249d81aff541e16998f5c5692fac10ccedee8527
7
+ data.tar.gz: 8bee1ab0a03d305bf5cb64dc663f6a763d481fb5aa5d6a6dcb795340797609bb21432b1ee55615ddbd409b8a48bb17d6e027fbb99c46c04be773598c21219989
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in houcluttex.gemspec
4
6
  gemspec
data/Rakefile CHANGED
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  task default: :spec
@@ -2,16 +2,49 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'fileutils'
5
+ require 'rbconfig'
5
6
  require 'shellwords'
6
7
  require 'yaml'
7
8
 
9
+ IS_WINDOWS = %w[mswin msys mingw cygwin bccwin wince emc].any?{|s| RbConfig::CONFIG['host_os'].include?(s)}
10
+
8
11
  def convert_bool(str)
9
- case str.downcase
10
- when 'yes', 'true'
11
- true
12
- when 'no', 'false'
13
- false
14
- end
12
+ case str.downcase
13
+ when 'yes', 'true'
14
+ true
15
+ when 'no', 'false'
16
+ false
17
+ end
18
+ end
19
+
20
+ def log(str, color_mode, color_fg = nil, color_bg = nil, bold = nil)
21
+ use_color = color_mode == 'always' || (color_mode == 'auto' && !IS_WINDOWS)
22
+ s = String.new('')
23
+ s << "\e[1m" if use_color && bold
24
+ s << "\e[3#{color_fg}m" if use_color && color_fg
25
+ s << "\e[4#{color_bg}m" if use_color && color_bg
26
+ s << str
27
+ s << "\e[0m" if use_color && (bold || color_fg)
28
+ warn s
29
+ end
30
+
31
+ def log_info(str, config)
32
+ return unless config['verbose']
33
+ log("[houcluttex] info: #{str}", config['color'] || 'auto', 2)
34
+ end
35
+
36
+ def log_warn(str, config)
37
+ log("[houcluttex] warn: #{str}", config['color'] || 'auto', 3, nil, true)
38
+ end
39
+
40
+ def log_error(str, config)
41
+ log("[houcluttex] error: #{str}", config['color'] || 'auto', 1, nil, true)
42
+ end
43
+
44
+ def version
45
+ require 'houcluttex/version'
46
+ puts "houcluttex v#{Houcluttex::VERSION}"
47
+ exit
15
48
  end
16
49
 
17
50
  config_file = %w[houcluttex.yml houcluttex.yaml houcluttex_config.yml houcluttex_config.yaml houcluttexrc .houcluttexrc].find{|e| File.exist?(e)}
@@ -21,142 +54,159 @@ config_file = %w[houcluttex.yml houcluttex.yaml houcluttex_config.yml houcluttex
21
54
  argv = ARGV.dup
22
55
  config_by_args = {}
23
56
  remain_args = []
57
+ ignored_args = []
24
58
 
25
59
  until argv.empty?
26
- arg = argv.shift
27
- if arg == '--'
28
- remain_args += argv
29
- argv = []
30
- elsif arg.start_with?('--')
31
- m = arg.match(/\A--([^=]+)(=(.*))?\z/)
32
- case m[1]
33
- when 'fresh', 'change-directory', 'watch', 'verbose', 'shell-escape', 'shell-restricted', 'file-line-error', 'halt-on-error'
34
- config_by_args[m[1]] = true
35
- when 'no-change-directory', 'no-shell-escape', 'no-file-line-error', 'no-halt-on-error'
36
- config_by_args[m[1][3..-1]] = false
37
- when 'tex-options', 'dvipdfmx-options'
38
- config_by_args[m[1][0..-2]] ||= []
39
- config_by_args[m[1][0..-2]] += (m[3] || argv.shift).shellsplit
40
- when 'tex-option', 'dvipdfmx-option'
41
- config_by_args[m[1]] ||= []
42
- config_by_args[m[1]] << (m[3] || argv.shift)
43
- when 'includeonly', 'package-support'
44
- config_by_args[m[1]] = (m[3] || argv.shift).split(',')
45
- when 'input'
46
- raise 'cannot use `--input` option in command-line'
47
- when 'config'
48
- config_file = m[3] || argv.shift
49
- when 'cluttex-path', 'engine', 'output', 'max-iterations', 'color', 'make-depends', 'engine-executable', 'makeindex', 'bibtex', 'biber', 'makeglossaries', 'synctex', 'interaction', 'jobname', 'fmt', 'output-directory', 'output-format'
50
- config_by_args[m[1]] = m[3] || argv.shift
51
- else
52
- warn "option `--#{m[1]}` is ignored"
53
- end
54
- elsif arg.start_with?('-')
55
- a = arg[1..-1]
56
- case a
57
- when 'e'
58
- config_by_args['engine'] = argv.shift
59
- when 'o'
60
- config_by_args['output'] = argv.shift
61
- when 'V'
62
- config_by_args['verbose'] = true
63
- when 'shell-escape', 'shell-restricted', 'file-line-error', 'halt-on-error'
64
- config_by_args[a] = true
65
- when 'no-shell-escape', 'no-file-line-error', 'no-halt-on-error'
66
- config_by_args[a[3..-1]] = false
67
- when 'synctex', 'interaction', 'jobname', 'fmt', 'output-directory', 'output-format'
68
- config_by_args[a] = argv.shift
69
- else
70
- warn "option `-#{arg}` is ignored"
71
- end
60
+ arg = argv.shift
61
+ if arg == '--'
62
+ remain_args += argv
63
+ argv = []
64
+ elsif arg.start_with?('--')
65
+ m = arg.match(/\A--([^=]+)(=(.*))?\z/)
66
+ key = m[1]
67
+ value = -> {m[3] || argv.shift}
68
+ case key
69
+ when 'fresh', 'change-directory', 'watch', 'verbose', 'shell-escape', 'shell-restricted', 'file-line-error', 'halt-on-error'
70
+ config_by_args[key] = true
71
+ when 'no-change-directory', 'no-shell-escape', 'no-file-line-error', 'no-halt-on-error'
72
+ config_by_args[key[3..-1]] = false
73
+ when 'tex-options', 'dvipdfmx-options'
74
+ config_by_args[key[0..-2]] ||= []
75
+ config_by_args[key[0..-2]] += value[].shellsplit
76
+ when 'tex-option', 'dvipdfmx-option'
77
+ config_by_args[key] ||= []
78
+ config_by_args[key] << value[]
79
+ when 'includeonly', 'package-support'
80
+ config_by_args[key] = value[].split(',')
81
+ when 'color'
82
+ config_by_args[key] = m[3] || 'always'
83
+ when 'input'
84
+ ignored_args << arg
85
+ value[]
86
+ when 'config'
87
+ config_file = value[]
88
+ when 'version'
89
+ version
90
+ when 'cluttex-path', 'engine', 'output', 'max-iterations', 'make-depends', 'engine-executable', 'makeindex', 'bibtex', 'biber', 'makeglossaries', 'synctex', 'interaction', 'jobname', 'fmt', 'output-directory', 'output-format'
91
+ config_by_args[key] = value[]
72
92
  else
73
- remain_args << arg
93
+ ignored_args << arg
74
94
  end
95
+ elsif arg.start_with?('-')
96
+ key = arg[1..-1]
97
+ case key
98
+ when 'e'
99
+ config_by_args['engine'] = argv.shift
100
+ when 'o'
101
+ config_by_args['output'] = argv.shift
102
+ when 'v'
103
+ version
104
+ when 'V'
105
+ config_by_args['verbose'] = true
106
+ when 'shell-escape', 'shell-restricted', 'file-line-error', 'halt-on-error'
107
+ config_by_args[key] = true
108
+ when 'no-shell-escape', 'no-file-line-error', 'no-halt-on-error'
109
+ config_by_args[key[3..-1]] = false
110
+ when 'synctex', 'interaction', 'jobname', 'fmt', 'output-directory', 'output-format'
111
+ config_by_args[key] = argv.shift
112
+ else
113
+ ignored_args << arg
114
+ end
115
+ else
116
+ remain_args << arg
117
+ end
75
118
  end
76
119
 
77
120
  # load yaml
78
121
  config = config_file ? YAML.load_file(config_file) : {}
79
122
 
80
123
  # decide input file
81
- raise 'multiple input files' if remain_args.size >= 2
124
+ if remain_args.size >= 2
125
+ log_error('multiple input files', config)
126
+ exit 1
127
+ end
128
+
82
129
  config['input'] = remain_args[0] unless remain_args.empty?
83
- raise 'no input file' unless config['input']
130
+ unless config['input']
131
+ log_error('no input file', config)
132
+ exit 1
133
+ end
84
134
 
85
135
  # parse magic comments
86
136
 
87
137
  loop do
88
- raise "input file `#{config['input']}` does not exist" unless File.exist?(config['input'])
89
-
90
- root_file = nil
91
- File.foreach(config['input']) do |line|
92
- next if line.strip.empty?
93
- break unless line[0] == '%'
94
- m = line.match(/^%\s*!TEX (\S+)\s*=\s*(.*?)\s*$/)
95
- next unless m
96
- key = m[1].tr('_-', '').downcase
97
- value = m[2]
98
- case key
99
- when 'root'
100
- root_file = value
101
- when 'engine', 'synctex', 'jobname', 'makeindex', 'bibtex'
102
- config[key] = value
103
- when 'program'
104
- config['engine'] = value
105
- when 'format', 'outputformat'
106
- config['output-format'] = value
107
- when 'outputdirectory'
108
- config['output-directory'] = value
109
- when 'enablesynctex'
110
- value = convert_bool(value)
111
- raise 'magic option `enableSynctex` must be boolean' if value.nil?
112
- config['synctex'] = value ? (config['synctex'] || 1) : nil
113
- when 'enableshellescape'
114
- value = convert_bool(value)
115
- raise 'magic option `enableShellEscape` must be boolean' if value.nil?
116
- config['shell-escape'] = value
117
- else
118
- warn "magic comment `#{m[1]}` is ignored"
119
- end
138
+ log_info("input file: #{config['input']}", config)
139
+ raise "input file `#{config['input']}` does not exist" unless File.exist?(config['input'])
140
+
141
+ root_file = nil
142
+ File.open(config['input'], external_encoding: 'utf-8') do |io|
143
+ io.each do |line|
144
+ next if line.strip.empty?
145
+ break unless line[0] == '%'
146
+ m = line.match(/^%\s*!TEX (\S+)\s*=\s*(.*?)\s*$/)
147
+ next unless m
148
+ key = m[1].tr('_-', '').downcase
149
+ value = m[2]
150
+ case key
151
+ when 'root'
152
+ root_file = value
153
+ when 'engine', 'synctex', 'jobname', 'makeindex', 'bibtex'
154
+ config[key] = value
155
+ when 'program'
156
+ config['engine'] = value
157
+ when 'format', 'outputformat'
158
+ config['output-format'] = value
159
+ when 'outputdirectory'
160
+ config['output-directory'] = value
161
+ when 'enablesynctex'
162
+ value = convert_bool(value)
163
+ raise 'magic option `enableSynctex` must be boolean' if value.nil?
164
+ config['synctex'] = value ? (config['synctex'] || 1) : nil
165
+ when 'enableshellescape'
166
+ value = convert_bool(value)
167
+ raise 'magic option `enableShellEscape` must be boolean' if value.nil?
168
+ config['shell-escape'] = value
169
+ else
170
+ log_warn("magic comment `#{m[1]}` is ignored", config)
171
+ end
120
172
  end
121
- break if root_file.nil? || config['input'] == root_file
122
- config['input'] = root_file
173
+ end
174
+ break if root_file.nil? || config['input'] == root_file
175
+ config['input'] = root_file
123
176
  end
124
177
 
125
178
  # merge config
126
179
  config.merge!(config_by_args)
127
180
 
181
+ log_warn("option #{ignored_args.map{|e| "`#{e}`"}.join(', ')} is ignored", config) unless ignored_args.empty?
182
+
128
183
  # specify command
129
184
  config['cluttex-path'] ||= 'cluttex'
130
185
  `type #{config['cluttex-path']} 2>&1`
131
186
  raise "command `#{config['cluttex-path']}` not found" unless $?.success?
132
187
 
133
- if config['verbose']
134
- warn 'ClutTeX options:'
135
- config.each do |k, v|
136
- warn " #{k}: #{v.inspect}"
137
- end
138
- end
188
+ log_info("configurations: #{config.inspect}", config)
139
189
 
140
190
  # generate command
141
191
 
142
192
  cmd_args = []
143
193
 
144
194
  config.each do |k, v|
145
- next if v.nil?
146
- case k
147
- when 'cluttex-path', 'input'
148
- nil
149
- when 'tex-option', 'dvipdfmx-option'
150
- v.each{|e| cmd_args << "--#{k}=#{e}"} unless v.empty?
151
- when 'includeonly', 'package-support'
152
- cmd_args << (v.is_a?(Array) ? "--#{k}=#{v.join(',')}" : "--#{k}=#{v}") unless v.empty?
153
- when 'fresh', 'watch', 'verbose', 'shell-restricted'
154
- cmd_args << "--#{k}" if v
155
- when 'change-directory', 'shell-escape', 'file-line-error', 'halt-on-error'
156
- cmd_args << (v ? "--#{k}" : "--no-#{k}")
157
- else
158
- cmd_args << "--#{k}=#{v}"
159
- end
195
+ next if v.nil?
196
+ case k
197
+ when 'cluttex-path', 'input'
198
+ nil
199
+ when 'tex-option', 'dvipdfmx-option'
200
+ v.each{|e| cmd_args << "--#{k}=#{e}"} unless v.empty?
201
+ when 'includeonly', 'package-support'
202
+ cmd_args << (v.is_a?(Array) ? "--#{k}=#{v.join(',')}" : "--#{k}=#{v}") unless v.empty?
203
+ when 'fresh', 'watch', 'verbose', 'shell-restricted'
204
+ cmd_args << "--#{k}" if v
205
+ when 'change-directory', 'shell-escape', 'file-line-error', 'halt-on-error'
206
+ cmd_args << (v ? "--#{k}" : "--no-#{k}")
207
+ else
208
+ cmd_args << "--#{k}=#{v}"
209
+ end
160
210
  end
161
211
 
162
212
  cmd_args << '--'
@@ -164,4 +214,6 @@ cmd_args << config['input']
164
214
 
165
215
  FileUtils.mkdir_p(config['output-directory']) if config['output-directory']
166
216
 
217
+ log_info("args: #{cmd_args.inspect}", config)
218
+
167
219
  system(config['cluttex-path'], *cmd_args)
@@ -5,25 +5,25 @@ $:.unshift(lib) unless $:.include?(lib)
5
5
  require 'houcluttex/version'
6
6
 
7
7
  Gem::Specification.new do |spec|
8
- spec.name = 'houcluttex'
9
- spec.version = Houcluttex::VERSION
10
- spec.authors = ['Ishotihadus']
11
- spec.email = ['hanachan.pao@gmail.com']
8
+ spec.name = 'houcluttex'
9
+ spec.version = Houcluttex::VERSION
10
+ spec.authors = ['Ishotihadus']
11
+ spec.email = ['hanachan.pao@gmail.com']
12
12
 
13
- spec.summary = 'configurable cluttex wrapper'
14
- spec.description = 'configurable cluttex wrapper'
15
- spec.homepage = 'https://github.com/ishotihadus/houcluttex'
16
- spec.license = 'MIT'
13
+ spec.summary = 'configurable cluttex wrapper'
14
+ spec.description = 'configurable cluttex wrapper'
15
+ spec.homepage = 'https://github.com/ishotihadus/houcluttex'
16
+ spec.license = 'MIT'
17
17
 
18
- # Specify which files should be added to the gem when it is released.
19
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
- spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
- `git ls-files -z`.split("\x0").reject{|f| f.match(%r{^(test|spec|features)/})}
22
- end
23
- spec.bindir = 'exe'
24
- spec.executables = spec.files.grep(%r{^exe/}){|f| File.basename(f)}
25
- spec.require_paths = ['lib']
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
+ `git ls-files -z`.split("\x0").reject{|f| f.match(%r{^(test|spec|features)/})}
22
+ end
23
+ spec.bindir = 'exe'
24
+ spec.executables = spec.files.grep(%r{^exe/}){|f| File.basename(f)}
25
+ spec.require_paths = ['lib']
26
26
 
27
- spec.add_development_dependency 'bundler'
28
- spec.add_development_dependency 'rake'
27
+ spec.add_development_dependency 'bundler'
28
+ spec.add_development_dependency 'rake'
29
29
  end
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'houcluttex/version'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Houcluttex
4
- VERSION = '1.0.1'
4
+ VERSION = '1.0.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: houcluttex
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ishotihadus
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-12-15 00:00:00.000000000 Z
11
+ date: 2020-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -81,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  requirements: []
84
- rubygems_version: 3.0.3
84
+ rubygems_version: 3.1.2
85
85
  signing_key:
86
86
  specification_version: 4
87
87
  summary: configurable cluttex wrapper