Class: Modifier

Inherits:
Object
  • Object
show all
Defined in:
lib/unigunkan/modifier.rb

Class Method Summary collapse

Class Method Details

.add_block_after(src, line, block) ⇒ Object



31
32
33
# File 'lib/unigunkan/modifier.rb', line 31

def self.add_block_after(src, line, block)
  src.gsub(line, line + "\n" + block)
end

.add_build_files(src, files) ⇒ Object



2
3
4
# File 'lib/unigunkan/modifier.rb', line 2

def self.add_build_files(src, files)
  return add_block_after(src, "/* Begin PBXBuildFile section */", files)
end

.add_file_ref(src, files) ⇒ Object



6
7
8
# File 'lib/unigunkan/modifier.rb', line 6

def self.add_file_ref(src, files)
	return add_block_after(src, "/* Begin PBXFileReference section */", files)
end

.add_file_to_tree(src, file) ⇒ Object



18
19
20
21
22
23
# File 'lib/unigunkan/modifier.rb', line 18

def self.add_file_to_tree(src, file)
	target = "/* CustomTemplate */ = {
	isa = PBXGroup;
	children = ("
	return add_block_after(src, target, file)
end

.add_framework_build_phase(src, files) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/unigunkan/modifier.rb', line 10

def self.add_framework_build_phase(src, files)
	src_ = src
  target = /Frameworks \*\/ = {\n\t\t\tisa = PBXFrameworksBuildPhase;\n\t\t\tbuildActionMask = (.*?);\n\t\t\tfiles = \(/
  mask = src_.scan(target)[0][0]
  build_phases = "Frameworks */ = {\n\t\t\tisa = PBXFrameworksBuildPhase;\n\t\t\tbuildActionMask = #{mask};\n\t\t\tfiles = (\n"
  return src_.gsub(build_phases, build_phases + files + ",")
end

.add_library_search_paths(src, paths) ⇒ Object



25
26
27
28
29
# File 'lib/unigunkan/modifier.rb', line 25

def self.add_library_search_paths(src, paths)
	# TODO This won't work in non-unity projects. Fix later.
  target = '$(SRCROOT)/Libraries\"",'
  return add_block_after(src, target, paths)
end

.add_shell_script(src, script, uuid) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/unigunkan/modifier.rb', line 35

def self.add_shell_script(src, script, uuid)
  target = "/* Begin PBXShellScriptBuildPhase section */\n"
  shell_script = uuid + " /* ShellScript */ = {\nisa = PBXShellScriptBuildPhase;\nbuildActionMask = 2147483647;\nfiles = (\n);\ninputPaths = (\n);\noutputPaths = (\n);\n
    runOnlyForDeploymentPostprocessing = 0;\nshellPath = /bin/sh;\nshellScript = \"" + script + "\";\n};\n"
  src.gsub!(target, target + shell_script)

  target = " /* Frameworks */,\n\t\t\t);"
  build_phases = " /* Frameworks */,\n\t\t\t" + uuid + " /* ShellScript */,\n\t\t\t);"
  src.gsub!(target, build_phases)
end