Skip to content

Instantly share code, notes, and snippets.

@rgm
Created June 27, 2011 23:40
Show Gist options
  • Save rgm/1050131 to your computer and use it in GitHub Desktop.
Save rgm/1050131 to your computer and use it in GitHub Desktop.
class Generate < Thor
desc 'menu', 'Create .cpp/.h/.r for a bare menu'
def menu
onoe 'IMPLEMENT ME'
end
desc 'parametric_menu', 'Create .cpp/.h/.r for a menu & parametric'
def parametric_menu
onoe 'IMPLEMENT ME'
end
desc 'tool', 'Create .cpp/.h/.r for a bare tool'
def tool
onoe 'IMPLEMENT ME'
end
desc 'parametric_tool', 'Create .cpp/.h/.r for a tool & parametric'
def parametric_tool
onoe 'IMPLEMENT ME'
end
desc 'library', 'Create .cpp/.h/.r for a Vectorscript library'
def library
onoe 'IMPLEMENT ME'
end
no_tasks do
def onoe(str)
say str, :blue
end
end
end
class Menu < Thor::Group
include Thor::Actions
source_paths << 'templates'
argument :universal_name
argument :display_name, :required=>false
argument :category, :default=>"My Custom Tools"
def self.source_root
File.dirname(__FILE__)
end
def create_menu_files
say "Generating menu files with UUID #{uuid}", :cyan
%w{cpp h r}.each {|ext| template "Menu.#{ext}"}
end
no_tasks do
def onoe(str)
say str,:red
end
end
protected
def uuid
@uuid ||= Uuid.new
end
end
class ParametricMenu < Menu
def create_parametric_files
say "Generating menu files with UUID #{uuid}", :cyan
%w{cpp h r}.each {|ext| template "Parametric.#{ext}"}
end
end
class Uuid
def initialize
@uuid = `uuid`.chomp
end
def to_s
@uuid.upcase
end
def to_cpp
# FIXME quel horreur... works but wow
parts = @uuid.split '-'
last_part = parts.pop
penultimate_part = parts.pop
last_part_processed = []
last_part.to_enum(:each_char).each_slice(2) {|p| last_part_processed << p}
penultimate_part_processed = []
penultimate_part.to_enum(:each_char).each_slice(2) {|p| penultimate_part_processed << p}
parts << penultimate_part_processed.map{|pair| pair.join}
parts << last_part_processed.map{|pair| pair.join}
parts.flatten.map{|p| "0x#{p}"}.join ","
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment