formatafacil 0.1.6 → 0.2.0

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: d4cfc8980d72d6ed3b43bfb603f9e3d9ae2c5fda
4
- data.tar.gz: 924d118ec870a0820a8b37f3e2a3564624d36bdf
3
+ metadata.gz: f0c096c752a0a20eb444229017b59b49407a1210
4
+ data.tar.gz: e2faf09f89169c392d85e53970e5fe076ca0bdfb
5
5
  SHA512:
6
- metadata.gz: 5da07785296d63c63527fa8e9731ac38391f7cecf24f96a9c8b2d3ecb9d8f57e16c360839573bd9c7acdb81123719fefbd7d83d63c56cfe8d5223291966cede6
7
- data.tar.gz: 63abfa4f447c23faa314ae3d84400761921d25334055f19d7d7cca665904afdf79ac008581ba612cc67bb9576b985eb15c29bcb67885945f4280feea76604231
6
+ metadata.gz: 5646799638b07ae838c50dfe1c3d711197725cd4416b9195779cb43d4533eb210bcab6202c75b059529ac991ef96fae0a1a4075a53c5f60b8de1be627f0e8509
7
+ data.tar.gz: e34642c90598f4528495cb2b1513f5d72cb143097c374c744665a8666c809b965713db058f8dcbb74369b75b98b9b4fa99a594eeadb15c2fc569fca1664d46ef
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
  /tmp/
10
10
  /formatafacil.log
11
11
  /texput.log
12
+ /artigo.*
data/README.md CHANGED
@@ -19,6 +19,8 @@ Or install it yourself as:
19
19
 
20
20
  ## Dependência
21
21
 
22
+ - `pandoc` para gerar os códigos latex
23
+ - `pdflatex` - para compilar texto em pdf
22
24
  - `qpdf` se deseja compilar pdf otimizados para web
23
25
 
24
26
  ## Usage
@@ -60,7 +62,7 @@ Cria um diretório e estrutura de um artigo no formato do sbc:
60
62
 
61
63
  ## make configuration easy for advanced users
62
64
 
63
- TODO
65
+ TODO
64
66
 
65
67
  ## install and distribute painlessly
66
68
 
data/Rakefile CHANGED
@@ -1,2 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
2
 
3
+ require "rspec/core/rake_task"
4
+
5
+ RSpec::Core::RakeTask.new
6
+
7
+ task :default => :spec
8
+ task :test => :spec
data/exe/formatafacil CHANGED
@@ -7,6 +7,7 @@ require "formatafacil"
7
7
  require 'formatafacil/template'
8
8
  require 'formatafacil/artigo_tarefa'
9
9
  require 'formatafacil/tarefa_chooser'
10
+ require 'formatafacil/tarefa_modelos'
10
11
  require 'formatafacil/compila'
11
12
  require 'formatafacil/otimizador_para_web'
12
13
 
@@ -24,13 +25,13 @@ switch :logfile
24
25
 
25
26
  desc 'Gera artigos em latex e compila para pdf'
26
27
  command :artigo do |c|
27
-
28
+
28
29
  c.desc 'Gera o arquivo pdf compilando o arquivo latex'
29
30
  c.switch :pdf
30
-
31
+
31
32
  c.desc 'Seleciona o modelo do artigo'
32
33
  c.flag [:m,:modelo]
33
-
34
+
34
35
  c.action do |global,options,args|
35
36
  if (global['logfile'])
36
37
  logger = Logger.new('formatafacil.log')
@@ -38,7 +39,7 @@ command :artigo do |c|
38
39
  logger = Logger.new(STDERR)
39
40
  end
40
41
  logger.level = Logger::WARN
41
-
42
+
42
43
  begin
43
44
  tarefa = Formatafacil::ArtigoTarefa.new()
44
45
  tarefa.logger = logger
@@ -47,11 +48,11 @@ command :artigo do |c|
47
48
  logger.error {e.message}
48
49
  end
49
50
  end
50
-
51
+
51
52
  end
52
53
 
53
54
 
54
- desc 'Auto detecta o comando com base no arquivo de configuração'
55
+ desc 'Compila artigo para pdf'
55
56
  command :compila do |c|
