Sha256: f6d20a155da899a5a5258c8b488fdc252f5f217701933a1afdbad408cfa9c0b9

Contents?: true

Size: 1.22 KB

Versions: 9

Compression:

Stored size: 1.22 KB

Contents

class ViewGenerator
  require 'erb'
  def generate(*args)

    @actor_view_name = ARGV[1]
    @actor_view_name += "View" unless @actor_view_name.end_with? "View"
    @behaviors = ARGV[2]
    @bind = binding

    build_actor_view
    build_test_actor_view
  end
  
  def build_actor_view
    template_file = File.open(File.join(GAMEBOX_PATH,'templates','actor_view.erb'))
    template_contents = template_file.readlines.join
    actor_view_template = ERB.new(template_contents)

    result = actor_view_template.result @bind

    out_file = File.join(APP_ROOT,'src',Inflector.underscore(@actor_view_name)+".rb")
    raise "File exists [#{out_file}]" if File.exists? out_file
    File.open(out_file,"w+") do |f|
      f.write result
    end
  end

  def build_test_actor_view
    template_file = File.open(File.join(GAMEBOX_PATH,'templates','actor_view_spec.erb'))
    template_contents = template_file.readlines.join
    actor_view_template = ERB.new(template_contents)

    result = actor_view_template.result @bind

    out_file = File.join(APP_ROOT,'spec',Inflector.underscore(@actor_view_name)+"_spec.rb")
    raise "File exists [#{out_file}]" if File.exists? out_file
    File.open(out_file,"w+") do |f|
      f.write result
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
gamebox-0.3.4 lib/gamebox/generators/view_generator.rb
gamebox-0.3.3 lib/gamebox/generators/view_generator.rb
gamebox-0.3.2 lib/gamebox/generators/view_generator.rb
gamebox-0.2.1 lib/gamebox/generators/view_generator.rb
gamebox-0.1.1 lib/gamebox/generators/view_generator.rb
gamebox-0.1.0 lib/gamebox/generators/view_generator.rb
gamebox-0.0.9 lib/gamebox/generators/view_generator.rb
gamebox-0.0.8 lib/gamebox/generators/view_generator.rb
gamebox-0.0.7 lib/gamebox/generators/view_generator.rb