Module: PublicanCreatorsChange
- Defined in:
- lib/publican_creators/change.rb
Overview
Module what contains all methods who are doing changes in files
Class Method Summary collapse
-
.add_entity(environment, global_entities, ent) ⇒ String
By working for my employer i’m creating publications which refers to a global entity file.
-
.add_result(nice_description, value_name, file) ⇒ String
Method for replacing content in agroup.
-
.change_holder(title, environment, name, company_name, ent) ⇒ String
In this method the standard-holder from the local entity-file will be replaced with the company_name or if it is a private work the name of the present user.
-
.change_holder_do(namefill, title, ent) ⇒ String
This method does the changes.
-
.check_environment(environment, title, type, language, brand, db5, homework, brand_homework, brand_private) ⇒ String
This method checks the environment and runs the method for.
-
.fix_authorgroup(name, email_business, company_name, company_division, email, environment, agroup) ⇒ String
This method replaces the standard values from Author_Group to the present user issues.
-
.fix_revhist(environment, name, email_business, email, revhist) ⇒ String
This method splits the name variable into firstname and surname.
-
.get_name(name) ⇒ String
Method for splitting the name variable into firstname and surname.
-
.remove_legal(environment, type, legal, artinfo) ⇒ String
This method removes the XI-Includes for the legal notice.
-
.remove_orgname(info, title_logo) ⇒ String
This method removes the <orgname> node from the XML file.
-
.remove_orgname_prepare(bookinfo, artinfo, title_logo, type) ⇒ Object
Checks if bookinfo or artinfo is needed, then it starts remove_orgname.
-
.replace_productnumber(revision, edition, language) ⇒ String
This method replaces the old productversion to the new revision.
Class Method Details
.add_entity(environment, global_entities, ent) ⇒ String
By working for my employer i’m creating publications which refers to a global entity file. This method adds the entities from that file into the local one. It returns a success or fail.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/publican_creators/change.rb', line 67 def self.add_entity(environment, global_entities, ent) if environment == 'Work' if global_entities.empty? puts 'Nothing to do' else puts 'Adding global entities...' # @note Adding global entities open(ent, 'a') do |add| add << "\n" add << "<!-- COMMON ENTITIES -->\n" end input = File.open(global_entities) data_to_copy = input.read output = File.open(ent, 'a') output.write(data_to_copy) input.close output.close end else puts 'Nothing to do' end end |
.add_result(nice_description, value_name, file) ⇒ String
Method for replacing content in agroup
29 30 31 32 33 34 35 36 |
# File 'lib/publican_creators/change.rb', line 29 def self.add_result(nice_description, value_name, file) text = File.read(file) new_value = text.gsub(nice_description, value_name) puts new_value File.open(file, 'w') do |file1| file1.puts new_value end end |
.change_holder(title, environment, name, company_name, ent) ⇒ String
If the environment “Work” is given the entity file will be set as HOLDER otherwise it sets your name.
In this method the standard-holder from the local entity-file will be replaced with the company_name or if it is a private work the name of the present user. It returns a sucess or fail.
101 102 103 104 105 106 107 108 109 110 |
# File 'lib/publican_creators/change.rb', line 101 def self.change_holder(title, environment, name, company_name, ent) # @note Replace the Holder with the real one puts 'Replace holder field with the present user' namefill = if environment == 'Work' company_name.to_s else name.to_s end change_holder_do(namefill, title, ent) end |
.change_holder_do(namefill, title, ent) ⇒ String
This method does the changes
120 121 122 123 124 125 |
# File 'lib/publican_creators/change.rb', line 120 def self.change_holder_do(namefill, title, ent) text = File.read(ent) new_contents = text.gsub("| You need to change the HOLDER entity in the de-DE/#{title}.ent file |", namefill.to_s) puts new_contents File.open(ent, 'w') { |file| file.puts new_contents } end |
.check_environment(environment, title, type, language, brand, db5, homework, brand_homework, brand_private) ⇒ String
This method checks the environment and runs the method for
52 53 54 55 56 57 58 |
# File 'lib/publican_creators/change.rb', line 52 def self.check_environment(environment, title, type, language, brand, db5, homework, brand_homework, brand_private) if environment == 'Work' PublicanCreatorsCreate.init_docu_work(title, type, language, brand, db5) else PublicanCreatorsCreate.init_docu_private(title, type, homework, language, brand_homework, brand_private, db5) end end |
.fix_authorgroup(name, email_business, company_name, company_division, email, environment, agroup) ⇒ String
This method replaces the standard values from Author_Group to the present user issues. It will be launched for the Work environment. It returns a sucess or fail. TODO: Try to fix this in future rubocop:disable Metrics/AbcSize
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'lib/publican_creators/change.rb', line 253 def self.(name, email_business, company_name, company_division, email, environment, agroup) firstname, surname = get_name(name) # @note Author Group: Change the default stuff to the present user puts 'Replace the default content with the new content from the user (Authors_Group)' add_result('Enter your first name here.', firstname.to_s, agroup) add_result('Enter your surname here.', surname.to_s, agroup) add_result('Initial creation by publican', 'Initial creation', agroup) if environment == 'Work' add_result('Enter your email address here.', email_business.to_s, agroup) add_result('Enter your organisation\'s name here.', company_name.to_s, agroup) add_result('Enter your organisational division here.', company_division.to_s, agroup) else add_result('Enter your email address here.', email.to_s, agroup) add_result('Enter your organisation\'s name here.', '', agroup) add_result('Enter your organisational division here.', '', agroup) end end |
.fix_revhist(environment, name, email_business, email, revhist) ⇒ String
This method splits the name variable into firstname and surname. These variables are setted into the Revision_History. If the environment is “Work” your email_business will be used, otherwise your private email_address. It returns a sucess or fail.
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/publican_creators/change.rb', line 223 def self.fix_revhist(environment, name, email_business, email, revhist) firstname, surname = get_name(name) # @note Revision_History: Change default stuff to the present user puts 'Replace the default content with the new content from the user (Revision History)' add_result('Enter your first name here.', firstname.to_s, revhist) add_result('Enter your surname here.', surname.to_s, revhist) add_result('Initial creation by publican', 'Initial creation', revhist) if environment == 'Work' add_result('Enter your email address here.', email_business.to_s, revhist) else add_result('Enter your email address here.', email.to_s, revhist) end end |
.get_name(name) ⇒ String
Method for splitting the name variable into firstname and surname
279 280 281 282 283 284 285 286 |
# File 'lib/publican_creators/change.rb', line 279 def self.get_name(name) namechomp = name.chomp # @note Split the variable to the array title[*] name = namechomp.split(' ') firstname = name[0] surname = name[1] [firstname, surname] end |
.remove_legal(environment, type, legal, artinfo) ⇒ String
This method removes the XI-Includes for the legal notice. It returns a sucess or fail.
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/publican_creators/change.rb', line 192 def self.remove_legal(environment, type, legal, artinfo) if environment == 'Work' if type == 'Article' if legal == 'true' # @note Remove the Legal Notice XI-Include in case it is an article. # XCOM articles using another way to add them. puts 'Remove XI-Includes for Legal Notice...' text = File.read(artinfo) # rubocop:disable Metrics/LineLength new_contents = text.gsub('<xi:include href="Common_Content/Legal_Notice.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />', '') puts new_contents File.open(artinfo, 'w') { |file| file.puts new_contents } end else puts 'Nothing to do' end else puts 'Nothing to do' end end |
.remove_orgname(info, title_logo) ⇒ String
This method removes the <orgname> node from the XML file. Remove titlepage logo because of doing this with the publican branding files. This method will applied if environment is Work, “type” is Article and title_logo is “false”. It returns a sucess or fail. TODO: Try to fix this in future rubocop:disable Style/GuardClause
136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/publican_creators/change.rb', line 136 def self.remove_orgname(info, title_logo) if title_logo == 'false' puts 'Remove title logo from Article_Info or Books_Info' puts info doc = Nokogiri::XML(IO.read(info)) doc.search('orgname').each do |node| node.remove node.content = 'Children removed' end IO.write(info, doc.to_xml) end end |
.remove_orgname_prepare(bookinfo, artinfo, title_logo, type) ⇒ Object
Checks if bookinfo or artinfo is needed, then it starts remove_orgname
155 156 157 158 159 |
# File 'lib/publican_creators/change.rb', line 155 def self.remove_orgname_prepare(bookinfo, artinfo, title_logo, type) info = artinfo if type == 'Article' info = bookinfo if type == 'Book' remove_orgname(info, title_logo) end |
.replace_productnumber(revision, edition, language) ⇒ String
This method replaces the old productversion to the new revision
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/publican_creators/change.rb', line 166 def self.replace_productnumber(revision, edition, language) puts 'Replacing the productnumber' info = if File.exist?("#{language}/Article_Info.xml") "#{language}/Article_Info.xml" else "#{language}/Book_Info.xml" end doc = Nokogiri::XML(IO.read(info)) doc.search('productnumber').each do |node| node.content = revision.to_s end doc.search('edition').each do |node| node.content = edition.to_s end IO.write(info, doc.to_xml) end |