56
57
 
57
58
  c.desc 'Possíveis valores: artigo'
@@ -59,46 +60,43 @@ command :compila do |c|
59
60
 
60
61
  c.desc 'Linealiza o pdf otimizando-o para web'
61
62
  c.switch [:w, 'otimiza-para-web']
62
-
63
-
63
+
64
+
64
65
  c.action do |global,options,args|
65
-
66
+
66
67
  if (global['logfile'])
67
68
  logger = Logger.new('formatafacil.log')
68
69
  else
69
70
  logger = Logger.new(STDOUT)
70
71
  end
71
-
72
+
72
73
  begin
73
74
  Formatafacil::Compila.new().compila_artigo
74
75
  if (options['w'])
75
76
  logger.info "Otimizando para web: #{Formatafacil::ARTIGO_PDF}"
76
- Formatafacil::OtimizadorParaWeb.new(Formatafacil::ARTIGO_PDF).otimiza
77
+ Formatafacil::OtimizadorParaWeb.new(Formatafacil::ARTIGO_PDF).otimiza
77
78
  end
78
79
  rescue Exception => e
79
80
  logger.error {e.message}
80
81
  end
81
-
82
- end
83
-
84
- end
85
-
86
82
 
83
+ end
87
84
 
85
+ end
88
86
 
89
87
  desc 'Auto detecta o comando com base no arquivo de configuração'
90
88
  command :auto do |c|
91
-
92
-
89
+
90
+
93
91
  c.action do |global,options,args|
94
-
92
+
95
93
  if (global['logfile'])
96
94
  logger = Logger.new('formatafacil.log')
97
95
  else
98
96
  logger = Logger.new(STDERR)
99
97
  end
100
98
  logger.level = Logger::WARN
101
-
99
+
102
100
  begin
103
101
  tarefa = Formatafacil::TarefaChooser.new().escolhe_tarefa
104
102
  tarefa.logger = logger
@@ -106,10 +104,36 @@ command :auto do |c|
106
104
  rescue Exception => e
107
105
  logger.error {e.message}
108
106
  end
109
-
107
+
108
+ end
109
+
110
+ end
111
+
112
+
113
+
114
+ desc 'Lista modelos disponíveis'
115
+ command :modelos do |c|
116
+
117
+ c.action do |global,options,args|
118
+
119
+ if (global['logfile'])
120
+ logger = Logger.new('formatafacil.log')
121
+ else
122
+ logger = Logger.new(STDERR)
123
+ end
124
+ logger.level = Logger::WARN
125
+
126
+ begin
127
+ tarefa = Formatafacil::TarefaModelos.new()
128
+ tarefa.logger = logger
129
+ tarefa.executa
130
+ rescue Exception => e
131
+ logger.error {e.message}
132
+ end
133
+
110
134
  end
111
-
135
+
112
136
  end
113
137
 
114
138
 
115
- exit run(ARGV)
139
+ exit run(ARGV)
data/formatafacil.gemspec CHANGED
@@ -8,11 +8,11 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Formatafacil::VERSION
9
9
  spec.authors = ["Eduardo de Santana Medeiros Alexandre"]
10
10
  spec.email = ["eduardo.ufpb@gmail.com"]
11
-
11
+
12
12
  if spec.respond_to?(:metadata)
13
13
  #spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com' to prevent pushes to rubygems.org, or delete to allow pushes to any server."
14
14
  end
15
-
15
+
16
16
  spec.summary = %q{Compila arquivos escritos em Markdown para formatos.}
17
17
  spec.description = %q{Com essa ferramenta você poderá compilar trabalhos de conclusão de curso (monografia, dissertação ou tese) ou artigos com as normas da ABNT ou outra específica }
18
18
  spec.homepage = "https://github.com/formatafacil/formatafacil"
@@ -25,9 +25,8 @@ Gem::Specification.new do |spec|
25
25
 
26
26
  spec.add_development_dependency "bundler", "~> 1.8"
27
27
  spec.add_development_dependency "rake", "~> 10.0"
