houcluttex 1.0.1 → 1.0.2
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 +4 -4
- data/Gemfile +3 -1
- data/Rakefile +2 -0
- data/exe/houcluttex +162 -110
- data/houcluttex.gemspec +18 -18
- data/lib/houcluttex.rb +2 -0
- data/lib/houcluttex/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 611c1ee3802bd076e4b6a0b055e9123311584ce405285de0b3e45e3cc476db5e
|
4
|
+
data.tar.gz: 66b69c57438a06bf69d8e249395e39f21a491a5a144a5f6a6aa24bbdc7d63791
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11e6b07578483d287142caefda22fb38c8826667d942ecf368371fbee13b3321380292ab2aade41ddf621216249d81aff541e16998f5c5692fac10ccedee8527
|
7
|
+
data.tar.gz: 8bee1ab0a03d305bf5cb64dc663f6a763d481fb5aa5d6a6dcb795340797609bb21432b1ee55615ddbd409b8a48bb17d6e027fbb99c46c04be773598c21219989
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/exe/houcluttex
CHANGED
@@ -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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
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
|
-
|
122
|
-
|
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
|
-
|
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
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
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)
|
data/houcluttex.gemspec
CHANGED
@@ -5,25 +5,25 @@ $:.unshift(lib) unless $:.include?(lib)
|
|
5
5
|
require 'houcluttex/version'
|
6
6
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
spec.name = 'houcluttex'
|
9
|
+
spec.version = Houcluttex::VERSION
|
10
|
+
spec.authors = ['Ishotihadus']
|
11
|
+
spec.email = ['hanachan.pao@gmail.com']
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
-
|
28
|
-
|
27
|
+
spec.add_development_dependency 'bundler'
|
28
|
+
spec.add_development_dependency 'rake'
|
29
29
|
end
|
data/lib/houcluttex.rb
CHANGED
data/lib/houcluttex/version.rb
CHANGED
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.
|
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:
|
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.
|
84
|
+
rubygems_version: 3.1.2
|
85
85
|
signing_key:
|
86
86
|
specification_version: 4
|
87
87
|
summary: configurable cluttex wrapper
|