Module: PublicanCreatorsExport

Defined in:
lib/publican_creators/export.rb

Overview

Module for running exports to a file

Class Method Summary collapse

Class Method Details

.export_buildscript(title, builds, language, xfc_brand_dir, pdfview) ⇒ String

Exports a predefined Shellscript to the target directory. It returns a sucess or fail. Description:

Parameters:

  • title (String)

    comes from the get method. This parameter represents the name or title of your work. It is used in all important code places.

  • builds (String)

    is the path to your buildscript

  • language (String)

    is just the ISO Code of your target language like: en-GB or such things.

  • xfc_brand_dir (String)

    if present the path to your branded xfc stylesheets (config file)

  • pdfview (String)

    your prefered PDF-Viewer (config file)

Returns:

  • (String)

    true or false



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/publican_creators/export.rb', line 36

def self.export_buildscript(title, builds, language, xfc_brand_dir, pdfview)
  puts 'Export the buildscript into new directory...'
  FileUtils.touch builds.to_s
  # rubocop:disable Layout/IndentHeredoc
  File.write builds.to_s, <<BUILDSCRIPT
# -*- ruby -*-
# encoding: utf-8
require 'fileutils'

task :default do
puts 'usage: rake [export_docx] [export_odt] [export_rtf] [export_wml] [export_pdf] [export_html] [export_man] [export_txt] [export_txt] [export_epub]'
puts
puts 'Options:'
puts 'export_docx : Export DocBook source to DOCX'
puts ' Example: rake export_docx'
puts 'export_odt : Export DocBook source to ODT'
puts ' Example: rake export_odt'
puts 'export_rtf : Export DocBook source to RTF'
puts ' Example: rake export_rtf'
puts 'export_wml: Export DocBook source to WML'
puts ' Example: rake export_wml'
puts 'export_pdf: Export Docbook source to PDF'
puts ' Example: rake export_pdf'
puts 'export_html: Export DocBook source to HTML'
puts ' Example: rake export_html'
puts 'export_man: Export DocBook source to MAN'
puts ' Example: rake export_man'
puts 'export_txt: Export DocBook source to TXT'
puts ' Example: rake export_txt'
puts 'export_epub: Export DocBook source to EPUB'
puts ' Example: rake export_epub'
puts 'export_eclipse: Export DocBook source to Eclipse Help'
puts ' Example: rake export_eclipse'
end

require 'dir'
require 'fileutils'
desc 'Checks if temp dir is available. Otherwise it creates it'
task :checker do
todos = "../tmp/#{language}/docx"
if Dir.exist?(todos)
  puts 'Found directory. Im using it.'
else
  puts 'No directory found. Im creating it.'
  FileUtils.mkdir_p(todos)
end
todos = "../tmp/#{language}/odt"
if Dir.exist?(todos)
  puts 'Found directory. Im using it.'
else
  puts 'No directory found. Im creating it.'
  FileUtils.mkdir_p(todos)
end
todos = "../tmp/#{language}/rtf"
if Dir.exist?(todos)
  puts 'Found directory. Im using it.'
else
  puts 'No directory found. Im creating it.'
  FileUtils.mkdir_p(todos)
end
todos = "../tmp/#{language}/wml"
if Dir.exist?(todos)
  puts 'Found directory. Im using it.'
else
  puts 'No directory found. Im creating it.'
  FileUtils.mkdir_p(todos)
end
end

desc 'Convert to DOCX'
task :export_docx => [:checker] do
puts 'Resolving all XML-Entities and XI-Includes'
system("xmllint --noent --dropdtd --xinclude #{title}.xml -o #{title}-resolved.xml")
puts 'Formatting XML to XSL-FO'
system("saxon-xslt -o #{title}.fo #{title}-resolved.xml #{xfc_brand_dir}")
puts 'Removing temporary resolved file'
FileUtils.rm('#{title}-resolved.xml')
puts 'Transforming to DOCX'
system("fo2docx #{title}.fo > ../tmp/#{language}/docx/#{title}.docx")
puts 'Launching LibreOffice Writer for Preview'
system("lowriter ../tmp/#{language}/docx/#{title}.docx &")
end

