Skip to content

Commit

Permalink
nz: sinatra slideshow code
Browse files Browse the repository at this point in the history
  • Loading branch information
techwhizbang committed Aug 7, 2010
0 parents commit 03fc739
Show file tree
Hide file tree
Showing 18 changed files with 983 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .document
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
README.rdoc
lib/**/*.rb
bin/*
features/**/*.feature
LICENSE
5 changes: 5 additions & 0 deletions .idea/copyright/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

729 changes: 729 additions & 0 deletions .idea/workspace.xml

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2009 Nick Zalabak

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 changes: 17 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
= Sinatra Demo App for Presentation

Basic examples of how to get up and running using Sinatra

== Note on Patches/Pull Requests

* Fork the project.
* Make your feature addition or bug fix.
* Add tests for it. This is important so I don't break it in a
future version unintentionally.
* Commit, do not mess with rakefile, version, or history.
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
* Send me a pull request. Bonus points for topic branches.

== Copyright

Copyright (c) 2010 Nick Zalabak. See LICENSE for details.
52 changes: 52 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
require 'rubygems'
require 'rake'

begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "simple_sinatra"
gem.summary = %Q{A sinatra_code Sinatra application}
gem.description = %Q{Demo Sinatra for the Ruby Meetup}
gem.email = "techwhizbang@gmail.com"
gem.homepage = "http://techwhizbang.com"
gem.authors = ["Nick Zalabak"]
gem.add_development_dependency "rspec", ">= 1.3.0"
gem.add_development_dependency "rack-test", ">= 0.5.3"
gem.add_dependency "sinatra", "1.0"
gem.add_dependency "rack", ">= 1.1.0"
gem.add_dependency "haml", ">= 3.0.13"
gem.add_dependency "builder", ">= 2.1.2"
gem.add_dependency "erubis", ">= 2.6.6"
gem.add_dependency "json"
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
Jeweler::GemcutterTasks.new
rescue LoadError
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
end

# Uncomment this is you want to run TestUnit instead
#require 'rake/testtask'
#Rake::TestTask.new(:test) do |test|
# test.libs << 'test'
# test.pattern = 'test/**/test_*.rb'
# test.verbose = true
#end

# Uncomment this is you want to run RSpec tests
require 'spec/rake/spectask'

Spec::Rake::SpecTask.new(:spec) do |spec|
spec.libs << 'lib' << 'spec'
spec.spec_files = FileList['spec/**/*_spec.rb']
end

Spec::Rake::SpecTask.new(:rcov) do |spec|
spec.libs << 'lib' << 'spec'
spec.pattern = 'spec/**/*_spec.rb'
spec.rcov = true
end

task :spec => :check_dependencies

task :default => :spec
19 changes: 19 additions & 0 deletions app/controllers/cart_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class CartController < Sinatra::Base


post '/' do

end

get '/' do

end

put "/" do

end

delete "/" do

end
end
31 changes: 31 additions & 0 deletions app/controllers/standalone_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class StandaloneController < Sinatra::Base

# Note that I'd had to "configure" the views for a more Rails-like controller/view mapping
set :views, Proc.new { File.expand_path(File.dirname(__FILE__) + "/../views/standalone") }

get "/" do
"Ridiculously simple"
end

get "/haml" do
haml :show
end

get "/builder" do
content_type 'application/xml', :charset => 'utf-8'
builder :show
end

get "/json" do
content_type 'application/json'
JSON.generate({"something like PI"=>3.141})
end

get "/erubis" do
erubis :show
end

# TODO: build an extension on Sinatra such that it recognizes the requested
# content type automatically like Rails respond_to { |format| ... }

end
4 changes: 4 additions & 0 deletions app/views/standalone/show.builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
xml.sinatra do
xml.rocks('Ridiculously Simple, well sort of...(the automagic xml variable is not documented)')
end
1 change: 1 addition & 0 deletions app/views/standalone/show.erubis
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= "Erubis - I'm faster than Erb" %>
4 changes: 4 additions & 0 deletions app/views/standalone/show.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
%html
%title Super Simple
%body
%strong Ridiculously simple
18 changes: 18 additions & 0 deletions config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# To use with thin
# thin start -p PORT -R config.ru
# thin -s 2 -C config.yml -R -R sinatra_code/config.ru start
# thin -s 2 -R sinatra_code/config.ru start

require File.expand_path(File.dirname(__FILE__) + "/init")

set :run, false
set :environment, :development

#Rack:URLMap in action
map "/cart" do
run CartController
end

map "/standalone" do
run StandaloneController
end
16 changes: 16 additions & 0 deletions init.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'rubygems'
require 'sinatra'
require 'builder'
require 'haml'
require 'erubis'
require 'active_record'
require 'json'
require 'net/http'

models = Dir.glob(File.expand_path(File.dirname(__FILE__) + "/app/models/*"))
helpers = Dir.glob(File.expand_path(File.dirname(__FILE__) + "/app/helpers/*"))
controllers = Dir.glob(File.expand_path(File.dirname(__FILE__) + "/app/controllers/*"))

models.each {|model| require model}
helpers.each {|helper| require helper}
controllers.each {|controller| require controller}
34 changes: 34 additions & 0 deletions spec/controllers/standalone_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")

describe StandaloneController do
include Rack::Test::Methods

def app
StandaloneController
end

it 'should return simple text' do
get "/"
last_response.body.should == "Ridiculously simple"
end

it 'should return JSON' do
get "/json"
last_response.body.should == "{\"something like PI\":3.141}"
end

it 'should return HTML from a HAML template' do
get "/haml"
last_response.body.should == "<html>\n <title>Super Simple</title>\n <body>\n <strong>Ridiculously simple</strong>\n </body>\n</html>\n"
end

it 'should return XML from a Builder template' do
get "/builder"
last_response.body.should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<sinatra>\n <rocks>Ridiculously Simple, well sort of...(the automagic xml variable is not documented)</rocks>\n</sinatra>\n"
end

it 'should return HTML from a Erubis template' do
get "/erubis"
last_response.body.should == "Erubis - I'm faster than Erb"
end
end
8 changes: 8 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'rubygems'
require 'spec'
require 'spec/autorun'
#Don't forget to include this to use Rack::Test
require 'rack/test'
#Load your application files
require File.expand_path(File.dirname(__FILE__) + "/../init")

3 changes: 3 additions & 0 deletions standalone_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require File.expand_path(File.dirname(__FILE__) + "/init")

StandaloneController.run!
10 changes: 10 additions & 0 deletions test/helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'rubygems'
require 'test/unit'
require 'shoulda'

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'app'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'sinatra_code'

class Test::Unit::TestCase
end
7 changes: 7 additions & 0 deletions test/test_simple.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'helper'

class TestSimple < Test::Unit::TestCase
should "probably rename this file and start testing for real" do
flunk "hey buddy, you should probably rename this file and start testing for real"
end
end

0 comments on commit 03fc739

Please sign in to comment.