-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit 03fc739
Showing
18 changed files
with
983 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
README.rdoc | ||
lib/**/*.rb | ||
bin/* | ||
features/**/*.feature | ||
LICENSE |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,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. |
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,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. |
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,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 |
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,19 @@ | ||
class CartController < Sinatra::Base | ||
|
||
|
||
post '/' do | ||
|
||
end | ||
|
||
get '/' do | ||
|
||
end | ||
|
||
put "/" do | ||
|
||
end | ||
|
||
delete "/" do | ||
|
||
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,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 |
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,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 |
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 @@ | ||
<%= "Erubis - I'm faster than Erb" %> |
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,4 @@ | ||
%html | ||
%title Super Simple | ||
%body | ||
%strong Ridiculously simple |
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,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 |
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,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} |
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,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 |
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,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") | ||
|
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,3 @@ | ||
require File.expand_path(File.dirname(__FILE__) + "/init") | ||
|
||
StandaloneController.run! |
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,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 |
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,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 |