Skip to content

Commit

Permalink
first sort of working example
Browse files Browse the repository at this point in the history
  • Loading branch information
tobowers committed Dec 30, 2008
1 parent 37c7b03 commit 22bc26e
Show file tree
Hide file tree
Showing 26 changed files with 854 additions and 9 deletions.
85 changes: 85 additions & 0 deletions app/controllers/pastes_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
class PastesController < ApplicationController
# GET /pastes
# GET /pastes.xml
def index
@pastes = Paste.find(:all)

respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @pastes }
end
end

# GET /pastes/1
# GET /pastes/1.xml
def show
@paste = Paste.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @paste }
end
end

# GET /pastes/new
# GET /pastes/new.xml
def new
@paste = Paste.new

respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @paste }
end
end

# GET /pastes/1/edit
def edit
@paste = Paste.find(params[:id])
end

# POST /pastes
# POST /pastes.xml
def create
@paste = Paste.new(params[:paste])

respond_to do |format|
if @paste.save
flash[:notice] = 'Paste was successfully created.'
format.html { redirect_to(@paste) }
format.xml { render :xml => @paste, :status => :created, :location => @paste }
else
format.html { render :action => "new" }
format.xml { render :xml => @paste.errors, :status => :unprocessable_entity }
end
end
end

# PUT /pastes/1
# PUT /pastes/1.xml
def update
@paste = Paste.find(params[:id])

respond_to do |format|
if @paste.update_attributes(params[:paste])
flash[:notice] = 'Paste was successfully updated.'
format.html { redirect_to(@paste) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @paste.errors, :status => :unprocessable_entity }
end
end
end

# DELETE /pastes/1
# DELETE /pastes/1.xml
def destroy
@paste = Paste.find(params[:id])
@paste.destroy

respond_to do |format|
format.html { redirect_to(pastes_url) }
format.xml { head :ok }
end
end
end
30 changes: 29 additions & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
module ApplicationHelper
def render_bundled_js_include_tags_for_dev
js = asset_dir("js").map { |js| "#{js}" }
javascript_include_tag(*js)
end

def render_bundled_stylesheet_link_tags_for_dev

styles = asset_dir("css").map { |css| "#{css}" }
styles << {:media => "screen"}
stylesheet_link_tag(*styles)
end

private
def asset_dir(which)
case which
when "js"
directory = "javascripts"
format = "js"
when "css"
directory = "stylesheets"
format = "css"
end

Dir.glob("#{RAILS_ROOT}/public/#{directory}//**/*.#{format}").map {|path|
path.split("//")[1].sub(".#{which}", "")
}.sort
end

end
2 changes: 2 additions & 0 deletions app/helpers/pastes_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module PastesHelper
end
4 changes: 4 additions & 0 deletions app/models/language.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Language < ActiveRecord::Base
has_many :pastes

end
2 changes: 2 additions & 0 deletions app/models/paste.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
class Paste < ActiveRecord::Base
belongs_to :language

end
20 changes: 20 additions & 0 deletions app/views/layouts/application.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
!!!
%html{:xmlns=>"http://www.w3.org/1999/xhtml"}
%head
= javascript_include_tag :all
= render_bundled_stylesheet_link_tags_for_dev

= yield :head

%body.mbx
#doc3{:class => "pastebin yui-t7 #{params[:controller]} #{params[:action]}"}
#bd.bd
#yui-main
.yui-b
.main_content
= yield :layout
.yui-b
.sidebar
= yield :sidebar

= render :partial => "shared/bottom_javascript"
13 changes: 13 additions & 0 deletions app/views/pastes/_form.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
- form_for(@paste) do |f|
= f.error_messages
%p
= f.label :content
= f.text_area :content
%p
= f.label :title
= f.text_field :title
%p
= f.label :language
= f.select :language_id, Language.find(:all).collect { |l| [ l.name, l.id ]}
%p
= f.submit "Create"
8 changes: 8 additions & 0 deletions app/views/pastes/edit.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
%h1
Editing paste

= render :partial => "form"

