added a cache to metapost
This commit is contained in:
parent
092cc0df0f
commit
03195168fb
1 changed files with 12 additions and 6 deletions
18
lib/mpost.rb
18
lib/mpost.rb
|
@ -1,6 +1,6 @@
|
||||||
class MPost < Nanoc3::Filter
|
class MPost < Nanoc3::Filter
|
||||||
identifier :mpost
|
identifier :mpost
|
||||||
@@tmpfic="/tmp/graphtemp.mp"
|
@@tmp="/tmp/mp/"
|
||||||
@@name=["Zero","One","Two","Three"]
|
@@name=["Zero","One","Two","Three"]
|
||||||
def solarized(str)
|
def solarized(str)
|
||||||
str.gsub(
|
str.gsub(
|
||||||
|
@ -211,14 +211,20 @@ beginfig(1)
|
||||||
drawoptions (withcolor base01);\n}
|
drawoptions (withcolor base01);\n}
|
||||||
code <<= str
|
code <<= str
|
||||||
code <<= %{\nendfig;\nbye;\n}
|
code <<= %{\nendfig;\nbye;\n}
|
||||||
File.open(@@tmpfic,'w') do |f|
|
File.open(@@tmp+filename+'.mp','w') do |f|
|
||||||
f.write solarized(code)
|
f.write solarized(code)
|
||||||
end
|
end
|
||||||
FileUtils.mkdir_p('output'+@item.path+'mpost')
|
|
||||||
webpath=@item.path + 'mpost/' + filename + '.png'
|
webpath=@item.path + 'mpost/' + filename + '.png'
|
||||||
path='output'+webpath
|
if not (File.exists?(@@tmp+filename+'.old') and FileUtils.compare_file(@@tmp+filename+'.mp',@@tmp+filename+'.old'))
|
||||||
cmd="cd /tmp && mpost graphtemp.mp >/dev/null 2>&1 && convert -density 180 graphtemp.1 $OLDPWD/#{path} >/dev/null 2>&1"
|
then
|
||||||
system(cmd)
|
FileUtils.mkdir_p(@@tmp)
|
||||||
|
FileUtils.mkdir_p('output'+@item.path+'mpost')
|
||||||
|
path='output'+webpath
|
||||||
|
cmd="cd #{@@tmp} && mpost #{filename}.mp >/dev/null 2>&1 && convert -density 180 #{filename}.1 $OLDPWD/#{path} >/dev/null"
|
||||||
|
if system(cmd)
|
||||||
|
FileUtils.copy(@@tmp+filename+'.mp',@@tmp+filename+'.old')
|
||||||
|
end
|
||||||
|
end
|
||||||
%{<figure><img alt="#{title}" src="#{webpath}"/><figcaption>#{title}</figcaption></figure>}
|
%{<figure><img alt="#{title}" src="#{webpath}"/><figcaption>#{title}</figcaption></figure>}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue