Permalink
Browse files

sbapp new app generator

  • Loading branch information...
1 parent 77f0279 commit 520220106361dfbfea3420f3c037e7c9f90acf24 @avinasha avinasha committed Nov 24, 2012
View
1 Gemfile
@@ -11,6 +11,7 @@ gem 'faraday_middleware'
gem 'hashie'
gem 'haml'
gem 'mail'
+gem 'thor'
# App Gems
gem 'tinder'
View
1 Gemfile.lock
@@ -119,4 +119,5 @@ DEPENDENCIES
rspec
sinatra
sinatra-initializers
+ thor
tinder
View
6 bin/sbapp
@@ -0,0 +1,6 @@
+#!/usr/bin/env ruby
+
+require 'rubygems'
+require_relative '../config/load'
+
+SupportBeeApp::Command.start
View
13 config/load.rb
@@ -1,24 +1,20 @@
-puts "Loading Platform Constants"
-
PLATFORM_ENV = ENV["RACK_ENV"] ||= "development"
PLATFORM_ROOT = File.expand_path '../../', __FILE__
-puts "Bundler doing its thing.."
-
require 'bundler'
Bundler.setup
Bundler.require(:default, PLATFORM_ENV.to_sym)
-puts "Loading lib and apps.."
+require "#{PLATFORM_ROOT}/config/environments/#{PLATFORM_ENV}"
+
require 'active_support/core_ext/string/inflections'
require 'active_support/core_ext/object/blank'
Dir["#{PLATFORM_ROOT}/lib/helpers/**/*.rb"].each { |f| require f }
Dir["#{PLATFORM_ROOT}/lib/*.rb"].each { |f| require f }
Dir["#{PLATFORM_ROOT}/apps/*/*.rb"].each { |f| require f }
-puts "Loading configurations..."
app_config = YAML.load_file("#{PLATFORM_ROOT}/config/sba_config.yml")[PLATFORM_ENV]['app_platform']
SECRET_CONFIG = YAML.load_file("#{PLATFORM_ROOT}/config/secret_config.yml")[PLATFORM_ENV]
@@ -31,15 +27,10 @@
APP_CONFIG = app_config
-puts "Loading envirnoments.."
-require "#{PLATFORM_ROOT}/config/environments/#{PLATFORM_ENV}"
-
-puts "Preparing Logs... "
log_dir = "#{PLATFORM_ROOT}/log"
log_filename = "#{PLATFORM_ENV}.log"
log_url = "#{log_dir}/#{log_filename}"
FileUtils.mkdir(log_dir) unless File.exists?(log_dir)
LOGGER = Logger.new(log_url)
-puts "Loading Sinatra app"
require "#{PLATFORM_ROOT}/run_app"
View
41 lib/command.rb
@@ -0,0 +1,41 @@
+module SupportBeeApp
+ class Command < Thor
+ include Thor::Actions
+
+ def self.source_root
+ "#{PLATFORM_ROOT}/templates"
+ end
+
+ attr_accessor :slug
+
+ desc "new APP_SLUG", "create a new SupportBee app"
+ def new(slug)
+ slug = slug.downcase
+ unless slug =~ /^[a-z_][a-z_0-9]*$/
+ puts "#{slug} should be a valid variable name"
+ return
+ end
+
+ destination_root = "#{APPS_PATH}/#{slug}"
+
+ if Dir.exists?(destination_root)
+ puts "An App with slug #{slug} already exists"
+ return
+ else
+ FileUtils.mkdir(destination_root)
+ end
+
+ puts "Generating app #{slug}..."
+ self.slug = slug
+ template("#{source_root}/config.yml.tt", "#{destination_root}/config.yml")
+ template("#{source_root}/slug.rb.tt", "#{destination_root}/#{slug}.rb")
+ directory("#{source_root}/assets", "#{destination_root}/assets")
+ end
+
+ no_tasks do
+ def source_root
+ self.class.source_root
+ end
+ end
+ end
+end
View
BIN templates/assets/images/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN templates/assets/images/screenshot.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
24 templates/assets/views/button/overlay.hbs
@@ -0,0 +1,24 @@
+<!--
+ Set overlay: true in the config
+ This file will be rendered on the overlay
+ The below code sample is taken from the Pivotal App
+-->
+
+<h3>Edit the Story Details</h3>
+{{#each tickets}}
+ {{#ticket}}
+ <ol>
+ <li>
+ <label for="title">Story Title</label>
+ <input name="title" value="{{subject}}">
+ </li>
+ <li>
+ <label for="description">Story Description</label>
+ <textarea name="description">
+{{content.text}} \n
+https://{{../../company.subdomain}}.supportbee.com/tickets/{{id}}
+ </textarea>
+ </li>
+ </ol>
+ {{/ticket}}
+{{/each}}
View
32 templates/config.yml.tt
@@ -0,0 +1,32 @@
+name: <%= slug.capitalize %>
+slug: <%= slug %>
+access: public
+
+description: "This is to test and a boilerplate app.
+Accepts newline"
+
+category: Integration
+
+tags:
+- tag1
+- tag2
+
+developer:
+ name: <Your Name>
+ email: <Your Email>
+ twitter: "<Your Twitter Handle>"
+ github: <Your Github Handle>
+
+# The following config keys are used by Action Handlers
+# Set button 'overlay' to true, if you want to have an overlay
+# The valid values for screens are [ticket, all, unassigned, my, groups]
+# Remove the following section if you do not want to define Action Handlers
+
+action:
+ button:
+ overlay: false
+ screens:
+ - ticket
+ - all
+ - unassigned
+ label: Send To <%= slug.capitalize %>
View
35 templates/slug.rb.tt
@@ -0,0 +1,35 @@
+module <%= slug.classify %>
+ module EventHandler
+ # Handle 'ticket.created' event
+ def ticket_created; end
+
+ # Handle all events
+ def all_events; end
+ end
+end
+
+module <%= slug.classify %>
+ module ActionHandler
+ def button
+ # Handle Action here
+ [200, "Success"]
+ end
+ end
+end
+
+module <%= slug.classify %>
+ class Base < SupportBeeApp::Base
+ # Define Settings
+ # string :name, :required => true, :hint => 'Tell me your name'
+ # string :username, :required => true, :label => 'User Name'
+ # password :password, :required => true
+ # boolean :notify_me, :default => true, :label => 'Notify Me'
+
+ # White list settings for logging
+ # white_list :name, :username
+
+ # Define public and private methods here which will be available
+ # in the EventHandler and ActionHandler modules
+ end
+end
+

0 comments on commit 5202201

Please sign in to comment.