Quakespotter.app/lib/ruby-processing/exporters/creator.rb
# Create a blank sketch, given a path.
Create a blank sketch, given a path.
Create a blank sketch given a path .
def create!(path, args, bare)
      usage path
      main_file = File.basename(path, ".rb")
      already_exists = File.exists?(path) || File.exists?("#{File.dirname(path)}/#{main_file.underscore}.rb")
      if already_exists
        puts "That sketch already exists."
        exit
      end
      @name           = main_file.camelize
      @file_name      = main_file.underscore
      @title          = main_file.titleize
      @width, @height = args[0], args[1]
      @with_size      = @width && @width.match(ALL_DIGITS) &&
                        @height && @height.match(ALL_DIGITS)
      dir = File.dirname path
      mkdir_p dir
      template_name = bare ? 'bare_sketch.rb.erb' : 'blank_sketch.rb.erb'
      template = File.new("#{RP5_ROOT}/lib/templates/create/#{template_name}")
      rendered = render_erb_from_string_with_binding(template.read, binding)
      full_path = File.join(dir, "#{@file_name}.rb")
      File.open(full_path, "w") {|f| f.print(rendered) }
      puts "Created Sketch \"#{@title}\" in #{full_path.sub(/\A\.\//, '')}"
    end
def create! ( path , args , bare ) usage path main_file = File . basename ( path , ".rb" ) already_exists = File . exists? ( path ) || File . exists? ( "#{File.dirname(path)}/#{main_file.underscore}.rb" ) if already_exists puts "That sketch already exists." exit end @name = main_file . camelize @file_name = main_file . underscore @title = main_file . titleize @width , @height = args [ 0 ] , args [ 1 ] @with_size = @width && @width . match ( ALL_DIGITS ) && @height && @height . match ( ALL_DIGITS ) dir = File . dirname path mkdir_p dir template_name = bare ? 'bare_sketch.rb.erb' : 'blank_sketch.rb.erb' template = File . new ( "#{RP5_ROOT}/lib/templates/create/#{template_name}" ) rendered = render_erb_from_string_with_binding ( template . read , binding ) full_path = File . join ( dir , "#{@file_name}.rb" ) File . open ( full_path , "w" ) { | f | f . print ( rendered ) } puts "Created Sketch \"#{@title}\" in #{full_path.sub(/\A\.\//, '')}" end
Create a blank sketch, given a path.
Create a blank sketch given a path .
# Check to make sure that the main file exists # Get the substitutions # Make the file
path
args
bare