verku 0.8.1.0 → 0.10.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: d915d0abd13d8bf3ed71118d62701b7e3463234a
4
- data.tar.gz: 4aca290bf10dcd3d45666927937d4b15d4f8c58f
3
+ metadata.gz: bcd466c03864fc5464f3df439e28aa8fc1098bb0
4
+ data.tar.gz: 54baa4868d4d9e0262fc5cc5fd63b788f5b0b84f
5
5
  SHA512:
6
- metadata.gz: ac6cabf9ce33dc8365a54ece9fe917549cf213813d2c0da91f5dbdbe3ec6a70f43d2352e071e4a2db905b05bbf2d4413a31456fce066c2d5113ce7ee5b539ada
7
- data.tar.gz: 26916ad016e04963dd63aca0b8ba173c25bc9d5efabda38d824912f69fa3861dafe61cce7e764d15f9c72bbb1d8f4f86fcbdca12a28890e1abc8b307be553d7c
6
+ metadata.gz: da0e954012c131ac106cb7aaf3674aa74de670aa1f6bbbc370eadf6e8cfbb7276cdb6546a6359ec43897b0d29d83eb755eb28ed642bfbe3ae99dc66b94538051
7
+ data.tar.gz: 65665eee30677cb109a4a0b37973141b805a7d4b2e3a7d802c0718ee65d059d2f8ddf6ae915d02290b89e9af10f7dda3c15df72444a7cb8201017ebf74717bb5
data/Rakefile CHANGED
@@ -16,7 +16,7 @@ require './lib/verku/version.rb'
16
16
  Jeweler::Tasks.new do |gem|
17
17
 
18
18
  gem.name = "verku"
19
- gem.version = Verku::Version::STRING
19
+ gem.version = Verku::VERSION
20
20
  gem.authors = ["Merovex"]
21
21
  gem.email = ["dausha+verku@gmail.com"]
22
22
  gem.homepage = "https://github.com/Merovex/verku"
data/lib/verku/cli.rb CHANGED
@@ -46,7 +46,7 @@ module Verku
46
46
  desc "version", "Prints the Verku's version information"
47
47
  map %w(-v --version) => :version
48
48
  def version
49
- say "Verku version #{Verku::Version::STRING}"
49
+ say "Verku version #{Verku::VERSION}"
50
50
  end
51
51
 
52
52
  desc "stats", "Display some stats about your e-book"
@@ -1,24 +1,19 @@
1
1
  require 'open3'
2
+ require "English"
2
3
 
3
4
  module Verku
4
- module Parser
5
- autoload :HTML , "verku/parser/html"
6
- autoload :PDF , "verku/parser/pdf"
7
- autoload :Epub , "verku/parser/epub"
8
- autoload :Mobi , "verku/parser/mobi"
9
- # autoload :Txt , "verku/parser/txt"
10
-
5
+ class Exporter
11
6
  class Base
12
- # The e-book directory.
13
- #
14
- attr_accessor :root_dir
15
-
16
- # Where the text files are stored.
17
- #
18
- attr_accessor :source
19
-
20
- def self.parse(root_dir)
21
- new(root_dir).parse
7
+
8
+ attr_accessor :root_dir # The e-book directory.
9
+ attr_accessor :source # Where the text files are stored.
10
+
11
+ def handle_error(error)
12
+ ui.say "#{error.class}: #{error.message}", :red
13
+ ui.say error.backtrace.join("\n"), :white
14
+ end
15
+ def self.export!(root_dir)
16
+ new(root_dir).export!
22
17
  end
23
18
 
24
19
  def initialize(root_dir)
@@ -27,27 +22,17 @@ module Verku
27
22
  end
28
23
 
29
24
  # Return directory's basename.
30
- #
31
25
  def name
32
26
  File.basename(root_dir)
33
27
  end
34
28
 
35
29
  # Return the configuration file.
36
- #
37
30
  def config
38
31
  Verku.config(root_dir)
39
32
  end