= link_to 'Show', @paste
|
= link_to 'Back', pastes_path
24 changes: 24 additions & 0 deletions app/views/pastes/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<h1>Listing pastes</h1>

<table>
<tr>
<th>Content</th>
<th>Title</th>
<th>Language</th>
</tr>

<% for paste in @pastes %>
<tr>
<td><%=h paste.content %></td>
<td><%=h paste.title %></td>
<td><%=h paste.language_id %></td>
<td><%= link_to 'Show', paste %></td>
<td><%= link_to 'Edit', edit_paste_path(paste) %></td>
<td><%= link_to 'Destroy', paste, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>

<br />

<%= link_to 'New paste', new_paste_path %>
6 changes: 6 additions & 0 deletions app/views/pastes/new.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
%h1
New Paste

= render :partial => "form"

= link_to 'Back', pastes_path
18 changes: 18 additions & 0 deletions app/views/pastes/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<p>
<b>Content:</b>
<%= Uv.parse(@paste.content, "xhtml", @paste.language.name, "true", "sunburst") %>
</p>

<p>
<b>Title:</b>
<%=h @paste.title %>
</p>

<p>
<b>Language:</b>
<%=h @paste.language_id %>
</p>


<%= link_to 'Edit', edit_paste_path(@paste) %> |
<%= link_to 'Back', pastes_path %>
Empty file.
5 changes: 5 additions & 0 deletions config/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
# Specify gems that this application depends on.
# They can then be installed with "rake gems:install" on new installations.
# You have to specify the :lib option for libraries, where the Gem name (sqlite3-ruby) differs from the file itself (sqlite3)
config.gem 'haml'
config.gem 'oniguruma'
config.gem 'textpow'
#also requires 'ultraviolet'

# config.gem "bj"
# config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
# config.gem "sqlite3-ruby", :lib => "sqlite3"
Expand Down
1 change: 1 addition & 0 deletions config/initializers/ultraviolet.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'uv'
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
ActionController::Routing::Routes.draw do |map|
map.resources :pastes

# The priority is based upon order of creation: first created -> highest priority.

# Sample of regular route:
Expand Down
4 changes: 3 additions & 1 deletion db/migrate/20081230170838_create_pastes.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
class CreatePastes < ActiveRecord::Migration
def self.up
create_table :pastes do |t|

t.text :content
t.string :title
t.belongs_to :class, :language
t.timestamps
end
end
Expand Down
15 changes: 15 additions & 0 deletions db/migrate/20081230174420_create_languages.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class CreateLanguages < ActiveRecord::Migration
def self.up
create_table :languages do |t|
t.string :name
t.timestamps
end
["javascript", "actionscript", "css", "ruby", "ruby_on_rails", "html", "plain_text"].each do |name|
Language.create(:name => name)
end
end

def self.down
drop_table :languages
end
end
29 changes: 29 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 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 => 20081230174420) do

create_table "languages", :force => true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "pastes", :force => true do |t|
t.text "content"
t.string "title"
t.integer "class_id"
t.integer "language_id"
t.datetime "created_at"
t.datetime "updated_at"
end

end
8 changes: 2 additions & 6 deletions public/stylesheets/000_reset_fonts_grids.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
html {
color: #000;
background: #FFF; }
color: #000; }

.mbx {
margin: 0;
padding: 0;
font: 13px/1.231 arial,helvetica,clean,sans-serif;
*font-size: small;
Expand Down Expand Up @@ -399,7 +397,6 @@ html {
.mbx .yui-gc .yui-u {
float: left;
margin-left: 1.99%;
*margin-left: 1%;
width: 32%;
float: right; }
.mbx .yui-gc .yui-g {
Expand All @@ -415,8 +412,7 @@ html {
.mbx .yui-gc div.first {
float: left;
margin-left: 0;
width: 66%;
*width: 65%; }
width: 66%; }
.mbx .yui-gc div.first div.first {
float: left; }
.mbx .yui-gc .yui-gb div.first {
Expand Down
Empty file.
Loading

0 comments on commit 22bc26e

Please sign in to comment.