Permalink
Browse files

add ability to email output

  • Loading branch information...
brandonmwest committed Apr 2, 2012
1 parent e62c0a2 commit 0ca3850ac796ef7d5a3157f2f32434a0112af6be
Showing with 120 additions and 33 deletions.
  1. +2 −1 Gemfile
  2. +13 −0 Gemfile.lock
  3. +26 −0 index.rb
  4. +25 −1 public/js/default.js
  5. +9 −4 views/endpoints.haml
  6. +45 −27 views/layout.haml
View
@@ -3,4 +3,5 @@ gem "sinatra"
gem "sinatra-contrib"
gem "haml"
gem "json"
-gem "hashie"
+gem "hashie"
+gem "pony"
View
@@ -5,7 +5,16 @@ GEM
eventmachine (0.12.10)
haml (3.1.4)
hashie (1.2.0)
+ i18n (0.6.0)
json (1.6.5)
+ mail (2.4.4)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.18)
+ polyglot (0.3.3)
+ pony (1.4)
+ mail (> 2.0)
rack (1.4.1)
rack-protection (1.2.0)
rack
@@ -23,6 +32,9 @@ GEM
sinatra (~> 1.3.0)
tilt (~> 1.3)
tilt (1.3.3)
+ treetop (1.4.10)
+ polyglot
+ polyglot (>= 0.3.1)
PLATFORMS
ruby
@@ -31,5 +43,6 @@ DEPENDENCIES
haml
hashie
json
+ pony
sinatra
sinatra-contrib
View
@@ -5,8 +5,21 @@
require 'haml'
require 'json'
require 'hashie'
+require 'pony'
config_file 'iodoctor.yml'
+Pony.options = {
+ :via => :smtp,
+ :via_options => {
+ :address => 'smtp.sendgrid.net',
+ :port => '587',
+ :domain => 'iodoctor.net',
+ :user_name => ENV['SENDGRID_USERNAME'],
+ :password => ENV['SENDGRID_PASSWORD'],
+ :authentication => :plain,
+ :enable_starttls_auto => true
+ }
+}
helpers Sinatra::Partials
@@ -27,6 +40,7 @@
@result = Hash.new
@result["endpoints"] = Hash.new
+
return haml(:endpoints)
end
@@ -38,6 +52,18 @@
haml :endpoints
end
+post '/email' do
+ body = "Thanks for using I/O Doctor! Your JSON output is attached."
+
+ puts params
+
+ Pony.mail(:to => params[:to_address],
+ :subject => "I/O Doctor JSON Output",
+ :html_body => body,
+ :body => body,
+ :attachments => {"output.json" => params[:json]})
+end
+
post '/file' do
content_type 'application/json'
attachment 'config.json'
View
@@ -13,7 +13,7 @@ $(function() {
firstMethod.popover({"trigger":"manual",
"title":"Edit this Method",
- "content":"Get started by editing this method! Click on the method title bar to show the form.",
+ "content":"Get started by editing this method! Click on this title bar to show the form for editing this method.",
"placement":"bottom"});
firstMethod.popover('show');
@@ -23,6 +23,12 @@ $(function() {
//save file button
$('.save-file').click(saveFile);
+ //email button
+ $('.email-output').click(showEmailForm);
+
+ $('#email-modal').find('.cancel').click(hideEmailForm);
+ $('#email-modal').find('.send').click(emailOutput);
+
//buttons to add new endpoints, methods, parameters
$('#addEndpoint').click(addEndpoint);
$('.addMethod').live('click', addMethod);
@@ -48,6 +54,24 @@ $(function() {
$($('.endpoint')[0]).show();
});
+var showEmailForm = function() {
+ $('#email-modal').modal();
+}
+
+var hideEmailForm = function() {
+ $('#email-modal').modal('hide');
+}
+
+var emailOutput = function(value, settings){
+ hideEmailForm();
+ email = $('#email').val();
+ $('#to_address').val(email);
+ console.log($('#to_address'));
+ formData = $("#outputForm").serialize();
+ $.post("/email", formData);
+ return;
+}
+
var saveFile = function(){
$('#outputForm').submit();
}
View
@@ -13,10 +13,15 @@
#output-container.tab-pane
%form#outputForm{:method => "post", :action => "/file"}
%input#json{:type => "hidden", :name => "json", :value => " "}
-
- %a.btn.btn-success.save-file
- %i.icon-download-alt.icon-white
- Save File
+ %input#to_address{:type => "hidden", :name => "to_address", :value => " "}
+ %a.btn.btn.email-output
+ %i.icon-envelope
+ Email
+
+ %a.btn.btn.save-file
+ %i.icon-download-alt
+ Save as File
+
#output
#editor.tab-pane.active.row
View
@@ -28,34 +28,51 @@
%h3
About I/O Doctor
+ .modal-body
+ .right.ribbon-holder
+ %a.white.ribbon(href="http://github.com/brandonmwest/iodoctor")
+ %span.text
+ Fork me on GitHub
+
+ %h4
+ What is I/O Doctor?
+ %br
+ %p
+ I/O Doctor is a GUI for creating and updating
+ %a(href="https://github.com/mashery/iodocs")
+ I/O Docs
+ Configuration files.
+
+ %h4 How does I/O Doctor work?
+ %br
+ %p
+ %strong Upload
+ an existing config, or
+ %strong create
+ a new config and start adding Endpoints, Methods, and Parameters. When an existing config is used, it is parsed and forms for editing each Endpoint, Method, and Parameter will be created.
+ %p
+ Click an item from the menu on the left to begin editing. View the JSON output at any time by hitting the "output" tab. When finished, click "Save File" to download the JSON file. I/O Doctor does not store any data. Make sure you save your JSON output.
+
+ .modal-footer
+ .btn.btn-primary.close Close
+
+ .hide#email-modal.modal
+ .modal-header
+ %h3
+ Email Output
+
.modal-body
- .right.ribbon-holder
- %a.white.ribbon(href="http://github.com/brandonmwest/iodoctor")
- %span.text
- Fork me on GitHub
-
- %h4
- What is I/O Doctor?
- %br
- %p
- I/O Doctor is a GUI for creating and updating
- %a(href="https://github.com/mashery/iodocs")
- I/O Docs
- Configuration files.
+ .control-group
+ %label.control-label{:for => "email"}
+ Email Address:
+ .controls
+ .input
+ %input{:name => "email", :id => "email", :value => ""}
- %h4 How does I/O Doctor work?
- %br
- %p
- %strong Upload
- an existing config, or
- %strong create
- a new config and start adding Endpoints, Methods, and Parameters. When an existing config is used, it is parsed and forms for editing each Endpoint, Method, and Parameter will be created.
- %p
- Click an item from the menu on the left to begin editing. View the JSON output at any time by hitting the "output" tab. When finished, click "Save File" to download the JSON file. I/O Doctor does not store any data. Make sure you save your JSON output.
-
- .modal-footer
- .btn.btn-primary.close Close
-
+ .modal-footer
+ %a.btn.cancel{:href => "#"} Cancel
+ %a.btn.send.btn-primary{:href => "#"} Send Email
+
-if @show_bottom_bar
.bottom-bar
.bottombar-inner
@@ -68,4 +85,5 @@
%script{:src => "/js/jquery-1.7.1.min.js"}
%script{:src => "/js/bootstrap.min.js"}
%script{:src => "/js/default.js"}
-%script{:src => "/js/form2js.js"}
+%script{:src => "/js/form2js.js"}
+%script{:src => "/js/jquery.jeditable.min.js"}

0 comments on commit 0ca3850

Please sign in to comment.