40
- def entries
41
- return @entries unless @entries.nil?
42
- files = Dir["text/**/*.md"]
43
- @entries = {}
44
- files.each do |f|
45
- k = File.dirname(f)
46
- k.gsub!('text/','')
47
- @entries[k] = [] if @entries[k].nil?
48
- @entries[k] << f
49
- end
50
- return @entries
33
+
34
+ def source_list
35
+ @source_list ||= SourceList.new(root_dir)
51
36
  end
52
37
  def render_template(file, locals = {})
53
38
  ERB.new(File.read(file)).result OpenStruct.new(locals).instance_eval{ binding }
@@ -56,18 +41,18 @@ module Verku
56
41
  content = File.read(file)
57
42
  data = {}
58
43
  begin
59
- # YAML_FRONT_MATTER_REGEXP = /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m
60
- if content =~ /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m
44
+ # YAML_FRONT_MATTER_REGEXP = /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m
45
+ if content =~ /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m
61
46
  # content = "\n#{$'}\n"
62
47
  content = $POSTMATCH
63
- data = SafeYAML.load($1)
64
- # data = YAML.load($1)
48
+ # data = SafeYAML.load($1)
49
+ data = YAML.load($1, :safe => true)
65
50
  end
66
51
  return [content, data]
67
52
  rescue SyntaxError => e
68
- puts "YAML Exception reading #{path}: #{e.message}"
53
+ puts "YAML Exception reading #{file}: #{e.message}"
69
54
  rescue Exception => e
70
- puts "Error reading file #{path}: #{e.message}"
55
+ puts "Error reading file #{file}: #{e.message}"
71
56
  end
72
57
  end
73
58
  def spawn_command(cmd)
@@ -1,6 +1,6 @@
1
1
  require 'fileutils'
2
2
  module Verku
3
- module Parser
3
+ class Exporter
4
4
  class Epub < Base
5
5
  def sections
6
6
  @sections ||= html.css("div.chapter").each_with_index.map do |chapter, index|
@@ -14,7 +14,7 @@ module Verku
14
14
  end
15
15
  def epub; @epub ||= EeePub.make ;end
16
16
  def html; @html ||= Nokogiri::HTML(html_path.read); end
17
- def parse
17
+ def export!
18
18
  puts "-- Exporting EPUB"
19
19
  epub.title config["title"]
20
20
  epub.language config["language"]
@@ -0,0 +1,46 @@
1
+ require 'kramdown'
2
+ require "awesome_print"
3
+
4
+ module Verku
5
+ class Exporter
6
+ class HTML < Base
7
+ def export!
8
+ locals = config.merge({ :contents => content })
9
+ locals['copyright'].gsub!("(C)", "&copy;")
10
+ output = render_template(root_dir.join("_templates/html/layout.erb"), locals)
11
+ File.open(root_dir.join(html_file), 'w').write(output)
12
+ true
13
+
14
+ rescue Exception => error
15
+ handle_error(error)
16
+ false
17
+ end
18
+
19
+ private
20
+ def content
21
+ content = String.new
22
+ source_list.each_chapter do |files|
23
+ content << render_chapter(files)
24
+ end
25
+ return content
26
+ end
27
+ def render_file(file)
28
+ data = read_content(file)
29
+ content = "#{data[0]}".to_html
30
+ return content
31
+ end
32
+ def render_chapter(files)
33
+ chapter = String.new
34
+ String.new.tap do
35
+ files.each do |file|
36
+ chapter << render_file(file) << "\n\n"
37
+ end
38
+ end
39
+ return "<div class='chapter'>\n\t#{chapter}\n</div>"
40
+ end
41
+ def html_file
42
+ root_dir.join("builds/#{name}.html")
43
+ end
44
+ end
45
+ end
46
+ end
@@ -1,7 +1,7 @@
1
1
  module Verku
2
- module Parser
2
+ class Exporter
3
3
  class Mobi < Base
4
- def parse
4
+ def export!
5
5
  puts "-- Exporting MOBI"
6
6
  spawn_command ["kindlegen", epub_file.to_s,]
7
7
  true
