Class: Xpub::CallBook::CallEpubBuilder

Inherits:
CallBuilder show all
Defined in:
lib/xpub/dsl/builder.rb

Instance Attribute Summary

Attributes inherited from CallBuilder

#name

Instance Method Summary collapse

Methods inherited from CallBuilder

#cmd_exec, #copy_to_tmp, #output_path, #src_path, #tmp_path, #validate

Constructor Details

#initialize(name, book) ⇒ CallEpubBuilder

Returns a new instance of CallEpubBuilder.



69
70
71
72
73
74
# File 'lib/xpub/dsl/builder.rb', line 69

def initialize(name, book)
  @vars = []
  @meta = []
  @vars << ['title', book.title] if book.title != ''
  super name, book
end

Instance Method Details

#_build_resource(files, _option) ⇒ Object



126
127
128
# File 'lib/xpub/dsl/builder.rb', line 126

def _build_resource(files, _option)
  copy_to_tmp files
end

#build(option) ⇒ Object



155
156
157
158
159
160
161
162
163
164
# File 'lib/xpub/dsl/builder.rb', line 155

def build(option)
  FileUtils.mkdir_p(tmp_path('')) unless FileTest.exist?(tmp_path(''))

   option

  pandoc_option = pandoc_option(option).concat(vars_option).concat(meta_option).concat(@book.src_files.map(&:full_path))

  cmd_exec "cd #{tmp_path ''};" + pandoc_cmd, ['-o', json_path, '-t', 'json'].concat(pandoc_option), option if option['pandoc-json-output']
  cmd_exec "cd #{tmp_path ''};" + pandoc_cmd, ['-o', epub_path, '-t', 'epub3'].concat(pandoc_option), option
end

#build_epub_metadata(option) ⇒ Object



146
147
148
149
150
151
152
153
# File 'lib/xpub/dsl/builder.rb', line 146

def (option)
  f = open 
  erb = ERB.new f.read, nil, '-'
  f.close
  f = open , 'w'
  f.write erb.result(binding)
  f.close
end

#epub_pathObject



118
119
120
# File 'lib/xpub/dsl/builder.rb', line 118

def epub_path
  output_path(@book.name) + '.epub'
end

#filter_optionObject



98
99
100
# File 'lib/xpub/dsl/builder.rb', line 98

def filter_option
  "--filter=#{Dir.getwd}/theme/#{theme}/#{@name}/#{filter}"
end

#json_pathObject



122
123
124
# File 'lib/xpub/dsl/builder.rb', line 122

def json_path
  tmp_path(@book.name) + '.json'
end

#meta_optionObject



76
77
78
79
80
81
82
83
# File 'lib/xpub/dsl/builder.rb', line 76

def meta_option
  result = []
  @meta.concat([['page-progression-direction', page_progression_direction]]).each do |m|
    result << '-M'
    result << "#{m[0]}=#{m[1]}"
  end
  result
end

#metadata_optionObject



106
107
108
# File 'lib/xpub/dsl/builder.rb', line 106

def 
  '--epub-metadata=' + 
end

#metadata_pathObject



110
111
112
# File 'lib/xpub/dsl/builder.rb', line 110

def 
  tmp_path("#{@book.name}.#{}")
end

#metadata_template_pathObject



114
115
116
# File 'lib/xpub/dsl/builder.rb', line 114

def 
  "#{Dir.getwd}/theme/#{theme}/#{@name}/#{}.erb"
end

#pandoc_option(option) ⇒ Object



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/xpub/dsl/builder.rb', line 130

def pandoc_option(option)
  option = [
    '--epub-chapter-level=1',
    '--toc',
    '-f',
    'markdown_phpextra+hard_line_breaks+raw_html',
    '-s',
    template_option,
    filter_option,
    stylesheet_option,
    
  ]
  option << '--epub-cover-image=' + src_path(cover_image) if cover_image
  option
end

#stylesheet_optionObject



102
103
104
# File 'lib/xpub/dsl/builder.rb', line 102

def stylesheet_option
  "--epub-stylesheet=#{Dir.getwd}/theme/#{theme}/#{@name}/#{stylesheet}"
end

#template_optionObject



94
95
96
# File 'lib/xpub/dsl/builder.rb', line 94

def template_option
  "--template=#{Dir.getwd}/theme/#{theme}/#{@name}/#{template}"
end

#vars_optionObject



85
86
87
88
89
90
91
92
# File 'lib/xpub/dsl/builder.rb', line 85

def vars_option
  result = []
  @vars.concat([[:book_name, @book.name]]).each do |v|
    result << '-V'
    result << "#{v[0]}=#{v[1]}"
  end
  result
end