-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c12d2a9
commit 253d461
Showing
13 changed files
with
129 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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 file contains 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 file contains 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 file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
class ApplicationController < ActionController::Base | ||
protect_from_forgery | ||
|
||
private | ||
def render(args={}) | ||
if Hash === args && args[:text] | ||
response.headers['Content-Type'] = 'text/plain; charset=utf-8' | ||
end | ||
super | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,37 @@ | ||
class PlotsController < ApplicationController | ||
def index | ||
end | ||
|
||
def upload | ||
title, upload = params.detect do |k, v| | ||
ActionDispatch::Http::UploadedFile === v | ||
end | ||
|
||
unless upload | ||
return render :status => 401, :error => "Usage: cat data | curl plotocrat.com -F 'X axis title'=@-" | ||
end | ||
|
||
plot = Plot.new(:data => upload.read, :title => title).tap(&:save!) | ||
render :text => url_for(:action => :view, :slug => plot.slug) | ||
rescue ActiveRecord::RecordInvalid => e | ||
render :status => 401, :text => url_for(:action => :error, :error => e.message) | ||
end | ||
|
||
def view | ||
@plot = Plot.where(:slug => params[:slug]).first | ||
end | ||
|
||
def error | ||
render :text => params[:error] | ||
end | ||
|
||
private | ||
|
||
def render(args={}) | ||
if error = args.delete(:error) | ||
super :text => url_for(:action => :error, :error => e.message) | ||
else | ||
super | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class UploadsController < ActionController::Metal | ||
|
||
def upload | ||
plot = Plot.new(:data => request.raw_post, :title => params[:title]).tap(&:save!) | ||
puts request.raw_post.inspect | ||
render :text => url_for(:action => :view, :slug => plot.slug) | ||
rescue ActiveRecord::RecordInvalid => e | ||
render :status => 401, :text => url_for(:action => :error, :error => e.message) | ||
end | ||
|
||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class Plot < ActiveRecord::Base | ||
attr_accessible :slug, :title, :data | ||
validates :data, :presence => true | ||
before_save :ensure_crlf | ||
before_create :set_defaults | ||
|
||
def ensure_crlf | ||
self.data = self.data.gsub(/\r\n|\r|\n/, "\r\n") | ||
end | ||
|
||
def set_defaults | ||
self.slug = Digest::SHA1.hexdigest(data)[0...20] if data | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<div data-title="<%= @plot.title %>" id="cdf"></div> | ||
<textarea id="data"><%= @plot.data %></textarea> |
This file contains 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 file contains 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 file contains 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 file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class CreatePlots < ActiveRecord::Migration | ||
def change | ||
create_table :plots do |t| | ||
t.text :slug, :null => false | ||
t.text :data, :null => false | ||
t.text :title, :null => true | ||
|
||
t.timestamps | ||
end | ||
|
||
add_index :plots, :slug | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# encoding: UTF-8 | ||
# This file is auto-generated from the current state of the database. Instead | ||
# of editing this file, please use the migrations feature of Active Record to | ||
# incrementally modify your database, and then regenerate this schema definition. | ||
# | ||
# Note that this schema.rb definition is the authoritative source for your | ||
# database schema. If you need to create the application database on another | ||
# system, you should be using db:schema:load, not running all the migrations | ||
# from scratch. The latter is a flawed and unsustainable approach (the more migrations | ||
# you'll amass, the slower it'll run and the greater likelihood for issues). | ||
# | ||
# It's strongly recommended to check this file into your version control system. | ||
|
||
ActiveRecord::Schema.define(:version => 20130101213921) do | ||
|
||
create_table "plots", :force => true do |t| | ||
t.text "slug", :null => false | ||
t.text "data", :null => false | ||
t.text "title" | ||
t.datetime "created_at", :null => false | ||
t.datetime "updated_at", :null => false | ||
end | ||
|
||
add_index "plots", ["slug"], :name => "index_plots_on_slug" | ||
|
||
end |