wortsammler 0.0.3 → 0.0.5

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 ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YTEzMGQxNGYzNTBmYjBhMTkzYjZkZjQ1YWVmYzE3ZmY5YzY5OGMyYg==
5
+ data.tar.gz: !binary |-
6
+ ZWViYmE0Njc3OGQ4NjEzZTgzNWNhMGUyYmYwN2EyNmNiYmVmNmNiMQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ZTBmOTE5OGU3NGRkNTJmNDE1ZDQ2MzU5ZWVlNzcxZTMxNWE2MTRhMGVkOTVk
10
+ YzlhMjE3NzczN2VhOWZiNzcwMzI4NTEwMjZiMDMyMzE1NWU1ZjljMTE0NzJk
11
+ ZTZiZjEyNjRjOGQ4ZWQxYzk5OWZiNzE5ODg0NzcyNGNjOGZiNGU=
12
+ data.tar.gz: !binary |-
13
+ YTAxYjZkNzdkMjdjMTMxMTRkODEyYjVjMjhjNjQwYmExYTQyOGU1MDllNzRh
14
+ NDhmNGRmMjFiYWQ3MWExZTFlNDQ1NmI4ZmJmZWEzOTdhOTdkYzU0YjhkZDVk
15
+ N2ZjOTcyMDZmNTU2YjNlMjlhNThlNmU1YjkxNzhmZGRiYzUzMjk=
data/.gitignore CHANGED
@@ -16,3 +16,9 @@ test/version_tmp
16
16
  tmp
17
17
  testproject
18
18
  wortsammler-gem.sublime-workspace
19
+ resources/pandocdefault.docx
20
+ resources/pandocdefault.epub
21
+ resources/pandocdefault.html
22
+ resources/pandocdefault.latex
23
+ pandoc.css
24
+ testoutput
data/README.md CHANGED
@@ -105,12 +105,14 @@ The rakefile is in `<folder>/30_Sources/ZSUPP_Tools`
105
105
  - Specific syntax in strikethrough is still processed as one line
106
106
  which is not very robust
107
107
  - as of now the "framework" is hard to use in other applications
108
+ - pdf_utilities only run on OSX
108
109
 
109
110
  ## future plans
110
111
 
111
112
  - provide a sublime text package
