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

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.

Parameters:

  • environment (String)

    shows if you actually want to create a private or Business Publication. If Work is given it reads your global entity file and appends it on the ent file.

  • global_entities (String)

    is just the path to the global entity file.

  • ent (String)

    Path to the entity file

Returns:

  • (String)

    true or false



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

Parameters:

  • nice_description (String)

    is the default text in the target file

  • value_name (String)

    the replace text

  • file (String)

    Target file like Author_Group.xml

Returns:

  • (String)

    true or false



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

Note:

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.

Parameters:

  • title (String)

    comes from the get method.

  • environment (String)

    shows if you actually want to create a private or Business Publication. If Work is given it reads your global entity file and appends it on the ent file.

  • name (String)

    is your name.

  • company_name (String)

    is the name of your company

  • ent (String)

    Path to the entity file

Returns:

  • (String)

    true or false



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

Parameters:

  • namefill (String)

    can be the name or the company_name depends on environment

  • title (String)

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

  • ent (String)

    Path to the entity file

Returns:

  • (String)

    true or false



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

Parameters:

  • environment (String)

    shows if you actually want to create a private or Business Publication. If Work is given it reads your global entity file and appends it on the ent file.

  • title (String)

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

  • type (String)

    represents the Document-Type like Article or Book.

  • language (String)

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

  • brand (String)

    can be a special customized brand for your company to fit the styleguide.

  • db5 (String)

    just sets your preferences.

  • brand_homework (String)

    can be a special customized brand for distance learning schools.

  • brand_private (String)

    is used in all methods with a “private” in the name. If this brand is set it will be used instead of the original publican brand.

  • homework (String)

    if homework is set

Returns:

  • (String)

    true or false



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

Parameters:

  • name (String)

    is your name.

  • email_business (String)

    is your business email address.

  • company_name (String)

    is just your companies name.

  • company_division (String)

    is your companies part/division.

  • email (String)

    is your private email address.

  • environment (String)

    shows if you actually want to create a private or Business Publication. If Work is given it reads your global entity file and appends it on the ent file.

  • agroup (String)

    Path to Author_Group.xml

Returns:

  • (String)

    true or false



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.fix_authorgroup(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.

Parameters:

  • revhist (String)

    Path to the Revision_History

  • environment (String)

    shows if you actually want to create a private or Business Publication. If Work is given it reads your global entity file and appends it on the ent file.

  • name (String)

    is your name.

  • email_business (String)

    is your business email address.

  • email (String)

    is your private email address.

Returns:

  • (String)

    true or false



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

Parameters:

  • name (String)

    The name from config file

Returns:

  • (String)

    true or false



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

This method removes the XI-Includes for the legal notice. It returns a sucess or fail.

Parameters:

  • environment (String)

    shows if you actually want to create a private or Business Publication. If Work is given it reads your global entity file and appends it on the ent file.

  • type (String)

    represents the Document-Type like Article or Book.

  • legal (String)

    means if you don’t like to have a Legal Notice on Publican’s default place you can define it there. Actually it just works with Articles. In my case i’m using the Legal Notice inside the Article’s Structure.

  • artinfo (String)

    Article_Info. Which is used there depends on the param “type”.

Returns:

  • (String)

    true or false



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

Parameters:

  • info (String)

    can be bookinfo or artinfo

  • title_logo (String)

    means that you can set if you want to use Publican’s Title Logo or use your own Title Logo with your Stylesheets.

Returns:

  • (String)

    true or false



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, )
  if  == '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

Parameters:

  • bookinfo (String)

    Book_Info. Which is used there depends on the param “type”.

  • artinfo (String)

    Article_Info. Which is used there depends on the param “type”.

  • title_logo (String)

    means that you can set if you want to use Publican’s Title Logo or use your own Title Logo with your Stylesheets.

  • type (String)

    represents the Document-Type like Article or Book.



155
156
157
158
159
# File 'lib/publican_creators/change.rb', line 155

def self.remove_orgname_prepare(bookinfo, artinfo, , type)
  info = artinfo if type == 'Article'
  info = bookinfo if type == 'Book'
  remove_orgname(info, )
end

.replace_productnumber(revision, edition, language) ⇒ String

This method replaces the old productversion to the new revision

Parameters:

  • language (String)

    The default language from the config file

  • revision (String)

    The new revision number

  • edition (String)

    The new edition number

Returns:

  • (String)

    true or false



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