Last active
August 29, 2015 14:20
-
-
Save jpotts18/9a648bb17e37a8186bf8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// THIS DOESN'T Come through | |
<%= @model %> | |
public class <%= 3 + 4 %> { | |
private int id; | |
private string email; | |
private string first; | |
private string lastname; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'erb' | |
require 'json' | |
require 'fileutils' | |
GEN_DIRS = ['gen', 'gen/models', 'gen/controllers'] | |
FileUtils::rm_rf GEN_DIRS[0] | |
FileUtils.mkdir_p GEN_DIRS | |
class Renderer < OpenStruct | |
def self.render_from_hash(t, h) | |
Renderer.new(h).render(t) | |
end | |
def render(template) | |
ERB.new(template).result(binding) | |
end | |
end | |
class Generator | |
def initialize(argv) | |
@argv = argv | |
end | |
def generate_model() | |
model_template = File.read('templates/src/Model.java.erb') | |
model = {} | |
model[:name] = @argv.slice!(0) | |
model[:fields] = @argv.map{|a| { name: a.split(':')[0], data_type: a.split(':')[1] } } | |
out_file = File.new(GEN_DIRS[1] + '/' + model[:name] + '.java','w+') | |
out_file.write(Renderer::render_from_hash(model_template, model)) | |
end | |
end | |
ARGV << 'help' if ARGV.empty? | |
command = ARGV.shift | |
if command == 'model' | |
puts 'model' | |
g = Generator.new(ARGV) | |
g.generate_model | |
elsif command == 'controller' | |
puts 'controller' | |
elsif command == 'scaffold' | |
puts 'scaffold' | |
else | |
puts 'help' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment