require 'rubygems' require 'templater' #TODO: This is temporary, see https://www.pivotaltracker.com/story/show/3399292 gem "activesupport", "~> 2.3.5" require 'active_support' require File.dirname(__FILE__) + '/../../lib/rhodes' module Rhogen extend Templater::Manifold desc <<-DESC Generate rhodes application DESC class BaseGenerator < Templater::Generator def class_name name.gsub('-', '_').camel_case end alias_method :module_name, :class_name end class AppGenerator < BaseGenerator def self.source_root File.join(File.dirname(__FILE__), 'templates', 'application') end desc <<-DESC Generates a new rhodes application. Required: name - application name Optional: syncserver - url to the rhosync application (i.e. "http://localhost:9292/application") zip_url - optional url to zipfile download of bundle (this can be your RhoHub Bundle URL) DESC #option :testing_framework, :desc => 'Specify which testing framework to use (spec, test_unit)' first_argument :name, :required => true, :desc => "application name" second_argument :syncserver, :required => false, :desc => 'url to the source adapter (i.e. "" or "http://rhosync.rhohub.com/apps/myapp/sources/")' third_argument :zip_url, :required => false, :desc => "optional url to zipfile download of bundle" template :config do |template| zip_url ||= '' syncserver ||= '' template.source = 'rhoconfig.txt' template.destination = "#{name}/rhoconfig.txt" end template :buildyml do |template| @sdk_path = File.expand_path(File.join(File.dirname(__FILE__),'..','..')) @app_name = name template.source = 'build.yml' template.destination = "#{name}/build.yml" end template :application do |template| template.source = 'app/application.rb' template.destination = "#{name}/app/application.rb" end template :index do |template| template.source = 'app/index.erb' template.destination = "#{name}/app/index.erb" end template :bb_index do |template| template.source = 'app/index.bb.erb' template.destination = "#{name}/app/index.bb.erb" end template :layout do |template| template.source = 'app/layout.erb' template.destination = "#{name}/app/layout.erb" end template :loading do |template| template.source = 'app/loading.html' template.destination = "#{name}/app/loading.html" end directory :helpers do |directory| directory.source = 'app/helpers' directory.destination = "#{name}/app/helpers" end directory :icon do |directory| directory.source = 'icon' directory.destination = "#{name}/icon" end directory :settings do |directory| directory.source = 'app/Settings' directory.destination = "#{name}/app/Settings/" end directory :public do |directory| directory.source = 'public' directory.destination = "#{name}/public/" end template :rakefile do |template| template.source = 'Rakefile' template.destination = "#{name}/Rakefile" end end class ModelGenerator < BaseGenerator include ActiveSupport::Inflector def self.source_root File.join(File.dirname(__FILE__), 'templates', 'model') end desc <<-DESC Generates a new model for a rhodes application. Required: name - model name attributes - list of one or more string attributes (i.e. name,industry,progress), NO spaces between attributes Optional: priority - sync priority (i.e. 100) type - DEPRECATED: type of model (i.e. "ask" for an ask model). This will be removed in 1.5, instead use search method. DESC #option :testing_framework, :desc => 'Specify which testing framework to use (spec, test_unit)' first_argument :name, :required => true, :desc => "model name" second_argument :attributes, :as => :array, :required => true, :desc => "list of one or more string attributes (i.e. name,industry,progress), NO spaces between attributes" third_argument :priority, :required => false, :desc => "optional sync priority (i.e. 100)" fourth_argument :type, :required => false, :desc => "optional type (i.e. \"ask\" for an ask model)" #template :config do |template| # @model_sync_server = syncserver_exists? ? class_name : '' # template.source = 'config.rb' # template.destination = "app/#{name.camel_case}/config.rb" #end template :index do |template| template.source = 'index.erb' template.destination = "app/#{name.camel_case}/index.erb" end template :edit do |template| template.source = 'edit.erb' template.destination = "app/#{name.camel_case}/edit.erb" end template :new do |template| template.source = 'new.erb' template.destination = "app/#{name.camel_case}/new.erb" end template :new do |template| template.source = 'show.erb' template.destination = "app/#{name.camel_case}/show.erb" end template :bb_index do |template| template.source = 'index.bb.erb' template.destination = "app/#{name.camel_case}/index.bb.erb" end template :bb_edit do |template| template.source = 'edit.bb.erb' template.destination = "app/#{name.camel_case}/edit.bb.erb" end template :bb_new do |template| template.source = 'new.bb.erb' template.destination = "app/#{name.camel_case}/new.bb.erb" end template :bb_show do |template| template.source = 'show.bb.erb' template.destination = "app/#{name.camel_case}/show.bb.erb" end template :controller do |template| underscore_name = name.camel_case.split(/(?=[A-Z])/).map{|w| w.downcase}.join("_") template.source = 'controller.rb' template.destination = "app/#{name.camel_case}/#{underscore_name}_controller.rb" end template :model do |template| underscore_name = name.camel_case.split(/(?=[A-Z])/).map{|w| w.downcase}.join("_") template.source = 'model.rb' template.destination = "app/#{name.camel_case}/#{underscore_name}.rb" end template :spec do |template| underscore_name = name.camel_case.split(/(?=[A-Z])/).map{|w| w.downcase}.join("_") template.source = 'spec.rb' template.destination = "app/test/#{underscore_name}_spec.rb" end def attributes? self.attributes && !self.attributes.empty? end def syncserver_exists? found = true File.open('rhoconfig.txt').each do |line| found = false if line.match("syncserver\ =\ ''") or line.match("syncserver\ =\ \"\"") or line.match("syncserver\ =\ nil") end found end end class SpecGenerator < BaseGenerator def self.source_root File.join(File.dirname(__FILE__), 'templates', 'spec') end desc <<-DESC Adds spec framework to rhodes application. DESC #option :testing_framework, :desc => 'Specify which testing framework to use (spec, test_unit)' #first_argument :name, :required => true, :desc => "application name" #second_argument :syncserver, :required => false, :desc => 'url to the source adapter (i.e. "" or "http://rhosync.rhohub.com/apps/myapp/sources/")' #third_argument :zip_url, :required => false, :desc => "optional url to zipfile download of bundle" directory :specrunner do |directory| directory.source = 'app/SpecRunner' directory.destination = "app/SpecRunner" end #directory :mspec do |directory| # directory.source = 'app/mspec' # directory.destination = "app/mspec" #end #directory :spec do |directory| # directory.source = 'app/spec' # directory.destination = "app/spec" #end #template :fileutils do |template| # template.source = 'app/fileutils.rb' # template.destination = "app/fileutils.rb" #end template :mspecrb do |template| template.source = 'app/mspec.rb' template.destination = "app/mspec.rb" end template :specrunnerrb do |template| template.source = 'app/spec_runner.rb' template.destination = "app/spec_runner.rb" end end add :app, AppGenerator add :model, ModelGenerator add :spec, SpecGenerator end