Sha256: c6d8a26e4dd2aa0ea5134ed764605f5adc91b3b0606ce2223e1c187b79538ff9
Contents?: true
Size: 1.46 KB
Versions: 2
Compression:
Stored size: 1.46 KB
Contents
#!/usr/bin/env ruby GEMFILE = <<EOF source 'https://rubygems.org' gem 'nephos-server' EOF ROUTE_RB = <<EOF #get url: "/", controller: "MainController", method: "root" #get url: "/add", controller: "MainController", method: "add_url" #get url: "/rm", controller: "MainController", method: "rm_url" EOF def generate_controller(name, file) if File.exists? file print "The file #{file} already exists. Are you sure to erase it ? (y/N)" r = STDIN.gets.to_s.chomp raise "File #{file} already exists" unless r.match(/y(es)?/) end f = File.open(file, 'w') f << <<EOF class #{name} < Nephos::Controller def root return {plain: "index"} end end EOF end def create_application_dir dir raise "Directory #{dir} already exists" if Dir.exists? dir Dir.mkdir dir end def move_to_application_dir dir Dir.chdir dir end def initialize_application raise "Not an empty dir" unless Dir[File.expand_path "*"].empty? File.write "routes.rb", ROUTE_RB File.write "Gemfile", GEMFILE Dir.mkdir "controllers" exec("bundle install") end case ARGV[0] when "c", "controller" if not ARGV[1].to_s.empty? generate_controller("#{ARGV[1]}Controller", "src/#{ARGV[1]}.rb") end when "a", "appli", "application" if not ARGV[1].to_s.empty? create_application_dir(ARGV[1]) puts "Application #{ARGV[1]} created" move_to_application_dir(ARGV[1]) end initialize_application puts "Application initialized" else puts "help: generate c[ontroller] name" end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
nephos-server-0.1.2 | bin/nephos-generator |
nephos-server-0.1.1 | bin/nephos-generator |