octopress-printable 0.1.3 → 0.1.4

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: dabc42f1f81dc131009d8dda9e5e1deac6d849f8
4
- data.tar.gz: 05667df60b06ef89ff8d4139d40189a45f85861f
3
+ metadata.gz: 18667c9134b618d837b41f0ae2c4aab025c708f3
4
+ data.tar.gz: e339283272b25792de8ad79721dbd89f0761daf8
5
5
  SHA512:
6
- metadata.gz: 65e5649dbd86fd3507bc245ccacaab7a2db8bfee4a35f1ac452af53cb504bbe7900c994b82e345f6e0da4e9cb4e689fa6c830bfd41c422b62cbd09758cbbe2d4
7
- data.tar.gz: 40454e9b7907db985cf607df3109c16b6c076900be4d780dd1026a255660737c244dfb9fc5129217e1e18e2c09964d6d7ac74cf55739dd948104c621414cc1ca
6
+ metadata.gz: a1d08a1ece5339cc781547b2b12dff44c1ec348c671fb96dac836eb6408e42b41703c09b6d2ac55b7f52a68f44f03461dd0ce1d4f3b5ee376bcae4c84058423d
7
+ data.tar.gz: f6dc85996e47b9043b391cc0532a023befa27dde5df8436d9b82157cd865ad311bc945e854d6351cfe71ae824f7965d801dc2f1175835aa544e220f9cf40b22c
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.4 - 2015-07-31
4
+ - Add support to \input for tex.
5
+
3
6
  ## 0.1.3 - 2015-07-29
4
7
  - Add 'tex2img' support
5
8
 
@@ -62,7 +62,7 @@ module Octopress
62
62
  end
63
63
  cmds
64
64
  end
65
-
65
+
66
66
  end
67
67
  end
68
68
  end
@@ -16,6 +16,10 @@ module Octopress
16
16
  []
17
17
  end
18
18
 
19
+ def envs()
20
+ []
21
+ end
22
+
19
23
  def pandoc_args
20
24
  []
21
25
  end
@@ -31,6 +35,22 @@ module Octopress
31
35
  def last_xelatex(texfile)
32
36
  []
33
37
  end
38
+
39
+ def self.get_includes(post, source_dir)
40
+ []
41
+ end
42
+
43
+ # return the newest timestamp for included files
44
+ def self.timestamp(post, source_dir)
45
+ includes = get_includes(post, source_dir)
46
+ ts = Time.new(0)
47
+ includes.each { |f|
48
+ if File.exists?(f) && File.stat(f).mtime > ts
49
+ ts = File.stat(f).mtime
50
+ end
51
+ }
52
+ ts
53
+ end
34
54
  end
35
55
  end
36
56
  end
@@ -54,6 +54,19 @@ module Octopress
54
54
  lines << '\\usepackage{graphicx}'
55
55
  lines << '\\usepackage[all]{hypcap}'
56
56
  end
57
+
58
+ def get_includes(post, source_dir)
59
+ includes = []
60
+ File.open(post, 'r') do |f|
61
+ while l = f.gets
62
+ if /{% img (?<markup>.*) %}/ =~ l
63
+ img = ImgConverter.get_img_label(markup)
64
+ includes << File.join(source_dir, img['src'])
65
+ end
66
+ end
67
+ end
68
+ includes
69
+ end
57
70
  end
58
71
  end
59
72
  end
