Class: Processing::ClassSketch

Inherits:
Creator
  • Object
show all
Defined in:
lib/ruby-processing/exporters/creator.rb

Overview

This class creates class wrapped sketches, with an optional render mode

Constant Summary

Constants inherited from Creator

Processing::Creator::ALL_DIGITS

Instance Method Summary collapse

Methods inherited from Creator

#already_exist, #usage

Instance Method Details

#class_templateObject



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/ruby-processing/exporters/creator.rb', line 111

def class_template
%(
class <%=@name%> < Processing::App
  def setup
size <%=@width%>, <%=@height%>
  end

  def draw

  end
end

# <%=@name%>.new(x: 20, y: 20)
)
end

#class_template_modeObject



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/ruby-processing/exporters/creator.rb', line 127

def class_template_mode
%(
class <%=@name%> < Processing::App
  def setup
size <%=@width%>, <%=@height%>, <%=@mode%>
  end

  def draw

  end
end

# <%=@name%>.new(x: 20, y: 20)
)
end

#create!(path, args) ⇒ Object

Create a bare blank sketch, given a path.



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/ruby-processing/exporters/creator.rb', line 143

def create!(path, args)
  return usage if /\?/ =~ path || /--help/ =~ path
  main_file = File.basename(path, '.rb')
  # Check to make sure that the main file doesn't exist already
  already_exist(path)
  @param = {
    name: main_file.camelize,
    file_name: "#{File.dirname(path)}/#{path.underscore}.rb",
    title: main_file.titleize,
    width: args[0],
    height: args[1],
    mode: args[2]
  }
  @with_size = @param[:width] && @param[:width].match(ALL_DIGITS) &&
    @param[:height] && @param[:height].match(ALL_DIGITS)
  template = @param[:mode].nil? ? class_template : class_template_mode
  SketchWriter.new(template, @param)
end