desc 'Convert to ODT'
task :export_odt => [:checker] do
puts 'Resolving all XML-Entities and XI-Includes'
system("xmllint --noent --dropdtd --xinclude #{title}.xml -o #{title}-resolved.xml")
puts 'Formatting XML to XSL-FO'
system("saxon-xslt -o #{title}.fo #{title}-resolved.xml #{xfc_brand_dir}")
puts 'Removing temporary resolved file'
FileUtils.rm('#{title}-resolved.xml')
puts 'Transforming to ODT'
system("fo2odt #{title}.fo > ../tmp/#{language}/odt/#{title}.odt")
puts 'Launching LibreOffice Writer for Preview'
system("lowriter ../tmp/#{language}/odt/#{title}.odt &")
end

desc 'Convert to RTF'
task :export_rtf => [:checker] do
puts 'Resolving all XML-Entities and XI-Includes'
system("xmllint --noent --dropdtd --xinclude #{title}.xml -o #{title}-resolved.xml")
puts 'Formatting XML to XSL-FO'
system("saxon-xslt -o #{title}.fo #{title}-resolved.xml #{xfc_brand_dir}")
puts 'Removing temporary resolved file'
FileUtils.rm('#{title}-resolved.xml')
puts 'Transforming to RTF'
system("fo2rtf #{title}.fo > ../tmp/#{language}/rtf/#{title}.rtf")
puts 'Launching LibreOffice Writer for Preview'
system("lowriter ../tmp/#{language}/rtf/#{title}.rtf &")
end

desc 'Convert to WML'
task :export_wml => [:checker] do
puts 'Resolving all XML-Entities and XI-Includes'
system("xmllint --noent --dropdtd --xinclude #{title}.xml -o #{title}-resolved.xml")
puts 'Formatting XML to XSL-FO'
system("saxon-xslt -o #{title}.fo #{title}-resolved.xml #{xfc_brand_dir}")
puts 'Removing temporary resolved file'
FileUtils.rm('#{title}-resolved.xml')
puts 'Transforming to WML'
system("fo2wml #{title}.fo > ../tmp/#{language}/wml/#{title}.wml")
end

desc 'Convert to PDF'
task :export_pdf do
FileUtils.cd('..')
puts 'Cleaning up temp directory'
system('publican clean')
puts 'Formatting to PDF'
system('publican build --langs=#{language} --formats=pdf --allow_network')
puts 'Launching PDF-Viewer'
system('#{pdfview} tmp/#{language}/pdf/*.pdf &')
end

desc 'Convert to HTML'
task :export_html do
FileUtils.cd('..')
puts 'Cleaning up temp directory'
system('publican clean')
puts 'Formatting to PDF'
system('publican build --langs=#{language} --formats=html --allow_network')
puts 'Launching Browser'
system('firefox tmp/#{language}/html/index.html &')
end

desc 'Convert to MAN'
task :export_man do
FileUtils.cd('..')
puts 'Cleaning up temp directory'
system('publican clean')
puts 'Formatting to MAN'
system('publican build --langs=#{language} --formats=man --allow_network')
end

desc 'Convert to TXT'
task :export_txt do
FileUtils.cd('..')
puts 'Cleaning up temp directory'
system('publican clean')
puts 'Formatting to TXT'
system('publican build --langs=#{language} --formats=txt --allow_network')
puts 'Launching Texteditor'
system('gedit tmp/#{language}/txt/*.txt &')
end

desc 'Convert to EPUB'
task :export_epub do
FileUtils.cd('..')
puts 'Cleaning up temp directory'
system('publican clean')
puts 'Formatting to EPUB'
system('publican build --langs=#{language} --formats=epub --allow_network')
if File.exist?('/usr/bin/ebook-viewer')
  puts 'Launching EPUB-Viewer'
  system('ebook-viewer /tmp/#{language}/*.epub &')
else
  puts 'You have to install calibre for using ebook-viewer for preview'
end
end

desc 'Convert to ECLIPSE'
task :export_eclipse do
FileUtils.cd('..')
puts 'Cleaning up temp directory'
system('publican clean')
puts 'Formatting to ECLIPSE'
system('publican build --langs=#{language} --formats=eclipse --allow_network')
end

desc 'Run convert to most used formats'
task :export_most => [:export_docx, :export_odt, :export_rtf, :export_html, :export_pdf] do
puts 'Successful exported to DOCX, ODT, RTF, HTML and PDF'
end

desc 'Run convert to all formats'
task :export_all => [:export_most, :export_wml, :export_man, :export_txt, :export_epub, :export_eclipse] do
puts 'Successfull exported to all formats'
end
BUILDSCRIPT
end