28
-
29
28
  spec.add_development_dependency "rspec"
30
-
29
+
31
30
  spec.add_dependency "gli"
32
31
  spec.add_dependency "formatafacil-templates"
33
32
 
@@ -7,63 +7,77 @@ require 'yaml'
7
7
  require 'json'
8
8
 
9
9
  module Formatafacil
10
-
10
+
11
11
  class ArtigoTarefa < Tarefa
12
12
  attr_accessor 'modelo'
13
+ attr_accessor 'metadados'
14
+ attr_accessor 'bibliografia'
15
+ attr_accessor 'texto'
16
+ attr_accessor 'resumo'
17
+ attr_accessor 'abstract'
18
+
13
19
  attr_accessor 'artigo' # conteúdo lidos os arquivos
14
20
  attr_accessor 'artigo_latex' # conteúdo convertido
15
-
21
+ # conteúdo convertido
22
+
16
23
  attr_accessor 'arquivo_texto'
17
24
  attr_accessor 'arquivo_resumo'
18
25
  attr_accessor 'arquivo_abstract'
19
- attr_accessor 'arquivo_ingles'
20
26
  attr_accessor 'arquivo_bibliografia'
27
+ # Arquivo padrão de leitura dos metadados: metadados.yaml
28
+ attr_accessor 'arquivo_metadados'
21
29
  attr_accessor 'arquivo_saida_yaml'
22
30
  attr_accessor 'arquivo_saida_pdf'
23
31
  attr_accessor 'arquivo_saida_latex'
24
32
 
33
+ ##
34
+ # Um parâmetro obrigatório é o modelo do artigo
35
+ #
25
36
  def initialize(h={})
26
- @arquivo_texto = 'artigo.md'
27
- @arquivo_resumo = 'config/resumo.md'
28
- @arquivo_abstract = 'config/abstract.md'
29
- @arquivo_ingles = 'config/ingles.yaml'
37
+ @arquivo_resumo = 'resumo.md'
38
+ @arquivo_abstract = 'abstract.md'
30
39
  @arquivo_bibliografia ='bibliografia.md'
40
+ @arquivo_metadados = 'metadados.yaml'
31
41
  @arquivo_saida_yaml = 'artigo.yaml'
32
42
  @arquivo_saida_pdf = 'artigo.pdf'
33
43
  @arquivo_saida_latex = 'artigo.tex'
34
44
  @artigo = {}
35
45
  @artigo_latex = {}
46
+ @metadados = {}
36
47
  h.each {|k,v| send("#{k}=",v)}
48
+ @arquivo_texto = "#{modelo}.md"
37
49
  end
38
-
50
+
39
51
  def executa
40
- ler_configuracao
41
- executa_com_configuracao
42
- end
43
-
44
- def executa_com_configuracao
45
- converte_configuracao_para_latex
46
- salva_configuracao_yaml_para_inclusao_em_pandoc
47
- executa_pandoc_salvando_latex
48
- executa_pdflatex
52
+ verifica_conteudos
53
+ unifica_metadados
54
+ escreve_artigo_latex
55
+ #ler_configuracao
56
+ #executa_com_configuracao
49
57
  end
50
-
58
+
59
+ ##
51
60
  # Ler as configurações dos arquivos:
52
61
  #
53
62
  # @arquivo_resumo
54
63
  def ler_configuracao
55
- @artigo.merge!(YAML.load(ler_arquivo(Formatafacil::Tarefa.arquivo_configuracao)))
56
- converte_parametros_para_boolean
57
-
58
- @modelo = @artigo['modelo']
59
-
60
- @artigo['abstract'] = ler_arquivo(@arquivo_abstract)
61
- @artigo.merge!(ler_metadados_do_arquivo(@arquivo_abstract))
62
- @artigo['resumo'] = ler_arquivo(@arquivo_resumo)
63
- @artigo['bibliografia'] = ler_arquivo(@arquivo_bibliografia)
64
-
65
- end
66
-
64
+ #@artigo.merge!(YAML.load(ler_arquivo(Formatafacil::Tarefa.arquivo_configuracao)))
65
+ #converte_parametros_para_boolean
66
+
67
+ #@modelo = @artigo['modelo']
68
+ if File.exist?(@arquivo_abstract) then
69
+ @artigo['abstract'] = ler_arquivo(@arquivo_abstract)
70
+ @artigo.merge!(ler_metadados_do_arquivo(@arquivo_abstract))
71
+ end
72
+ if File.exist?(@arquivo_resumo) then
73
+ @artigo['resumo'] = ler_arquivo(@arquivo_resumo)
74
+ end
75
+ @artigo['bibliografia'] = ler_arquivo(@arquivo_bibliografia) if File.exist?(@arquivo_bibliografia)
76
+
77
+ #unifica_metadados
78
+
79
+ end
80
+
67
81
  def ler_metadados_do_arquivo(arquivo)
