Class: IB::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/ib/generator.rb,
lib/ib/generator/rendering_helper.rb

Defined Under Namespace

Classes: RenderingHelper

Instance Method Summary collapse

Constructor Details

#initialize(motion_template_type) ⇒ Generator

Returns a new instance of Generator.



7
8
9
10
11
# File 'lib/ib/generator.rb', line 7

def initialize motion_template_type
  # NOTE: motion_template_type equal to Motion::Project::App.template
  #       but, this class use its value for judging build platform.
  @build_platform = motion_template_type
end

Instance Method Details

#absolute_template_path(path) ⇒ Object



13
14
15
# File 'lib/ib/generator.rb', line 13

def absolute_template_path path
  File.expand_path(File.join(File.dirname(__FILE__), path))
end

#render_stub_file(path, files) ⇒ Object



17
18
19
20
# File 'lib/ib/generator.rb', line 17

def render_stub_file path, files
  template = Tilt::ERBTemplate.new(absolute_template_path(path), { :trim => '<>' })
  template.render(RenderingHelper.new(@build_platform, files))
end

#write(files, dest) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ib/generator.rb', line 22

def write files, dest
  files = IB::Parser.new(@build_platform).find_all(files)

  FileUtils.mkpath dest

  File.open("#{dest}/Stubs.h", 'w') do |f|
    f.write render_stub_file('generator/templates/Stubs.h.erb', files)
  end

  File.open("#{dest}/Stubs.m", 'w') do |f|
    f.write render_stub_file('generator/templates/Stubs.m.erb', files)
  end
end