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,309 @@
1
+ # Changer Module for PublicanCreators
2
+ # PublicanCreatorsChange
3
+ # @author Sascha Manns
4
+ # @abstract Class for all file changes
5
+ #
6
+ # Copyright (C) 2015 Sascha Manns <samannsml@directbox.com>
7
+ # License: MIT
8
+
9
+ # Dependencies
10
+
11
+ require 'nokogiri'
12
+ require 'publican_creators/create'
13
+ require 'publican_creators/checker'
14
+ require 'manns_shared'
15
+
16
+ # Module what contains all methods who are doing changes in files
17
+ module PublicanCreatorsChange
18
+ # Method for replacing content in agroup
19
+ # @param [String] nice_description is the default text in the target file
20
+ # @param [String] value_name the replace text
21
+ # @param [String] file Target file like Author_Group.xml
22
+ # @return [String] true or false
23
+ def self.add_result(nice_description, value_name, file)
24
+ text = File.read(file)
25
+ new_value = text.gsub(nice_description, value_name)
26
+ puts new_value
27
+ File.open(file, 'w') do |file1|
28
+ file1.puts new_value
29
+ end
30
+ end
31
+
32
+ # This method checks the environment and runs the method for
33
+ # @param [String] environment shows if you actually want to create a private
34
+ # or Business Publication. If Work is given it
35
+ # reads your global entity file and appends it on
36
+ # the ent file.
37
+ # @param [String] title comes from the get method. This param represents the
38
+ # name or title of your work. It is used in all important
39
+ # code places.
40
+ # @param [String] type represents the Document-Type like Article or Book.
41
+ # @param [String] language is just the ISO Code of your target language like:
42
+ # de-DE, en-GB or such things.
43
+ # @param [String] brand can be a special customized brand for your company to
44
+ # fit the styleguide.
45
+ # @param [String] db5 just sets your preferences. If you like to have DocBook
46
+ # 5.x as default you can set it there.
47
+ # @param [String] brand_homework can be a special customized brand for
48
+ # distance learning schools.
49
+ # @param [String] brand_private is used in all methods with a "private" in the
50
+ # name. If this brand is set it will be used instead of the
51
+ # original publican brand.
52
+ # @param [String] homework if homework is set
53
+ # @return [String] true or false
54
+ def self.check_environment(environment, title, type, language, brand, db5,
55
+ homework, brand_homework, brand_private)
56
+ if environment == 'Work'
57
+ PublicanCreatorsCreate.init_docu_work(title, type, language, brand, db5)
58
+ else
59
+ PublicanCreatorsCreate.init_docu_private(title, type, homework, language,
60
+ brand_homework, brand_private,
61
+ db5)
62
+ end
63
+ end
64
+
65
+ # By working for my employer i'm creating publications which refers to a
66
+ # global entity file.
67
+ # This method adds the entities from that file into the local one. It returns
68
+ # a success or fail.
69
+ # @param [String] environment shows if you actually want to create a private
70
+ # or Business Publication. If Work is given it reads your
71
+ # global entity file and appends it on the ent file.
72
+ # @param [String] global_entities is just the path to the global entity file.
73
+ # @param [String] ent Path to the entity file
74
+ # @return [String] true or false
75
+ # This method smells of :reek:UncommunicativeVariableName
76
+ def self.add_entity(environment, global_entities, ent)
77
+ if environment == 'Work'
78
+ if global_entities.empty?
79
+ puts 'Nothing to do'
80
+ else
81
+ puts 'Adding global entities...'
82
+ # @note Adding global entities
83
+ open(ent, 'a') do |f|
84
+ f << "\n"
85
+ f << "<!-- COMMON ENTITIES -->\n"
86
+ end
87
+ input = File.open(global_entities)
88
+ data_to_copy = input.read
89
+ output = File.open(ent, 'a')
90
+ output.write(data_to_copy)
91
+ input.close
92
+ output.close
93
+ end
94
+ else
95
+ puts 'Nothing to do'
96
+ end
97
+ end
98
+
99
+ # In this method the standard-holder from the local entity-file will be
100
+ # replaced with the company_name or if it is a private work the name of the
101
+ # present user. It returns a sucess or fail.
102
+ # @param [String] title comes from the get method. This @param represents the
103
+ # name or title of your work. It is used in all important code
104
+ # places.
105
+ # @param [String] environment shows if you actually want to create a private
106
+ # or Business Publication. If Work is given it reads your
107
+ # global entity file and appends it on the ent file.
108
+ # @param [String] name is your name.
109
+ # @param [String] company_name is the name of your company
110
+ # @param [String] ent Path to the entity file
111
+ # @return [String] true or false
112
+ # @note If the environment "Work" is given the entity file will be set as
113
+ # HOLDER otherwise it sets your name.
114
+ def self.change_holder(title, environment, name, company_name, ent)
115
+ # @note Replace the Holder with the real one
116
+ puts 'Replace holder field with the present user'
117
+ if environment == 'Work'
118
+ namefill = "#{company_name}"
119
+ else
120
+ namefill = "#{name}"
121
+ end
122
+ change_holder_do(namefill, title, ent)
123
+ end
124
+
125
+ # This method does the changes
126
+ # @param [String] namefill can be the name or the company_name depends on
127
+ # environment
128
+ # @param [String] title comes from the get method. This @param represents the
129
+ # name or title of your work. It is used in all important code
130
+ # places.
131
+ # @param [String] ent Path to the entity file
132
+ # @return [String] true or false
133
+ def self.change_holder_do(namefill, title, ent)
134
+ text = File.read(ent)
135
+ new_contents = text.gsub("| You need to change the HOLDER entity in the \
136
+ de-DE/#{title}.ent file |", "#{namefill}")
137
+ puts new_contents
138
+ File.open(ent, 'w') { |file| file.puts new_contents }
139
+ end
140
+
141
+ # This method removes the <orgname> node from the XML file. Remove titlepage
142
+ # logo because of doing this with the publican branding files. This method
143
+ # will applied if environment is Work, "type" is Article and title_logo is
144
+ # "false".
145
+ # It returns a sucess or fail.
146
+ # @param [String] info can be bookinfo or artinfo
147
+ # @param [String] title_logo means that you can set if you want to use
148
+ # Publican's Title Logo or use your own Title Logo with your
149
+ # Stylesheets.
150
+ # @return [String] true or false
151
+ def self.remove_orgname(info, title_logo)
152
+ if title_logo == 'false'
153
+ puts 'Remove title logo from Article_Info or Books_Info'
154
+ puts info
155
+ doc = Nokogiri::XML(IO.read(info))
156
+ doc.search('orgname').each do |node|
157
+ node.remove
158
+ node.content = 'Children removed'
159
+ end
160
+ IO.write(info, doc.to_xml)
161
+ end
162
+ end
163
+
164
+ # Checks if bookinfo or artinfo is needed, then it starts remove_orgname
165
+ # @param [String] bookinfo Book_Info. Which is used there depends on the
166
+ # param "type".
167
+ # @param [String] artinfo Article_Info. Which is used there depends on the
168
+ # param "type".
169
+ # @param [String] title_logo means that you can set if you want to use
170
+ # Publican's Title Logo or use your own Title Logo with your
171
+ # Stylesheets.
172
+ # @param [String] type represents the Document-Type like Article or Book.
173
+ def self.remove_orgname_prepare(bookinfo, artinfo, title_logo, type)
174
+ info = artinfo if type == 'Article'
175
+ info = bookinfo if type == 'Book'
176
+ remove_orgname(info, title_logo)
177
+ end
178
+ # This method replaces the old productversion to the new revision
179
+ # @param [String] language The default language from the config file
180
+ # @param [String] revision The new revision number
181
+ # @param [String] edition The new edition number
182
+ # @return [String] true or false
183
+ def self.replace_productnumber(revision, edition, language)
184
+ puts 'Replacing the productnumber'
185
+ if File.exist?("#{language}/Article_Info.xml")
186
+ info = "#{language}/Article_Info.xml"
187
+ else
188
+ info = "#{language}/Book_Info.xml"
189
+ end
190
+ doc = Nokogiri::XML(IO.read(info))
191
+ doc.search('productnumber').each do |node|
192
+ node.content = "#{revision}"
193
+ end
194
+ doc.search('edition').each do |node|
195
+ node.content = "#{edition}"
196
+ end
197
+ IO.write(info, doc.to_xml)
198
+ end
199
+
200
+ # This method removes the XI-Includes for the legal notice
201
+ # It returns a sucess or fail.
202
+ # @param [String] environment shows if you actually want to create a private
203
+ # or Business Publication. If Work is given it reads your
204
+ # global entity file and appends it on the ent file.
205
+ # @param [String] type represents the Document-Type like Article or Book.
206
+ # @param [String] legal means if you don't like to have a Legal Notice on
207
+ # Publican's default place you can define it there. Actually
208
+ # it just works with Articles. In my case i'm using the
209
+ # Legal Notice inside the Article's Structure.
210
+ # @param [String] artinfo Article_Info. Which is used there depends on the
211
+ # param "type".
212
+ # @return [String] true or false
213
+ def self.remove_legal(environment, type, legal, artinfo)
214
+ if environment == 'Work'
215
+ if type == 'Article'
216
+ if legal == 'true'
217
+ # @note Remove the Legal Notice XI-Include in case it is an article.
218
+ # XCOM articles using another way to add them.
219
+ puts 'Remove XI-Includes for Legal Notice...'
220
+ text = File.read(artinfo)
221
+ # rubocop:disable Metrics/LineLength
222
+ new_contents = text.gsub('<xi:include href="Common_Content/Legal_Notice.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />', '')
223
+ puts new_contents
224
+ File.open(artinfo, 'w') { |file| file.puts new_contents }
225
+ end
226
+ else
227
+ puts 'Nothing to do'
228
+ end
229
+ else
230
+ puts 'Nothing to do'
231
+ end
232
+ end
233
+
234
+ # This method splits the name variable into firstname and surname. These
235
+ # variables are setted into the Revision_History. If the environment is "Work"
236
+ # your email_business will be used, otherwise your private email_address.
237
+ # It returns a sucess or fail.
238
+ # @param [String] revhist Path to the Revision_History
239
+ # @param [String] environment shows if you actually want to create a private
240
+ # or Business Publication. If Work is given it reads your
241
+ # global entity file and appends it on the ent file.
242
+ # @param [String] name is your name.
243
+ # @param [String] email_business is your business email address.
244
+ # @param [String] email is your private email address.
245
+ # @return [String] true or false
246
+ def self.fix_revhist(environment, name, email_business, email, revhist)
247
+ firstname, surname = get_name(name)
248
+ # @note Revision_History: Change default stuff to the present user
249
+ puts 'Replace the default content with the new content from the user
250
+ (Revision History)'
251
+ add_result('Enter your first name here.', "#{firstname}", revhist)
252
+ add_result('Enter your surname here.', "#{surname}", revhist)
253
+ add_result('Initial creation by publican', 'Initial creation', revhist)
254
+
255
+ if environment == 'Work'
256
+ add_result('Enter your email address here.', "#{email_business}", revhist)
257
+ else
258
+ add_result('Enter your email address here.', "#{email}", revhist)
259
+ end
260
+ end
261
+
262
+ # This method replaces the standard values from Author_Group to the present
263
+ # user issues. It will be launched for the Work environment. It returns a
264
+ # sucess or fail.
265
+ # @param [String] name is your name.
266
+ # @param [String] email_business is your business email address.
267
+ # @param [String] company_name is just your companies name.
268
+ # @param [String] company_division is your companies part/division.
269
+ # @param [String] email is your private email address.
270
+ # @param [String] environment shows if you actually want to create a private
271
+ # or Business Publication. If Work is given it reads your
272
+ # global entity file and appends it on the ent file.
273
+ # @param [String] agroup Path to Author_Group.xml
274
+ # @return [String] true or false
275
+ def self.fix_authorgroup(name, email_business, company_name, company_division,
276
+ email, environment, agroup)
277
+ firstname, surname = get_name(name)
278
+ # @note Author Group: Change the default stuff to the present user
279
+ puts 'Replace the default content with the new content from the user
280
+ (Authors_Group)'
281
+ add_result('Enter your first name here.', "#{firstname}", agroup)
282
+ add_result('Enter your surname here.', "#{surname}", agroup)
283
+ add_result('Initial creation by publican', 'Initial creation', agroup)
284
+
285
+ if environment == 'Work'
286
+ add_result('Enter your email address here.', "#{email_business}", agroup)
287
+ add_result('Enter your organisation\'s name here.', "#{company_name}",
288
+ agroup)
289
+ add_result('Enter your organisational division here.',
290
+ "#{company_division}", agroup)
291
+ else
292
+ add_result('Enter your email address here.', "#{email}", agroup)
293
+ add_result('Enter your organisation\'s name here.', '', agroup)
294
+ add_result('Enter your organisational division here.', '', agroup)
295
+ end
296
+ end
297
+
298
+ # Method for splitting the name variable into firstname and surname
299
+ # @param [String] name The name from config file
300
+ # @return [String] true or false
301
+ def self.get_name(name)
302
+ namechomp = name.chomp
303
+ # @note Split the variable to the array title[*]
304
+ name = namechomp.split(' ')
305
+ firstname = name[0]
306
+ surname = name[1]
307
+ [firstname, surname]
308
+ end
309
+ end
@@ -0,0 +1,48 @@
1
+ # PublicanCreatorsChecker
2
+ # @author Sascha Manns
3
+ # @abstract Class for checking directories and creating them
4
+ #
5
+ # Copyright (C) 2015 Sascha Manns <samannsml@directbox.com>
6
+ # License: MIT
7
+
8
+ # Dependencies
9
+
10
+ require 'fileutils'
11
+ require 'rainbow/ext/string'
12
+
13
+ # Module for different checks
14
+ module Checker
15
+ # Checks if the targetdirectory are present. If not, it creates one. It
16
+ # returns a success or fail.
17
+ # @param [String] todos contains the target directory
18
+ # @return [String] true or false
19
+ def self.check_dir(todos)
20
+ # @note Checking if dir exists
21
+ if Dir.exist?(todos)
22
+ puts 'Found directory. Im using it.'
23
+ else
24
+ puts 'No directory found. Im creating it.'
25
+ # @note Creates the new directory
26
+ FileUtils.mkdir_p(todos)
27
+ if Dir.exist?(todos)
28
+ puts 'Created new directory...'
29
+ else
30
+ fail('Cant create directory')
31
+ end
32
+ end
33
+ end
34
+
35
+ # This method will be launched from the init_docu_* methods. It returns a
36
+ # success, otherwise it raises with a error.
37
+ # @param [String] title comes from the get method. This @param represents the
38
+ # name or title of your work. It is used in all important code places.
39
+ # @return [String] true or false
40
+ def self.check_result(title)
41
+ # @note checking if new documentation directory exists
42
+ if Dir.exist?(title)
43
+ puts 'Creating documentation was a success...'
44
+ else
45
+ fail('Cant create documentation. Please try it manual with publican...')
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,125 @@
1
+ # Create Module for PublicanCreators
2
+ # PublicanCreatorsChange
3
+ # @author Sascha Manns
4
+ # @abstract Class for all file changes
5
+ #
6
+ # Copyright (C) 2015 Sascha Manns <samannsml@directbox.com>
7
+ # License: MIT
8
+
9
+ # Dependencies
10
+ require 'nokogiri'
11
+ require 'publican_creators/checker'
12
+
13
+ # Class for creating stuff
14
+ class PublicanCreatorsCreate
15
+ # Method for creating initial documentation for work. It asks for title, type,
16
+ # language, brand and db5 variable, creates a launch-string from them and
17
+ # launches publican.
18
+ # @param [String] title comes from the get method. This @param represents the
19
+ # name or title of your work. It is used in all important code
20
+ # places.
21
+ # @param [String] type represents the Document-Type like Article or Book.
22
+ # @param [String] language is just the ISO Code of your target language like:
23
+ # de-DE, en-GB or such things.
24
+ # @param [String] brand can be a special customized brand for your company to
25
+ # fit the styleguide.
26
+ # @param [String] db5 just sets your preferences. If you like to have DocBook
27
+ # 5.x as default you can set it there.
28
+ # @return [String] true or false
29
+ # @note That method returns just a success or a fail. After the main part of
30
+ # the method it starts another method "PublicanCreatorsChange.check_result".
31
+ # This method checks if the directory with the content of the parameter title
32
+ # is available.
33
+ def self.init_docu_work(title, type, language, brand, db5)
34
+ puts 'Creating initial documentation ...'
35
+ # Set standard string
36
+ string = "--lang #{language} --name #{title}"
37
+ # Add Article if type is Article
38
+ string << ' --type Article' if type == 'Article'
39
+ # Set business brand if given
40
+ string << " --brand #{brand}" if brand != ''
41
+ # @note Check if DocBook 5 wished as default, if yes it adds the parameter
42
+ # dtdver 5.0 to string
43
+ string << ' --dtdver 5.0' if db5 == 'true'
44
+ create_docu(string, title)
45
+ end
46
+
47
+ # Method for creating initial documentation for private. It asks for title,
48
+ # type, language, homework, brand_homework, brand_private
49
+ # and db5 variable, creates a launch-string from them and launches publican.
50
+ # @param [String] title comes from the get method. This parameter represents
51
+ # the name or title of your work. It is used in all
52
+ # important code places.
53
+ # @param [String] type represents the Document-Type like Article or Book.
54
+ # @param [String] brand_private is used in all methods with a "private" in the
55
+ # name. If this brand is set it will be used instead of
56
+ # the original publican brand.
57
+ # @param [String] language is just the ISO Code of your target language like:
58
+ # de-DE, en-GB or such things.
59
+ # @param [String] brand_homework can be a special customized brand for
60
+ # distance learning schools.
61
+ # @param [String] db5 just sets your preferences. If you like to have DocBook
62
+ # 5.x as default you can set it there.
63
+ # @return [String] true or false
64
+ # @note That method returns just a success or a fail. After the main part of
65
+ # the method it starts another method "PublicanCreatorsChange.check_result".
66
+ # This method checks if the directory with the content of the parameter title
67
+ # is available.
68
+ def self.init_docu_private(title, type, homework, language, brand_homework,
69
+ brand_private, db5)
70
+ puts 'Creating initial documentation ...'
71
+
72
+ if type == 'Article'
73
+ string = private_article(language, title, brand_private,
74
+ brand_homework, homework)
75
+ else
76
+ # @note Initial creation of documentation with publican
77
+ string = "--lang #{language} --name #{title}"
78
+ string << " --brand #{brand_private}" if brand_private != ''
79
+ end
80
+ # @note Check if DocBook 5 wished as default, if yes it adds the parameter
81
+ # dtdver 5.0 to string
82
+ string << ' --dtdver 5.0' if db5 == 'true'
83
+ create_docu(string, title)
84
+ end
85
+
86
+ # Method for preparing the string for private articles
87
+ # @param [String] language is just the ISO Code of your target language like:
88
+ # de-DE, en-GB or such things.
89
+ # @param [String] title comes from the get method. This parameter represents
90
+ # the name or title of your work. It is used in all
91
+ # important code places.
92
+ # @param [String] brand_private is used in all methods with a "private" in the
93
+ # name. If this brand is set it will be used instead of
94
+ # the original publican brand.
95
+ # @param [String] brand_homework can be a special customized brand for
96
+ # distance learning schools.
97
+ # @param [String] homework true if homework set
98
+ def self.private_article(language, title, brand_private, brand_homework,
99
+ homework)
100
+ # @note Initial creation of documentation with publican
101
+ string = "--type Article --lang #{language} --name #{title}"
102
+ # Use brand_private if brand_private is set
103
+ if brand_private != '' && homework == 'FALSE'
104
+ string << " --brand #{brand_private}"
105
+ end
106
+ # Use brand_homework if its set
107
+ if brand_homework != '' && homework == 'TRUE'
108
+ string << " --brand #{brand_homework}"
109
+ end
110
+ return string
111
+ end
112
+
113
+ # This method uses the input of init_docu methods to create the documentation
114
+ # @param [String] string This input comes from init_docu
115
+ # @param [String] title comes from the get method. This param represents the
116
+ # name or title of your work. It is used in all important
117
+ # code places.
118
+ # @return [String] true or false
119
+ def self.create_docu(string, title)
120
+ system("publican create #{string}")
121
+ # @param [String] title comes from the get method. This param represents
122
+ # the name or title of your work. It is used in all important code places.
123
+ Checker.check_result(title)
124
+ end
125
+ end