Class: Formatafacil::ArtigoTarefa
- Defined in:
- lib/formatafacil/artigo_tarefa.rb
Instance Attribute Summary collapse
-
#abstract ⇒ Object
Returns the value of attribute abstract.
-
#arquivo_abstract ⇒ Object
Returns the value of attribute arquivo_abstract.
-
#arquivo_bibliografia ⇒ Object
Returns the value of attribute arquivo_bibliografia.
-
#arquivo_metadados ⇒ Object
Arquivo padrão de leitura dos metadados: metadados.yaml.
-
#arquivo_resumo ⇒ Object
Returns the value of attribute arquivo_resumo.
-
#arquivo_saida_latex ⇒ Object
Returns the value of attribute arquivo_saida_latex.
-
#arquivo_saida_pdf ⇒ Object
Returns the value of attribute arquivo_saida_pdf.
-
#arquivo_saida_yaml ⇒ Object
Returns the value of attribute arquivo_saida_yaml.
-
#arquivo_texto ⇒ Object
conteúdo convertido.
-
#artigo ⇒ Object
conteúdo lidos os arquivos.
-
#artigo_latex ⇒ Object
conteúdo convertido.
-
#bibliografia ⇒ Object
Returns the value of attribute bibliografia.
-
#compilador ⇒ Object
Tarefa que pode ser encadeada para compilar o artigo para pdf.
-
#metadados ⇒ Object
Returns the value of attribute metadados.
-
#modelo ⇒ Object
Returns the value of attribute modelo.
-
#resumo ⇒ Object
Returns the value of attribute resumo.
-
#texto ⇒ Object
Returns the value of attribute texto.
Attributes inherited from Tarefa
Instance Method Summary collapse
- #converte_artigo_para_latex ⇒ Object
- #converte_conteudo_para_latex(conteudo) ⇒ Object
- #executa ⇒ Object
- #exporta_conteudo_markdown ⇒ Object
-
#initialize(h = {}) ⇒ ArtigoTarefa
constructor
Um parâmetro obrigatório é o modelo do artigo.
-
#ler_configuracao ⇒ Object
Ler as configurações dos arquivos:.
- #ler_metadados_do_arquivo(arquivo) ⇒ Object
- #modelos ⇒ Object
-
#unifica_metadados ⇒ Object
Converte os arquivos secundários para latex, e salva junto com os blocos yaml no hash
metadados
.
Constructor Details
#initialize(h = {}) ⇒ ArtigoTarefa
Um parâmetro obrigatório é o modelo do artigo
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/formatafacil/artigo_tarefa.rb', line 46 def initialize(h={}) @arquivo_resumo = 'resumo.md' @arquivo_abstract = 'abstract.md' @arquivo_bibliografia ='bibliografia.md' @arquivo_metadados = 'metadados.yaml' @arquivo_saida_yaml = 'artigo.yaml' @arquivo_saida_pdf = 'artigo.pdf' @arquivo_saida_latex = 'artigo.tex' @artigo = {} @artigo_latex = {} @metadados = {} h.each {|k,v| send("#{k}=",v)} @arquivo_texto = "#{modelo}.md" end |
Instance Attribute Details
#abstract ⇒ Object
Returns the value of attribute abstract.
24 25 26 |
# File 'lib/formatafacil/artigo_tarefa.rb', line 24 def abstract @abstract end |
#arquivo_abstract ⇒ Object
Returns the value of attribute arquivo_abstract.
32 33 34 |
# File 'lib/formatafacil/artigo_tarefa.rb', line 32 def arquivo_abstract @arquivo_abstract end |
#arquivo_bibliografia ⇒ Object
Returns the value of attribute arquivo_bibliografia.
33 34 35 |
# File 'lib/formatafacil/artigo_tarefa.rb', line 33 def arquivo_bibliografia @arquivo_bibliografia end |
#arquivo_metadados ⇒ Object
Arquivo padrão de leitura dos metadados: metadados.yaml
35 36 37 |
# File 'lib/formatafacil/artigo_tarefa.rb', line 35 def @arquivo_metadados end |
#arquivo_resumo ⇒ Object
Returns the value of attribute arquivo_resumo.
31 32 33 |
# File 'lib/formatafacil/artigo_tarefa.rb', line 31 def arquivo_resumo @arquivo_resumo end |
#arquivo_saida_latex ⇒ Object
Returns the value of attribute arquivo_saida_latex.
38 39 40 |
# File 'lib/formatafacil/artigo_tarefa.rb', line 38 def arquivo_saida_latex @arquivo_saida_latex end |
#arquivo_saida_pdf ⇒ Object
Returns the value of attribute arquivo_saida_pdf.
37 38 39 |
# File 'lib/formatafacil/artigo_tarefa.rb', line 37 def arquivo_saida_pdf @arquivo_saida_pdf end |
#arquivo_saida_yaml ⇒ Object
Returns the value of attribute arquivo_saida_yaml.
36 37 38 |
# File 'lib/formatafacil/artigo_tarefa.rb', line 36 def arquivo_saida_yaml @arquivo_saida_yaml end |
#arquivo_texto ⇒ Object
conteúdo convertido
30 31 32 |
# File 'lib/formatafacil/artigo_tarefa.rb', line 30 def arquivo_texto @arquivo_texto end |
#artigo ⇒ Object
conteúdo lidos os arquivos
26 27 28 |
# File 'lib/formatafacil/artigo_tarefa.rb', line 26 def artigo @artigo end |
#artigo_latex ⇒ Object
conteúdo convertido
27 28 29 |
# File 'lib/formatafacil/artigo_tarefa.rb', line 27 def artigo_latex @artigo_latex end |
#bibliografia ⇒ Object
Returns the value of attribute bibliografia.
21 22 23 |
# File 'lib/formatafacil/artigo_tarefa.rb', line 21 def bibliografia @bibliografia end |
#compilador ⇒ Object
Tarefa que pode ser encadeada para compilar o artigo para pdf
41 42 43 |
# File 'lib/formatafacil/artigo_tarefa.rb', line 41 def compilador @compilador end |
#metadados ⇒ Object
Returns the value of attribute metadados.
20 21 22 |
# File 'lib/formatafacil/artigo_tarefa.rb', line 20 def @metadados end |
#modelo ⇒ Object
Returns the value of attribute modelo.
19 20 21 |
# File 'lib/formatafacil/artigo_tarefa.rb', line 19 def modelo @modelo end |
#resumo ⇒ Object
Returns the value of attribute resumo.
23 24 25 |
# File 'lib/formatafacil/artigo_tarefa.rb', line 23 def resumo @resumo end |
#texto ⇒ Object
Returns the value of attribute texto.
22 23 24 |
# File 'lib/formatafacil/artigo_tarefa.rb', line 22 def texto @texto end |
Instance Method Details
#converte_artigo_para_latex ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/formatafacil/artigo_tarefa.rb', line 122 def converte_artigo_para_latex result = "" t = Formatafacil::Template.new() Open3.popen3("pandoc --smart --standalone --no-wrap --data-dir=#{t.directory} --template=#{modelo} -f markdown -t latex") {|stdin, stdout, stderr, wait_thr| pid = wait_thr.pid # pid of the started process. stdin.write exporta_conteudo_markdown stdin.close result = stdout.read } result end |
#converte_conteudo_para_latex(conteudo) ⇒ Object
134 135 136 137 138 139 140 141 142 143 |
# File 'lib/formatafacil/artigo_tarefa.rb', line 134 def converte_conteudo_para_latex(conteudo) result = "" Open3.popen3("pandoc --smart -f markdown -t latex") {|stdin, stdout, stderr, wait_thr| pid = wait_thr.pid # pid of the started process. stdin.write conteudo stdin.close result = stdout.read } result.strip end |
#executa ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/formatafacil/artigo_tarefa.rb', line 61 def executa verifica_conteudos escreve_artigo_latex compila_pdf #ler_configuracao #executa_com_configuracao end |
#exporta_conteudo_markdown ⇒ Object
118 119 120 |
# File 'lib/formatafacil/artigo_tarefa.rb', line 118 def exporta_conteudo_markdown "#{@texto}\n#{@metadados.to_yaml}---\n" end |
#ler_configuracao ⇒ Object
Ler as configurações dos arquivos:
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/formatafacil/artigo_tarefa.rb', line 74 def ler_configuracao #@artigo.merge!(YAML.load(ler_arquivo(Formatafacil::Tarefa.arquivo_configuracao))) #converte_parametros_para_boolean #@modelo = @artigo['modelo'] if File.exist?(@arquivo_abstract) then @artigo['abstract'] = ler_arquivo(@arquivo_abstract) @artigo.merge!((@arquivo_abstract)) end if File.exist?(@arquivo_resumo) then @artigo['resumo'] = ler_arquivo(@arquivo_resumo) end @artigo['bibliografia'] = ler_arquivo(@arquivo_bibliografia) if File.exist?(@arquivo_bibliografia) #unifica_metadados end |
#ler_metadados_do_arquivo(arquivo) ⇒ Object
92 93 94 95 96 97 98 99 |
# File 'lib/formatafacil/artigo_tarefa.rb', line 92 def (arquivo) result = {} = JSON.parse(`pandoc -t json #{arquivo}`)[0]['unMeta'] .each do |k,v| result[k]=converte_valor_da_arvore_pandoc(v) end result end |
#modelos ⇒ Object
114 115 116 |
# File 'lib/formatafacil/artigo_tarefa.rb', line 114 def modelos Formatafacil::Template.new().artigo_modelos end |
#unifica_metadados ⇒ Object
Converte os arquivos secundários para latex, e salva junto com os blocos yaml no hash metadados
.
105 106 107 108 109 110 111 112 |
# File 'lib/formatafacil/artigo_tarefa.rb', line 105 def #salva_resumo_em_metadados #salva_blocos_de_metadados @metadados['resumo'] = converte_conteudo_para_latex(@resumo) @metadados['abstract'] = converte_conteudo_para_latex(@abstract) @metadados['bibliografia'] = converte_conteudo_para_latex(@bibliografia) @metadados.merge!(extrai_blocos_yaml(@abstract)) end |