112
113
  - improve documentation (it is flying around in German and needs to be
113
- consolidated, please refer to <https://github.com/bwl21/wortsammler/wiki>)
114
+ consolidated, please refer to
115
+ <https://github.com/bwl21/wortsammler/wiki>)
114
116
  - support epub
115
117
 
116
118
  ## contributing
@@ -147,17 +149,17 @@ Please use Ruby 1.9.3
147
149
  ### pandoc
148
150
 
149
151
  - Download [ttp://code.google.com/p/pandoc/downloads/list][]
150
- - Installation [http://rubyinstaller.org/downloads/][1]
151
- - Homepage [http://johnmacfarlane.net/pandoc/][pandoc]
152
+ - Installation <http://rubyinstaller.org/downloads/>
153
+ - Homepage <http://johnmacfarlane.net/pandoc/>
152
154
 
153
155
  ### TeX
154
156
 
155
- - mac: download [http://tug.org/mactex/][]
157
+ - mac: download <http://tug.org/mactex/>
156
158
 
157
159
  - windows:
158
160
 
159
- - [http://www.exomatik.net/U-Latex/USBTeXEnglish\#toc1][]
160
- - [http://www.miktex.org/2.9/setup][]
161
+ - <http://www.exomatik.net/U-Latex/USBTeXEnglish#toc1>
162
+ - <http://www.miktex.org/2.9/setup>
161
163
 
162
164
  Alternatively you can use
163
165
 
@@ -167,8 +169,4 @@ Please use Ruby 1.9.3
167
169
  [http://rubyinstaller.org/downloads/]: http://rubyforge.org/frs/%20download.php/76277/rubyinstaller-1.8.7-p370.exe
168
170
  [DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe]: https://github.com/downloads/oneclick/rubyinstaller/DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe
169
171
  [ttp://code.google.com/p/pandoc/downloads/list]: http://code.google.com/p/pandoc/downloads/list
170
- [1]: http://rubyinstaller.org/downloads/
171
- [http://tug.org/mactex/]: http://tug.org/mactex/
172
- [http://www.exomatik.net/U-Latex/USBTeXEnglish\#toc1]: http://www.exomatik.net/U-Latex/USBTeXEnglish#toc1
173
- [http://www.miktex.org/2.9/setup]: http://www.miktex.org/2.9/setup
174
172
  [usbtex]: http://www.exomatik.net/U-Latex/USBTeXEnglish
data/Rakefile CHANGED
@@ -2,16 +2,22 @@ require "bundler/gem_tasks"
2
2
  require 'rake/clean'
3
3
  require 'rspec/core/rake_task'
4
4
  #require 'ruby-debug'
5
-
5
+
6
6
  CLEAN << "testproject"
7
7
 
8
8
  desc "Run specs"
9
- RSpec::Core::RakeTask.new do |t|
9
+ RSpec::Core::RakeTask.new(:spec, :focus) do |t, args|
10
10
  t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
11
- t.rspec_opts = ['-fd -fd --out ./testresults/wortsammler_testresults.log -fh --out ./testresults/wortsammler_testresults.html']
11
+ if args[:focus] then
12
+ usetags="--tag #{args[:focus]}"
13
+ else
14
+ usetags="--tag ~exp"
15
+ end
16
+ t.rspec_opts = [usetags,
17
+ " -fd -fd --out ./testresults/wortsammler_testresults.log -fh --out ./testresults/wortsammler_testresults.html"]
12
18
  # Put spec opts in a file named .rspec in root
13
19
  end
14
-
20
+
15
21
  desc "Generate code coverage"
16
22
  RSpec::Core::RakeTask.new(:coverage) do |t|
17
23
  t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
@@ -21,14 +27,19 @@ end
21
27
 
22
28
  desc "create documentation"
23
29
  task :doc do
24
- sh "bin/wortsammler -bi README.md"
25
- sh "bin/wortsammler -pi README.md -o ."
26
- sh "yard doc"
30
+ sh "bin/wortsammler -bi README.md"
31
+ sh "bin/wortsammler -bi changelog.md"
32
+ sh "yard --markup markdown doc ."
27
33
  end
28
34
 
35
+ desc "get the default stylefiles from pandoc"
36
+ task :getpandocstyles do
37
+ [:latex, :docx, :html, :epub].each{|format |sh "pandoc -D #{format} > resources/pandocdefault.#{format}"}
38
+ end
39
+
29
40
  desc "run tests"
30
- task :test => [:clean, :spec]
41
+ task :test => [:clean, :spec]
31
42
 
32
43
  task :default do
33
- rake -T
34
- end
44
+ sh "rake -T"
45
+ end
data/changelog.md ADDED
@@ -0,0 +1,35 @@
1
+ # 0.0.5
2
+
3
+ - Fixed the usual encoding but which occurred on windows
4
+
5
+ # 0.0.4 (yanked)
6
+
7
+ - Improve handling of lists
8
+ (https://github.com/bwl21/wortsammler/issues/14)
9
+ - adapt to pandoc 1.11.1
10
+ (https://github.com/bwl21/wortsammler/issues/13)
11
+ - provide utilites to convert office documents to pdf with crops
12
+ enhancement (works only on mac)
13
+ (https://github.com/bwl21/wortsammler/issues/12)
14
+ - wortsammler uses pandoc -S when combining documents
15
+ (https://github.com/bwl21/wortsammler/issues/11)
16
+ - improved Error message: config file could not be loaded
17
+ (https://github.com/bwl21/wortsammler/issues/10)
18
+ - improve handling of the stylefile
19
+ (https://github.com/bwl21/wortsammler/issues/8)
20
+ - shall support text flowing around graphics
21
+ (https://github.com/bwl21/wortsammler/issues/7)
22
+
23
+ # 0.0.3 (16.4.2013)
24
+
25
+ - support front matter (https://github.com/bwl21/wortsammler/issues/6)
26
+ - refactor low level api Step 1
27
+ (https://github.com/bwl21/wortsammler/issues/4)
28
+
29
+ # 0.0.2 (11.4.2013)
30
+
31
+ - the first working gem
32
+
33
+ # 0.0.1
34
+
35
+ - initial version
data/lib/wortsammler.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require "wortsammler/version"
2
- require 'pry' if false
2
+ require "wortsammler/class.proolib"
3
3
 
4
4
 
5
5
  ##
@@ -22,14 +22,18 @@ module Wortsammler
22
22
  #
23
23
  # @return [Nil] No Return
24
24
  def self.execute(options)
25
+
26
+
27
+ PandocBeautifier.new($log).check_pandoc_version
28
+
25
29
  ##
26
30
  #
27
31
  # print version info
28
32
  #
29
33
  if options[:version] then
30
- puts "Wortsammler #{Wortsammler::VERSION}"
34
+ puts "#{Wortsammler::PROGNAME} #{Wortsammler::VERSION}"
31
35
 
32
- pandoc=`pandocx -v`.split("\n")[0] rescue pandoc="error running pandoc"
36
+ pandoc=`pandoc -v`.split("\n")[0] rescue pandoc="error running pandoc"
33
37
  xetex=`xelatex -v`.split("\n")[0] rescue pandoc="error running xelatex"
34
38
 
35
39
  puts "found #{pandoc}"
@@ -236,7 +240,8 @@ module Wortsammler
236
240
  "ZSUPP_Tools",
237
241
  "ZSUPP_Styles",
238
242
  "ZGEN_RequirementsTracing",
239
- "001_Main"
243
+ "001_Main",
244
+ "900_snippets"
240
245
  ]
241
246
 
242
247
  folders.each{|folder|
@@ -249,8 +254,9 @@ module Wortsammler
249
254
  }
250
255
  FileUtils.cp("#{resourcedir}/main.md", "#{root}/001_Main")
251
256
  FileUtils.cp("#{resourcedir}/rakefile.rb", "#{root}/ZSUPP_Tools")
252
- FileUtils.cp("#{resourcedir}/default.latex", "#{root}/ZSUPP_Styles")
257
+ FileUtils.cp("#{resourcedir}/default.wortsammler.latex", "#{root}/ZSUPP_Styles")
253
258
  FileUtils.cp("#{resourcedir}/logo.jpg", "#{root}/ZSUPP_Styles")
259
+ FileUtils.cp("#{resourcedir}/snippets.xlsx", "#{root}/900_snippets")
254
260
 
255
261
  nil
256
262
  end
@@ -16,8 +16,10 @@ require 'yaml'
16
16
  require 'tmpdir'
17
17
  require 'nokogiri'
18
18
  require "rubyXL"
19
+ require 'logger'
19
20
 
20
-
21
+ Encoding.default_external = Encoding::UTF_8
22
+ Encoding.default_internal = Encoding::UTF_8
21
23
 
22
24
  # TODO: make these patterns part of the configuration
23
25
 
@@ -39,6 +41,7 @@ INCLUDE_MD_PATTERN = /^\s+~~MD\s+"(.+)" \s+ "(.+)" \s* (\d*) \s* (\d+-\d+)? \
39
41
 
40
42
  SNIPPET_PATTERN = /(\s*)~~SN \s+ (\w+)~~/x
41
43
 
44
+ EMBEDDED_IMAGE_PATTERN = /~~EMBED\s+ "(.+)" \s+ (r|l|i|o) \s+ (.+) \s+ (.+)~~/x
42
45
 
43
46
  #
44
47
  # This mixin convertes a file path to the os Path representation
@@ -129,7 +132,7 @@ class ReferenceTweaker
129
132
 
130
133
  # this does the postprocessing
131
134
  # of the file
132
- # in particluar handloe wortsammler's specific syntax.
135
+ # in particluar handle wortsammler's specific syntax.
133
136
  def prepareFile(infile, outfile)
134
137
 
135
138
  infileIo=File.new(infile)
@@ -167,6 +170,19 @@ class ReferenceTweaker
167
170
  }
168
171
  end
169
172
 
173
+
174
+ # embed images
175
+ #
176
+ if @target == "pdf"
177
+ text.gsub!(EMBEDDED_IMAGE_PATTERN){|m|
178
+ "\\wsembedimage{#{$1}}{#{$2}}{#{$3}}{#{$4}}"
179
+ }
180
+ else #if not pdf then it gets a regular image
181
+ text.gsub!(EMBEDDED_IMAGE_PATTERN){|m|
182
+ "![#{$1}](#{$1})"
183
+ }
184
+ end
185
+
170
186
  #inject the anchors for references to traces ->[traceid]
171
187
  if @target == "pdf" then
172
188
  text.gsub!(TRACE_ANCHOR_PATTERN){|m| "[#{$1}]#{$2}\\hypertarget{#{mkInternalTraceId($1)}}{}"}
@@ -236,6 +252,10 @@ class ProoConfig
236
252
  $log.error "config file not found '#{configFileName}'"
237
253
  else
238
254
  $log.error "config file could not be loaded '#{configFileName}'"
255
+ if File.directory?(configFileName)then
256
+ # note that windows does not disinguish this.
257
+ $log.error "#{configFileName} is a directory"
258
+ end
239
259
  $log.error "reason '#{e.message}'"
240
260
  end
241
261
  exit(false)
@@ -329,6 +349,33 @@ class PandocBeautifier
329
349
  end
330
350
  end
331
351
 
352
+
353
+
354
+ #
355
+
356
+ # This checks if an appropriate pandoc version can be
357
+ # started on the machine
358
+
359
+ #
360
+
361
+ # @return [boolean] true if an appropriate version is available
362
+ def check_pandoc_version
363
+ required_version_string="1.11"
364
+ begin
365
+ pandoc_version=`pandoc -v`.split("\n").first.split(" ")[1]
366
+ if pandoc_version < required_version_string then
367
+ @log.error "found pandoc #{pandoc_version} need #{required_version_string}"
368
+ result = false
369
+ else
370
+ result = true
371
+ end
372
+ rescue Exception => e
373
+ @log.error("could not run pandoc: #{e.message}")
374
+ result=false
375
+ end
376
+ result
377
+ end
378
+
332
379
  # perform the beautify
333
380
  # * process the file with pandoc
334
381
  # * revoke some quotes introduced by pandoc
@@ -392,16 +439,16 @@ class PandocBeautifier
392
439
  def replace_snippets_in_text(text, snippets)
393
440
  changed=false
394
441
  text.gsub!(SNIPPET_PATTERN){|m|
395
- unless $1.nil? then
396
- replacetext_raw=snippets[$2.to_sym]
397
- leading_whitespace=$1.split("\n",100)
398
- leading_lines=leading_whitespace[0..-1].join("\n")
399
- leading_spaces=leading_whitespace.last || ""
400
- replacetext=leading_lines+replacetext_raw.gsub("\n", "\n#{leading_spaces}")
401
- end
442
+ replacetext_raw=snippets[$2.to_sym]
402
443
 
403
444
  if replacetext_raw
404
445
  changed=true
446
+ unless $1.nil? then
447
+ leading_whitespace=$1.split("\n",100)
448
+ leading_lines=leading_whitespace[0..-1].join("\n")
449
+ leading_spaces=leading_whitespace.last || ""
450
+ replacetext=leading_lines+replacetext_raw.gsub("\n", "\n#{leading_spaces}")
451
+ end
405
452
  @log.debug("replaced snippet #{$2} with #{replacetext}")
406
453
  else
407
454
  replacetext=m
@@ -481,7 +528,7 @@ class PandocBeautifier
481
528
  color="red"
482
529
  end
483
530
 
484
- "\\color{#{color}}\\rule{2cm}{0.5mm}\\marginpar{#{$1.strip}}"
531
+ "\\color{#{color}}\\rule{2cm}{0.5mm}\\newline\\marginpar{#{$1.strip}}"
485
532
 
486
533
  }
487
534
 
@@ -505,7 +552,7 @@ class PandocBeautifier
505
552
 
506
553
  #now combine the input files
507
554
  @log.debug("combining the input files #{inputname} et al")
508
- cmd="pandoc -s -S -o #{output} --ascii #{inputs}" # note that inputs is already quoted
555
+ cmd="pandoc -s -o #{output} --ascii #{inputs}" # note that inputs is already quoted
509
556
  system(cmd)
510
557
  if $?.success? then
511
558
  PandocBeautifier.new().beautify(output)
@@ -514,7 +561,7 @@ class PandocBeautifier
514
561
 
515
562
  #
516
563
  # This loads snipptes from xlsx file
517
- # @param [String] filename of the xlsx file
564
+ # @param [String] file name of the xlsx file
518
565
  # @return [Hash] a hash with the snippetes
519
566
  #
520
567
  def load_snippets_from_xlsx(file)
@@ -562,7 +609,7 @@ class PandocBeautifier
562
609
  # @param [Hash] vars - the variables passed to pandoc
563
610
  # @param [Hash] editions - the editions to process; default nil - no edition processing
564
611
  # @param [Array of String] snippetfiles the list of files containing snippets
565
- # @param [String] file path to frontmatter the file to processed as frontmatter
612
+ # @param [String] frontmatter file path to frontmatter the file to processed as frontmatter
566
613
  # @param [ProoConfig] config - the configuration file to be used
567
614
  def generateDocument(input, outdir, outname, format, vars, editions=nil, snippetfiles=nil, frontmatter=nil, config=nil)
568
615
 
@@ -651,7 +698,7 @@ class PandocBeautifier
651
698
  # @return [nil] no useful return value
652
699
  def render_single_document(input, outdir, format)
653
700
  outname=File.basename(input, ".*")
654
- render_document(input, outdir, outname, format, Hash.new)
701
+ render_document(input, outdir, outname, format, {:geometry=>"a4paper"})
655
702
  end
656
703
  #
657
704
  # This renders the final document
@@ -698,9 +745,9 @@ class PandocBeautifier
698
745
 
699
746
  #todo: make config required, so it can be reduced to the else part
700
747
  if config.nil? then
701
- latexStyleFile = File.dirname(File.expand_path(__FILE__))+"/../../resources/default.latex"
748
+ latexStyleFile = File.dirname(File.expand_path(__FILE__))+"/../../resources/default.wortsammler.latex"
702
749
  latexStyleFile = File.expand_path(latexStyleFile).to_osPath
703
- css_style_file = File.dirname(File.expand_path(__FILE__))+"/../../resources/default.css"
750
+ css_style_file = File.dirname(File.expand_path(__FILE__))+"/../../resources/default.wortsammler.css"
704
751
  css_style_file = File.expand_path(css_style_file).to_osPath
705
752
  else
706
753
  latexStyleFile = config.stylefiles[:latex]
@@ -711,6 +758,12 @@ class PandocBeautifier
711
758
  toc = "--toc"
712
759
  toc = "" if vars[:usetoc]=="nousetoc"
713
760
 
761
+ if vars[:documentclass]=="book"
762
+ option_chapters = "--chapters"
763
+ else
764
+ option_chapter = ""
765
+ end
766
+
714
767
  begin
715
768
  vars_string=vars.map.map{|key, value| "-V #{key}=#{value.esc}"}.join(" ")
716
769
  rescue
@@ -721,14 +774,6 @@ class PandocBeautifier
721
774
 
722
775
  begin
723
776
 
724
- if format.include?("pdf") then
725
- ReferenceTweaker.new("pdf").prepareFile(tempfile, tempfilePdf)
726
- cmd="pandoc -S #{tempfilePdf.esc} #{toc} --standalone --latex-engine xelatex --number-sections #{vars_string}" +
727
- " --template #{latexStyleFile.esc} --ascii -o #{outfilePdf.esc} #{latexTitleInclude}"
728
- `#{cmd}`
729
- end
730
-
731
-
732
777
 
733
778
  if format.include?("frontmatter") then
734
779
 
@@ -738,17 +783,27 @@ class PandocBeautifier
738
783
  `#{cmd}`
739
784
  end
740
785
 
741
- if format.include?("latex") then
786
+ if format.include?("pdf") then
787
+ @log.debug("creating #{outfilePdf}")
788
+ ReferenceTweaker.new("pdf").prepareFile(tempfile, tempfilePdf)
789
+ cmd="pandoc -S #{tempfilePdf.esc} #{toc} --standalone #{option_chapters} --latex-engine xelatex --number-sections #{vars_string}" +
790
+ " --template #{latexStyleFile.esc} --ascii -o #{outfilePdf.esc} #{latexTitleInclude}"
791
+ `#{cmd}`
792
+ end
742
793
 
794
+ if format.include?("latex") then
795
+ @log.debug("creating #{outfileLatex}")
743
796
  ReferenceTweaker.new("pdf").prepareFile(tempfile, tempfilePdf)
744
797
 
745
- cmd="pandoc -S #{tempfilePdf.esc} #{toc} --standalone --latex-engine xelatex --number #{vars_string}" +
798
+ cmd="pandoc -S #{tempfilePdf.esc} #{toc} --standalone #{option_chapters} --latex-engine xelatex --number-sections #{vars_string}" +
746
799
  " --template #{latexStyleFile.esc} --ascii -o #{outfileLatex.esc} #{latexTitleInclude}"
747
800
  `#{cmd}`
748
801
  end
749
802
 
750
803
  if format.include?("html") then
751
804
  #todo: handle css
805
+ @log.debug("creating #{outfileHtml}")
806
+
752
807
  ReferenceTweaker.new("html").prepareFile(tempfile, tempfileHtml)
753
808
 
754
809
  cmd="pandoc -S #{tempfileHtml.esc} --toc --standalone --self-contained --ascii --number-sections #{vars_string}" +
@@ -759,9 +814,11 @@ class PandocBeautifier
759
814
 
760
815
  if format.include?("docx") then
761
816
  #todo: handle style file
817
+ @log.debug("creating #{outfileDocx}")
818
+
762
819
  ReferenceTweaker.new("html").prepareFile(tempfile, tempfileHtml)
763
820
 
764
- cmd="pandoc -S #{tempfileHtml.esc} #{toc} --standalone --self-contained --ascii --number #{vars_string}" +
821
+ cmd="pandoc -S #{tempfileHtml.esc} #{toc} --standalone --self-contained --ascii --number-sections #{vars_string}" +
765
822
  " -o #{outfileDocx.esc}"
766
823
  cmd="pandoc -S #{tempfileHtml.esc} --toc --standalone --self-contained --ascii --number-sections #{vars_string}" +
767
824
  " -o #{outfileDocx.esc}"
@@ -769,7 +826,7 @@ class PandocBeautifier
769
826
  end
770
827
 
771
828
  if format.include?("rtf") then
772
-
829
+ @log.debug("creating #{outfileRtf}")
773
830
  ReferenceTweaker.new("html").prepareFile(tempfile, tempfileHtml)
774
831
 
775
832
  cmd="pandoc -S #{tempfileHtml.esc} --toc --standalone --self-contained --ascii --number-sections #{vars_string}" +
@@ -778,6 +835,7 @@ class PandocBeautifier
778
835
  end
779
836
 
780
837
  if format.include?("txt") then
838
+ @log.debug("creating #{outfileText}")
781
839
 
782
840
  ReferenceTweaker.new("pdf").prepareFile(tempfile, tempfileHtml)
783
841
 
@@ -787,10 +845,11 @@ class PandocBeautifier
787
845
  end
788
846
 
789
847
  if format.include?("slide") then
848
+ @log.debug("creating #{outfileSlide}")
790
849
 
791
850
  ReferenceTweaker.new("slide").prepareFile(tempfile, tempfilePdf)
792
851
  #todo: hanlde stylefile
793
- cmd="pandoc -S #{tempfileHtml.esc} --toc --standalone --number #{vars_string}" +
852
+ cmd="pandoc -S #{tempfileHtml.esc} --toc --standalone --number-sections #{vars_string}" +
794
853
  " --ascii -t dzslides --slide-level 2 -o #{outfileSlide.esc}"
795
854
  `#{cmd}`
796
855
  end