Conditions | 1 |
Total Lines | 200 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | # PublicanCreatorsExport |
||
30 | def self.export_buildscript(title, builds, language, xfc_brand_dir, pdfview) |
||
31 | puts 'Export the buildscript into new directory...' |
||
32 | FileUtils.touch "#{builds}" |
||
33 | # rubocop:disable Metrics/LineLength |
||
34 | File.write "#{builds}", <<EOF |
||
35 | # -*- ruby -*- |
||
36 | # encoding: utf-8 |
||
37 | require 'fileutils' |
||
38 | |||
39 | task :default do |
||
40 | puts 'usage: rake [export_docx] [export_odt] [export_rtf] [export_wml] [export_pdf] [export_html] [export_man] [export_txt] [export_txt] [export_epub]' |
||
41 | puts |
||
42 | puts 'Options:' |
||
43 | puts 'export_docx : Export DocBook source to DOCX' |
||
44 | puts ' Example: rake export_docx' |
||
45 | puts 'export_odt : Export DocBook source to ODT' |
||
46 | puts ' Example: rake export_odt' |
||
47 | puts 'export_rtf : Export DocBook source to RTF' |
||
48 | puts ' Example: rake export_rtf' |
||
49 | puts 'export_wml: Export DocBook source to WML' |
||
50 | puts ' Example: rake export_wml' |
||
51 | puts 'export_pdf: Export Docbook source to PDF' |
||
52 | puts ' Example: rake export_pdf' |
||
53 | puts 'export_html: Export DocBook source to HTML' |
||
54 | puts ' Example: rake export_html' |
||
55 | puts 'export_man: Export DocBook source to MAN' |
||
56 | puts ' Example: rake export_man' |
||
57 | puts 'export_txt: Export DocBook source to TXT' |
||
58 | puts ' Example: rake export_txt' |
||
59 | puts 'export_epub: Export DocBook source to EPUB' |
||
60 | puts ' Example: rake export_epub' |
||
61 | puts 'export_eclipse: Export DocBook source to Eclipse Help' |
||
62 | puts ' Example: rake export_eclipse' |
||
63 | end |
||
64 | |||
65 | require 'dir' |
||
66 | require 'fileutils' |
||
67 | desc 'Checks if temp dir is available. Otherwise it creates it' |
||
68 | task :checker do |
||
69 | todos = "../tmp/#{language}/docx" |
||
70 | if Dir.exist?(todos) |
||
71 | puts 'Found directory. Im using it.' |
||
72 | else |
||
73 | puts 'No directory found. Im creating it.' |
||
74 | FileUtils.mkdir_p(todos) |
||
75 | end |
||
76 | todos = "../tmp/#{language}/odt" |
||
77 | if Dir.exist?(todos) |
||
78 | puts 'Found directory. Im using it.' |
||
79 | else |
||
80 | puts 'No directory found. Im creating it.' |
||
81 | FileUtils.mkdir_p(todos) |
||
82 | end |
||
83 | todos = "../tmp/#{language}/rtf" |
||
84 | if Dir.exist?(todos) |
||
85 | puts 'Found directory. Im using it.' |
||
86 | else |
||
87 | puts 'No directory found. Im creating it.' |
||
88 | FileUtils.mkdir_p(todos) |
||
89 | end |
||
90 | todos = "../tmp/#{language}/wml" |
||
91 | if Dir.exist?(todos) |
||
92 | puts 'Found directory. Im using it.' |
||
93 | else |
||
94 | puts 'No directory found. Im creating it.' |
||
95 | FileUtils.mkdir_p(todos) |
||
96 | end |
||
97 | end |
||
98 | |||
99 | desc 'Convert to DOCX' |
||
100 | task :export_docx => [:checker] do |
||
101 | puts 'Resolving all XML-Entities and XI-Includes' |
||
102 | system("xmllint --noent --dropdtd --xinclude #{title}.xml -o #{title}-resolved.xml") |
||
103 | puts 'Formatting XML to XSL-FO' |
||
104 | system("saxon-xslt -o #{title}.fo #{title}-resolved.xml #{xfc_brand_dir}") |
||
105 | puts 'Removing temporary resolved file' |
||
106 | FileUtils.rm('#{title}-resolved.xml') |
||
107 | puts 'Transforming to DOCX' |
||
108 | system("fo2docx #{title}.fo > ../tmp/#{language}/docx/#{title}.docx") |
||
109 | puts 'Launching LibreOffice Writer for Preview' |
||
110 | system("lowriter ../tmp/#{language}/docx/#{title}.docx &") |
||
111 | end |
||
112 | |||
113 | desc 'Convert to ODT' |
||
114 | task :export_odt => [:checker] do |
||
115 | puts 'Resolving all XML-Entities and XI-Includes' |
||
116 | system("xmllint --noent --dropdtd --xinclude #{title}.xml -o #{title}-resolved.xml") |
||
117 | puts 'Formatting XML to XSL-FO' |
||
118 | system("saxon-xslt -o #{title}.fo #{title}-resolved.xml #{xfc_brand_dir}") |
||
119 | puts 'Removing temporary resolved file' |
||
120 | FileUtils.rm('#{title}-resolved.xml') |
||
121 | puts 'Transforming to ODT' |
||
122 | system("fo2odt #{title}.fo > ../tmp/#{language}/odt/#{title}.odt") |
||
123 | puts 'Launching LibreOffice Writer for Preview' |
||
124 | system("lowriter ../tmp/#{language}/odt/#{title}.odt &") |
||
125 | end |
||
126 | |||
127 | desc 'Convert to RTF' |
||
128 | task :export_rtf => [:checker] do |
||
129 | puts 'Resolving all XML-Entities and XI-Includes' |
||
130 | system("xmllint --noent --dropdtd --xinclude #{title}.xml -o #{title}-resolved.xml") |
||
131 | puts 'Formatting XML to XSL-FO' |
||
132 | system("saxon-xslt -o #{title}.fo #{title}-resolved.xml #{xfc_brand_dir}") |
||
133 | puts 'Removing temporary resolved file' |
||
134 | FileUtils.rm('#{title}-resolved.xml') |
||
135 | puts 'Transforming to RTF' |
||
136 | system("fo2rtf #{title}.fo > ../tmp/#{language}/rtf/#{title}.rtf") |
||
137 | puts 'Launching LibreOffice Writer for Preview' |
||
138 | system("lowriter ../tmp/#{language}/rtf/#{title}.rtf &") |
||
139 | end |
||
140 | |||
141 | desc 'Convert to WML' |
||
142 | task :export_wml => [:checker] do |
||
143 | puts 'Resolving all XML-Entities and XI-Includes' |
||
144 | system("xmllint --noent --dropdtd --xinclude #{title}.xml -o #{title}-resolved.xml") |
||
145 | puts 'Formatting XML to XSL-FO' |
||
146 | system("saxon-xslt -o #{title}.fo #{title}-resolved.xml #{xfc_brand_dir}") |
||
147 | puts 'Removing temporary resolved file' |
||
148 | FileUtils.rm('#{title}-resolved.xml') |
||
149 | puts 'Transforming to WML' |
||
150 | system("fo2wml #{title}.fo > ../tmp/#{language}/wml/#{title}.wml") |
||
151 | end |
||
152 | |||
153 | desc 'Convert to PDF' |
||
154 | task :export_pdf do |
||
155 | FileUtils.cd('..') |
||
156 | puts 'Cleaning up temp directory' |
||
157 | system('publican clean') |
||
158 | puts 'Formatting to PDF' |
||
159 | system('publican build --langs=#{language} --formats=pdf --allow_network') |
||
160 | puts 'Launching PDF-Viewer' |
||
161 | system('#{pdfview} tmp/#{language}/pdf/*.pdf &') |
||
162 | end |
||
163 | |||
164 | desc 'Convert to HTML' |
||
165 | task :export_html do |
||
166 | FileUtils.cd('..') |
||
167 | puts 'Cleaning up temp directory' |
||
168 | system('publican clean') |
||
169 | puts 'Formatting to PDF' |
||
170 | system('publican build --langs=#{language} --formats=html --allow_network') |
||
171 | puts 'Launching Browser' |
||
172 | system('firefox tmp/#{language}/html/index.html &') |
||
173 | end |
||
174 | |||
175 | desc 'Convert to MAN' |
||
176 | task :export_man do |
||
177 | FileUtils.cd('..') |
||
178 | puts 'Cleaning up temp directory' |
||
179 | system('publican clean') |
||
180 | puts 'Formatting to MAN' |
||
181 | system('publican build --langs=#{language} --formats=man --allow_network') |
||
182 | end |
||
183 | |||
184 | desc 'Convert to TXT' |
||
185 | task :export_txt do |
||
186 | FileUtils.cd('..') |
||
187 | puts 'Cleaning up temp directory' |
||
188 | system('publican clean') |
||
189 | puts 'Formatting to TXT' |
||
190 | system('publican build --langs=#{language} --formats=txt --allow_network') |
||
191 | puts 'Launching Texteditor' |
||
192 | system('gedit tmp/#{language}/txt/*.txt &') |
||
193 | end |
||
194 | |||
195 | desc 'Convert to EPUB' |
||
196 | task :export_epub do |
||
197 | FileUtils.cd('..') |
||
198 | puts 'Cleaning up temp directory' |
||
199 | system('publican clean') |
||
200 | puts 'Formatting to EPUB' |
||
201 | system('publican build --langs=#{language} --formats=epub --allow_network') |
||
202 | if File.exist?('/usr/bin/ebook-viewer') |
||
203 | puts 'Launching EPUB-Viewer' |
||
204 | system('ebook-viewer /tmp/#{language}/*.epub &') |
||
205 | else |
||
206 | puts 'You have to install calibre for using ebook-viewer for preview' |
||
207 | end |
||
208 | end |
||
209 | |||
210 | desc 'Convert to ECLIPSE' |
||
211 | task :export_eclipse do |
||
212 | FileUtils.cd('..') |
||
213 | puts 'Cleaning up temp directory' |
||
214 | system('publican clean') |
||
215 | puts 'Formatting to ECLIPSE' |
||
216 | system('publican build --langs=#{language} --formats=eclipse --allow_network') |
||
217 | end |
||
218 | |||
219 | desc 'Run convert to most used formats' |
||
220 | task :export_most => [:export_docx, :export_odt, :export_rtf, :export_html, :export_pdf] do |
||
221 | puts 'Successful exported to DOCX, ODT, RTF, HTML and PDF' |
||
222 | end |
||
223 | |||
224 | desc 'Run convert to all formats' |
||
225 | task :export_all => [:export_most, :export_wml, :export_man, :export_txt, :export_epub, :export_eclipse] do |
||
226 | puts 'Successfull exported to all formats' |
||
227 | end |
||
228 | EOF |
||
229 | end |
||
230 | end |
||
231 |