68
82
  result = {}
69
83
  meta = JSON.parse(`pandoc -t json #{arquivo}`)[0]['unMeta']
@@ -72,7 +86,119 @@ module Formatafacil
72
86
  end
73
87
  result
74
88
  end
75
-
89
+
90
+ ##
91
+ # Converte os arquivos secundários para latex, e salva junto com os
92
+ # blocos yaml no hash +metadados+.
93
+ #
94
+ def unifica_metadados
95
+ #salva_resumo_em_metadados
96
+ #salva_blocos_de_metadados
97
+ @metadados['resumo'] = converte_conteudo_para_latex(@resumo)
98
+ @metadados['abstract'] = converte_conteudo_para_latex(@abstract)
99
+ @metadados['bibliografia'] = converte_conteudo_para_latex(@bibliografia)
100
+ @metadados.merge!(extrai_blocos_yaml(@abstract))
101
+ end
102
+
103
+ def modelos
104
+ Formatafacil::Template.new().artigo_modelos
105
+ end
106
+
107
+ def exporta_conteudo_markdown
108
+ "#{@texto}\n#{@metadados.to_yaml}---\n"
109
+ end
110
+
111
+ def converte_artigo_para_latex
112
+ result = ""
113
+ t = Formatafacil::Template.new()
114
+ Open3.popen3("pandoc --smart --standalone --no-wrap --data-dir=#{t.directory} --template=#{modelo} -f markdown -t latex") {|stdin, stdout, stderr, wait_thr|
115
+ pid = wait_thr.pid # pid of the started process.
116
+ stdin.write exporta_conteudo_markdown
117
+ stdin.close
118
+ result = stdout.read
119
+ }
120
+ result
121
+ end
122
+
123
+ def converte_conteudo_para_latex(conteudo)
124
+ result = ""
125
+ Open3.popen3("pandoc --smart -f markdown -t latex") {|stdin, stdout, stderr, wait_thr|
126
+ pid = wait_thr.pid # pid of the started process.
127
+ stdin.write conteudo
128
+ stdin.close
129
+ result = stdout.read
130
+ }
131
+ result.strip
132
+ end
133
+
134
+ private
135
+
136
+ def escreve_artigo_latex
137
+ #File.open('artigo.tex', 'w'){|f| f.write('Primeira seção aqui')}
138
+ #File.open(@arquivo_saida_latex, 'w') {|f| f.write (converte_artigo_para_latex)}
139
+ File.open('artigo.tex', 'w') {|f| f.write (converte_artigo_para_latex)}
140
+ end
141
+
142
+ # Se não houver conteúdos, tentar ler dos arquivos correspondentes
143
+ def verifica_conteudos
144
+ identifica_modelo
145
+ File.open(@arquivo_texto, 'r') {|f| @texto = f.read} if @texto.nil?
146
+ File.open(@arquivo_resumo, 'r') {|f| @resumo = f.read} if @resumo.nil?
147
+ File.open(@arquivo_abstract, 'r') {|f| @abstract = f.read} if @abstract.nil?
148
+ File.open(@arquivo_bibliografia, 'r') {|f| @bibliografia = f.read} if @bibliografia.nil?
149
+ File.open(@arquivo_metadados, 'r') {|f| @metadados = YAML.load(f.read)} if @metadados.empty?
150
+ end
151
+
152
+ def identifica_modelo
153
+ if (@modelo.nil?) then
154
+ t = Formatafacil::Template.new()
155
+ @modelo = t.procura_modelo_de_artigo
156
+ if (@modelo.nil?) then
157
+ raise "Modelo não encontrado. Modelos disponíveis: #{t.list_names}"
158
+ end
159
+ end
160
+ @arquivo_texto = "#{@modelo}.md"
161
+ end
162
+
163
+ ##
164
+ # Returna um hash contendo os conteúdos lidos dos blocos yaml.
165
+ #
166
+ def extrai_blocos_yaml(conteudo)
167
+ result = {}
168
+ Open3.popen3("pandoc -t json") {|stdin, stdout, stderr, wait_thr|
169
+ pid = wait_thr.pid # pid of the started process.
170
+ stdin.write conteudo
171
+ stdin.close
172
+ meta = JSON.parse(stdout.read)[0]['unMeta']
173
+ meta.each do |k,v|
174
+ result[k]=converte_valor_da_arvore_pandoc(v)
175
+ end
176
+ }
177
+ result
178
+ end
179
+
180
+
181
+ def salva_blocos_de_metadados
182
+ [@resumo].each {|texto|
183
+ Open3.popen3("pandoc -t json -f markdown") {|stdin, stdout, stderr, wait_thr|
184
+ pid = wait_thr.pid # pid of the started process.
185
+ stdin.write texto
186
+
187
+ stdin.close
188
+
189
+ conteudo = stdout.read
190
+ meta = JSON.parse(conteudo)[0]['unMeta']
191
+ puts "\nMeta: #{meta}"
192
+ puts "\nmetadados: #{@metadados}"
193
+ meta.each do |k,v|
194
+ #result[k]=converte_valor_da_arvore_pandoc(v)
195
+ #@metadados[k] = converte_valor_da_arvore_pandoc(v)
196
+ @metadados[k] = v
197
+ end
198
+ }
199
+ }
200
+ end
201
+
76
202
  def converte_valor_da_arvore_pandoc(node)
