limarka 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github_changelog_generator +6 -0
- data/.gitignore +201 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CHANGELOG.md +77 -0
- data/CODE_OF_CONDUCT.md +71 -0
- data/Gemfile +4 -0
- data/ISSUE_TEMPLATE.md +8 -0
- data/LICENSE +21 -0
- data/README.md +33 -0
- data/Rakefile +58 -0
- data/anexos.md +9 -0
- data/apendices.md +9 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/configuracao.odt +0 -0
- data/errata.md +6 -0
- data/exe/limarka +7 -0
- data/imagens/configuracao/agradecimentos.png +0 -0
- data/imagens/configuracao/capa.png +0 -0
- data/imagens/configuracao/capitulos-e-secoes.png +0 -0
- data/imagens/configuracao/consulta-vigencia-normas-abnt.png +0 -0
- data/imagens/configuracao/dedicatoria.png +0 -0
- data/imagens/configuracao/epigrafe.png +0 -0
- data/imagens/configuracao/errata.png +0 -0
- data/imagens/configuracao/folha-de-aprovacao.png +0 -0
- data/imagens/configuracao/folha-de-rosto.png +0 -0
- data/imagens/configuracao/lista-nao-ordenada.png +0 -0
- data/imagens/configuracao/lista-ordenada-numericamente1.png +0 -0
- data/imagens/configuracao/lista-ordenada-por-letras-parentese.png +0 -0
- data/imagens/configuracao/lista-ordenada-por-letras-ponto.png +0 -0
- data/imagens/configuracao/lista-siglas.png +0 -0
- data/imagens/configuracao/lista-simbolos.png +0 -0
- data/imagens/configuracao/mapa-arquivos.mm +130 -0
- data/imagens/configuracao/mapa-arquivos.svg +908 -0
- data/imagens/configuracao/trabalho-academico-elementos.png +0 -0
- data/imagens/ficha-catalografica.odt +0 -0
- data/imagens/ficha-catalografica.pdf +0 -0
- data/imagens/folha-de-aprovacao-escaneada.pdf +0 -0
- data/imagens/passaro.jpg +0 -0
- data/lib/limarka/cli.rb +124 -0
- data/lib/limarka/configuracao.rb +46 -0
- data/lib/limarka/conversor.rb +238 -0
- data/lib/limarka/pdfconf.rb +186 -0
- data/lib/limarka/trabalho.rb +170 -0
- data/lib/limarka/version.rb +3 -0
- data/lib/limarka.rb +8 -0
- data/limarka.gemspec +35 -0
- data/referencias.bib +344 -0
- data/templates/README.md +17 -0
- data/templates/configuracao-tecnica.yaml +10 -0
- data/templates/postextual1-referencias.latex +10 -0
- data/templates/postextual2-glossario.latex +7 -0
- data/templates/postextual3-apendices.latex +22 -0
- data/templates/postextual4-anexos.latex +16 -0
- data/templates/postextual5-indice.latex +8 -0
- data/templates/pretextual1-folha_de_rosto.latex +24 -0
- data/templates/pretextual10-lista_tabelas.latex +14 -0
- data/templates/pretextual11-lista_siglas.latex +14 -0
- data/templates/pretextual12-lista_simbolos.latex +15 -0
- data/templates/pretextual13-sumario.latex +8 -0
- data/templates/pretextual2-errata.latex +17 -0
- data/templates/pretextual3-folha_de_aprovacao.latex +68 -0
- data/templates/pretextual4-dedicatoria.latex +15 -0
- data/templates/pretextual5-agradecimentos.latex +11 -0
- data/templates/pretextual6-epigrafe.latex +15 -0
- data/templates/pretextual7-resumo.latex +17 -0
- data/templates/pretextual8-abstract.latex +41 -0
- data/templates/pretextual9-lista_ilustracoes.latex +12 -0
- data/templates/trabalho-academico.latex +266 -0
- data/trabalho-academico.md +79 -0
- metadata +258 -0
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/imagens/passaro.jpg
ADDED
Binary file
|
data/lib/limarka/cli.rb
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require "thor"
|
3
|
+
require 'pdf_forms'
|
4
|
+
require 'yaml'
|
5
|
+
require 'colorize'
|
6
|
+
require 'open3'
|
7
|
+
|
8
|
+
require 'limarka/configuracao'
|
9
|
+
require 'limarka/conversor'
|
10
|
+
|
11
|
+
module Limarka
|
12
|
+
|
13
|
+
class Cli < Thor
|
14
|
+
default_command :exec
|
15
|
+
|
16
|
+
method_option :configuracao_yaml, :aliases => '-y', :type => :boolean, :desc => 'Ler configuração exportada (configuracao.yaml) em vez de configuracao.pdf', :default => false
|
17
|
+
method_option :input_dir, :aliases => '-i', :desc => 'Diretório onde será executado a ferramenta', :default => '.'
|
18
|
+
method_option :output_dir, :aliases => '-o', :desc => 'Diretório onde serão gerados os arquivos', :default => '.'
|
19
|
+
method_option :compila_tex, :aliases => '-c', :desc => 'Compila arquivo tex gerando um PDF', :default => true, :type => :boolean
|
20
|
+
method_option :templates_dir, :aliases => '-t', :desc => 'Diretório que contem a pasta templates (pandoc --data-dir)', :default => Dir.pwd
|
21
|
+
method_option :verbose, :aliases => '-v', :desc => 'Imprime mais detalhes da execução', :default => false, :type => :boolean
|
22
|
+
desc "exec", "Executa o sistema para geração do documento latex e compilação"
|
23
|
+
def exec
|
24
|
+
#options[:output_dir] = File.absolute_path(options[:output_dir])
|
25
|
+
Dir.chdir(options[:input_dir]) do
|
26
|
+
t = Limarka::Trabalho.new
|
27
|
+
t.atualiza_de_arquivos(options)
|
28
|
+
cv = Limarka::Conversor.new(t,options)
|
29
|
+
cv.convert
|
30
|
+
cv.compila if options[:compila_tex]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
desc "importa ARQUIVO", "Cria um arquivo trabalho-academico.md com o conteúdo convertido de ARQUIVO"
|
36
|
+
long_desc "Converte documento do Word (ou similar) para trabalho-academico.md. O arquivo será criado no mesmo diretório que contém ARQUIVO. Útil quando possuímos um arquivo já digitado no word e desejamos utilizar o limarka. Mantém, por exemplo, as marcações de itálico, negrito e notas de rodapé."
|
37
|
+
def importa(arquivo)
|
38
|
+
diretorio = File.dirname(arquivo)
|
39
|
+
system "pandoc", "-t", "markdown", "-o", "#{diretorio}/trabalho-academico.md", arquivo
|
40
|
+
end
|
41
|
+
|
42
|
+
=begin
|
43
|
+
method_option :entrada, :default => "configuracao.pdf", :aliases => "-i", :banner => "FILE"
|
44
|
+
method_option :saida, :default => "templates/configuracao.yaml", :aliases => "-o", :banner => "FILE"
|
45
|
+
desc "pdfconf", "Ler configuração de arquivo pdf"
|
46
|
+
def pdfconf
|
47
|
+
|
48
|
+
if not (File.exist?(options[:entrada])) then
|
49
|
+
raise IOError, "Arquivo não existe: #{options[:entrada]}"
|
50
|
+
end
|
51
|
+
|
52
|
+
@pdftk = PdfForms.new 'pdftk'
|
53
|
+
pdf = PdfForms::Pdf.new options[:entrada], @pdftk, utf8_fields: true
|
54
|
+
h = {} # hash
|
55
|
+
|
56
|
+
# Campos do PDF
|
57
|
+
pdf.fields.each do |f|
|
58
|
+
value = f.value
|
59
|
+
if value == "Off" then value = false end
|
60
|
+
if value == "" then value = nil end
|
61
|
+
h[f.name] = value
|
62
|
+
end
|
63
|
+
|
64
|
+
# Substitui ',' e ';' por '.'
|
65
|
+
['palavras_chave', 'palabras_clave', 'keywords', 'mots_cles'].each do |p|
|
66
|
+
if(h[p])
|
67
|
+
h[p] = h[p].gsub(/[;,]/, '.')
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
h['monografia'] = h["tipo_do_trabalho"] == "Monografia"
|
72
|
+
h["ficha_catalografica"] = h["ficha_catalografica"] == "Incluir ficha-catalografica.pdf da pasta imagens"
|
73
|
+
|
74
|
+
|
75
|
+
# siglas e simbolos
|
76
|
+
['siglas','simbolos'].each do |sigla_ou_simbolo|
|
77
|
+
if (h[sigla_ou_simbolo]) then
|
78
|
+
sa = [] # sa: s-array
|
79
|
+
h[sigla_ou_simbolo].each_line do |linha|
|
80
|
+
s,d = linha.split(":")
|
81
|
+
sa << { 's' => s.strip, 'd' => d ? d.strip : ""} if s
|
82
|
+
end
|
83
|
+
h[sigla_ou_simbolo] = sa
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# shows
|
88
|
+
h["errata"] = pdf.field("errata_combo").value == "Utilizar Errata"
|
89
|
+
h["folha_de_aprovacao_gerar"] = pdf.field("folha_de_aprovacao").value == "Gerar folha de aprovação"
|
90
|
+
h["folha_de_aprovacao_incluir"] = pdf.field("folha_de_aprovacao").value == "Utilizar folha de aprovação escaneada"
|
91
|
+
h["lista_ilustracoes"] = pdf.field("lista_ilustracoes").value == "Gerar lista de ilustrações"
|
92
|
+
h["lista_tabelas"] = pdf.field("lista_tabelas").value == "Gerar lista de tabelas"
|
93
|
+
|
94
|
+
# Referências
|
95
|
+
selecao = 'referencias_combo'
|
96
|
+
{"referencias_bib" => "Banco de referências Bibtex (referencias.bib) + \\cite",
|
97
|
+
'referencias_numerica_inline' => "Inseridas ao longo do texto \\citarei + \\cita",
|
98
|
+
'referencias_md' => 'Separadamente, no arquivo referencias.md'}.each do |template_key,valor_para_verdadeiro|
|
99
|
+
h[template_key] = pdf.field(selecao).value == valor_para_verdadeiro
|
100
|
+
end
|
101
|
+
|
102
|
+
#TESTES
|
103
|
+
|
104
|
+
# Escreve na saída
|
105
|
+
s = StringIO.new
|
106
|
+
s << h.to_yaml
|
107
|
+
s << "---\n\n"
|
108
|
+
|
109
|
+
if (options['saida'] == '-')
|
110
|
+
puts s.string
|
111
|
+
else
|
112
|
+
File.open(options['saida'], 'w') { |f| f.write s.string}
|
113
|
+
puts "Arquivo criado: #{options['saida']}".green
|
114
|
+
end
|
115
|
+
end
|
116
|
+
=end
|
117
|
+
|
118
|
+
desc "configuracao help", "Exporta e atualiza configurações"
|
119
|
+
subcommand "configuracao", Limarka::Configuracao
|
120
|
+
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require "thor"
|
3
|
+
require 'pdf_forms'
|
4
|
+
require 'yaml'
|
5
|
+
require 'colorize'
|
6
|
+
require 'open3'
|
7
|
+
|
8
|
+
|
9
|
+
module Limarka
|
10
|
+
|
11
|
+
class Configuracao < Thor
|
12
|
+
|
13
|
+
method_option :output_dir, :aliases => '-o', :desc => 'Diretório onde será salvo a exportação', :default => '.'
|
14
|
+
method_option :input_dir, :aliases => '-i', :desc => 'Diretório onde será executado a ferramenta', :default => '.'
|
15
|
+
desc "exporta", "Exporta configuração para YAML. Ler configuracao.pdf e salva em configuracao.yaml no diretório indicado"
|
16
|
+
def exporta
|
17
|
+
configuracao_pdf = "configuracao.pdf"
|
18
|
+
configuracao_yaml = "configuracao.yaml"
|
19
|
+
Dir.chdir(options[:input_dir]) do
|
20
|
+
raise IOError, "Arquivo não encontrado: #{options[:input_dir]}/" + configuracao_pdf unless File.exist? (configuracao_pdf)
|
21
|
+
pdf = PdfForms::Pdf.new configuracao_pdf, (PdfForms.new 'pdftk'), utf8_fields: true
|
22
|
+
pdfconf = Limarka::Pdfconf.new(pdf: pdf)
|
23
|
+
|
24
|
+
# exporta sem validação
|
25
|
+
h = pdfconf.exporta(false)
|
26
|
+
|
27
|
+
target_file = options[:output_dir]+'/'+configuracao_yaml
|
28
|
+
puts "Sobrescrevendo #{target_file}".green if File.exist?(target_file)
|
29
|
+
Limarka::Trabalho.save_yaml(h, target_file)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
method_option :pdf_antigo, :aliases => "-p", :required => true
|
35
|
+
desc "upgrade", "Após atualização de versão, atualiza os valores do novo arquivo configuracao.pdf a partir do antigo (que precisa ser especificado)"
|
36
|
+
def upgrade
|
37
|
+
puts "Ainda falta implementar".red
|
38
|
+
#t = Limarka::Trabalho.new
|
39
|
+
#configuracao = t.ler_configuracao(:configuracao_yaml => true)
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
@@ -0,0 +1,238 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require "thor"
|
3
|
+
require 'pdf_forms'
|
4
|
+
require 'yaml'
|
5
|
+
require 'colorize'
|
6
|
+
require 'open3'
|
7
|
+
require 'fileutils'
|
8
|
+
require 'bibtex'
|
9
|
+
|
10
|
+
|
11
|
+
module Limarka
|
12
|
+
|
13
|
+
class Conversor
|
14
|
+
# trabalho
|
15
|
+
attr_accessor :t
|
16
|
+
attr_accessor :options
|
17
|
+
attr_accessor :pretextual_tex
|
18
|
+
attr_accessor :postextual_tex
|
19
|
+
attr_accessor :texto_tex
|
20
|
+
attr_accessor :txt
|
21
|
+
|
22
|
+
def initialize(trabalho, options)
|
23
|
+
self.t = trabalho
|
24
|
+
self.options = options
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
## Cria o arquivo
|
29
|
+
def convert()
|
30
|
+
FileUtils.mkdir_p(options[:output_dir])
|
31
|
+
|
32
|
+
# A invocação de pandoc passando parâmetro como --before-body necessita
|
33
|
+
# de ser realizado através de arquivos, portanto, serão criados arquivos
|
34
|
+
# temporários para sua execução
|
35
|
+
pretextual_tempfile = Tempfile.new('pretextual')
|
36
|
+
postextual_tempfile = Tempfile.new('postextual')
|
37
|
+
begin
|
38
|
+
pretextual(pretextual_tempfile)
|
39
|
+
postextual(postextual_tempfile)
|
40
|
+
textual(pretextual_tempfile,postextual_tempfile)
|
41
|
+
|
42
|
+
ensure
|
43
|
+
pretextual_tempfile.close
|
44
|
+
pretextual_tempfile.unlink
|
45
|
+
postextual_tempfile.close
|
46
|
+
postextual_tempfile.unlink
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
## Compila tex_file no diretorio atual, retorna o conteudo somente texto do PDF
|
52
|
+
def compila
|
53
|
+
Dir.chdir(options[:output_dir]) do
|
54
|
+
basename = File.basename(texto_tex_file, '.tex')
|
55
|
+
system "latexmk --quiet --xelatex -f #{basename}", :out=>"/dev/null", :err=>"/dev/null"
|
56
|
+
system "pdftotext -enc UTF-8 #{basename}.pdf"
|
57
|
+
File.open("#{basename}.txt", 'r') {|f| @txt = f.read}
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def hash_to_yaml(h)
|
62
|
+
s = StringIO.new
|
63
|
+
s << h.to_yaml
|
64
|
+
s << "---\n\n"
|
65
|
+
s.string
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
PRETEXTUAL = "templates/pretextual.tex"
|
71
|
+
|
72
|
+
def pretextual(tempfile)
|
73
|
+
s = StringIO.new
|
74
|
+
necessita_de_arquivo_de_texto = ["errata"]
|
75
|
+
["folha_de_rosto", "errata", "folha_de_aprovacao", "dedicatoria", "agradecimentos",
|
76
|
+
"epigrafe", "resumo", "abstract", "lista_ilustracoes", "lista_tabelas",
|
77
|
+
"lista_siglas", "lista_simbolos", "sumario"].each_with_index do |secao,indice|
|
78
|
+
template = "pretextual#{indice+1}-#{secao}"
|
79
|
+
Open3.popen3("pandoc -f markdown --data-dir=#{options[:templates_dir]} --template=#{template} -t latex") {|stdin, stdout, stderr, wait_thr|
|
80
|
+
stdin.write(hash_to_yaml(t.configuracao))
|
81
|
+
stdin.write("\n")
|
82
|
+
if t.errata? and necessita_de_arquivo_de_texto.include?(secao) then
|
83
|
+
arquivo_de_entrada = "#{secao}.md"
|
84
|
+
conteudo = File.read(arquivo_de_entrada)
|
85
|
+
stdin.write(conteudo)
|
86
|
+
end
|
87
|
+
stdin.close
|
88
|
+
s << stdout.read
|
89
|
+
exit_status = wait_thr.value # Process::Status object returned.
|
90
|
+
if(exit_status!=0) then puts ("Erro: " + stderr.read).red end
|
91
|
+
}
|
92
|
+
end
|
93
|
+
@pretextual_tex = s.string
|
94
|
+
File.open(tempfile, 'w') { |file| file.write(pretextual_tex) }
|
95
|
+
# puts "#{PRETEXTUAL} criado".green
|
96
|
+
end
|
97
|
+
|
98
|
+
POSTEXTUAL = "templates/postextual.tex"
|
99
|
+
def postextual(tempfile)
|
100
|
+
# Referências (obrigatório)
|
101
|
+
# Glossário (opcional)
|
102
|
+
# Apêndice (opcional)
|
103
|
+
# Anexo (opcional)
|
104
|
+
# Índice (opcional)
|
105
|
+
|
106
|
+
s = StringIO.new
|
107
|
+
|
108
|
+
s << secao_referencias
|
109
|
+
s << secao_glossario
|
110
|
+
s << secao_apendices
|
111
|
+
s << secao_anexos
|
112
|
+
s << secao_indice
|
113
|
+
|
114
|
+
cria_xxx_referencias
|
115
|
+
|
116
|
+
@postextual_tex = s.string
|
117
|
+
File.open(tempfile, 'w') { |file| file.write(postextual_tex) }
|
118
|
+
end
|
119
|
+
|
120
|
+
## arquivo temporário de referencias
|
121
|
+
def cria_xxx_referencias
|
122
|
+
referencias_tempfile = Tempfile.new('referencias')
|
123
|
+
File.open(referencias_tempfile, 'w') {|file| file.write(t.referencias)}
|
124
|
+
b = BibTeX.open(referencias_tempfile.path)
|
125
|
+
b.each do |entry|
|
126
|
+
if entry.title.include?(':') then
|
127
|
+
s = entry.title.split(':')
|
128
|
+
entry['title'] = s[0].strip
|
129
|
+
entry['subtitle'] = s[1].strip
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
b.save_to referencias_bib_file
|
134
|
+
end
|
135
|
+
|
136
|
+
def secao(template, condicao_para_conteudo, conteudo_externo)
|
137
|
+
s = StringIO.new
|
138
|
+
|
139
|
+
Open3.popen3("pandoc -f markdown --data-dir=#{options[:templates_dir]} --template=#{template} --chapter -t latex") {|stdin, stdout, stderr, wait_thr|
|
140
|
+
stdin.write(hash_to_yaml(t.configuracao))
|
141
|
+
stdin.write("\n")
|
142
|
+
if (condicao_para_conteudo) then
|
143
|
+
stdin.write(conteudo_externo)
|
144
|
+
stdin.write("\n")
|
145
|
+
end
|
146
|
+
stdin.close
|
147
|
+
s << stdout.read
|
148
|
+
exit_status = wait_thr.value # Process::Status object returned.
|
149
|
+
if(exit_status!=0) then puts ("Erro: " + stderr.read).red end
|
150
|
+
}
|
151
|
+
s.string
|
152
|
+
end
|
153
|
+
|
154
|
+
|
155
|
+
def secao_referencias
|
156
|
+
secao("postextual1-referencias", false, t.referencias)
|
157
|
+
end
|
158
|
+
|
159
|
+
def secao_apendices
|
160
|
+
secao("postextual3-apendices", t.apendices?, t.apendices)
|
161
|
+
end
|
162
|
+
|
163
|
+
def secao_anexos
|
164
|
+
secao("postextual4-anexos", t.anexos?, t.anexos)
|
165
|
+
end
|
166
|
+
|
167
|
+
def secao_glossario
|
168
|
+
end
|
169
|
+
|
170
|
+
def secao_indice
|
171
|
+
end
|
172
|
+
|
173
|
+
def textual(pretextual_tempfile, postextual_tempfile)
|
174
|
+
valida_yaml
|
175
|
+
Open3.popen3("pandoc -f markdown+raw_tex -t latex -s --data-dir=#{options[:templates_dir]} --template=trabalho-academico --normalize --chapter --include-before-body=#{pretextual_tempfile.path} --include-after-body=#{postextual_tempfile.path}") {|stdin, stdout, stderr, wait_thr|
|
176
|
+
stdin.write(File.read(options[:templates_dir] + '/templates/configuracao-tecnica.yaml'))
|
177
|
+
stdin.write("\n")
|
178
|
+
stdin.write(hash_to_yaml(t.configuracao))
|
179
|
+
stdin.write("\n")
|
180
|
+
stdin.write(t.texto)
|
181
|
+
stdin.close
|
182
|
+
@texto_tex = stdout.read
|
183
|
+
exit_status = wait_thr.value # Process::Status object returned.
|
184
|
+
if(exit_status!=0) then puts ("Erro: " + stderr.read).red end
|
185
|
+
}
|
186
|
+
File.open(texto_tex_file, 'w') { |f| f.write(@texto_tex)}
|
187
|
+
end
|
188
|
+
|
189
|
+
def pretextual_tex_file
|
190
|
+
"#{options[:output_dir]}/xxx-pretextual.tex"
|
191
|
+
end
|
192
|
+
def postextual_tex_file
|
193
|
+
"#{options[:output_dir]}/xxx-postextual.tex"
|
194
|
+
end
|
195
|
+
|
196
|
+
def texto_tex_file
|
197
|
+
"#{options[:output_dir]}/#{Conversor.tex_file(t.configuracao)}"
|
198
|
+
end
|
199
|
+
def pdf_file
|
200
|
+
texto_tex_file.sub('.tex','.pdf')
|
201
|
+
end
|
202
|
+
|
203
|
+
def referencias_bib_file
|
204
|
+
"#{options[:output_dir]}/xxx-referencias.bib"
|
205
|
+
end
|
206
|
+
|
207
|
+
def valida_yaml
|
208
|
+
# não faz nada por enquanto
|
209
|
+
end
|
210
|
+
|
211
|
+
def self.tex_file(configuracao)
|
212
|
+
if (configuracao['graduacao'] and configuracao['projeto']) then
|
213
|
+
'xxx-Monografia-projeto.tex'
|
214
|
+
elsif (configuracao['graduacao'] and not configuracao['projeto']) then
|
215
|
+
'xxx-Monografia.tex'
|
216
|
+
elsif (configuracao['especializacao'] and configuracao['projeto']) then
|
217
|
+
'xxx-TFC-projeto.tex'
|
218
|
+
elsif (configuracao['especializacao'] and not configuracao['projeto']) then
|
219
|
+
'xxx-TFC.tex'
|
220
|
+
elsif (configuracao['mestrado'] and configuracao['projeto']) then
|
221
|
+
'xxx-Dissertacao-projeto.tex'
|
222
|
+
elsif (configuracao['mestrado'] and not configuracao['projeto']) then
|
223
|
+
'xxx-Dissertacao.tex'
|
224
|
+
elsif (configuracao['doutorado'] and configuracao['projeto']) then
|
225
|
+
'xxx-Tese-projeto.tex'
|
226
|
+
elsif (configuracao['doutorado'] and not configuracao['projeto']) then
|
227
|
+
'xxx-Tese.tex'
|
228
|
+
else
|
229
|
+
# valor padrão, caso não configurado.
|
230
|
+
'xxx-Monografia-projeto.tex'
|
231
|
+
end
|
232
|
+
|
233
|
+
end
|
234
|
+
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
|
@@ -0,0 +1,186 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require "thor"
|
3
|
+
require 'pdf_forms'
|
4
|
+
require 'yaml'
|
5
|
+
require 'colorize'
|
6
|
+
require 'open3'
|
7
|
+
|
8
|
+
module Limarka
|
9
|
+
|
10
|
+
class Pdfconf
|
11
|
+
|
12
|
+
attr_reader :pdf
|
13
|
+
|
14
|
+
def initialize(pdf: nil)
|
15
|
+
@pdf = pdf
|
16
|
+
end
|
17
|
+
|
18
|
+
def update(field, value)
|
19
|
+
pdf.field(field).instance_variable_set(:@value, value)
|
20
|
+
end
|
21
|
+
|
22
|
+
def exporta(valida=true)
|
23
|
+
h = {}
|
24
|
+
h.merge! caixas_de_texto
|
25
|
+
h.merge! nivel_educacao
|
26
|
+
h.merge! ficha_catalografica
|
27
|
+
h.merge! folha_de_aprovacao
|
28
|
+
h.merge! projeto
|
29
|
+
h.merge! apendices
|
30
|
+
h.merge! anexos
|
31
|
+
h.merge! errata
|
32
|
+
h.merge! referencias
|
33
|
+
h.merge! lista_ilustracoes
|
34
|
+
h.merge! lista_tabelas
|
35
|
+
h.merge! lista_siglas
|
36
|
+
|
37
|
+
|
38
|
+
# TODO: converter para chaves?
|
39
|
+
valida_campos(h) if valida
|
40
|
+
h
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def valida_campos(h)
|
46
|
+
arquivo_de_referencias = h['referencias_caminho']
|
47
|
+
raise ArgumentError, "Arquivo de referências configurado não foi encontrado: #{arquivo_de_referencias}" unless File.exist?(arquivo_de_referencias)
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
def apendices
|
52
|
+
{'apendices' => !desativado?('apendices_combo')}
|
53
|
+
end
|
54
|
+
def anexos
|
55
|
+
{'anexos' => !desativado?('anexos_combo')}
|
56
|
+
end
|
57
|
+
|
58
|
+
def errata
|
59
|
+
{'errata' => !desativado?('errata_combo')}
|
60
|
+
end
|
61
|
+
|
62
|
+
def lista_ilustracoes
|
63
|
+
campo = 'lista_ilustracoes_combo'
|
64
|
+
{'lista_ilustracoes' => pdf.field(campo).value.include?('Gerar')}
|
65
|
+
end
|
66
|
+
|
67
|
+
def lista_tabelas
|
68
|
+
campo = 'lista_tabelas_combo'
|
69
|
+
{'lista_tabelas' => pdf.field(campo).value.include?('Gerar')}
|
70
|
+
end
|
71
|
+
|
72
|
+
def lista_siglas
|
73
|
+
h = {}
|
74
|
+
['siglas','simbolos'].each do |campo|
|
75
|
+
str = pdf.field(campo).value
|
76
|
+
if (str) then
|
77
|
+
sa = [] # sa: s-array
|
78
|
+
str.each_line do |linha|
|
79
|
+
s,d = linha.split(":")
|
80
|
+
sa << { 's' => s.strip, 'd' => d ? d.strip : ""} if s
|
81
|
+
end
|
82
|
+
h[campo] = sa.empty? ? nil : sa
|
83
|
+
end
|
84
|
+
end
|
85
|
+
h
|
86
|
+
end
|
87
|
+
|
88
|
+
def referencias
|
89
|
+
value = pdf.field('referencias_sistema_combo').value
|
90
|
+
if value.include?('Numérica') then
|
91
|
+
{'referencias_sistema' => 'num'}
|
92
|
+
elsif value.include?('Alfabética') then
|
93
|
+
{'referencias_sistema' => 'alf'}
|
94
|
+
else
|
95
|
+
raise ArgumentError, "Caixa referencias_sistema_combo com valor inválido"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def projeto
|
100
|
+
campo = 'projeto_combo'
|
101
|
+
value = pdf.field(campo).value
|
102
|
+
|
103
|
+
if value.include?('Projeto') then
|
104
|
+
{'projeto' => true}
|
105
|
+
elsif value.include?('final') then
|
106
|
+
{'projeto' => false}
|
107
|
+
else
|
108
|
+
raise ArgumentError, "Caixa #{campo} com valor inválido"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def ficha_catalografica
|
113
|
+
campo = 'ficha_catalografica_combo'
|
114
|
+
value = pdf.field(campo).value
|
115
|
+
|
116
|
+
if value.include?('Sem ficha') then
|
117
|
+
{'incluir_ficha_catalografica' => false}
|
118
|
+
elsif value.include?('Incluir ficha') then
|
119
|
+
{'incluir_ficha_catalografica' => true}
|
120
|
+
else
|
121
|
+
raise ArgumentError, "Caixa #{campo} com valor inválido"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
def nivel_educacao
|
127
|
+
campo = 'nivel_educacao_combo'
|
128
|
+
value = pdf.field(campo).value
|
129
|
+
|
130
|
+
if value.include?('Graduação') then
|
131
|
+
{'graduacao' => true, 'especializacao' => false, 'mestrado' => false, 'doutorado' => false, 'tipo_do_trabalho'=>'Monografia'}
|
132
|
+
elsif value.include?('Especialização') then
|
133
|
+
{'graduacao' => false, 'especializacao' => true, 'mestrado' => false, 'doutorado' => false, 'tipo_do_trabalho'=>'Trabalho de final de curso'}
|
134
|
+
elsif value.include?('Mestrado') then
|
135
|
+
{'graduacao' => false, 'especializacao' => false, 'mestrado' => true, 'doutorado' => false, 'tipo_do_trabalho'=>'Dissertação'}
|
136
|
+
elsif value.include?('Doutorado') then
|
137
|
+
{'graduacao' => false, 'especializacao' => false, 'mestrado' => false, 'doutorado' => true, 'tipo_do_trabalho'=>'Tese'}
|
138
|
+
else
|
139
|
+
raise ArgumentError, "Caixa #{campo} com valor inválido"
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def folha_de_aprovacao
|
144
|
+
campo = 'folha_de_aprovacao_combo'
|
145
|
+
value = pdf.field(campo).value
|
146
|
+
|
147
|
+
if value.include?('Não gerar') then
|
148
|
+
{'folha_de_aprovacao' => false}
|
149
|
+
elsif value.include?('Gerar folha') then
|
150
|
+
{'folha_de_aprovacao' => true}
|
151
|
+
elsif value.include?('escaneada') then
|
152
|
+
{'incluir_folha_de_aprovacao' => true}
|
153
|
+
else
|
154
|
+
raise ArgumentError, "Caixa #{campo} com valor inválido"
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
|
159
|
+
def desativado?(campo)
|
160
|
+
pdf.field(campo).value.include?('Desativad') # a(o)
|
161
|
+
end
|
162
|
+
|
163
|
+
# Substitui ',' e ';' por '.'
|
164
|
+
def atualiza_palavras_chave(h)
|
165
|
+
['palavras_chave', 'palabras_clave', 'keywords', 'mots_cles'].each do |p|
|
166
|
+
if(h[p])
|
167
|
+
h[p] = h[p].gsub(/[;,]/, '.')
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def caixas_de_texto
|
173
|
+
h = {}
|
174
|
+
pdf.fields.each do |f|
|
175
|
+
if (f.type == "Text") then
|
176
|
+
h[f.name] = f.value
|
177
|
+
end
|
178
|
+
end
|
179
|
+
atualiza_palavras_chave(h)
|
180
|
+
h
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
end
|
185
|
+
|
186
|
+
|