Class: Processing::Creator
- Inherits:
-
BaseExporter
- Object
- BaseExporter
- Processing::Creator
- Defined in:
- lib/ruby-processing/exporters/creator.rb
Overview
This class creates blank sketches, with the boilerplate filled in.
Constant Summary
Constants inherited from BaseExporter
BaseExporter::DEFAULT_DESCRIPTION, BaseExporter::DEFAULT_DIMENSIONS, BaseExporter::DEFAULT_TITLE
Instance Method Summary collapse
-
#create!(path, args) ⇒ Object
Create a blank sketch, given a path.
-
#usage(predicate) ⇒ Object
Show the help/usage message for create.
Methods inherited from BaseExporter
#extract_class_name, #extract_description, #extract_dimension, #extract_information, #extract_libraries, #extract_real_requires, #extract_title, #get_main_file
Instance Method Details
#create!(path, args) ⇒ Object
Create a blank sketch, given a path.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ruby-processing/exporters/creator.rb', line 7 def create!(path, args) usage path main_file = File.basename(path, ".rb") # Check to make sure that the main file exists already_exists = File.exists?(path) || File.exists?("#{File.dirname(path)}/#{main_file.underscore}.rb") puts "That sketch already exists." and exit if already_exists # Get the substitutions @name = main_file.camelize @file_name = main_file.underscore @title = main_file.titleize @width = args[0] || "500" @height = args[1] || "500" # Make the file dir = File.dirname path mkdir_p dir template = File.new("#{RP5_ROOT}/lib/templates/create/blank_sketch.rb.erb") rendered = render_erb_from_string_with_binding(template.read, binding) File.open(File.join(dir, "#{@file_name}.rb"), "w") do |file| file.print rendered end end |
#usage(predicate) ⇒ Object
Show the help/usage message for create.
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ruby-processing/exporters/creator.rb', line 32 def usage(predicate) unless predicate puts <<-USAGE Usage: script/generate <sketch_to_generate> <width> <height> Width and Height are optional. Example: script/generate fancy_drawing/app 800 600 USAGE exit end end |