@@ -0,0 +1,61 @@
1
+ require 'kramdown'
2
+ require "awesome_print"
3
+
4
+ module Verku
5
+ class Exporter
6
+ class PDF < Base
7
+ def export!
8
+ locals = config.merge({ :contents => content })
9
+ locals['copyright'].gsub!("(C)", "\\copyright{}")
10
+ output = render_template(root_dir.join("_templates/pdf/layout.erb"), locals)
11
+ File.open(root_dir.join(tex_file), 'w').write(output)
12
+
13
+ puts "-- Exporting PDF"
14
+ puts " - Pass 1"; spawn_command ["xelatex", tex_file.to_s,]
15
+ puts " - Pass 2"; spawn_command ["xelatex", tex_file.to_s,]
16
+
17
+ if config['status'] == 'final'
18
+ puts " - Pass 3 - Indexing"
19
+ spawn_command ["makeindex #{name}.idx"]
20
+ # spawn_command ["makeglossaries #{name}.glo"]
21
+ spawn_command ["xelatex", tex_file.to_s,]
22
+ spawn_command ["rm *ilg *ind "]
23
+ end
24
+
25
+ spawn_command ["rm *.glo *.idx *.log *.out *.toc *aux *ist"]
26
+ spawn_command ["mv #{name}.pdf builds/#{name}.pdf"]
27
+ true
28
+
29
+ rescue Exception => error
30
+ handle_error(error)
31
+ false
32
+ end
33
+
34
+ private
35
+ def render_file(file)
36
+ data = read_content(file)
37
+ content = "#{data[0]}".to_latex
38
+ return content
39
+ end
40
+ def content
41
+ content = String.new
42
+ source_list.each_chapter do |files|
43
+ content << render_chapter(files)
44
+ end
45
+ return content
46
+ end
47
+ def render_chapter(files)
48
+ chapter = String.new
49
+ String.new.tap do
50
+ files.each do |file|
51
+ chapter << render_file(file) << "\n\n"
52
+ end
53
+ end
54
+ return chapter
55
+ end
56
+ def tex_file
57
+ root_dir.join("builds/#{name}.tex")
58
+ end
59
+ end
60
+ end
61
+ end
@@ -2,7 +2,7 @@ module Verku
2
2
  class Exporter
3
3
  def self.run(root_dir, options)
4
4
  exporter = new(root_dir, options)
5
- exporter.export!
5
+ exporter.export
6
6
  end
7
7
 
8
8
  attr_accessor :root_dir
@@ -17,7 +17,7 @@ module Verku
17
17
  @ui ||= Thor::Base.shell.new
18
18
  end
19
19
 
20
- def export!
20
+ def export
21
21
  helper = root_dir.join("config/helper.rb")
22
22
  load(helper) if helper.exist?
23
23
 
@@ -36,12 +36,12 @@ module Verku
36
36
  export_txt = [nil, "txt"].include?(options[:only])
37
37
 
38
38
  exported = []
39
- exported << Parser::PDF.parse(root_dir) if export_pdf && Dependency.xelatex?# && Dependency.prince?
40
- exported << Parser::HTML.parse(root_dir) if export_html
41
- epub_done = Parser::Epub.parse(root_dir) if export_epub
39
+ exported << PDF.export!(root_dir) if export_pdf && Dependency.xelatex?# && Dependency.prince?
40
+ exported << HTML.export!(root_dir) if export_html
41
+ epub_done = Epub.export!(root_dir) if export_epub
42
42
  exported << epub_done
43
- exported << Parser::Mobi.parse(root_dir) if export_mobi && epub_done && Dependency.kindlegen?
44
- # exported << Parser::Txt.parse(root_dir) if export_txt && Dependency.html2text?
43
+ exported << Mobi.export!(root_dir) if export_mobi && epub_done && Dependency.kindlegen?
44
+ # exported << Txt.parse if export_txt && Dependency.html2text?
45
45
 
46
46
  if exported.all?
47
47
  color = :green
@@ -10,7 +10,8 @@ class String
10
10
  end
11
11
  def to_latex
12
12
  require 'kramdown'
13
- Kramdown::Document.new(self.dup).to_latex
13
+ s = Kramdown::Document.new(self.dup, :latex_headers => %w{chapter section subsection subsubsection paragraph subparagraph}).to_latex
14
+ s << "\\pbreak{}"
14
15
  end