@@ -46,7 +46,7 @@ module Octopress
46
46
  pdf = pdf.gsub(/\//, "-")
47
47
  pdf = "#{printables_dir}/#{pdf}.pdf"
48
48
 
49
- if !File.exists?(pdf) || File.stat(post).mtime > File.stat(pdf).mtime
49
+ if !File.exists?(pdf) || timestamp(post, source_dir) > File.stat(pdf).mtime
50
50
  puts "Converting #{post} to #{pdf}"
51
51
  gen_pdf(post, pdf, source_dir, posts_dir, blog_url,
52
52
  bib_dir, bib, p.url)
@@ -188,17 +188,23 @@ module Octopress
188
188
  cmds << cmd
189
189
  end
190
190
 
191
+ envs = []
192
+ for converter in converters
193
+ envs += converter.envs
194
+ end
195
+ File.open("#{base}.sh", 'w') { |f|
196
+ f.write(envs.join("\n"))
197
+ f.write("\n")
198
+ f.write(cmds.join("\n"))
199
+ }
200
+ FileUtils.chmod(0755, "#{base}.sh")
201
+
191
202
  if ! @conf['dry_run']
192
- for cmd in cmds
193
- system cmd
194
- end
203
+ system "#{base}.sh"
195
204
  end
196
205
 
197
- if @conf['dump_cmds']
198
- File.open("#{base}.sh", 'w') { |f|
199
- f.write(cmds.join("\n"))
200
- }
201
- FileUtils.chmod(0755, "#{base}.sh")
206
+ if ! @conf['dump_cmds']
207
+ FileUtils.rm_f("#{base}.sh")
202
208
  end
203
209
 
204
210
  if File.exists?("#{File.basename(base)}.pyg")
@@ -234,6 +240,18 @@ module Octopress
234
240
  bib.cleanup
235
241
  end
236
242
  end
243
+
244
+ def timestamp(post, source_dir)
245
+ ts = [ File.stat(post).mtime ]
246
+ ts << MathConverter.timestamp(post, source_dir)
247
+ ts << ImgConverter.timestamp(post, source_dir)
248
+ ts << Tex2imgConverter.timestamp(post, source_dir)
249
+ ts << BibConverter.timestamp(post, source_dir)
250
+ ts << GistConverter.timestamp(post, source_dir)
251
+ ts << PostLinkConverter.timestamp(post, source_dir)
252
+ ts << LatexConverter.timestamp(post, source_dir)
253
+ ts.max
254
+ end
237
255
 
238
256
  end
239
257
  end
@@ -11,6 +11,7 @@ module Octopress
11
11
 
12
12
  @source_dir = source_dir
13
13
  @headers = []
14
+ @inputs = []
14
15
  end
15
16
 
16
17
  def convert(line)
@@ -19,18 +20,19 @@ module Octopress
19
20
  if /{% tex2img (?<markup>.*) %}/ =~ str
20
21
  @match = true
21
22
 
22
- @texpath, *params = markup.strip.split(/\s/)
23
- @texpath = File.join(@source_dir, @texpath)
24
- if !File.exists?(@texpath)
25
- raise ArgumentError.new("texfile[#{@texpath}] does not exist!")
23
+ texpath, *params = markup.strip.split(/\s/)
24
+ texpath = File.join(@source_dir, texpath)
25
+ if !File.exists?(texpath)
26
+ raise ArgumentError.new("texfile[#{texpath}] does not exist!")
26
27
  end
27
28
 
28
29
  img = Octopress::Printable::ImgConverter.get_img_label(params.join(" "))
29
- str="\\begin{figure}[h]\\centering\\input{#{@texpath}}\\caption{#{img['title']}}\\label{#{img['alt']}}\\end{figure}"
30
+ str="\\begin{figure}[h]\\centering\\input{#{texpath}}\\caption{#{img['title']}}\\label{#{img['alt']}}\\end{figure}"
30
31
 
31
- @headers += open(@texpath) { |f| f.grep(/\\usepackage/) }
32
+ @headers += open(texpath) { |f| f.grep(/\\usepackage/) }
33
+
34
+ add_envs(texpath)
32
35
  end
33
-
34
36
  str
35
37
  end
36
38
 
@@ -40,6 +42,45 @@ module Octopress
40
42
  @headers.each {|a| a.strip!if a.respond_to? :strip! }
41
43
  @headers.uniq!
42
44
  end
45
+
46
+ def add_envs(texpath)
47
+ File.open(texpath, 'r') do |ff|
48
+ while ll = ff.gets
49
+ if /\\input{(?<inputfile>.*)}/ =~ ll
50
+ @inputs << File.dirname(texpath)
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ def envs
57
+ ["export TEXINPUTS+='#{@inputs.join(':')}:'"]
58
+ end
59
+
60
+ def self.get_includes(post, source_dir)
61
+ includes = []
62
+ File.open(post, 'r') do |f|
63
+ while l = f.gets
64
+ if /{% tex2img (?<markup>.*) %}/ =~ l
65
+ texpath, *params = markup.strip.split(/\s/)
66
+ texpath = File.join(source_dir, texpath)
67
+ if !File.exists?(texpath)
68
+ next
69
+ end
70
+ includes << texpath
71
+
72
+ File.open(texpath, 'r') do |ff|
73
+ while ll = ff.gets
74
+ if /\\input{(?<inputfile>.*)}/ =~ ll
75
+ includes << File.join(File.dirname(texpath), inputfile)
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
82
+ includes
83
+ end
43
84
  end
44
85
  end
45
86
  end
@@ -1,5 +1,5 @@
1
1
  module Octopress
2
2
  module Printable
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octopress-printable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wang Jian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-30 00:00:00.000000000 Z
11
+ date: 2015-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler