Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

2 #1

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open

2 #1

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
bd80cc0
Corrected small grammatical error
tedlee Nov 26, 2012
3dc9799
Merge pull request #60 from tedlee/master
Nov 26, 2012
66ddedc
use wkhtmltopdf-binary gem instead of vendor'd binary. fixes #61
May 23, 2013
7f35272
Updated Heroku deployment guide
kathgironpe Nov 18, 2013
893a649
Added PATCH
kathgironpe Nov 18, 2013
92bb3d7
Merge pull request #63 from katgironpe/master
kgrz Nov 21, 2013
02297ff
Fix syntax highlighting
kgrz Nov 21, 2013
de8f8bc
Fix typo by reported #66
Dec 14, 2013
6e1dfef
Merge pull request #67 from sinatra-sapporo/models
Dec 15, 2013
61f1464
Fix Qt related SSL connection errors
kgrz Dec 31, 2013
13e5b22
add MIT license
Apr 28, 2015
489913a
Updated gemcutter reference to rubygems
emachnic Jul 3, 2015
33218f2
Merge pull request #75 from emachnic/master
Jul 6, 2015
d16d826
Merge pull request #74 from ksolo/master
Jul 6, 2015
6c10748
Upgrade Ruby to 2.2.4
kgrz Apr 11, 2016
0a6ab93
fix image url in page
Apr 19, 2016
c5f2417
Merge pull request #77 from hfl/master
locks Apr 19, 2016
418cebd
fix broken code example (__FILE__ constant had typo)
afogel Jun 8, 2017
1470006
Merge pull request #79 from afogel/fix_file_constant
locks Jun 8, 2017
de19172
README: Link to the very terse wiki page on style
olleolleolle Jun 11, 2018
8f528e2
Change 'four' to 'five' for HTTP method count
johnisom Nov 27, 2019
f62ea89
Update Rack::Builder hyperlink URL
johnisom Nov 27, 2019
5e12953
add dockerfile
Mark24Code May 8, 2021
f1f2cf0
update ruby to 2.7.2
Mark24Code May 8, 2021
8b2639b
Merge pull request #85 from Mark24Code/master
zzak May 8, 2021
a03b30d
Merge pull request #84 from johnisom/patch-2
zzak May 8, 2021
7ae1b5f
Merge pull request #83 from johnisom/patch-1
zzak May 8, 2021
7f792ab
Merge pull request #81 from olleolleolle/patch-1
zzak May 8, 2021
5873a90
docs: drop unsupported coffee_script section
olleolleolle Oct 9, 2022
0300135
docs: modernize some of the wording
olleolleolle Oct 9, 2022
bb5769f
docs: link to post deprecating github-services
olleolleolle Oct 9, 2022
318d397
Merge pull request #87 from olleolleolle/patch-2
zzak Dec 9, 2022
16ed3af
Merge pull request #86 from olleolleolle/patch-1
zzak Dec 9, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
source 'http://rubygems.org'
source 'https://rubygems.org'

ruby '2.7.2'

gem 'pdfkit'
gem 'rake'
gem 'redcarpet', '~> 2.0'
gem 'sinatra'
gem 'wkhtmltopdf-binary', :require => false
10 changes: 9 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GEM
remote: http://rubygems.org/
remote: https://rubygems.org/
specs:
pdfkit (0.5.2)
rack (1.4.1)
Expand All @@ -12,6 +12,7 @@ GEM
rack-protection (~> 1.2)
tilt (~> 1.3, >= 1.3.3)
tilt (1.3.3)
wkhtmltopdf-binary (0.9.9.1)

PLATFORMS
ruby
Expand All @@ -21,3 +22,10 @@ DEPENDENCIES
rake
redcarpet (~> 2.0)
sinatra
wkhtmltopdf-binary

RUBY VERSION
ruby 2.7.2p137