15
16
  def to_html
16
17
  require 'kramdown'
@@ -0,0 +1,74 @@
1
+ module Verku
2
+ class SourceList
3
+ # List of directories that should be skipped.
4
+ #
5
+ IGNORE_DIR = %w[. .. .svn .git]
6
+
7
+ # Files that should be skipped.
8
+ #
9
+ IGNORE_FILES = /^(CHANGELOG|TOC)\..*?$/
10
+
11
+ # List of recognized extensions.
12
+ #
13
+ EXTENSIONS = %w[md markdown text]
14
+
15
+ attr_reader :root_dir
16
+ attr_reader :source
17
+
18
+ def initialize(root_dir)
19
+ @root_dir = root_dir
20
+ @source = root_dir.join('text')
21
+ # @source = root_dir
22
+ end
23
+
24
+ #
25
+ #
26
+ def each_chapter(&block)
27
+ files_grouped_by_chapter.each(&block)
28
+ end
29
+
30
+ def files_grouped_by_chapter
31
+ entries.each_with_object([]) do |entry, buffer|
32
+ files = chapter_files(entry)
33
+ buffer << files unless files.empty?
34
+ end
35
+ end
36
+
37
+ def chapter_files(entry)
38
+ # Chapters can be files outside a directory.
39
+ if File.file?(entry)
40
+ [entry]
41
+ else
42
+ Dir["#{entry}/**/*.{#{EXTENSIONS.join(",")}}"].sort
43
+ end
44
+ end
45
+
46
+ # Return a list of all recognized files.
47
+ #
48
+ def entries
49
+ Dir.entries(source).sort.each_with_object([]) do |entry, buffer|
50
+ buffer << source.join(entry) if valid_entry?(entry)
51
+ end
52
+ end
53
+
54
+ # Check if path is a valid entry.
55
+ # Files/directories that start with a dot or underscore will be skipped.
56
+ #
57
+ def valid_entry?(entry)
58
+ entry !~ /^(\.|_)/ && (valid_directory?(entry) || valid_file?(entry))
59
+ end
60
+
61
+ # Check if path is a valid directory.
62
+ #
63
+ def valid_directory?(entry)
64
+ File.directory?(source.join(entry)) && !IGNORE_DIR.include?(File.basename(entry))
65
+ end
66
+
67
+ # Check if path is a valid file.
68
+ #
69
+ def valid_file?(entry)
70
+ ext = File.extname(entry).gsub(/\./, "").downcase
71
+ File.file?(source.join(entry)) && EXTENSIONS.include?(ext) && entry !~ IGNORE_FILES
72
+ end
73
+ end
74
+ end
data/lib/verku/version.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  module Verku
2
- module Version
3
- MAJOR = 0
4
- MINOR = 8
5
- PATCH = 1
6
- BUILD = 0
2
+ VERSION = '0.10.0'
3
+ # module Version
4
+ # MAJOR = 0
5
+ # MINOR = 9
6
+ # PATCH = 0
7
+ # BUILD = 1
7
8
 
8
- STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
9
- end
9
+ # STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
10
+ # end
10
11
  end
data/lib/verku.rb CHANGED
@@ -16,23 +16,31 @@ require "thor"
16
16
  require "thor/group"
17
17
  require "yaml"
18
18
  require "cgi"
19
+ require "safe_yaml"
19
20
 
20
21
  module Verku
21
-
22
- require "verku/extensions/string"
23
22
  ROOT = Pathname.new(File.dirname(__FILE__) + "/..")
23
+
24
+ require "verku/extensions/string"
25
+ require "verku/cli"
26
+ require "verku/dependency"
24
27
 
