diff --git a/Gemfile b/Gemfile index 02254df..78495ee 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock index 2e7f742..8fbb811 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,5 +1,5 @@ GEM - remote: http://rubygems.org/ + remote: https://rubygems.org/ specs: pdfkit (0.5.2) rack (1.4.1) @@ -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 @@ -21,3 +22,10 @@ DEPENDENCIES rake redcarpet (~> 2.0) sinatra + wkhtmltopdf-binary + +RUBY VERSION + ruby 2.7.2p137 + +BUNDLED WITH + 2.2.9 diff --git a/README.md b/README.md index e98ff03..bcdf126 100755 --- a/README.md +++ b/README.md @@ -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. diff --git a/app.rb b/app.rb index 58f7dc5..a12c275 100644 --- a/app.rb +++ b/app.rb @@ -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 @@ -22,14 +22,19 @@ Sinatra Book - +
- Download the Sinatra Book + Download the Sinatra Book
+ <%= yield %> diff --git a/assets/images/book-logo.png b/assets/images/book-logo.png new file mode 100644 index 0000000..ac38ee2 Binary files /dev/null and b/assets/images/book-logo.png differ diff --git a/assets/images/favicon.ico b/assets/images/favicon.ico new file mode 100644 index 0000000..ae73c25 Binary files /dev/null and b/assets/images/favicon.ico differ diff --git a/book.rb b/book.rb index ff20385..e625df8 100644 --- a/book.rb +++ b/book.rb @@ -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 @@ -30,7 +30,7 @@ def header <<-header header diff --git a/book/Deployment.markdown b/book/Deployment.markdown index 1ac4389..387a9cc 100644 --- a/book/Deployment.markdown +++ b/book/Deployment.markdown @@ -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 # 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 # 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 diff --git a/book/Getting_to_know_Sinatra.markdown b/book/Getting_to_know_Sinatra.markdown index 5df5ae5..5772eb6 100644 --- a/book/Getting_to_know_Sinatra.markdown +++ b/book/Getting_to_know_Sinatra.markdown @@ -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 @@ -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 @@ -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 @@ -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 ``` diff --git a/book/Introduction.markdown b/book/Introduction.markdown index 46c3b6a..4cb4c38 100644 --- a/book/Introduction.markdown +++ b/book/Introduction.markdown @@ -38,7 +38,7 @@ $ gem install sinatra ### Dependencies -Sinatra depends on the _Rack_ gem (). +Sinatra depends on the _Rack_ gem (). Sinatra supports many different template engines (it uses the Tilt library internally to support practically every template engine in Ruby) @@ -52,28 +52,25 @@ $ gem install haml ### Living on the Edge -The _edge_ version of Sinatra lives in its Git repository, available at -****. +The _edge_ version of Sinatra lives in its Git repository, available at +****. 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 @@ -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' @@ -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. @@ -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: -* -* -* +* explains how it was introduced +* is a deprecated repository +* is the post deprecating github-services +* 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 --------------- @@ -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. - diff --git a/book/Middleware.markdown b/book/Middleware.markdown index efb4405..da71159 100755 --- a/book/Middleware.markdown +++ b/book/Middleware.markdown @@ -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 diff --git a/book/Models.markdown b/book/Models.markdown index dc81c77..d45e637 100644 --- a/book/Models.markdown +++ b/book/Models.markdown @@ -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| %> diff --git a/book/Organizing_your_application.markdown b/book/Organizing_your_application.markdown index 02badd3..a768085 100644 --- a/book/Organizing_your_application.markdown +++ b/book/Organizing_your_application.markdown @@ -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 ``` diff --git a/book/Views.markdown b/book/Views.markdown index 8b1734d..a567582 100644 --- a/book/Views.markdown +++ b/book/Views.markdown @@ -34,77 +34,3 @@ end ``` This will render the RSS inline, directly from the handler. - -CoffeeScript ------------- -To render CoffeeScript templates you first need the `coffee-script` gem and -`therubyracer`, or access to the `coffee` binary. - -Here's an example of using CoffeeScript with Sinatra's template rendering -engine Tilt: - -```ruby -## You'll need to require coffee-script in your app -require 'coffee-script' - -get '/application.js' do - coffee :application -end -``` - -Renders `./views/application.coffee`. - -This works great if you have access to [nodejs][nodejs] or `therubyracer` gem -on your platform of choice and hosting environment. If that's not the case, but -you'd still like to use CoffeeScript, you can precompile your scripts using the -`coffee` binary: - -``` -$ coffee -c -o public/javascripts/ src/ -``` - -Or you can use this example [rake][rake] task to compile them for you with the -`coffee-script` gem, which can use either `therubyracer` gem or the `coffee` -binary: - -```ruby -require 'coffee-script' - -namespace :js do - desc "compile coffee-scripts from ./src to ./public/javascripts" - task :compile do - source = "#{File.dirname(__FILE__)}/src/" - javascripts = "#{File.dirname(__FILE__)}/public/javascripts/" - - Dir.foreach(source) do |cf| - unless cf == '.' || cf == '..' - js = CoffeeScript.compile File.read("#{source}#{cf}") - open "#{javascripts}#{cf.gsub('.coffee', '.js')}", 'w' do |f| - f.puts js - end - end - end - end -end -``` - -Now, with this rake task you can compile your coffee-scripts to -`public/javascripts` by using the `rake js:compile` command. - -**Resources** - -If you get stuck or want to look into other ways of implementing CoffeeScript -in your application, these are a great place to start: - -* [coffee-script][coffee-script-url] -* [therubyracer][therubyracer] -* [ruby-coffee-script][ruby-coffee-script] - -[therubyracer]: http://github.com/cowboyd/therubyracer -[coffee-script-repo]: http://github.com/jashkenas/coffee-script -[coffee-script-url]: http://coffeescript.org/ -[builder]: http://builder.rubyforge.org/ -[rake]: http://rake.rubyforge.org/ -[nodejs]: http://nodejs.org/ -[ruby-coffee-script]: http://github.com/josh/ruby-coffee-script - diff --git a/dockerfile b/dockerfile new file mode 100644 index 0000000..5cd411c --- /dev/null +++ b/dockerfile @@ -0,0 +1,11 @@ +FROM ruby:2.7.2 + +WORKDIR /app + +COPY . . + +RUN bundle install + +CMD bundle exec rackup + +EXPOSE 9292 diff --git a/vendor/wkhtmltopdf b/vendor/wkhtmltopdf deleted file mode 100755 index cc932ac..0000000 Binary files a/vendor/wkhtmltopdf and /dev/null differ