publican_creators 1.0.2

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.
@@ -0,0 +1,230 @@
1
+ # PublicanCreatorsExport
2
+ # @author Sascha Manns
3
+ # @abstract Class for exporting bash scripts
4
+ #
5
+ # Copyright (C) 2015 Sascha Manns <samannsml@directbox.com>
6
+ # License: MIT
7
+
8
+ # Dependencies
9
+
10
+ require 'publican_creators/change'
11
+ require 'fileutils'
12
+ require 'rainbow/ext/string'
13
+
14
+ # rubocop:disable Metrics/MethodLength
15
+ # Module for running exports to a file
16
+ module PublicanCreatorsExport
17
+ # Exports a predefined Shellscript to the target directory.
18
+ # It returns a sucess or fail.
19
+ # Description:
20
+ # @param [String] title comes from the get method. This parameter represents
21
+ # the name or title of your work. It is used in all important
22
+ # code places.
23
+ # @param [String] builds is the path to your buildscript
24
+ # @param [String] language is just the ISO Code of your target language
25
+ # like: en-GB or such things.
26
+ # @param [String] xfc_brand_dir if present the path to your branded xfc
27
+ # stylesheets (config file)
28
+ # @param [String] pdfview your prefered PDF-Viewer (config file)
29
+ # @return [String] true or false
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
@@ -0,0 +1,66 @@
1
+ # PublicanCreatorsGet
2
+ # @author Sascha Manns
3
+ # @abstract Class for gathering information from config file and user input
4
+ #
5
+ # Copyright (C) 2015 Sascha Manns <samannsml@directbox.com>
6
+ # License: MIT
7
+
8
+ # Dependencies
9
+
10
+ require 'parseconfig'
11
+
12
+ # This method provides methods for user inputs
13
+ module PublicanCreatorsGet
14
+ # This method ask for the title, environment, type and optional settings.
15
+ # It returns the title variable.
16
+ # @return [String] environment, type, opt, title
17
+ def self.title
18
+ # @note Put the yad input as variable titlein
19
+ titlein = `yad --title="Create documentation" --center --on-top --form \
20
+ --item-separator=, --separator="|" --field="Environment:CBE" \
21
+ --field="Type:CBE" --field="Optional:CBE" --field="Enter a title name \
22
+ (with underscores instead of blanks and without umlauts):TEXT" \
23
+ --field="Please file bugs or feature requests \
24
+ on http://saigkill-bugs.myjetbrains.com/youtrack/:LBL" --button="Go!" "Work,Private" \
25
+ "Article,Book" "Normal,Report,Homework"`
26
+ # @note Format: Work/Private Article/Book title!Normal Report Homework
27
+ # @note Cleanup the array
28
+ environment, type, opt, titlefix = titlein.chomp.split('|')
29
+
30
+ # @note replace blanks with underscores
31
+ title = titlefix.gsub(/ /, '_')
32
+
33
+ [environment, type, opt, title]
34
+ end
35
+
36
+ # This method ask for revision information
37
+ # Description:
38
+ # @return [String] revision
39
+ def self.revision
40
+ # @note Put the yad input as variable revhistin
41
+ revhistin = `yad --title="Create Revision" --center --on-top --form \
42
+ --item-separator=, --separator="|" --field="Choose the directory where your \
43
+ project publican.cfg is:LBL" --field="Projectdir:DIR" --field="Enter your \
44
+ first revision text:TEXT" --field="Enter your second revision text:TEXT" \
45
+ --field="Enter your third revision text:TEXT" --field="Enter your fourth \
46
+ revision text:TEXT" --field="Enter your fifth revision text:TEXT" \
47
+ --field="Enter Revision number:TEXT" --field="You can use backslashes for \
48
+ entering Revision textes with blanks.:LBL" --button="Go!"`
49
+ # @note Format: Directory|One|Two|Three|Four|Five|Revision
50
+ # @note Cleanup the array
51
+ revision = revhistin.chomp.split('|')
52
+ # @note Split the variable to array revision[*]
53
+ puts revision
54
+ end
55
+
56
+ # This method gets the language from the config file for using in
57
+ # RevisionCreator
58
+ # @return [String] language
59
+ def self.config_revision
60
+ include ParseConfig
61
+ home = Dir.home
62
+ config = ParseConfig.new("#{home}/.publican_creators/publicancreators.cfg")
63
+ language = config['language']
64
+ puts language
65
+ end
66
+ end
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ # @author Sascha Manns
4
+ # @abstract Notifier Module for latex_curriculum_vitae
5
+ #
6
+ # Copyright (C) 2015 Sascha Manns <samannsml@directbox.com>
7
+ # License: MIT
8
+
9
+ # Dependencies
10
+
11
+ # Module for notify the user
12
+ require 'notifier'
13
+
14
+ module Notifier
15
+ def self.run
16
+ home = Dir.home
17
+ prefix = "#{home}/.rvm/rubies/default"
18
+ datadir = "#{prefix}/share"
19
+ img = "#{datadir}/.publican_creators/publican.png"
20
+ Notifier.notify(
21
+ :image => "#{img}",
22
+ :title => "Your Documentation",
23
+ :message => "The preparation of your Documentation is finished."
24
+ )
25
+ end
26
+ end
@@ -0,0 +1,82 @@
1
+ # PublicanCreatorsPrepare
2
+ # @author Sascha Manns
3
+ # @abstract Class for preparing the configuration
4
+ #
5
+ # Copyright (C) 2015 Sascha Manns <samannsml@directbox.com>
6
+ # License: MIT
7
+
8
+ # Dependencies
9
+
10
+ # The module Prepare contains some methods for preparing the directories. They
11
+ # will be used in the make directory function
12
+ module PublicanCreatorsPrepare
13
+ # This method sets the needed targetdir depending on the environment
14
+ # @param [String] type represents the Document-Type like Article or Book.
15
+ # @param [String] reports_dir_business contains the directory to your reports
16
+ # @param [String] articles_dir_bus represents the directory for your articles
17
+ # @param [String] report contains a true or false. There you can set if the
18
+ # new Publication is a Report or not.
19
+ # @param [String] books_dir_business contains the directory for your business
20
+ # books
21
+ # @param [String] homework contains true or false. If your present Publication
22
+ # is a homework you can set it there.
23
+ # @param [String] articles_dir_private contains the path to your private
24
+ # articles_dir
25
+ # @param [String] homework_dir_private contains the path to your homework dir.
26
+ # @param [String] books_dir_private contains the path to your private
27
+ # books_dir
28
+ # @return [String] targetdir
29
+ def self.targetdir(environment, type, report, reports_dir_business,
30
+ articles_dir_bus, books_dir_business, homework,
31
+ articles_dir_private, homework_dir_private, books_dir_private)
32
+ home = Dir.home
33
+ if environment == 'Work'
34
+ if type == 'Article'
35
+ targetdir_work(report, reports_dir_business, articles_dir_bus)
36
+ else
37
+ books_dir = "#{home}/#{books_dir_business}"
38
+ return books_dir
39
+ end
40
+ else
41
+ if type == 'Article'
42
+ targetdir_private(homework, articles_dir_private,
43
+ homework_dir_private)
44
+ else
45
+ books_dir = "#{home}/#{books_dir_private}"
46
+ return books_dir
47
+ end
48
+ end
49
+ end
50
+
51
+ # Prepares the articles_dir for work environment
52
+ # @param [String] reports_dir_business contains the directory to your reports
53
+ # @param [String] articles_dir_bus represents the directory for your articles
54
+ # @param [String] report contains a true or false. There you can set if the
55
+ # new Publication is a Report or not.
56
+ def self.targetdir_work(report, reports_dir_business, articles_dir_bus)
57
+ home = Dir.home
58
+ if report == 'TRUE'
59
+ articles_dir = "#{home}/#{reports_dir_business}"
60
+ else
61
+ articles_dir = "#{home}/#{articles_dir_bus}"
62
+ end
63
+ return articles_dir
64
+ end
65
+
66
+ # Prepares the articles_dir for home environment
67
+ # @param [String] homework contains true or false. If your present Publication
68
+ # is a homework you can set it there.
69
+ # @param [String] articles_dir_private contains the path to your private
70
+ # articles_dir
71
+ # @param [String] homework_dir_private contains the path to your homework dir.
72
+ def self.targetdir_private(homework, articles_dir_private,
73
+ homework_dir_private)
74
+ home = Dir.home
75
+ if homework == 'FALSE'
76
+ articles_dir = "#{home}/#{articles_dir_private}"
77
+ else
78
+ articles_dir = "#{home}/#{homework_dir_private}"
79
+ end
80
+ return articles_dir
81
+ end
82
+ end
@@ -0,0 +1,61 @@
1
+ # @author Sascha Manns
2
+ # @abstract Class RevisionCreator for PublicanCreator
3
+ #
4
+ # Copyright (C) 2015 Sascha Manns <samannsml@directbox.com>
5
+ # License: MIT
6
+ #
7
+ # Dependencies
8
+ require 'fileutils'
9
+ require 'rainbow/ext/string'
10
+ require File.expand_path(File.join(File.dirname(__FILE__), 'change.rb'))
11
+ require File.expand_path(File.join(File.dirname(__FILE__), 'get.rb'))
12
+
13
+ # A class for creating a revison to a publican project
14
+ class RevisionCreator
15
+ # @note Ask for the revision information
16
+ null, directory, member1, member2, member3, member4, member5,
17
+ revnumber = PublicanCreatorsGet.revision
18
+ language = PublicanCreatorsGet.config_revision
19
+
20
+ revision, edition = revnumber.split('-')
21
+
22
+ puts "Directory: #{directory}"
23
+ puts "Member1: #{member1}"
24
+ puts "Member2: #{member2}"
25
+ puts "Member3: #{member3}"
26
+ puts "Member4: #{member4}"
27
+ puts "Member5: #{member5}"
28
+ puts "Language: #{language}"
29
+ puts "Revnumber: #{revnumber}"
30
+ puts "Revision: #{revision}"
31
+ puts "Edition: #{edition}"
32
+ puts null
33
+
34
+ # This method prepares the string for adding a new revision
35
+ # @param [String] member1 is the first string into revdescription
36
+ # @param [String] member2 is the second string into revdescription
37
+ # @param [String] member3 is the third string into revdescription
38
+ # @param [String] member4 is the fourth string into revdescription
39
+ # @param [String] member5 is the fifth string into revdescription
40
+ # @param [String] revnumber is the revision number
41
+ # @param [String] language is the language. Comes from config file.
42
+ # @return [String] string is that string for creating the commit
43
+ def self.prepare_revision(member1, member2, member3, member4, member5,
44
+ revnumber, language)
45
+ string = "--member \"#{member1}\""
46
+ string << " --member \"#{member2}\"" if member2 != ''
47
+ string << " --member \"#{member3}\"" if member3 != ''
48
+ string << " --member \"#{member4}\"" if member4 != ''
49
+ string << " --member \"#{member5}\"" if member5 != ''
50
+ string << " --revnumber \"#{revnumber}\""
51
+ string << " --lang \"#{language}\""
52
+ end
53
+
54
+ # This method changes to the target directory
55
+ FileUtils.cd(directory) do
56
+ string = prepare_revision(member1, member2, member3, member4, member5,
57
+ revnumber, language)
58
+ PublicanCreatorsChange.replace_productnumber(revision, edition, language)
59
+ system("publican add_revision #{string}")
60
+ end
61
+ end