25
- autoload :Cli, "verku/cli"
26
- autoload :Dependency, "verku/dependency"
27
- autoload :Exporter, "verku/exporter"
28
- autoload :Generator, "verku/generator"
29
- autoload :Markdown, "verku/adapters/markdown"
30
- autoload :Parser, "verku/parser"
31
- autoload :Stats, "verku/stats"
32
- autoload :Stream, "verku/stream"
33
- autoload :Structure, "verku/structure"
34
- autoload :TOC, "verku/toc"
35
- # autoload :Version, "verku/version"
28
+ require "verku/exporter"
29
+ require "verku/exporter/base"
30
+ require "verku/exporter/pdf"
31
+ require "verku/exporter/html"
32
+ require "verku/exporter/epub"
33
+ require "verku/exporter/mobi"
34
+
35
+ require "verku/generator"
36
+ require "verku/adapters/markdown"
37
+ # require "verku/parser"
38
+ require "verku/source_list"
39
+ require "verku/stats"
40
+ require "verku/stream"
41
+ # require "verku/structure"
42
+ require "verku/toc"
43
+ require 'verku/version'
36
44
 
37
45
  Encoding.default_internal = "utf-8"
38
46
  Encoding.default_external = "utf-8"
@@ -44,8 +52,8 @@ module Verku
44
52
  raise "Invalid Verku directory; couldn't found #{path} file." unless File.file?(path)
45
53
  content = File.read(path)
46
54
  erb = ERB.new(content).result
47
-
48
- YAML.load(erb)#.with_indifferent_access
55
+ YAML.load(erb, :safe => true)
56
+ #YAML.load(erb)#.with_indifferent_access
49
57
  end
50
58
  def self.logger
51
59
  @logger ||= Logger.new(File.open("/tmp/verku.log", "a"))
data/verku.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: verku 0.8.1.0 ruby lib
5
+ # stub: verku 0.10.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "verku"
9
- s.version = "0.8.1.0"
9
+ s.version = "0.10.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
@@ -36,14 +36,15 @@ Gem::Specification.new do |s|
36
36
  "lib/verku/cli.rb",
37
37
  "lib/verku/dependency.rb",
38
38
  "lib/verku/exporter.rb",
39
+ "lib/verku/exporter/base.rb",
40
+ "lib/verku/exporter/epub.rb",
41
+ "lib/verku/exporter/html.rb",
42
+ "lib/verku/exporter/mobi.rb",
43
+ "lib/verku/exporter/pdf.rb",
44
+ "lib/verku/exporter/txt.rb",
39
45
  "lib/verku/extensions/string.rb",
40
46
  "lib/verku/generator.rb",
41
- "lib/verku/parser.rb",
42
- "lib/verku/parser/epub.rb",
43
- "lib/verku/parser/html.rb",
44
- "lib/verku/parser/mobi.rb",
45
- "lib/verku/parser/pdf.rb",
46
- "lib/verku/parser/txt.rb",
47
+ "lib/verku/source_list.rb",
47
48
  "lib/verku/stats.rb",
48
49
  "lib/verku/stream.rb",
49
50
  "lib/verku/toc.rb",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: verku
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Merovex
@@ -247,14 +247,15 @@ files:
247
247
  - lib/verku/cli.rb
248
248
  - lib/verku/dependency.rb
249
249
  - lib/verku/exporter.rb
250
+ - lib/verku/exporter/base.rb
251
+ - lib/verku/exporter/epub.rb
252
+ - lib/verku/exporter/html.rb
253
+ - lib/verku/exporter/mobi.rb
254
+ - lib/verku/exporter/pdf.rb
255
+ - lib/verku/exporter/txt.rb
250
256
  - lib/verku/extensions/string.rb
251
257
  - lib/verku/generator.rb
252
- - lib/verku/parser.rb
253
- - lib/verku/parser/epub.rb
254
- - lib/verku/parser/html.rb
255
- - lib/verku/parser/mobi.rb
256
- - lib/verku/parser/pdf.rb
257
- - lib/verku/parser/txt.rb
258
+ - lib/verku/source_list.rb
258
259
  - lib/verku/stats.rb
259
260
  - lib/verku/stream.rb
260
261
  - lib/verku/toc.rb