BUNDLED WITH
2.2.9
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,31 @@ Join us on IRC (#sinatra at irc.freenode.org) if you need help with anything.
[sinatra-book]: http://github.com/sinatra/sinatra-book
[sinatra-recipes]: http://recipes.sinatrarb.com/
[issues]: http://github.com/sinatra/sinatra-book/issues
[styling-guidelines]: http://github.com/sinatra/sinatra-book-contrib/wiki/Style-Guidelines
[styling-guidelines]: https://github.com/sinatra/sinatra-book/wiki/How-to-contribute
[forking]: http://help.github.com/forking/
[pull-requests]: http://help.github.com/pull-requests/

License
-----------------

The MIT License (MIT)

Copyright (c) 2015 Sinatra

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.
13 changes: 9 additions & 4 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
get('/book.css') { send_file "#{ASSETS_DIR}/book.css", :type => 'text/css' }
get('/print.css') { send_file "#{ASSETS_DIR}/print.css", :type => 'text/css' }

get('/download.png') { send_file "#{ASSETS_DIR}/images/download.png", :type => :png }

get('/images/download.png') { send_file "#{ASSETS_DIR}/images/download.png", :type => :png }
get('/images/book-logo.png') { send_file "#{ASSETS_DIR}/images/book-logo.png", :type => :png }
__END__
@@layout
<!DOCTYPE html>
Expand All @@ -22,14 +22,19 @@
<title>Sinatra Book</title>
<link rel="stylesheet" type="text/css" href="/book.css" media="screen, projection" />
<link rel="stylesheet" type="text/css" href="/print.css" media="print" />
<link rel="shortcut icon" href="https://github.com/sinatra/resources/raw/master/logo/favicon.ico">
<link rel="shortcut icon" href="/images/favicon.ico">
</head>
<body>
<div id="download">
<a href="/download">
<img src="/download.png" alt="Download the Sinatra Book" />
<img src="/images/download.png" alt="Download the Sinatra Book" />
</a>
</div>
<div id="header">
<p>
<img src="/images/book-logo.png" />
</p>
</div>
<%= yield %>
</body>
</html>
Binary file added assets/images/book-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/favicon.ico
Binary file not shown.
14 changes: 7 additions & 7 deletions book.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
require 'fileutils'

module Book
ASSETS_DIR = File.join(File.dirname(__FILE__), "assets")
ASSETS_DIR = File.join(File.dirname(__FILE__), "assets")
BOOK_DIR = File.join(File.dirname(__FILE__), "book")
OUTPUT_DIR = File.join(File.dirname(__FILE__), "output")

def build(pdf=false)
doc = header
if pdf
doc = header
else
doc = ""
end
doc << toc
doc << content
if pdf
PDFKit.configure { |config|
config.wkhtmltopdf = File.join(File.dirname(__FILE__),
'vendor', 'wkhtmltopdf')
}
kit = PDFKit.new(doc, :page_size=>'Letter')
kit.stylesheets << "#{ASSETS_DIR}/print.css"
pdf = kit.to_pdf
Expand All @@ -30,7 +30,7 @@ def header
<<-header
<div id="header">
<p>
<img src="https://raw.github.com/sinatra/resources/master/logo/book-logo.png" />
<img src="#{ASSETS_DIR}/images/book-logo.png" />
</p>
</div>
header
Expand Down
47 changes: 30 additions & 17 deletions book/Deployment.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,45 @@ pushing to a remote git repository.
Steps to deploy to Heroku:

* Create an [account](http://heroku.com/signup) if you don't have one
* `gem install heroku`
* Download and install [Heroku toolbelt](https://toolbelt.heroku.com/)
* Make sure you have a `Gemfile`. Otherwise, you can create one and install the `sinatra` gem using `bundler`.
* Make a config.ru in the root-directory
* Create the app on heroku
* Push to it

1. Here is an example config.ru file that does two things. First, it requires
your main app file, whatever it's called. In the example, it will look for
`myapp.rb`. Second, run your application. If you're subclassing, use the
subclass's name, otherwise use Sinatra::Application.
1. Install `bundler` if you haven't yet (`gem install bundler`). Create a `Gemfile` using `bundle init`. Modify your `Gemfile` to look like:

```ruby
source 'http://rubygems.org'

gem 'sinatra'
```

```ruby
require "myapp"
Run `bundle` to install the gem.

run Sinatra::Application
```
It is possible to specify a specific Ruby version on your Gemfile.
For more information, check [this](https://devcenter.heroku.com/articles/ruby-versions).

2. Here is an example config.ru file that does two things. First, it requires
your main app file, whatever it's called. In the example, it will look for
`myapp.rb`. Second, run your application. If you're subclassing, use the
subclass's name, otherwise use Sinatra::Application.

2. Create the app and push to it
```ruby
require "myapp"

From the root-directory of the application
run Sinatra::Application
```

```
$ heroku create <app-name> # This will add heroku as a remote
$ git push heroku master
```
3. Create the app and push to it

For more details see [this](http://github.com/sinatra/heroku-sinatra-app)
From the root directory of the application, run these commands:

```bash
$ heroku create <app-name> # This will add heroku as a remote
$ git push heroku master
```

[Heroku]: http://www.heroku.com
For more details see [this](http://github.com/sinatra/heroku-sinatra-app).

[Heroku]: http://www.heroku.com
15 changes: 11 additions & 4 deletions book/Getting_to_know_Sinatra.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ whirlwind tour of the framework and familiarize yourself with its features.
## Routing

Sinatra is super flexible when it comes to routing, which is essentially an
HTTP method and a regular expression to match the requested URL. The four basic
HTTP method and a regular expression to match the requested URL. The five basic
HTTP request methods will get you a long ways:

* GET
* POST
* PATCH
* PUT
* DELETE

Expand Down Expand Up @@ -43,6 +44,11 @@ put '/dog/:id' do
# HTTP PUT request method to update an existing dog
end

patch '/dog/:id' do
# HTTP PATCH request method to update an existing dog
# See RFC 5789 for more information
end

delete '/dog/:id' do
# HTTP DELETE request method to remove a dog who's been sold!
end
Expand All @@ -52,14 +58,15 @@ As you can see from this contrived example, Sinatra's routing is very easy to ge
along with. Don't be fooled, though, Sinatra can do some pretty amazing things
with Routes.

Take a more in-depth look at [Sinatra's routes][routes], and see for yourself.
Take a more in-depth look at [Sinatra's routes][routes], and see for yourself.

[routes]: http://www.sinatrarb.com/intro#Routes
[restful-web-services]: http://en.wikipedia.org/wiki/Representational_State_Transfer#RESTful_web_services
[RFC 5789]: http://www.rfc-base.org/rfc-5789.html

## Filters

Sinatra offers a way for you too hook into the request chain of your
Sinatra offers a way for you to hook into the request chain of your
application via [Filters][filters].

Filters define two methods available, `before` and `after` which both accept a
Expand Down Expand Up @@ -143,7 +150,7 @@ application:
get '/' do
session['counter'] ||= 0
session['counter'] += 1
"You've hit this page #{session['counter']} times!"
"You've hit this page #{session['counter']} times!"
end
```

Expand Down
39 changes: 17 additions & 22 deletions book/Introduction.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ $ gem install sinatra

### Dependencies

Sinatra depends on the _Rack_ gem (<http://rack.rubyforge.org>).
Sinatra depends on the _Rack_ gem (<https://rubygems.org/rack>).

Sinatra supports many different template engines (it uses the Tilt library
internally to support practically every template engine in Ruby)
Expand All @@ -52,28 +52,25 @@ $ gem install haml

### Living on the Edge

The _edge_ version of Sinatra lives in its Git repository, available at
**<http://github.com/sinatra/sinatra/tree/master>**.
The _edge_ version of Sinatra lives in its Git repository, available at
**<https://github.com/sinatra/sinatra/>**.

You can use the _edge_ version to try new functionality or to contribute to the
framework. You need to have [Git version control
software](http://www.git-scm.com) and [bundler](http://gembundler.com/).
software](https://www.git-scm.com/) and [Bundler](https://bundler.io/).

```
$ gem install bundler
```

To use Sinatra _edge_ with bundler, you'll have to create a `Gemfile` listing
To use Sinatra _edge_ with Bundler, you'll have to create a `Gemfile` listing
Sinatra's and any other dependencies you're going to need.

```ruby
source :rubygems
gem 'sinatra', :git => 'git://github.com/sinatra/sinatra.git'
```

Here we use the gemcutter source to specify where to get Sinatra's
dependencies; alternatively you can use the git version, but that is up to you.
So now we can install our bundle:
Now we can install our dependencies:

```
$ bundle install
Expand All @@ -85,8 +82,6 @@ Hello World Application
Sinatra is installed, how about making your first application?

```ruby
require 'rubygems'

# If you're using bundler, you will need to add this
require 'bundler/setup'

Expand All @@ -100,7 +95,7 @@ end
Run this application by `$ ruby hello_world.rb` and load
`http://localhost:4567` in your browser.

As you can see, Sinatra doesn't force you to setup much infrastructure: a
As you can see, Sinatra doesn't force you to set up much infrastructure: a
request to a URL evaluates some Ruby code and returns some text in response.
Whatever the block returns is sent back to the browser.

Expand All @@ -110,16 +105,17 @@ Real World Applications in Sinatra

### Github Services

Git hosting provider Github uses Sinatra for post-receive hooks, calling user
specified services/URLs, whenever someone pushes to their repository:
Git hosting provider Github used Sinatra for Git post-receive hooks, calling user-specified
services/URLs, whenever someone pushed to their repository:

* <http://github.com/blog/53-github-services-ipo>
* <http://github.com/guides/post-receive-hooks>
* <http://github.com/pjhyett/github-services>
* <https://github.blog/2008-04-29-github-services-ipo/> explains how it was introduced
* <https://github.com/github/github-services> is a deprecated repository
* <https://developer.github.com/changes/2018-04-25-github-services-deprecation/> is the post deprecating github-services
* <https://docs.github.com/en/rest/webhooks> is the documentation for the current non-Sinatra solution

Check out a full list of Sinatra apps [in the wild][in-the-wild].

[in-the-wild]: http://www.sinatrarb.com/wild.html
[in-the-wild]: https://sinatrarb.com/wild.html

About this book
---------------
Expand All @@ -128,13 +124,12 @@ and a working Ruby interpreter.

For more information about the Ruby language visit the following links:

* [ruby-lang](http://www.ruby-lang.org)
* [ruby-lang / documentation](http://www.ruby-lang.org/en/documentation/)
* [ruby-lang](https://www.ruby-lang.org)
* [ruby-lang / documentation](https://www.ruby-lang.org/en/documentation/)

Need Help?
Need Help?
----------

The Sinatra club is small, but super-friendly. Join us on IRC at
irc.freenode.org in #sinatra if you have any questions. It's a bit
slow at times, so give us a bit to get back to your questions.

2 changes: 1 addition & 1 deletion book/Middleware.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ of of these components automatically based on configuration so you typically
don’t have to use them explicitly.

[rack]: http://rack.rubyforge.org/
[rack_builder]: http://rack.rubyforge.org/doc/classes/Rack/Builder.html
[rack_builder]: https://rubydoc.info/github/rack/rack/Rack/Builder

2 changes: 1 addition & 1 deletion book/Models.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ get '/' do
end
```

Finally, the view at `./view/index.html`:
Finally, the view at `./view/index.erb`:

```ruby
<% @posts.each do |post| %>
Expand Down
2 changes: 1 addition & 1 deletion book/Organizing_your_application.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Server < Sinatra::Base
end

# Load all route files
Dir[File.dirname(__FILE___) + "/app/routes/**"].each do |route|
Dir[File.dirname(__FILE__) + "/app/routes/**"].each do |route|
require route
end
```
Expand Down
Loading