lib/jruby_art/creators/creator.rb in jruby_art-1.1.2 vs lib/jruby_art/creators/creator.rb in jruby_art-1.1.3

- old
+ new

@@ -1,150 +1,149 @@ # frozen_string_literal: false BASIC = <<-CODE def setup -sketch_title '%s' + sketch_title '%s' end def draw end def settings -size %s, %s -# pixel_density(2) # here for hi-dpi displays only -# smooth # here + size %s, %s + # pixel_density(2) # here for hi-dpi displays only + # smooth # here end CODE BASIC_MODE = <<-CODE def setup -sketch_title '%s' + sketch_title '%s' end def draw end def settings -size %s, %s, %s -# smooth # here + size %s, %s, %s + # smooth # here end CODE CLASS_BASIC = <<-CODE # encoding: utf-8 # frozen_string_literal: false class %s < Processing::App -def setup -sketch_title '%s' -end + def setup + sketch_title '%s' + end -def draw + def draw -end + end -def settings -size %s, %s -# pixel_density(2) # here for hi-dpi displays only -# smooth # here + def settings + size %s, %s + # pixel_density(2) # here for hi-dpi displays only + # smooth # here + end end -end CODE EMACS_BASIC = <<-CODE # encoding: utf-8 # frozen_string_literal: false require 'jruby_art' require 'jruby_art/app' -Processing::App::SKETCH_PATH = __FILE__ +Processing::App::SKETCH_PATH = __FILE__.freeze class %s < Processing::App -def setup -sketch_title '%s' -end + def setup + sketch_title '%s' + end -def draw + def draw -end + end -def settings -size %s, %s -# smooth # here + def settings + size %s, %s + # smooth # here + end end -end %s.new unless defined? $app CODE CLASS_MODE = <<-CODE # encoding: utf-8 # frozen_string_literal: false class %s < Processing::App -def setup -sketch_title '%s' -end + def setup + sketch_title '%s' + end -def draw + def draw -end + end -def settings -size %s, %s, %s -# smooth # here + def settings + size %s, %s, %s + # smooth # here + end end -end CODE EMACS_MODE = <<-CODE # encoding: utf-8 # frozen_string_literal: false require 'jruby_art' require 'jruby_art/app' -Processing::App::SKETCH_PATH = __FILE__ +Processing::App::SKETCH_PATH = __FILE__.freeze class %s < Processing::App -def setup -sketch_title '%s' -end + def setup + sketch_title '%s' + end -def draw + def draw -end + end -def settings -size %s, %s, %s -# smooth # here + def settings + size %s, %s, %s + # smooth # here + end end -end %s.new unless defined? $app CODE INNER = <<-CODE # encoding: utf-8 # frozen_string_literal: false class %s -include Processing::Proxy + include Processing::Proxy end CODE # creator wrapper module using StringExtra module Creator require_relative '../helpers/string_extra' - using StringExtra # Write file to disk class SketchWriter attr_reader :file def initialize(path) - underscore = path.underscore + underscore = StringExtra.new(path).underscore @file = "#{File.dirname(path)}/#{underscore}.rb" end def save(template) File.open(file, 'w+') do |f| @@ -155,11 +154,11 @@ # An abstract class providing common methods for real creators class Base ALL_DIGITS = /\A\d+\Z/ def already_exist(path) - underscore = path.underscore + underscore = StringExtra.new(path).underscore new_file = "#{File.dirname(path)}/#{underscore}.rb" return if !FileTest.exist?(path) && !FileTest.exist?(new_file) puts 'That file already exists!' exit end @@ -195,16 +194,16 @@ return usage if /\?/ =~ path || /--help/ =~ path # Check to make sure that the main file doesn't exist already already_exist(path) main_file = File.basename(path, '.rb') # allow uneeded extension input writer = SketchWriter.new(main_file) - @title = main_file.titleize + @title = StringExtra.new(main_file).titleize @width = args[0] @height = args[1] - @mode = args[2].upcase unless args[2].nil? - template = @mode.nil? ? basic_template : basic_template_mode - writer.save(template) + return writer.save(basic_template) if args[2].nil? + @mode = args[2].upcase + writer.save(basic_template_mode) end end # This class creates class wrapped sketches, with an optional render mode class ClassSketch < Base @@ -220,13 +219,13 @@ def create!(path, args) return usage if /\?/ =~ path || /--help/ =~ path main_file = File.basename(path, '.rb') # allow uneeded extension input # Check to make sure that the main file doesn't exist already already_exist(path) - @name = main_file.camelize + @name = StringExtra.new(main_file).camelize writer = SketchWriter.new(main_file) - @title = main_file.titleize + @title = StringExtra.new(main_file).titleize @width, @height = args[0], args[1] @mode = args[2].upcase unless args[2].nil? template = @mode.nil? ? class_template : class_template_mode writer.save(template) end @@ -245,12 +244,12 @@ def create!(path, args) return usage if /\?/ =~ path || /--help/ =~ path main_file = File.basename(path, '.rb') # allow uneeded extension input # Check to make sure that the main file doesn't exist already already_exist(path) - @name = main_file.camelize + @name = StringExtra.new(main_file).camelize writer = SketchWriter.new(main_file) - @title = main_file.titleize + @title = StringExtra.new(main_file).titleize @width, @height = args[0], args[1] @mode = args[2].upcase unless args[2].nil? template = @mode.nil? ? emacs_template : emacs_template_mode writer.save(template) end