Module: DragonrubyEgg::IO

Defined in:
lib/dragonruby_egg/io.rb

Class Method Summary collapse

Class Method Details

.change_content(content, repo_module, keywords, find_keyword = '') ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/dragonruby_egg/io.rb', line 5

def change_content(content, repo_module, keywords, find_keyword = '')
  h_change = lambda do |*e|
    result = e[0]
    e[1].each do |k|
      result = result
      .gsub("#{find_keyword}\"#{k}", "#{find_keyword}\"modules/#{repo_module}/#{k}")
      .gsub("#{find_keyword}\'#{k}", "#{find_keyword}\'modules/#{repo_module}/#{k}")
    end
    result
  end

  h_change.call(content, keywords)
end

.change_paths(module_path, repo_module) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/dragonruby_egg/io.rb', line 19

def change_paths(module_path, repo_module)
  rb_files = Dir.glob("#{module_path}/**/*.rb")
  rb_files.each do |path|
    content = nil
    File.open path do |f|
      content = f.read
    end
    if content
      # Require
      content = change_content(content, repo_module, ['app', 'lib'], 'require ')
      # Path for assets
      content = change_content(content, repo_module, ['sounds/', 'sprites/', 'fonts/', 'data/'])

      File.open path, "w+" do |f|
        f.write content
      end
    end
  end
end