@@ -1,245 +0,0 @@
1
- require 'kramdown'
2
- module Verku
3
- module Parser
4
- class HTML < Base
5
- def content
6
- raw = []
7
- entries.keys.each do |chapter|
8
- text = "\n\n## Chapter\n\n"
9
- sections = []
10
- entries[chapter].each do |section|
11
- sections << read_content(section)[0]
12
- # sections << "<p>#{read_content(section)[0].split(/\n{2,}/).map do |s|
13
- # s.gsub!(/%.*/, '')
14
- # s.squish
15
- # end.join("</p>\n\n<p>")}</p>"
16
- end
17
- text << sections.join("\n\n* * *\n\n")
18
- raw << "<div class='chapter'>\n#{text.to_html}\n</div>\n"
19
- end
20
- raw
21
- end
22
- def parse
23
- puts "-- Exporting HTML"
24
- html = parse_layout(content)
25
- toc = TOC::HTML.generate(html)
26
- locals = config.merge({
27
- :contents => toc.content,
28
- :toc => toc.to_html,
29
- })
30
- output = render_template(root_dir.join("_templates/html/layout.erb"), locals)
31
- f = File.open(root_dir.join("builds/#{name}.html"), 'w')
32
- f.write(output)
33
- f.close
34
- true
35
- rescue Exception
36
- p $!, $@
37
- false
38
- end
39
- def parse_layout(chapters)
40
- output = ''
41
- chapters.each do |text|
42
- # text.gsub!("{%", "{")
43
- # text.gsub!(/%.*/,'')
44
- text = text.split("\n\n").map{|s| s.gsub("\n", " ")}.join("\n\n")
45
- text.gsub!(/``(.*?'?)''/) { "&ldquo;#{$1}&rdquo;"}
46
- text.gsub!(/``(.*?'?)"/) { "&ldquo;#{$1}&rdquo;"}
47
- text.gsub!(/``/, "&ldquo;")
48
- text.gsub!(/\b'\b/) { "&rsquo;" }
49
- text.gsub!(/`(.*?)'/) { "&lsquo;#{$1}&rsquo;"}
50
- # \{([^\}]+?)\} Within the curly braces.
51
- text.gsub!(/\\pf?break\{\}/,"<hr />")
52
- text.gsub!(/\\pf?break/,"<hr />")
53
- text.gsub!(/\\%/,'%')
54
- text.gsub!(/\\`e/,'&eacute;')
55
- text.gsub!(/\\textgreater\{?\}?/, "&gt;")
56
- text.gsub!(/\\Bophendze/,'Bophendze')
57
- text.gsub!(/\\ldots\{\}/,"&hellip;")
58
- text.gsub!(/\\Dash\{\}/, "&mdash;")
59
- text.gsub!(/\\Dash/, "&mdash;")
60
- text.gsub!(/\\begin\{quote\}(.*?)\\end\{quote\}/m) { "<blockquote>#{$1.strip}</blockquote>"}
61
- text.gsub!(/<\/blockquote>\s+?<blockquote>/m, "\n")
62
- text.gsub!(/\\begin\{([^\}]+?)\}(.*?)\\end\{[^\}]+?\}/m) { "<div class='#{$1.strip}'>#{$2.strip}</div>"}
63
- text.gsub!(/\\section\{([^\}]+?)\}/m) { "<h3>#{$1.strip}</h3>"}
64
- ['Character','Equipment','Organization','Index'].each do |s|
65
- text.gsub!(/\\#{s}\{[^\}]+?\}\{([^\}]+?)\}/) { "<span class='#{s.downcase}'>#{$1.strip}</span>"}
66
- text.gsub!(/\\#{s}\{([^\}]+?)\}/) { ""}
67
- # text.gsub!(/\\#{s}\{([^\}]+?)\}/) { "<span class='#{s.downcase}'>#{$1.strip}</span>"}
68
- end
69
- text.gsub!(/\\footnote\{([^\}]+?)\}/m) { ""}
70
- text.gsub!(/\\emph\{([^\}]+?)\}/m) { "<em>#{$1.strip}</em>"}
71
- text.gsub!(/\\thought\{([^\}]+?)\}/m) { "<em>#{$1.strip}</em>"}
72
- text.gsub!(/\\(.*?)\{([^\}]+?)\}/) { "<span class='#{$1.downcase}'>#{$2.strip}</span>"}
73
- text.gsub!(/\\(.*?)\{([^\}]+?)\}/) { "<span class='#{$1.downcase}'>#{$2.strip}</span>"}
74
- text.gsub!(/<\/span>\{[^\}]+?}/, "</span>")
75
- text.gsub!(/<p><h([1-6])>(.*?)<\/h[1-6]><\/p>/) { "<h#{$1}>#{$2.strip}</h#{$1}>"}
76
- text.gsub!(/(\S+)~(\S+)/) { "#{$1}&nbsp;#{$2}"}
77
- output << text
78
- end
79
- output.gsub!(/\n\n+/, "\n\n")
80
- return output
81
- end
82
- end
83
- # # List of directories that should be skipped.
84
- # #
85
- # IGNORE_DIR = %w[. .. .svn]
86
- #
87
- # # Files that should be skipped.
88
- # #
89
- # IGNORE_FILES = /^(CHANGELOG|TOC)\..*?$/
90
- #
91
- # # List of recognized extensions.
92
- # #
93
- # EXTENSIONS = %w[md mkdn markdown]
94
- #
95
- # class << self
96
- # # The footnote index control. We have to manipulate footnotes
97
- # # because each chapter starts from 1, so we have duplicated references.
98
- # #
99
- # attr_accessor :footnote_index
100
- # end
101
- #
102
- # # Parse all files and save the parsed content
103
- # # to <tt>output/book_name.html</tt>.
104
- # #
105
- # def parse
106
- # reset_footnote_index!
107
- #
108
- # # File.open(root_dir.join("builds/#{name}.html"), "w") do |file|
109
- # # file << parse_layout(content)
110
- # # end
111
- # true
112
- # rescue Exception
113
- # false
114
- # end
115
- #
116
- # def reset_footnote_index!
117
- # self.class.footnote_index = 1
118
- # end
119
- #
120
- # private
121
- # def chapter_files(entry)
122
- # # Chapters can be files outside a directory.
123
- # if File.file?(entry)
124
- # [entry]
125
- # else
126
- # Dir.glob("#{entry}/**/*.{#{EXTENSIONS.join(",")}}").sort
127
- # end
128
- # end
129
- #
130
- # # Check if path is a valid entry.
131
- # # Files/directories that start with a dot or underscore will be skipped.
132
- # #
133
- # def valid_entry?(entry)
134
- # entry !~ /^(\.|_)/ && (valid_directory?(entry) || valid_file?(entry))
135
- # end
136
- #
137
- # # Check if path is a valid directory.
138
- # #
139
- # def valid_directory?(entry)
140
- # File.directory?(source.join(entry)) && !IGNORE_DIR.include?(File.basename(entry))
141
- # end
142
- #
143
- # # Check if path is a valid file.
144
- # #
145
- # def valid_file?(entry)
146
- # ext = File.extname(entry).gsub(/\./, "").downcase
147
- # File.file?(source.join(entry)) && EXTENSIONS.include?(ext) && entry !~ IGNORE_FILES
148
- # end
149
- #
150
- # # Render +file+ considering its extension.
151
- # #
152
- # def render_file(file, plain_syntax = false)
153
- # file_format = format(file)
154
- #
155
- # content = Verku::Syntax.render(root_dir, file_format, File.read(file), plain_syntax)
156
- #
157
- # content = case file_format
158
- # when :markdown
159
- # Markdown.to_html(content)
160
- # when :textile
161
- # RedCloth.convert(content)
162
- # else
163
- # content
164
- # end
165
- #
166
- # render_footnotes(content, plain_syntax)
167
- # end
168
- #
169
- # def render_footnotes(content, plain_syntax = false)
170
- # html = Nokogiri::HTML(content)
171
- # footnotes = html.css("p[id^='fn']")
172
- #
173
- # return content if footnotes.empty?
174
- #
175
- # reset_footnote_index! unless self.class.footnote_index
176
- #
177
- # footnotes.each do |fn|
178
- # index = self.class.footnote_index
179
- # actual_index = fn["id"].gsub(/[^\d]/, "")
180
- #
181
- # fn.set_attribute("id", "_fn#{index}")
182
- #
183
- # html.css("a[href='#fn#{actual_index}']").each do |link|
184
- # link.set_attribute("href", "#_fn#{index}")
185
- # end
186
- #
187
- # html.css("a[href='#fnr#{actual_index}']").each do |link|
188
- # link.set_attribute("href", "#_fnr#{index}")
189
- # end
190
- #
191
- # html.css("[id=fnr#{actual_index}]").each do |tag|
192
- # tag.set_attribute("id", "_fnr#{index}")
193
- # end
194
- #
195
- # self.class.footnote_index += 1
196
- # end
197
- #
198
- # html.css("body").inner_html
199
- # end
200
- #
201
- # def format(file)
202
- # case File.extname(file).downcase
203
- # when ".markdown", ".mkdn", ".md"
204
- # :markdown
205
- # when ".textile"
206
- # :textile
207
- # else
208
- # :html
209
- # end
210
- # end
211
- #
212
- # # Parse layout file, making available all configuration entries.
213
- # #
214
- # def parse_layout(html)
215
- # puts "parse layout."
216
- # toc = TOC::HTML.generate(html)
217
- # locals = config.merge({
218
- # :content => toc.content,
219
- # :toc => toc.to_html,
220
- # :changelog => render_changelog
221
- # })
222
- # render_template(root_dir.join("_templates/html/layout.erb"), locals)
223
- # end
224
- #
225
- # # Render changelog file.
226
- # # This file can be used to inform any book change.
227
- # #
228
- # def render_changelog
229
- # changelog = Dir[root_dir.join("text/CHANGELOG.*")].first
230
- # return render_file(changelog) if changelog
231
- # nil
232
- # end
233
- #
234
- # # Render all +files+ from a given chapter.
235
- # #
236
- # def render_chapter(files, plain_syntax = false)
237
- # String.new.tap do |chapter|
238
- # files.each do |file|
239
- # chapter << render_file(file, plain_syntax) << "\n\n"
240
- # end
241
- # end
242
- # end
243
- # end
244
- end
245
- end
@@ -1,54 +0,0 @@
1
- require 'kramdown'
2
-
3
- module Verku
4
- module Parser
5
- class PDF < Base
6
- def content
7
- raw = []
8
- entries.keys.each do |chapter|
9
- title = (chapter.empty?) ? "Untitled" : chapter.split('_')[1]
10
- title = 'Untitled' if title.nil?
11
- raw << "\\Chapter{#{title.gsub('-',' ')}}\n\n"
12
- entries[chapter].each do |section|
13
- s = read_content(section)[0].to_latex.gsub(/\$(\\index\{[^\$]*?\})\$/) {"#{$1}"}
14
- raw << "#{s}\n\n* * *"
15
- end
16
- end
17
- raw
18
- end
19
-
20
- def parse
21
- puts "-- Exporting PDF"
22
- locals = config.merge({ :contents => parse_layout(content) })
23
- locals['copyright'].gsub!("(C)", "\\copyright{}")
24
- output = render_template(root_dir.join("_templates/pdf/layout.erb"), locals)
25
- File.open(root_dir.join(tex_file), 'w').write(output)
26
- puts " - Pass 1"
27
- spawn_command ["xelatex", tex_file.to_s,]
28
- puts " - Pass 2"
29
- spawn_command ["xelatex", tex_file.to_s,]
30
- if config['is_final'].to_i == 0
31
- puts " - Pass 3 - Indexing"
32
- spawn_command ["makeindex #{name}.idx"]
33
- # spawn_command ["makeglossaries #{name}.glo"]
34
- spawn_command ["xelatex", tex_file.to_s,]
35
- spawn_command ["rm *ilg *ind "]
36
- end
37
-
38
- spawn_command ["rm *.glo *.idx *.log *.out *.toc *aux *ist"]
39
- spawn_command ["mv #{name}.pdf builds/#{name}.pdf"]
40
- true
41
- rescue Exception
42
- p $!, $@
43
- false
44
- end
45
- def parse_layout(text)
46
- text = text.join("\n\n")
47
- text.gsub!('* * *', "\n\n\\pbreak{}\n\n")
48
- end
49
- def tex_file
50
- root_dir.join("builds/#{name}.tex")
51
- end
52
- end
53
- end
54
- end
File without changes