77
203
  # {"boo_false"=>{"t"=>"MetaBool", "c"=>false}, "boo_true"=>{"t"=>"MetaBool", "c"=>true}, "nome_do_parametro"=>{"t"=>"MetaInlines", "c"=>[{"t"=>"Str", "c"=>"valor"}, {"t"=>"Space", "c"=>[]}, {"t"=>"Str", "c"=>"do"}, {"t"=>"Space", "c"=>[]}, {"t"=>"Str", "c"=>"parâmetro"}]}, "numero"=>{"t"=>"MetaString", "c"=>"15"}}
78
204
  result = nil
@@ -104,13 +230,13 @@ module Formatafacil
104
230
  end
105
231
  result
106
232
  end
107
-
233
+
108
234
  def ler_arquivo(arquivo)
109
235
  result = ""
110
236
  File.open(arquivo, 'r') { |f| result = f.read }
111
237
  result
112
238
  end
113
-
239
+
114
240
  def converte_parametros_para_boolean
115
241
  ['incluir_abstract'].each do |param|
116
242
  case @artigo[param]
@@ -125,12 +251,15 @@ module Formatafacil
125
251
  end
126
252
  end
127
253
  end
128
-
254
+
255
+ ##
256
+ # Converte os arquivos de texto markdown para texto latex
257
+ #
129
258
  def converte_configuracao_para_latex
130
259
  @artigo_latex.merge!(@artigo)
