Class: Vipergen::Generator
- Inherits:
-
Object
- Object
- Vipergen::Generator
- Defined in:
- lib/vipergen/generator.rb
Overview
Cosntants
Constant Summary collapse
- LANGUAGES =
Constants
["swift", "objc"]
- REPLACEMENT_KEY =
"VIPER"
- AUTHOR_REPLACEMENT_KEY =
"___FULLUSERNAME___"
- YEAR_REPLACEMENT_KEY =
"___YEAR___"
- COMPANY_REPLACEMENT_KEY =
"___ORGANIZATIONNAME___"
- PROJECT_REPLACEMENT_KEY =
"___PROJECTNAME___"
- FILE_REPLACEMENT_KEY =
"___FILENAME___"
- DATE_REPLACEMENT_KEY =
"___DATE___"
- BASE_VC_REPLACEMENT_KEY =
"_BASE_VIEW_CONTROLLER_"
- BASE_VC_IMPORT_REPLACE_KEY =
'#import "_BASE_VIEW_CONTROLLER_.h"'
Class Method Summary collapse
-
.generate_viper(template, language, name, path, author, company, project, baseviewcontroller) ⇒ Object
Main method that generate the VIPER files structure.
-
.rename_file(file, name, author, company, project, baseviewcontroller) ⇒ Object
Rename a given file - It renames the name of the file - It renames the content of the file.
-
.rename_file_content(filename, name, author, company, project, baseviewcontroller) ⇒ Object
Rename the file content @return: An String with the every VIPER replaced by ‘name’.
-
.rename_files(files, name, author, company, project, baseviewcontroller) ⇒ Object
Rename all the files in the files array - It renames the name of the file - It renames the content of the file.
Class Method Details
.generate_viper(template, language, name, path, author, company, project, baseviewcontroller) ⇒ Object
Main method that generate the VIPER files structure
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/vipergen/generator.rb', line 17 def self.generate_viper(template, language, name, path, , company, project, baseviewcontroller) puts "Generating VIPER-Module" puts "Template: #{template}" puts "Language: #{language}" puts "Name: #{name}" puts "Path: #{path}" puts "Author: #{}" puts "Company: #{company}" puts "Project: #{project}" puts "BaseViewController : #{baseviewcontroller}" path_from = Vipergen::FileManager.path_from(template, language) path_to = Vipergen::FileManager.destination_viper_path(path, name) Vipergen::FileManager.copy(path_from, path_to) files = Vipergen::FileManager.files_in_path(path_to) rename_files(files, name, , company, project, baseviewcontroller) end |
.rename_file(file, name, author, company, project, baseviewcontroller) ⇒ Object
Rename a given file
-
It renames the name of the file
-
It renames the content of the file
47 48 49 50 51 |
# File 'lib/vipergen/generator.rb', line 47 def self.rename_file(file, name, , company, project, baseviewcontroller) new_path = file.gsub((Vipergen::Generator::REPLACEMENT_KEY), name) Vipergen::FileManager.move(file, new_path) rename_file_content(new_path, name, , company, project, baseviewcontroller) end |
.rename_file_content(filename, name, author, company, project, baseviewcontroller) ⇒ Object
Rename the file content @return: An String with the every VIPER replaced by ‘name’
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/vipergen/generator.rb', line 55 def self.rename_file_content(filename, name, , company, project, baseviewcontroller) # Reading content file = File.open(filename, "rb") content = file.read file.close # Replacing content content = content.gsub((Vipergen::Generator::REPLACEMENT_KEY), name) content = content.gsub((Vipergen::Generator::AUTHOR_REPLACEMENT_KEY), ) content = content.gsub((Vipergen::Generator::YEAR_REPLACEMENT_KEY), "#{Time.new.year}") content = content.gsub((Vipergen::Generator::COMPANY_REPLACEMENT_KEY), company) content = content.gsub((Vipergen::Generator::PROJECT_REPLACEMENT_KEY), project) content = content.gsub((Vipergen::Generator::FILE_REPLACEMENT_KEY), File.basename(filename,File.extname(filename))) str = '%02d/%02d/%02d' % [Time.new.day, Time.new.month, Time.new.year%100] content = content.gsub((Vipergen::Generator::DATE_REPLACEMENT_KEY), str) if baseviewcontroller == 'UIViewController' then content = content.gsub((Vipergen::Generator::BASE_VC_IMPORT_REPLACE_KEY), '') end content = content.gsub((Vipergen::Generator::BASE_VC_REPLACEMENT_KEY), baseviewcontroller) # Saving content with replaced string File.open(filename, "w+") do |file| file.write(content) end end |
.rename_files(files, name, author, company, project, baseviewcontroller) ⇒ Object
Rename all the files in the files array
-
It renames the name of the file
-
It renames the content of the file
37 38 39 40 41 42 |
# File 'lib/vipergen/generator.rb', line 37 def self.rename_files(files, name, , company, project, baseviewcontroller) files.each do |file| raise SyntaxError unless file.include? (Vipergen::Generator::REPLACEMENT_KEY) rename_file(file, name, , company, project, baseviewcontroller) end end |