131
-
260
+
132
261
  ['resumo','abstract','bibliografia'].each {|key|
133
- Open3.popen3("pandoc --smart -f markdown -t latex") {|stdin, stdout, stderr, wait_thr|
262
+ Open3.popen3("pandoc --smart -f markdown -t latex --no-wrap") {|stdin, stdout, stderr, wait_thr|
134
263
  pid = wait_thr.pid # pid of the started process.
135
264
  stdin.write @artigo[key]
136
265
  stdin.close
@@ -139,28 +268,47 @@ module Formatafacil
139
268
  }
140
269
  end
141
270
 
142
- # Precisa gerar arquivos com quebra de linha antes e depois
143
- # porque pandoc utiliza
144
- def salva_configuracao_yaml_para_inclusao_em_pandoc
145
- File.open(@arquivo_saida_yaml, 'w'){ |file|
146
- file.write("\n")
147
- file.write @artigo_latex.to_yaml
148
- file.write("---\n")
149
- }
271
+ def executa_com_configuracao
272
+ converte_configuracao_para_latex
273
+ salva_configuracao_yaml_para_inclusao_em_pandoc
274
+ executa_pandoc_salvando_latex
275
+ executa_pdflatex
150
276
  end
151
277
 
152
-
153
278
  def executa_pandoc_salvando_latex
154
279
  t = Formatafacil::Template.new()
155
280
  data_dir = t.directory
156
-
157
- system "pandoc --smart -s #{@arquivo_texto} #{@arquivo_saida_yaml} --data-dir=#{data_dir} --template=#{modelo} -f markdown -t latex -o #{@arquivo_saida_latex}"
281
+
282
+ Open3.popen3("pandoc --smart --standalone --data-dir=#{data_dir} --template=#{modelo} -f markdown -t latex -o #{@arquivo_saida_latex}") {|stdin, stdout, stderr, wait_thr|
283
+ pid = wait_thr.pid # pid of the started process.
284
+ stdin.write @texto
285
+ # yaml com metados:
286
+ stdin.write "\n"
287
+ stdin.write @artigo_latex.to_yaml
288
+ stdin.write("---\n")
289
+
290
+ stdin.close
291
+ # stdout.read
292
+ }
293
+ # system "pandoc --smart -s #{@arquivo_texto} #{@arquivo_saida_yaml} --data-dir=#{data_dir} --template=#{modelo} -f markdown -t latex -o #{@arquivo_saida_latex}"
158
294
  end
159
-
295
+
160
296
  def executa_pdflatex
161
297
  #system "pdflatex #{@arquivo_saida_latex}"
162
298
  #system "pdflatex #{@arquivo_saida_latex}"
163
299
  end
164
-
300
+
301
+ # Precisa gerar arquivos com quebra de linha antes e depois
302
+ # porque pandoc utiliza
303
+ def salva_configuracao_yaml_para_inclusao_em_pandoc
304
+ File.open(@arquivo_saida_yaml, 'w'){ |file|
305
+ file.write("\n")
306
+ file.write @artigo_latex.to_yaml
307
+ file.write("---\n")
308
+ }
309
+ end
310
+
311
+
312
+
165
313
  end
166
314
  end
@@ -3,19 +3,13 @@
3
3
  module Formatafacil
4
4
  class Tarefa
5
5
  attr_accessor :logger
6
-
6
+
7
7
  def initialize(h={})
8
8
  h.each {|k,v| send("#{k}=",v)}
9
9
  end
10
-
10
+
11
11
  def executa
12
12
  end
13
-
14
-
15
- def self.arquivo_configuracao
16
- 'config/1-configuracoes-gerais.yaml'
17
- end
18
13
 
19
-
20
14
  end
21
15
  end
@@ -7,15 +7,33 @@ module Formatafacil
7
7
  class ArquivoConfiguracaoAusenteException < Exception
8
8
  end
9
9
 
10
+ ##
11
+ # Não encontrou um arquivo de texto com base nos modelos disponíveis.
12
+ #
13
+ class ArquivoDeTextoNaoEncontradoException < Exception
14
+ end
15
+
16
+
10
17
  class TarefaChooser
11
18
 
12
19
  def escolhe_tarefa
13
- raise Formatafacil::ArquivoConfiguracaoAusenteException, "Não foi possível localizar o arquivo de configuração: #{Formatafacil::Tarefa.arquivo_configuracao}" unless File.exist?(Formatafacil::Tarefa.arquivo_configuracao)
14
- Formatafacil::ArtigoTarefa.new
20
+ Formatafacil::TarefaModelos.new().modelos_disponiveis.each do |modelo|
21
+ if existe_arquivo_de_texto?(markdown_file(modelo)) then
22
+ return Formatafacil::ArtigoTarefa.new(modelo: modelo)
23
+ else
24
+ raise ArquivoDeTextoNaoEncontradoException
25
+ end
26
+ end
27
+ end
28
+
29
+ def markdown_file(file)
30
+ "#{file}.md"
31
+ end
32
+
33
+ def existe_arquivo_de_texto?(arquivo)
34
+ File.exist?(arquivo)
15
35
  end
16
-
36
+
17
37
  end
18
-
19
-
20
38
 
21
39
  end
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+
3
+ require 'formatafacil/tarefa'
4
+
5
+ module Formatafacil
6
+
7
+ class TarefaModelos < Tarefa
8
+
9
+ def executa
10
+ modelos_disponiveis.each {|n| puts n}
11
+ end
12
+
13
+ def modelos_disponiveis
14
+ Formatafacil::Template.new().list_names()
15
+ end
16
+
17
+ end
18
+
19
+ end
@@ -4,18 +4,18 @@ require 'formatafacil/tarefa'
4
4
 
5
5
  module Formatafacil
6
6
  class Template
7
-
7
+
8
8
  attr_accessor 'modelos'
9
9
  # Derectory of templates
10
10
  attr_accessor 'directory'
11
-
11
+
12
12
  def initialize()
13
13
  @modelos = {}
14
14
 
15
15
  # ler os templates do projeto formatafacil-templates
16
- $LOAD_PATH.each { |dir|
16
+ $LOAD_PATH.each { |dir|
17
17
  files = Dir["#{dir}/formatafacil/templates/*.latex"]
18
- files.each { |file|
18
+ files.each { |file|
19
19
  if file
20
20
  @modelos[File.basename(file, '.tex')] = file
21
21
  @directory = "#{dir}/formatafacil"
@@ -24,14 +24,38 @@ module Formatafacil
24
24
  }
25
25
 
26
26
  end
27
-
28
- def executa
27
+
28
+ # Procura por um arquivo que possua o mesmo nome de um modelo.
29
+ # Retorna o modelo com base no arquivo encontrado ou nil se não encontrou.
30
+ # O nome do arquivo procurado será: "#{modelo}.md"
31
+ def procura_modelo_de_artigo
32
+ arquivo = nil
33
+ artigo_modelos.each do |modelo|
34
+ return modelo if File.exist?("#{modelo}.md")
35
+ end
36
+ arquivo
29
37
  end
30
-
38
+
31
39
  # $LOAD_PATH.each { |dir| ... look for resources relative to dir ... }
32
40
  def list
33
41
  modelos.keys
34
42
  end
43
+
44
+ def artigo_modelos
45
+ modelos_de_artigos = []
46
+ list_names.each do |modelo|
47
+ modelos_de_artigos << modelo if modelo.start_with?('artigo')
48
+ end
49
+ modelos_de_artigos
50
+ end
51
+
52
+ def list_names
53
+ names = []
54
+ modelos.keys.each do |file|
55
+ names << File.basename(file, ".latex")
56
+ end
57
+ names
58
+ end
35
59
  end
36
-
60
+
37
61
  end
@@ -1,3 +1,3 @@
1
1
  module Formatafacil
2
- VERSION = "0.1.6"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formatafacil
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo de Santana Medeiros Alexandre
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-07-16 00:00:00.000000000 Z
11
+ date: 2015-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -116,6 +116,7 @@ files:
116
116
  - lib/formatafacil/otimizador_para_web.rb
117
117
  - lib/formatafacil/tarefa.rb
118
118
  - lib/formatafacil/tarefa_chooser.rb
119
+ - lib/formatafacil/tarefa_modelos.rb
119
120
  - lib/formatafacil/template.rb
120
121
  - lib/formatafacil/version.rb
121
122
  homepage: https://github.com/formatafacil/formatafacil
@@ -138,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
139
  version: '0'
139
140
  requirements: []
140
141
  rubyforge_project:
141
- rubygems_version: 2.4.6
142
+ rubygems_version: 2.4.8
142
143
  signing_key:
143
144
  specification_version: 4
144
145
  summary: Compila arquivos escritos em Markdown para formatos.