Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #103 from kgrz/1.4.x

This is not a final PR
  • Loading branch information...
commit 71d7122008ea7c54ccfeebd9ce148b4d87ac5de4 2 parents e4c31bd + 7d7770b
@rkh rkh authored
View
23 Rakefile
@@ -3,15 +3,9 @@ require 'rake/clean'
require 'rdoc/encoding'
require 'rdoc/markup/to_html'
require 'redcarpet'
-require 'rouge'
-require 'rouge/plugins/redcarpet'
require 'uri'
require 'nokogiri'
-
-
-class HTML < Redcarpet::Render::HTML
- include Rouge::Plugins::Redcarpet # yep, that's it.
-end
+require 'kramdown'
def cleanup(html)
@@ -72,7 +66,7 @@ end
task :default => ['_sinatra', '_contrib', :build]
desc "Build outdated static files and API docs"
-task :build => ['build:static']
+task :build => [:pull, 'build:static']
desc "Build outdated static files"
task 'build:static' => readme("_includes/%s.html") + contrib("_includes/%s.html")
@@ -109,16 +103,17 @@ task 'pull:contrib' => "_contrib" do
sh "cd _contrib && git pull &>/dev/null"
end
-readme("_sinatra/%s") { |fn| file fn => '_sinatra' }
+readme("_sinatra/%s.md") { |fn| file fn => '_sinatra' }
file 'AUTHORS' => '_sinatra'
-
readme do |fn|
- file "_includes/#{fn}.html" => ["_sinatra/#{fn}", "Rakefile"] do |f|
- rndr = HTML.new(:safe_links_only => true)
- markdown = Redcarpet::Markdown.new(rndr, :lax_spacing => true, :fenced_code_blocks => true)
+ file "_includes/#{fn}.html" => ["_sinatra/#{fn}.md", "Rakefile"] do |f|
markdown_string = File.read("_sinatra/#{fn}.md").encode('UTF-16le', :invalid => :replace, :replace => "").encode("UTF-8")
- html = cleanup(markdown.render(markdown_string))
+ markdown_string.gsub!(/```(\s?(\w+\n))?/) do |match|
+ match =~ /```\s?\n/ ? "~~~~~\n" : match.sub(/```\s?/, "~~~~")
+ end
+ markdown = Kramdown::Document.new(markdown_string, :fenced_code_blocks => true, :coderay_line_numbers => nil, :auto_ids => false)
+ html = cleanup(markdown.to_html)
File.open(f.name, 'w') { |io| io.write with_toc(html) }
end
end
View
508 _includes/CHANGES.txt
@@ -1,508 +0,0 @@
-= 1.0 / 2010-01-28 (prerelease)
-
- * It's now possible to register blocks to run after each request using
- after filters. After filters run at the end of each request, after
- routes and error handlers. (Jimmy Schementi)
-
- * Sinatra now uses Tilt &lt;http://github.com/rtomayko/tilt> for rendering
- templates. This adds support for template caching, consistent
- template backtraces, and support for new template engines, like
- mustache and liquid. (Ryan Tomayko)
-
- * ERB, Erubis, and Haml templates are now compiled the first time
- they're rendered instead of being string eval'd on each invocation.
- Benchmarks show a 5x-10x improvement in render time. This also
- reduces the number of objects created, decreasing pressure on Ruby's
- GC. (Ryan Tomayko)
-
- * New 'settings' method gives access to options in both class and request
- scopes. This replaces the 'options' method. (Chris Wanstrath)
-
- * New boolean 'reload_templates' setting controls whether template files
- are reread from disk and recompiled on each request. Template read/compile
- is cached by default in all environments except development. (Ryan Tomayko)
-
- * New 'erubis' helper method for rendering ERB template with Erubis. The
- erubis gem is required. (Dylan Egan)
-
- * New 'cache_control' helper method provides a convenient way of
- setting the Cache-Control response header. Takes a variable number
- of boolean directives followed by a hash of value directives, like
- this: cache_control :public, :must_revalidate, :max_age => 60
- (Ryan Tomayko)
-
- * New 'expires' helper method is like cache_control but takes an
- integer number of seconds or Time object:
- expires 300, :public, :must_revalidate
- (Ryan Tomayko)
-
- * New request.secure? method for checking for an SSL connection.
- (Adam Wiggins)
-
- * Sinatra apps can now be run with a `-o &lt;addr>` argument to specify
- the address to bind to. (Ryan Tomayko)
-
- * Rack::Session::Cookie is now added to the middleware pipeline when
- running in test environments if the :sessions option is set.
- (Simon Rozet)
-
- * Route handlers, before filters, templates, error mappings, and
- middleware are now resolved dynamically up the inheritance hierarchy
- when needed instead of duplicating the superclass's version when
- a new Sinatra::Base subclass is created. This should fix a variety
- of issues with extensions that need to add any of these things
- to the base class. (Ryan Tomayko)
-
- * Exception error handlers always override the raise_errors option now.
- Previously, all exceptions would be raised outside of the application
- when the raise_errors option was enabled, even if an error handler was
- defined for that exception. The raise_errors option now controls
- whether unhandled exceptions are raised (enabled) or if a generic 500
- error is returned (disabled). (Ryan Tomayko)
-
- * The X-Cascade response header is set to 'pass' when no matching route
- is found or all routes pass. (Josh Peek)
-
- * Filters do not run when serving static files anymore. (Ryan Tomayko)
-
-The following Sinatra features have been obsoleted (removed entirely) in
-the 1.0 release:
-
- * The `sinatra/test` library is obsolete. This includes the `Sinatra::Test`
- module, the `Sinatra::TestHarness` class, and the `get_it`, `post_it`,
- `put_it`, `delete_it`, and `head_it` helper methods. The
- [`Rack::Test` library](http://gitrdoc.com/brynary/rack-test) should
- be used instead.
-
- * Test framework specific libraries (`sinatra/test/spec`,
- `sinatra/test/bacon`,`sinatra/test/rspec`, etc.) are obsolete. See
- http://www.sinatrarb.com/testing.html for instructions on setting up a
- testing environment under each of these frameworks.
-
- * `Sinatra::Default` is obsolete; use `Sinatra::Base` instead.
- `Sinatra::Base` acts more like `Sinatra::Default` in development mode.
- For example, static file serving and sexy development error pages are
- enabled by default.
-
- * Auto-requiring template libraries in the `erb`, `builder`, `haml`,
- and `sass` methods is obsolete due to thread-safety issues. You must
- require the template libraries explicitly in your app.
-
- * The `:views_directory` option to rendering methods is obsolete; use
- `:views` instead.
-
- * The `:haml` and `:sass` options to rendering methods are obsolete.
- Template engine options should be passed in the second Hash argument
- instead.
-
- * The `use_in_file_templates` method is obsolete. Use
- `enable :inline_templates` or `set :inline_templates, 'path/to/file'`
-
- * The 'media_type' helper method is obsolete. Use 'mime_type' instead.
-
- * The 'mime' main and class method is obsolete. Use 'mime_type' instead.
-
- * The request-level `send_data` method is no longer supported.
-
- * The `Sinatra::Event` and `Sinatra::EventContext` classes are no longer
- supported. This may effect extensions written for versions prior to 0.9.2.
- See [Writing Sinatra Extensions](http://www.sinatrarb.com/extensions.html)
- for the officially supported extensions API.
-
- * The `set_option` and `set_options` methods are obsolete; use `set`
- instead.
-
- * The `:env` setting (`settings.env`) is obsolete; use `:environment`
- instead.
-
- * The request level `stop` method is obsolete; use `halt` instead.
-
- * The request level `entity_tag` method is obsolete; use `etag`
- instead.
-
- * The request level `headers` method (HTTP response headers) is obsolete;
- use `response['Header-Name']` instead.
-
- * `Sinatra.application` is obsolete; use `Sinatra::Application` instead.
-
- * Using `Sinatra.application = nil` to reset an application is obsolete.
- This should no longer be necessary.
-
- * Using `Sinatra.default_options` to set base configuration items is
- obsolete; use `Sinatra::Base.set(key, value)` instead.
-
- * The `Sinatra::ServerError` exception is obsolete. All exceptions raised
- within a request are now treated as internal server errors and result in
- a 500 response status.
-
- * The `:methodoverride' option to enable/disable the POST _method hack is
- obsolete; use `:method_override` instead.
-
-= 0.9.2 / 2009-05-18
-
- * This version is compatible with Rack 1.0. [Rein Henrichs]
-
- * The development-mode unhandled exception / error page has been
- greatly enhanced, functionally and aesthetically. The error
- page is used when the :show_exceptions option is enabled and an
- exception propagates outside of a route handler or before filter.
- [Simon Rozet / Matte Noble / Ryan Tomayko]
-
- * Backtraces that move through templates now include filenames and
- line numbers where possible. [#51 / S. Brent Faulkner]
-
- * All templates now have an app-level option for setting default
- template options (:haml, :sass, :erb, :builder). The app-level
- option value must be a Hash if set and is merged with the
- template options specified to the render method (Base#haml,
- Base#erb, Base#builder). [S. Brent Faulkner, Ryan Tomayko]
-
- * The method signature for all template rendering methods has
- been unified: "def engine(template, options={}, locals={})".
- The options Hash now takes the generic :views, :layout, and
- :locals options but also any template-specific options. The
- generic options are removed before calling the template specific
- render method. Locals may be specified using either the
- :locals key in the options hash or a second Hash option to the
- rendering method. [#191 / Ryan Tomayko]
-
- * The receiver is now passed to "configure" blocks. This
- allows for the following idiom in top-level apps:
- configure { |app| set :foo, app.root + '/foo' }
- [TJ Holowaychuck / Ryan Tomayko]
-
- * The "sinatra/test" lib is deprecated and will be removed in
- Sinatra 1.0. This includes the Sinatra::Test module and
- Sinatra::TestHarness class in addition to all the framework
- test helpers that were deprecated in 0.9.1. The Rack::Test
- lib should be used instead: http://gitrdoc.com/brynary/rack-test
- [#176 / Simon Rozet]
-
- * Development mode source file reloading has been removed. The
- "shotgun" (http://rtomayko.github.com/shotgun/) program can be
- used to achieve the same basic functionality in most situations.
- Passenger users should use the "tmp/always_restart.txt"
- file (http://tinyurl.com/c67o4h). [#166 / Ryan Tomayko]
-
- * Auto-requiring template libs in the erb, builder, haml, and
- sass methods is deprecated due to thread-safety issues. You must
- require the template libs explicitly in your app file. [Simon Rozet]
-
- * A new Sinatra::Base#route_missing method was added. route_missing
- is sent when no route matches the request or all route handlers
- pass. The default implementation forwards the request to the
- downstream app when running as middleware (i.e., "@app" is
- non-nil), or raises a NotFound exception when no downstream app
- is defined. Subclasses can override this method to perform custom
- route miss logic. [Jon Crosby]
-
- * A new Sinatra::Base#route_eval method was added. The method
- yields to the block and throws :halt with the result. Subclasses
- can override this method to tap into the route execution logic.
- [TJ Holowaychuck]
-
- * Fix the "-x" (enable request mutex / locking) command line
- argument. Passing -x now properly sets the :lock option.
- [S. Brent Faulkner, Ryan Tomayko]
-
- * Fix writer ("foo=") and predicate ("foo?") methods in extension
- modules not being added to the registering class.
- [#172 / Pat Nakajima]
-
- * Fix in-file templates when running alongside activesupport and
- fatal errors when requiring activesupport before sinatra
- [#178 / Brian Candler]
-
- * Fix various issues running on Google AppEngine.
- [Samuel Goebert, Simon Rozet]
-
- * Fix in-file templates __END__ detection when __END__ exists with
- other stuff on a line [Yoji Shidara]
-
-= 0.9.1.1 / 2009-03-09
-
- * Fix directory traversal vulnerability in default static files
- route. See [#177] for more info.
-
-= 0.9.1 / 2009-03-01
-
- * Sinatra now runs under Ruby 1.9.1 [#61]
-
- * Route patterns (splats, :named, or Regexp captures) are now
- passed as arguments to the block. [#140]
-
- * The "helpers" method now takes a variable number of modules
- along with the normal block syntax. [#133]
-
- * New request-level #forward method for middleware components: passes
- the env to the downstream app and merges the response status, headers,
- and body into the current context. [#126]
-
- * Requests are now automatically forwarded to the downstream app when
- running as middleware and no matching route is found or all routes
- pass.
-
- * New simple API for extensions/plugins to add DSL-level and
- request-level methods. Use Sinatra.register(mixin) to extend
- the DSL with all public methods defined in the mixin module;
- use Sinatra.helpers(mixin) to make all public methods defined
- in the mixin module available at the request level. [#138]
- See http://www.sinatrarb.com/extensions.html for details.
-
- * Named parameters in routes now capture the "." character. This makes
- routes like "/:path/:filename" match against requests like
- "/foo/bar.txt"; in this case, "params[:filename]" is "bar.txt".
- Previously, the route would not match at all.
-
- * Added request-level "redirect back" to redirect to the referring
- URL.
-
- * Added a new "clean_trace" option that causes backtraces dumped
- to rack.errors and displayed on the development error page to
- omit framework and core library backtrace lines. The option is
- enabled by default. [#77]
-
- * The ERB output buffer is now available to helpers via the @_out_buf
- instance variable.
-
- * It's now much easier to test sessions in unit tests by passing a
- ":session" option to any of the mock request methods. e.g.,
- get '/', {}, :session => { 'foo' => 'bar' }
-
- * The testing framework specific files ('sinatra/test/spec',
- 'sinatra/test/bacon', 'sinatra/test/rspec', etc.) have been deprecated.
- See http://sinatrarb.com/testing.html for instructions on setting up
- a testing environment with these frameworks.
-
- * The request-level #send_data method from Sinatra 0.3.3 has been added
- for compatibility but is deprecated.
-
- * Fix :provides causing crash on any request when request has no
- Accept header [#139]
-
- * Fix that ERB templates were evaluated twice per "erb" call.
-
- * Fix app-level middleware not being run when the Sinatra application is
- run as middleware.
-
- * Fixed some issues with running under Rack's CGI handler caused by
- writing informational stuff to stdout.
-
- * Fixed that reloading was sometimes enabled when starting from a
- rackup file [#110]
-
- * Fixed that "." in route patterns erroneously matched any character
- instead of a literal ".". [#124]
-
-= 0.9.0.4 / 2009-01-25
-
- * Using halt with more than 1 args causes ArgumentError [#131]
- * using halt in a before filter doesn't modify response [#127]
- * Add deprecated Sinatra::EventContext to unbreak plugins [#130]
- * Give access to GET/POST params in filters [#129]
- * Preserve non-nested params in nested params hash [#117]
- * Fix backtrace dump with Rack::Lint [#116]
-
-= 0.9.0.3 / 2009-01-21
-
- * Fall back on mongrel then webrick when thin not found. [#75]
- * Use :environment instead of :env in test helpers to
- fix deprecation warnings coming from framework.
- * Make sinatra/test/rspec work again [#113]
- * Fix app_file detection on windows [#118]
- * Fix static files with Rack::Lint in pipeline [#121]
-
-= 0.9.0.2 / 2009-01-18
-
- * Halting a before block should stop processing of routes [#85]
- * Fix redirect/halt in before filters [#85]
-
-= 0.9.0 / 2009-01-18
-
- * Works with and requires Rack >= 0.9.1
-
- * Multiple Sinatra applications can now co-exist peacefully within a
- single process. The new "Sinatra::Base" class can be subclassed to
- establish a blank-slate Rack application or middleware component.
- Documentation on using these features is forth-coming; the following
- provides the basic gist: http://gist.github.com/38605
-
- * Parameters with subscripts are now parsed into a nested/recursive
- Hash structure. e.g., "post[title]=Hello&post[body]=World" yields
- params: {'post' => {'title' => 'Hello', 'body' => 'World'}}.
-
- * Regular expressions may now be used in route pattens; captures are
- available at "params[:captures]".
-
- * New ":provides" route condition takes an array of mime types and
- matches only when an Accept request header is present with a
- corresponding type. [cypher]
-
- * New request-level "pass" method; immediately exits the current block
- and passes control to the next matching route.
-
- * The request-level "body" method now takes a block; evaluation is
- deferred until an attempt is made to read the body. The block must
- return a String or Array.
-
- * New "route conditions" system for attaching rules for when a route
- matches. The :agent and :host route options now use this system.
-
- * New "dump_errors" option controls whether the backtrace is dumped to
- rack.errors when an exception is raised from a route. The option is
- enabled by default for top-level apps.
-
- * Better default "app_file", "root", "public", and "views" location
- detection; changes to "root" and "app_file" automatically cascade to
- other options that depend on them.
-
- * Error mappings are now split into two distinct layers: exception
- mappings and custom error pages. Exception mappings are registered
- with "error(Exception)" and are run only when the app raises an
- exception. Custom error pages are registered with "error(status_code)",
- where "status_code" is an integer, and are run any time the response
- has the status code specified. It's also possible to register an error
- page for a range of status codes: "error(500..599)".
-
- * In-file templates are now automatically imported from the file that
- requires 'sinatra'. The use_in_file_templates! method is still available
- for loading templates from other files.
-
- * Sinatra's testing support is no longer dependent on Test::Unit. Requiring
- 'sinatra/test' adds the Sinatra::Test module and Sinatra::TestHarness
- class, which can be used with any test framework. The 'sinatra/test/unit',
- 'sinatra/test/spec', 'sinatra/test/rspec', or 'sinatra/test/bacon' files
- can be required to setup a framework-specific testing environment. See the
- README for more information.
-
- * Added support for Bacon (test framework). The 'sinatra/test/bacon' file
- can be required to setup Sinatra test helpers on Bacon::Context.
-
- * Deprecated "set_option" and "set_options"; use "set" instead.
-
- * Deprecated the "env" option ("options.env"); use "environment" instead.
-
- * Deprecated the request level "stop" method; use "halt" instead.
-
- * Deprecated the request level "entity_tag" method; use "etag" instead.
- Both "entity_tag" and "etag" were previously supported.
-
- * Deprecated the request level "headers" method (HTTP response headers);
- use "response['Header-Name']" instead.
-
- * Deprecated "Sinatra.application"; use "Sinatra::Application" instead.
-
- * Deprecated setting Sinatra.application = nil to reset an application.
- This should no longer be necessary.
-
- * Deprecated "Sinatra.default_options"; use
- "Sinatra::Default.set(key, value)" instead.
-
- * Deprecated the "ServerError" exception. All Exceptions are now
- treated as internal server errors and result in a 500 response
- status.
-
- * Deprecated the "get_it", "post_it", "put_it", "delete_it", and "head_it"
- test helper methods. Use "get", "post", "put", "delete", and "head",
- respectively, instead.
-
- * Removed Event and EventContext classes. Applications are defined in a
- subclass of Sinatra::Base; each request is processed within an
- instance.
-
-= 0.3.3 / 2009-01-06
-
- * Pin to Rack 0.4.0 (this is the last release on Rack 0.4)
-
- * Log unhandled exception backtraces to rack.errors.
-
- * Use RACK_ENV environment variable to establish Sinatra
- environment when given. Thin sets this when started with
- the -e argument.
-
- * BUG: raising Sinatra::NotFound resulted in a 500 response
- code instead of 404.
-
- * BUG: use_in_file_templates! fails with CR/LF (#45)
-
- * BUG: Sinatra detects the app file and root path when run under
- thin/passenger.
-
-= 0.3.2
-
- * BUG: Static and send_file read entire file into String before
- sending. Updated to stream with 8K chunks instead.
-
- * Rake tasks and assets for building basic documentation website.
- See http://sinatra.rubyforge.org
-
- * Various minor doc fixes.
-
-= 0.3.1
-
- * Unbreak optional path parameters [jeremyevans]
-
-= 0.3.0
-
- * Add sinatra.gemspec w/ support for github gem builds. Forks can now
- enable the build gem option in github to get free username-sinatra.gem
- builds: gem install username-sinatra.gem --source=http://gems.github.com/
-
- * Require rack-0.4 gem; removes frozen rack dir.
-
- * Basic RSpec support; require 'sinatra/test/rspec' instead of
- 'sinatra/test/spec' to use. [avdi]
-
- * before filters can modify request environment vars used for
- routing (e.g., PATH_INFO, REQUEST_METHOD, etc.) for URL rewriting
- type functionality.
-
- * In-file templates now uses @@ instead of ## as template separator.
-
- * Top-level environment test predicates: development?, test?, production?
-
- * Top-level "set", "enable", and "disable" methods for tweaking
- app options. [rtomayko]
-
- * Top-level "use" method for building Rack middleware pipelines
- leading to app. See README for usage. [rtomayko]
-
- * New "reload" option - set false to disable reloading in development.
-
- * New "host" option - host/ip to bind to [cschneid]
-
- * New "app_file" option - override the file to reload in development
- mode [cschneid]
-
- * Development error/not_found page cleanup [sr, adamwiggins]
-
- * Remove a bunch of core extensions (String#to_param, String#from_param,
- Hash#from_params, Hash#to_params, Hash#symbolize_keys, Hash#pass)
-
- * Various grammar and formatting fixes to README; additions on
- community and contributing [cypher]
-
- * Build RDoc using Hanna template: http://sinatrarb.rubyforge.org/api
-
- * Specs, documentation and fixes for splat'n routes [vic]
-
- * Fix whitespace errors across all source files. [rtomayko]
-
- * Fix streaming issues with Mongrel (body not closed). [bmizerany]
-
- * Fix various issues with environment not being set properly (configure
- blocks not running, error pages not registering, etc.) [cypher]
-
- * Fix to allow locals to be passed to ERB templates [cschneid]
-
- * Fix locking issues causing random errors during reload in development.
-
- * Fix for escaped paths not resolving static files [Matthew Walker]
-
-= 0.2.1
-
- * File upload fix and minor tweaks.
-
-= 0.2.0
-
- * Initial gem release of 0.2 codebase.
View
2,652 _includes/README.de.html
1,726 additions, 926 deletions not shown
View
2,517 _includes/README.es.html
1,662 additions, 855 deletions not shown
View
2,862 _includes/README.fr.html
1,823 additions, 1,039 deletions not shown
View
2,704 _includes/README.html
1,771 additions, 933 deletions not shown
View
776 _includes/README.hu.html
@@ -34,23 +34,34 @@
</div>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body>
-
<p><em>Fontos megjegyzés: Ez a dokumentum csak egy fordítása az angol nyelvű
változat, és lehet, hogy nem naprakész.</em></p>
<p>A Sinatra egy <a href="http://en.wikipedia.org/wiki/Domain-specific_language">DSL</a>
webalkalmazások Ruby nyelven történő fejlesztéséhez, minimális
energiabefektetéssel:</p>
-<pre class="highlight ruby"> <span class="c1"># myapp.rb</span>
- <span class="nb">require</span> <span class="s1">'sinatra'</span>
- <span class="n">get</span> <span class="s1">'/'</span> <span class="k">do</span>
- <span class="s1">'Helló Világ!'</span>
- <span class="k">end</span>
-</pre>
+
+<div>
+<div class="CodeRay">
+ <div class="code"><pre> <span style="color:#777"># myapp.rb</span>
+ require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">sinatra</span><span style="color:#710">'</span></span>
+ get <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
+ <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Helló Világ!</span><span style="color:#710">'</span></span>
+ <span style="color:#080;font-weight:bold">end</span>
+</pre></div>
+</div>
+</div>
+
<p>Telepítsd a gem-et és indítsd el az alkalmazást a következőképpen:</p>
-<pre class="highlight ruby"> <span class="n">sudo</span> <span class="n">gem</span> <span class="n">install</span> <span class="n">sinatra</span>
- <span class="n">ruby</span> <span class="n">myapp</span><span class="nf">.rb</span>
-</pre>
+
+<div>
+<div class="CodeRay">
+ <div class="code"><pre> sudo gem install sinatra
+ ruby myapp.rb
+</pre></div>
+</div>
+</div>
+
<p>Az alkalmazás elérhető lesz itt: <code>http://localhost:4567</code></p>
<a name='%C3%9Atvonalak%20(routes)'></a>
@@ -58,72 +69,114 @@
<p>A Sinatrában az útvonalat egy HTTP metódus és egy URL-re illeszkedő minta
párosa alkotja. Minden egyes útvonalhoz tartozik egy blokk:</p>
-<pre class="highlight ruby"> <span class="n">get</span> <span class="s1">'/'</span> <span class="k">do</span>
- <span class="nf">..</span> <span class="n">megjelen</span><span class="err">í</span><span class="n">t</span><span class="err">ü</span><span class="n">nk</span> <span class="n">valamit</span> <span class="nf">..</span>
- <span class="k">end</span>
-
- <span class="n">post</span> <span class="s1">'/'</span> <span class="k">do</span>
- <span class="nf">..</span> <span class="n">l</span><span class="err">é</span><span class="n">trehozunk</span> <span class="n">valamit</span> <span class="nf">..</span>
- <span class="k">end</span>
-
- <span class="n">put</span> <span class="s1">'/'</span> <span class="k">do</span>
- <span class="nf">..</span> <span class="n">friss</span><span class="err">í</span><span class="n">t</span><span class="err">ü</span><span class="n">nk</span> <span class="n">valamit</span> <span class="nf">..</span>
- <span class="k">end</span>
-
- <span class="n">delete</span> <span class="s1">'/'</span> <span class="k">do</span>
- <span class="nf">..</span> <span class="n">t</span><span class="err">ö</span><span class="n">rl</span><span class="err">ü</span><span class="n">nk</span> <span class="n">valamit</span> <span class="nf">..</span>
- <span class="k">end</span>
-</pre>
+
+<div>
+<div class="CodeRay">
+ <div class="code"><pre> get <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
+ .. megjelenítünk valamit ..
+ <span style="color:#080;font-weight:bold">end</span>
+
+ post <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
+ .. létrehozunk valamit ..
+ <span style="color:#080;font-weight:bold">end</span>
+
+ put <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
+ .. frissítünk valamit ..
+ <span style="color:#080;font-weight:bold">end</span>
+
+ delete <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
+ .. törlünk valamit ..
+ <span style="color:#080;font-weight:bold">end</span>
+</pre></div>
+</div>
+</div>
+
<p>Az útvonalak illeszkedését a rendszer a definiálásuk sorrendjében
ellenőrzi. Sorrendben mindig az első illeszkedő útvonalhoz tartozó metódus kerül
meghívásra.</p>
<p>Az útvonalminták tartalmazhatnak paramétereket is, melyeket a <code>params</code>
hash-ből érhetünk el:</p>
-<pre class="highlight ruby"> <span class="n">get</span> <span class="s1">'/hello/:name'</span> <span class="k">do</span>
- <span class="c1"># illeszkedik a "GET /hello/foo" és a "GET /hello/bar" útvonalakra</span>
- <span class="c1"># ekkor params[:name] értéke 'foo' vagy 'bar' lesz</span>
- <span class="s2">"Helló </span><span class="si">#{</span><span class="n">params</span><span class="o">[</span><span class="ss">:name</span><span class="o">]</span><span class="si">}</span><span class="s2">!"</span>
- <span class="k">end</span>
-</pre>
+
+<div>
+<div class="CodeRay">
+ <div class="code"><pre> get <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/hello/:name</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
+ <span style="color:#777"># illeszkedik a "GET /hello/foo" és a "GET /hello/bar" útvonalakra</span>
+ <span style="color:#777"># ekkor params[:name] értéke 'foo' vagy 'bar' lesz</span>
+ <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Helló </span><span style="background-color:hsla(0,0%,0%,0.07);color:black"><span style="font-weight:bold;color:#666">#{</span>params[<span style="color:#A60">:name</span>]<span style="font-weight:bold;color:#666">}</span></span><span style="color:#D20">!</span><span style="color:#710">"</span></span>
+ <span style="color:#080;font-weight:bold">end</span>
+</pre></div>
+</div>
+</div>
+
<p>A kulcsszavas argumentumokat (named parameters) blokk paraméterek útján
is el tudod érni:</p>
-<pre class="highlight ruby"> <span class="n">get</span> <span class="s1">'/hello/:name'</span> <span class="k">do</span> <span class="o">|</span><span class="n">n</span><span class="o">|</span>
- <span class="s2">"Helló </span><span class="si">#{</span><span class="n">n</span><span class="si">}</span><span class="s2">!"</span>
- <span class="k">end</span>
-</pre>
+
+<div>
+<div class="CodeRay">
+ <div class="code"><pre> get <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/hello/:name</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span> |n|
+ <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Helló </span><span style="background-color:hsla(0,0%,0%,0.07);color:black"><span style="font-weight:bold;color:#666">#{</span>n<span style="font-weight:bold;color:#666">}</span></span><span style="color:#D20">!</span><span style="color:#710">"</span></span>
+ <span style="color:#080;font-weight:bold">end</span>
+</pre></div>
+</div>
+</div>
+
<p>Az útvonalmintákban szerepelhetnek joker paraméterek is, melyeket a
<code>params[:splat]</code> tömbön keresztül tudunk elérni.</p>
-<pre class="highlight ruby"> <span class="n">get</span> <span class="s1">'/say/*/to/*'</span> <span class="k">do</span>
- <span class="c1"># illeszkedik a /say/hello/to/world mintára</span>
- <span class="n">params</span><span class="o">[</span><span class="ss">:splat</span><span class="o">]</span> <span class="c1"># =&gt; ["hello", "world"]</span>
- <span class="k">end</span>
-
- <span class="n">get</span> <span class="s1">'/download/*.*'</span> <span class="k">do</span>
- <span class="c1"># illeszkedik a /download/path/to/file.xml mintára</span>
- <span class="n">params</span><span class="o">[</span><span class="ss">:splat</span><span class="o">]</span> <span class="c1"># =&gt; ["path/to/file", "xml"]</span>
- <span class="k">end</span>
-</pre>
+
+<div>
+<div class="CodeRay">
+ <div class="code"><pre> get <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/say/*/to/*</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
+ <span style="color:#777"># illeszkedik a /say/hello/to/world mintára</span>
+ params[<span style="color:#A60">:splat</span>] <span style="color:#777"># =&gt; ["hello", "world"]</span>
+ <span style="color:#080;font-weight:bold">end</span>
+
+ get <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/download/*.*</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
+ <span style="color:#777"># illeszkedik a /download/path/to/file.xml mintára</span>
+ params[<span style="color:#A60">:splat</span>] <span style="color:#777"># =&gt; ["path/to/file", "xml"]</span>
+ <span style="color:#080;font-weight:bold">end</span>
+</pre></div>
+</div>
+</div>
+
<p>Reguláris kifejezéseket is felvehetünk az útvonalba:</p>
-<pre class="highlight ruby"> <span class="n">get</span> <span class="sr">%r{/hello/([</span><span class="se">\w</span><span class="sr">]+)}</span> <span class="k">do</span>
- <span class="s2">"Helló, </span><span class="si">#{</span><span class="n">params</span><span class="o">[</span><span class="ss">:captures</span><span class="o">]</span><span class="nf">.first</span><span class="si">}</span><span class="s2">!"</span>
- <span class="k">end</span>
-</pre>
+
+<div>
+<div class="CodeRay">
+ <div class="code"><pre> get <span style="background-color:hsla(300,100%,50%,0.06)"><span style="color:#404">%r{</span><span style="color:#808">/hello/([</span><span style="color:#D20">\w</span><span style="color:#808">]+)</span><span style="color:#404">}</span></span> <span style="color:#080;font-weight:bold">do</span>
+ <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Helló, </span><span style="background-color:hsla(0,0%,0%,0.07);color:black"><span style="font-weight:bold;color:#666">#{</span>params[<span style="color:#A60">:captures</span>].first<span style="font-weight:bold;color:#666">}</span></span><span style="color:#D20">!</span><span style="color:#710">"</span></span>
+ <span style="color:#080;font-weight:bold">end</span>
+</pre></div>
+</div>
+</div>
+
<p>Vagy blokk paramétereket:</p>
-<pre class="highlight ruby"> <span class="n">get</span> <span class="sr">%r{/hello/([</span><span class="se">\w</span><span class="sr">]+)}</span> <span class="k">do</span> <span class="o">|</span><span class="n">c</span><span class="o">|</span>
- <span class="s2">"Helló, </span><span class="si">#{</span><span class="n">c</span><span class="si">}</span><span class="s2">!"</span>
- <span class="k">end</span>
-</pre>
+
+<div>
+<div class="CodeRay">
+ <div class="code"><pre> get <span style="background-color:hsla(300,100%,50%,0.06)"><span style="color:#404">%r{</span><span style="color:#808">/hello/([</span><span style="color:#D20">\w</span><span style="color:#808">]+)</span><span style="color:#404">}</span></span> <span style="color:#080;font-weight:bold">do</span> |c|
+ <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Helló, </span><span style="background-color:hsla(0,0%,0%,0.07);color:black"><span style="font-weight:bold;color:#666">#{</span>c<span style="font-weight:bold;color:#666">}</span></span><span style="color:#D20">!</span><span style="color:#710">"</span></span>
+ <span style="color:#080;font-weight:bold">end</span>
+</pre></div>
+</div>
+</div>
+
<p>Az útvonalak azonban számos egyéb illeszkedési feltétel szerint is
tervezhetők, így például az user agent karakterláncot alapul véve:</p>
-<pre class="highlight ruby"> <span class="n">get</span> <span class="s1">'/foo'</span><span class="p">,</span> <span class="ss">:agent</span> <span class="o">=&gt;</span> <span class="sr">/Songbird (\d\.\d)[\d\/]*?/</span> <span class="k">do</span>
- <span class="s2">"A Songbird </span><span class="si">#{</span><span class="n">params</span><span class="o">[</span><span class="ss">:agent</span><span class="o">][</span><span class="mi">0</span><span class="o">]</span><span class="si">}</span><span class="s2"> verzióját használod"</span>
- <span class="k">end</span>
-
- <span class="n">get</span> <span class="s1">'/foo'</span> <span class="k">do</span>
- <span class="c1"># illeszkedik az egyéb user agentekre</span>
- <span class="k">end</span>
-</pre>
+
+<div>
+<div class="CodeRay">
+ <div class="code"><pre> get <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/foo</span><span style="color:#710">'</span></span>, <span style="color:#A60">:agent</span> =&gt; <span style="background-color:hsla(300,100%,50%,0.06)"><span style="color:#404">/</span><span style="color:#808">Songbird (</span><span style="color:#D20">\d</span><span style="color:#D20">\.</span><span style="color:#D20">\d</span><span style="color:#808">)[</span><span style="color:#D20">\d</span><span style="color:#D20">\/</span><span style="color:#808">]*?</span><span style="color:#404">/</span></span> <span style="color:#080;font-weight:bold">do</span>
+ <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">A Songbird </span><span style="background-color:hsla(0,0%,0%,0.07);color:black"><span style="font-weight:bold;color:#666">#{</span>params[<span style="color:#A60">:agent</span>][<span style="color:#00D">0</span>]<span style="font-weight:bold;color:#666">}</span></span><span style="color:#D20"> verzióját használod</span><span style="color:#710">"</span></span>
+ <span style="color:#080;font-weight:bold">end</span>
+
+ get <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/foo</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
+ <span style="color:#777"># illeszkedik az egyéb user agentekre</span>
+ <span style="color:#080;font-weight:bold">end</span>
+</pre></div>
+</div>
+</div>
+
<a name='Statikus%20%C3%A1llom%C3%A1nyok'></a>
<h2>Statikus állományok</h2>
@@ -131,7 +184,7 @@
történik, de természetesen más könyvtárat is megadhatsz erre a célra,
mégpedig a :public_folder kapcsoló beállításával:</p>
-<p>set :public<em>folder, File.dirname(</em><em>FILE</em>_) + '/static'</p>
+<p>set :public_folder, File.dirname(<strong>FILE</strong>) + /static</p>
<p>Fontos mgejegyezni, hogy a nyilvános könyvtár neve nem szerepel az URL-ben.
A ./public/css/style.css fájl az
@@ -143,46 +196,64 @@
<p>A sablonfájlokat rendszerint a <code>./views</code> könyvtárba helyezzük, de
itt is lehetőség nyílik egyéb könyvtár használatára:</p>
-<p>set :views, File.dirname(<strong>FILE</strong>) + '/templates'</p>
+<p>set :views, File.dirname(<strong>FILE</strong>) + /templates</p>
<p>Nagyon fontos észben tartani, hogy a sablononkra mindig szimbólumokkal
hivatkozunk, még akkor is, ha egyéb (ebben az esetben a
-:'subdir/template') könyvtárban tároljuk őket. A renderelő
+:subdir/template) könyvtárban tároljuk őket. A renderelő
metódusok minden, nekik közvetlenül átadott karakterláncot megjelenítenek.</p>
<a name='Haml%20sablonok'></a>
<h3>Haml sablonok</h3>
<p>HAML sablonok rendereléséhez szükségünk lesz a haml gem-re vagy könyvtárra:</p>
-<pre class="highlight ruby"> <span class="c1"># Importáljuk be a haml-t az alkalmazásba</span>
- <span class="nb">require</span> <span class="s1">'haml'</span>
- <span class="n">get</span> <span class="s1">'/'</span> <span class="k">do</span>
- <span class="n">haml</span> <span class="ss">:index</span>
- <span class="k">end</span>
-</pre>
+<div>
+<div class="CodeRay">
+ <div class="code"><pre> <span style="color:#777"># Importáljuk be a haml-t az alkalmazásba</span>
+ require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">haml</span><span style="color:#710">'</span></span>
+
+ get <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
+ haml <span style="color:#A60">:index</span>
+ <span style="color:#080;font-weight:bold">end</span>
+</pre></div>
+</div>
+</div>
+
<p>Ez szépen lerendereli a <code>./views/index.haml</code> sablont.</p>
<p>A <a href="http://haml.hamptoncatlin.com/docs/rdoc/classes/Haml.html">Haml kapcsolói</a>
globálisan is beállíthatók a Sinatra konfigurációi között, lásd az
<a href="http://www.sinatrarb.com/configuration.html">Options and Configurations</a> lapot.
A globális beállításokat lehetőségünk van felülírni metódus szinten is.</p>
-<pre class="highlight ruby"> <span class="n">set</span> <span class="ss">:haml</span><span class="p">,</span> <span class="p">{</span><span class="ss">:format</span> <span class="o">=&gt;</span> <span class="ss">:html5</span> <span class="p">}</span> <span class="c1"># az alapértelmezett Haml formátum az :xhtml</span>
- <span class="n">get</span> <span class="s1">'/'</span> <span class="k">do</span>
- <span class="n">haml</span> <span class="ss">:index</span><span class="p">,</span> <span class="ss">:haml_options</span> <span class="o">=&gt;</span> <span class="p">{</span><span class="ss">:format</span> <span class="o">=&gt;</span> <span class="ss">:html4</span> <span class="p">}</span> <span class="c1"># immár felülírva</span>
- <span class="k">end</span>
-</pre>
+<div>
+<div class="CodeRay">
+ <div class="code"><pre> set <span style="color:#A60">:haml</span>, {<span style="color:#A60">:format</span> =&gt; <span style="color:#A60">:html5</span> } <span style="color:#777"># az alapértelmezett Haml formátum az :xhtml</span>
+
+ get <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
+ haml <span style="color:#A60">:index</span>, <span style="color:#A60">:haml_options</span> =&gt; {<span style="color:#A60">:format</span> =&gt; <span style="color:#A60">:html4</span> } <span style="color:#777"># immár felülírva</span>
+ <span style="color:#080;font-weight:bold">end</span>
+</pre></div>
+</div>
+</div>
+
<a name='Erb%20sablonok'></a>
<h3>Erb sablonok</h3>
<p># Importáljuk be az erb-t az alkalmazásba</p>
-<pre class="highlight ruby"> <span class="nb">require</span> <span class="s1">'erb'</span>
- <span class="n">get</span> <span class="s1">'/'</span> <span class="k">do</span>
- <span class="n">erb</span> <span class="ss">:index</span>
- <span class="k">end</span>
-</pre>
+<div>
+<div class="CodeRay">
+ <div class="code"><pre> require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">erb</span><span style="color:#710">'</span></span>
+
+ get <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
+ erb <span style="color:#A60">:index</span>
+ <span style="color:#080;font-weight:bold">end</span>
+</pre></div>
+</div>
+</div>
+
<p>Ez a <code>./views/index.erb</code> sablont fogja lerenderelni.</p>
<a name='Builder%20sablonok'></a>
@@ -192,12 +263,18 @@
rendereléséhez:</p>
<p># Importáljuk be a builder-t az alkalmazásba</p>
-<pre class="highlight ruby"> <span class="nb">require</span> <span class="s1">'builder'</span>
- <span class="n">get</span> <span class="s1">'/'</span> <span class="k">do</span>
- <span class="n">builder</span> <span class="ss">:index</span>
- <span class="k">end</span>
-</pre>
+<div>
+<div class="CodeRay">
+ <div class="code"><pre> require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">builder</span><span style="color:#710">'</span></span>
+
+ get <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
+ builder <span style="color:#A60">:index</span>
+ <span style="color:#080;font-weight:bold">end</span>
+</pre></div>
+</div>
+</div>
+
<p>Ez pedig a <code>./views/index.builder</code> állományt fogja renderelni.</p>
<a name='Sass%20sablonok'></a>
@@ -206,30 +283,48 @@
<p>Sass sablonok használatához szükség lesz a haml gem-re vagy könyvtárra:</p>
<p># Be kell importálni a haml, vagy a sass könyvtárat</p>
-<pre class="highlight ruby"> <span class="nb">require</span> <span class="s1">'sass'</span>
- <span class="n">get</span> <span class="s1">'/stylesheet.css'</span> <span class="k">do</span>
- <span class="n">sass</span> <span class="ss">:stylesheet</span>
- <span class="k">end</span>
-</pre>
+<div>
+<div class="CodeRay">
+ <div class="code"><pre> require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">sass</span><span style="color:#710">'</span></span>
+
+ get <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/stylesheet.css</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
+ sass <span style="color:#A60">:stylesheet</span>
+ <span style="color:#080;font-weight:bold">end</span>
+</pre></div>
+</div>
+</div>
+
<p>Így a <code>./views/stylesheet.sass</code> fájl máris renderelhető.</p>
<p>A <a href="http://haml.hamptoncatlin.com/docs/rdoc/classes/Sass.html">Sass kapcsolói</a>
globálisan is beállíthatók a Sinatra konfigurációi között, lásd az
<a href="http://www.sinatrarb.com/configuration.html">Options and Configurations</a> lapot.
A globális beállításokat lehetőségünk van felülírni metódus szinten is.</p>
-<pre class="highlight ruby"> <span class="n">set</span> <span class="ss">:sass</span><span class="p">,</span> <span class="p">{</span><span class="ss">:style</span> <span class="o">=&gt;</span> <span class="ss">:compact</span> <span class="p">}</span> <span class="c1"># az alapértelmezett Sass stílus a :nested</span>
- <span class="n">get</span> <span class="s1">'/stylesheet.css'</span> <span class="k">do</span>
- <span class="n">sass</span> <span class="ss">:stylesheet</span><span class="p">,</span> <span class="ss">:sass_options</span> <span class="o">=&gt;</span> <span class="p">{</span><span class="ss">:style</span> <span class="o">=&gt;</span> <span class="ss">:expanded</span> <span class="p">}</span> <span class="c1"># felülírva</span>
- <span class="k">end</span>
-</pre>
+<div>
+<div class="CodeRay">
+ <div class="code"><pre> set <span style="color:#A60">:sass</span>, {<span style="color:#A60">:style</span> =&gt; <span style="color:#A60">:compact</span> } <span style="color:#777"># az alapértelmezett Sass stílus a :nested</span>
+
+ get <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/stylesheet.css</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
+ sass <span style="color:#A60">:stylesheet</span>, <span style="color:#A60">:sass_options</span> =&gt; {<span style="color:#A60">:style</span> =&gt; <span style="color:#A60">:expanded</span> } <span style="color:#777"># felülírva</span>
+ <span style="color:#080;font-weight:bold">end</span>
+</pre></div>
+</div>
+</div>
+
<a name='Be%C3%A1gyazott%20sablonok'></a>
<h3>Beágyazott sablonok</h3>
-<pre class="highlight ruby"> <span class="n">get</span> <span class="s1">'/'</span> <span class="k">do</span>
- <span class="n">haml</span> <span class="s1">'%div.title Helló Világ'</span>
- <span class="k">end</span>
-</pre>
+
+<div>
+<div class="CodeRay">
+ <div class="code"><pre> get <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
+ haml <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">%div.title Helló Világ</span><span style="color:#710">'</span></span>
+ <span style="color:#080;font-weight:bold">end</span>
+</pre></div>
+</div>
+</div>
+
<p>Lerendereli a beágyazott sablon karakerláncát.</p>
<a name='V%C3%A1ltoz%C3%B3k%20el%C3%A9r%C3%A9se%20a%20sablonokban'></a>
@@ -238,17 +333,29 @@
<p>A sablonok ugyanabban a kontextusban kerülnek kiértékelésre, mint az
útvonal metódusok (route handlers). Az útvonal metódusokban megadott
változók közvetlenül elérhetőek lesznek a sablonokban:</p>
-<pre class="highlight ruby"> <span class="n">get</span> <span class="s1">'/:id'</span> <span class="k">do</span>
- <span class="vi">@foo</span> <span class="o">=</span> <span class="no">Foo</span><span class="nf">.find</span><span class="p">(</span><span class="n">params</span><span class="o">[</span><span class="ss">:id</span><span class="o">]</span><span class="p">)</span>
- <span class="n">haml</span> <span class="s1">'%h1= @foo.name'</span>
- <span class="k">end</span>
-</pre>
+
+<div>
+<div class="CodeRay">
+ <div class="code"><pre> get <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/:id</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
+ <span style="color:#33B">@foo</span> = <span style="color:#036;font-weight:bold">Foo</span>.find(params[<span style="color:#A60">:id</span>])
+ haml <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">%h1= @foo.name</span><span style="color:#710">'</span></span>
+ <span style="color:#080;font-weight:bold">end</span>
+</pre></div>
+</div>
+</div>
+
<p>De megadhatod egy lokális változókat tartalmazó explicit hash-ben is:</p>
-<pre class="highlight ruby"> <span class="n">get</span> <span class="s1">'/:id'</span> <span class="k">do</span>
- <span class="n">foo</span> <span class="o">=</span> <span class="no">Foo</span><span class="nf">.find</span><span class="p">(</span><span class="n">params</span><span class="o">[</span><span class="ss">:id</span><span class="o">]</span><span class="p">)</span>
- <span class="n">haml</span> <span class="s1">'%h1= foo.name'</span><span class="p">,</span> <span class="ss">:locals</span> <span class="o">=&gt;</span> <span class="p">{</span> <span class="ss">:foo</span> <span class="o">=&gt;</span> <span class="n">foo</span> <span class="p">}</span>
- <span class="k">end</span>
-</pre>
+
+<div>
+<div class="CodeRay">
+ <div class="code"><pre> get <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/:id</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
+ foo = <span style="color:#036;font-weight:bold">Foo</span>.find(params[<span style="color:#A60">:id</span>])
+ haml <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">%h1= foo.name</span><span style="color:#710">'</span></span>, <span style="color:#A60">:locals</span> =&gt; { <span style="color:#A60">:foo</span> =&gt; foo }
+ <span style="color:#080;font-weight:bold">end</span>
+</pre></div>
+</div>
+</div>
+
<p>Ezt leginkább akkor érdemes megtenni, ha partial-eket akarunk renderelni
valamely más sablonból.</p>
@@ -257,67 +364,91 @@
<p>Sablonokat úgy is megadhatunk, hogy egyszerűen az alkalmazás fájl
végére begépeljük őket:</p>
-<pre class="highlight ruby"> <span class="nb">require</span> <span class="s1">'rubygems'</span>
- <span class="nb">require</span> <span class="s1">'sinatra'</span>
- <span class="n">get</span> <span class="s1">'/'</span> <span class="k">do</span>
- <span class="n">haml</span> <span class="ss">:index</span>
- <span class="k">end</span>
+<div>
+<div class="CodeRay">
+ <div class="code"><pre> require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">rubygems</span><span style="color:#710">'</span></span>
+ require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">sinatra</span><span style="color:#710">'</span></span>
+
+ get <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
+ haml <span style="color:#A60">:index</span>
+ <span style="color:#080;font-weight:bold">end</span>
- <span class="cp">__END__
+ __END__
- @@ layout
+ <span style="color:#F00;background-color:#FAA">@</span><span style="color:#F00;background-color:#FAA">@</span> layout
%html
- = yield
+ = <span style="color:#080;font-weight:bold">yield</span>
+
+ <span style="color:#F00;background-color:#FAA">@</span><span style="color:#F00;background-color:#FAA">@</span> index
+ %div.title <span style="color:#036;font-weight:bold">Helló</span> Világ!!!!!
+</pre></div>
+</div>
+</div>
- @@ index
- %div.title Helló Világ!!!!!
-</span></pre>
<p>Megjegyzés: azok a fájlon belüli sablonok, amelyek az alkalmazás fájl végére
kerülnek és függnek a sinatra könyvtártól, automatikusan betöltődnek.
Ha ugyanezt más alkalmazásfájlban is szeretnéd megtenni, hívd meg
-a <tt>use<em>in</em>file_templates!</tt> metódust az adott fájlban.</p>
+a <tt>use_in_file_templates!</tt> metódust az adott fájlban.</p>
<a name='Kulcsszavas%20sablonok'></a>
<h3>Kulcsszavas sablonok</h3>
<p>Sablonokat végül a felsőszintű <tt>template</tt> metódussal is
definiálhatunk: </p>
-<pre class="highlight ruby"> <span class="n">template</span> <span class="ss">:layout</span> <span class="k">do</span>
- <span class="s2">"%html</span><span class="se">\n</span><span class="s2"> =yield</span><span class="se">\n</span><span class="s2">"</span>
- <span class="k">end</span>
-
- <span class="n">template</span> <span class="ss">:index</span> <span class="k">do</span>
- <span class="s1">'%div.title Helló Világ!'</span>
- <span class="k">end</span>
-
- <span class="n">get</span> <span class="s1">'/'</span> <span class="k">do</span>
- <span class="n">haml</span> <span class="ss">:index</span>
- <span class="k">end</span>
-</pre>
-<p>Ha létezik "layout" nevű sablon, akkor az minden esetben meghívódik, amikor
+
+<div>
+<div class="CodeRay">
+ <div class="code"><pre> template <span style="color:#A60">:layout</span> <span style="color:#080;font-weight:bold">do</span>
+ <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">%html</span><span style="color:#b0b">\n</span><span style="color:#D20"> =yield</span><span style="color:#b0b">\n</span><span style="color:#710">"</span></span>
+ <span style="color:#080;font-weight:bold">end</span>
+
+ template <span style="color:#A60">:index</span> <span style="color:#080;font-weight:bold">do</span>
+ <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">%div.title Helló Világ!</span><span style="color:#710">'</span></span>
+ <span style="color:#080;font-weight:bold">end</span>
+
+ get <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
+ haml <span style="color:#A60">:index</span>
+ <span style="color:#080;font-weight:bold">end</span>
+</pre></div>
+</div>
+</div>
+
+<p>Ha létezik “layout” nevű sablon, akkor az minden esetben meghívódik, amikor
csak egy sablon renderelésre kerül. A layoutokat ki lehet kapcsolni a
<code>:layout =&gt; false</code> meghívásával.</p>
-<pre class="highlight ruby"> <span class="n">get</span> <span class="s1">'/'</span> <span class="k">do</span>
- <span class="n">haml</span> <span class="ss">:index</span><span class="p">,</span> <span class="ss">:layout</span> <span class="o">=&gt;</span> <span class="o">!</span><span class="n">request</span><span class="nf">.xhr?</span>
- <span class="k">end</span>
-</pre>
+
+<div>
+<div class="CodeRay">
+ <div class="code"><pre> get <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
+ haml <span style="color:#A60">:index</span>, <span style="color:#A60">:layout</span> =&gt; !request.xhr?
+ <span style="color:#080;font-weight:bold">end</span>
+</pre></div>
+</div>
+</div>
+
<a name='Helperek'></a>
<h2>Helperek</h2>
<p>Használd a felső szintű <tt>helpers</tt> metódust azokhoz a helper
függvényekhez, amiket az útvonal metódusokban és a sablonokban akarsz
használni:</p>
-<pre class="highlight ruby"> <span class="n">helpers</span> <span class="k">do</span>
- <span class="k">def</span> <span class="nf">bar</span><span class="p">(</span><span class="nb">name</span><span class="p">)</span>
- <span class="s2">"</span><span class="si">#{</span><span class="nb">name</span><span class="si">}</span><span class="s2">bar"</span>
- <span class="k">end</span>
- <span class="k">end</span>
-
- <span class="n">get</span> <span class="s1">'/:name'</span> <span class="k">do</span>
- <span class="n">bar</span><span class="p">(</span><span class="n">params</span><span class="o">[</span><span class="ss">:name</span><span class="o">]</span><span class="p">)</span>
- <span class="k">end</span>
-</pre>
+
+<div>
+<div class="CodeRay">
+ <div class="code"><pre> helpers <span style="color:#080;font-weight:bold">do</span>
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">bar</span>(name)
+ <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="background-color:hsla(0,0%,0%,0.07);color:black"><span style="font-weight:bold;color:#666">#{</span>name<span style="font-weight:bold;color:#666">}</span></span><span style="color:#D20">bar</span><span style="color:#710">"</span></span>
+ <span style="color:#080;font-weight:bold">end</span>
+ <span style="color:#080;font-weight:bold">end</span>
+
+ get <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/:name</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
+ bar(params[<span style="color:#A60">:name</span>])
+ <span style="color:#080;font-weight:bold">end</span>
+</pre></div>
+</div>
+</div>
+
<a name='Sz%C5%B1r%C5%91k%20(filters)'></a>
<h2>Szűrők (filters)</h2>
@@ -325,7 +456,10 @@
kérés alkalmával kiértékelődnek, így módosíthatják a kérést és a
választ egyaránt. A szűrőkbe felvett példányváltozók elérhetőek lesznek
az útvonalakban és a sablonokban is:</p>
-<pre class="highlight text"> before do
+
+<div>
+<div class="CodeRay">
+ <div class="code"><pre> before do
@note = 'Csá!'
request.path_info = '/foo/bar/baz'
end
@@ -334,15 +468,24 @@
@note #=&gt; 'Szeva!'
params[:splat] #=&gt; 'bar/baz'
end
-</pre>
+</pre></div>
+</div>
+</div>
+
<p>Az utószűrők az egyes kérések után, az adott kérés kontextusában kerülnek
kiértékelésre, így ezek is képesek módosítani a kérést és a választ egyaránt.
Az előszűrőkben és úvonalakban létrehozott példányváltozók elérhetőek lesznek
az utószűrők számára:</p>
-<pre class="highlight ruby"> <span class="n">after</span> <span class="k">do</span>
- <span class="nb">puts</span> <span class="n">response</span><span class="nf">.status</span>
- <span class="k">end</span>
-</pre>
+
+<div>
+<div class="CodeRay">
+ <div class="code"><pre> after <span style="color:#080;font-weight:bold">do</span>
+ puts response.status
+ <span style="color:#080;font-weight:bold">end</span>
+</pre></div>
+</div>
+</div>
+
<a name='Meg%C3%A1ll%C3%ADt%C3%A1s'></a>
<h2>Megállítás</h2>
@@ -351,28 +494,34 @@
<p>halt</p>
-<p>A megállításkor egy blokktörzset is megadhatsz ...</p>
+<p>A megállításkor egy blokktörzset is megadhatsz </p>
-<p>halt 'ez fog megjelenni a törzsben'</p>
+<p>halt ez fog megjelenni a törzsben</p>
-<p>Vagy állítsd be a HTTP státuszt és a törzset is egyszerre ...</p>
+<p>Vagy állítsd be a HTTP státuszt és a törzset is egyszerre </p>
-<p>halt 401, 'menj innen!'</p>
+<p>halt 401, menj innen!</p>
<a name='Passzol%C3%A1s'></a>
<h2>Passzolás</h2>
<p>Az útvonalak továbbadhatják a végrehajtást egy másik útvonalnak
a <code>pass</code> függvényhívással:</p>
-<pre class="highlight ruby"> <span class="n">get</span> <span class="s1">'/guess/:who'</span> <span class="k">do</span>
- <span class="n">pass</span> <span class="k">unless</span> <span class="n">params</span><span class="o">[</span><span class="ss">:who</span><span class="o">]</span> <span class="o">==</span> <span class="s1">'Frici'</span>
- <span class="s2">"Elkaptál!"</span>
- <span class="k">end</span>
-
- <span class="n">get</span> <span class="s1">'/guess/*'</span> <span class="k">do</span>
- <span class="s2">"Elhibáztál!"</span>
- <span class="k">end</span>
-</pre>
+
+<div>
+<div class="CodeRay">
+ <div class="code"><pre> get <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/guess/:who</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
+ pass <span style="color:#080;font-weight:bold">unless</span> params[<span style="color:#A60">:who</span>] == <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Frici</span><span style="color:#710">'</span></span>
+ <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Elkaptál!</span><span style="color:#710">"</span></span>
+ <span style="color:#080;font-weight:bold">end</span>
+
+ get <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/guess/*</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
+ <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Elhibáztál!</span><span style="color:#710">"</span></span>
+ <span style="color:#080;font-weight:bold">end</span>
+</pre></div>
+</div>
+</div>
+
<p>Az útvonal blokkja azonnal kilép és átadja a vezérlést a következő
illeszkedő útvonalnak. Ha nem talál megfelelő útvonalat, a Sinatra
egy 404-es hibával tér vissza.</p>
@@ -381,21 +530,39 @@
<h2>Beállítások</h2>
<p>Csak indításkor, de minden környezetre érvényesen fusson le:</p>
-<pre class="highlight ruby"> <span class="n">configure</span> <span class="k">do</span>
- <span class="nf">..</span><span class="o">.</span>
- <span class="k">end</span>
-</pre>
+
+<div>
+<div class="CodeRay">
+ <div class="code"><pre> configure <span style="color:#080;font-weight:bold">do</span>
+ ...
+ <span style="color:#080;font-weight:bold">end</span>
+</pre></div>
+</div>
+</div>
+
<p>Csak akkor fusson le, ha a környezet (a RACK_ENV környezeti változóban)
<code>:production</code>-ra van állítva:</p>
-<pre class="highlight ruby"> <span class="n">configure</span> <span class="ss">:production</span> <span class="k">do</span>
- <span class="nf">..</span><span class="o">.</span>
- <span class="k">end</span>
-</pre>
+
+<div>
+<div class="CodeRay">
+ <div class="code"><pre> configure <span style="color:#A60">:production</span> <span style="color:#080;font-weight:bold">do</span>
+ ...
+ <span style="color:#080;font-weight:bold">end</span>
+</pre></div>
+</div>
+</div>
+
<p>Csak akkor fusson le, ha a környezet <tt>:production</tt> vagy <tt>:test</tt>:</p>
-<pre class="highlight ruby"> <span class="n">configure</span> <span class="ss">:production</span><span class="p">,</span> <span class="ss">:test</span> <span class="k">do</span>
- <span class="nf">..</span><span class="o">.</span>
- <span class="k">end</span>
-</pre>
+
+<div>
+<div class="CodeRay">
+ <div class="code"><pre> configure <span style="color:#A60">:production</span>, <span style="color:#A60">:test</span> <span style="color:#080;font-weight:bold">do</span>
+ ...
+ <span style="color:#080;font-weight:bold">end</span>
+</pre></div>
+</div>
+</div>
+
<a name='Hibakezel%C3%A9s'></a>
<h2>Hibakezelés</h2>
@@ -409,33 +576,57 @@
<p>Amikor a <code>Sinatra::NotFound</code> kivétel fellép, vagy a válasz HTTP
státuszkódja 404-es, mindig a <code>not_found</code> metódus hívódik meg.</p>
-<pre class="highlight ruby"> <span class="n">not_found</span> <span class="k">do</span>
- <span class="s1">'Sehol sem találom, amit keresel'</span>
- <span class="k">end</span>
-</pre>
+
+<div>
+<div class="CodeRay">
+ <div class="code"><pre> not_found <span style="color:#080;font-weight:bold">do</span>
+ <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Sehol sem találom, amit keresel</span><span style="color:#710">'</span></span>
+ <span style="color:#080;font-weight:bold">end</span>
+</pre></div>
+</div>
+</div>
+
<a name='Hiba'></a>
<h3>Hiba</h3>
<p>Az <code>error</code> metódus hívódik meg olyankor, amikor egy útvonal, blokk vagy
előszűrő kivételt vált ki. A kivétel objektum lehívható a
<code>sinatra.error</code> Rack változótól:</p>
-<pre class="highlight ruby"> <span class="n">error</span> <span class="k">do</span>
- <span class="s1">'Elnézést, de valami szörnyű hiba lépett fel - '</span> <span class="o">+</span> <span class="n">env</span><span class="o">[</span><span class="s1">'sinatra.error'</span><span class="o">]</span><span class="nf">.name</span>
- <span class="k">end</span>
-</pre>
+
+<div>
+<div class="CodeRay">
+ <div class="code"><pre> error <span style="color:#080;font-weight:bold">do</span>
+ <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Elnézést, de valami szörnyű hiba lépett fel - </span><span style="color:#710">'</span></span> + env[<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">sinatra.error</span><span style="color:#710">'</span></span>].name
+ <span style="color:#080;font-weight:bold">end</span>
+</pre></div>
+</div>
+</div>
+
<p>Egyéni hibakezelés:</p>
-<pre class="highlight ruby"> <span class="n">error</span> <span class="no">MyCustomError</span> <span class="k">do</span>
- <span class="s1">'Szóval az van, hogy...'</span> <span class="o">+</span> <span class="n">env</span><span class="o">[</span><span class="s1">'sinatra.error'</span><span class="o">]</span><span class="nf">.message</span>
- <span class="k">end</span>
-</pre>
+
+<div>
+<div class="CodeRay">
+ <div class="code"><pre> error <span style="color:#036;font-weight:bold">MyCustomError</span> <span style="color:#080;font-weight:bold">do</span>
+ <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Szóval az van, hogy...</span><span style="color:#710">'</span></span> + env[<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">sinatra.error</span><span style="color:#710">'</span></span>].message
+ <span style="color:#080;font-weight:bold">end</span>
+</pre></div>
+</div>
+</div>
+
<p>És amikor fellép:</p>
-<pre class="highlight ruby"> <span class="n">get</span> <span class="s1">'/'</span> <span class="k">do</span>
- <span class="k">raise</span> <span class="no">MyCustomError</span><span class="p">,</span> <span class="s1">'valami nem stimmel!'</span>
- <span class="k">end</span>
-</pre>
+
+<div>
+<div class="CodeRay">
+ <div class="code"><pre> get <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
+ raise <span style="color:#036;font-weight:bold">MyCustomError</span>, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">valami nem stimmel!</span><span style="color:#710">'</span></span>
+ <span style="color:#080;font-weight:bold">end</span>
+</pre></div>
+</div>
+</div>
+
<p>Ez fog megjelenni:</p>
-<p>Szóval az van, hogy... valami nem stimmel!</p>
+<p>Szóval az van, hogy valami nem stimmel!</p>
<p>A Sinatra speciális <code>not_found</code> és <code>error</code> hibakezelőket
használ, amikor a futtatási környezet fejlesztői módba van kapcsolva.</p>
@@ -447,40 +638,58 @@
kiszolgálásakor előfordulhat, hogy a Sinatra nem ismeri fel a fájlok
mime típusát. Ilyenkor használd a +mime_type+ kapcsolót a fájlkiterjesztés
bevezetéséhez:</p>
-<pre class="highlight ruby"> <span class="n">mime_type</span> <span class="ss">:foo</span><span class="p">,</span> <span class="s1">'text/foo'</span>
-</pre>
+
+<div>
+<div class="CodeRay">
+ <div class="code"><pre> mime_type <span style="color:#A60">:foo</span>, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">text/foo</span><span style="color:#710">'</span></span>
+</pre></div>
+</div>
+</div>
+
<a name='Rack%20Middleware'></a>
<h2>Rack Middleware</h2>
<p>A Sinatra egy Ruby keretrendszerek számára kifejlesztett egyszerű és szabványos
interfészre, a <a href="http://rack.rubyforge.org/">Rack</a> -re épül. A Rack fejlesztői
szempontból egyik legérdekesebb jellemzője, hogy támogatja az úgynevezett
-"middleware" elnevezésű komponenseket, amelyek beékelődnek a szerver és az
+middleware elnevezésű komponenseket, amelyek beékelődnek a szerver és az
alkalmazás közé, így képesek megfigyelni és/vagy módosítani a HTTP
kéréseket és válaszokat. Segítségükkel különféle, egységesen működő
funkciókat építhetünk be rendszerünkbe.</p>
<p>A Sinatra keretrendszerben gyerekjáték a Rack middleware-ek behúzása a
<code>use</code> metódus segítségével:</p>
-<pre class="highlight ruby"> <span class="nb">require</span> <span class="s1">'sinatra'</span>
- <span class="nb">require</span> <span class="s1">'my_custom_middleware'</span>
- <span class="n">use</span> <span class="no">Rack</span><span class="o">::</span><span class="no">Lint</span>
- <span class="n">use</span> <span class="no">MyCustomMiddleware</span>
+<div>
+<div class="CodeRay">
+ <div class="code"><pre> require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">sinatra</span><span style="color:#710">'</span></span>
+ require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">my_custom_middleware</span><span style="color:#710">'</span></span>
+
+ use <span style="color:#036;font-weight:bold">Rack</span>::<span style="color:#036;font-weight:bold">Lint</span>
+ use <span style="color:#036;font-weight:bold">MyCustomMiddleware</span>
+
+ get <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/hello</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
+ <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Helló Világ</span><span style="color:#710">'</span></span>
+ <span style="color:#080;font-weight:bold">end</span>
+</pre></div>
+</div>
+</div>
- <span class="n">get</span> <span class="s1">'/hello'</span> <span class="k">do</span>
- <span class="s1">'Helló Világ'</span>
- <span class="k">end</span>
-</pre>
<p>A <code>use</code> metódus szemantikája megegyezik a
<a href="http://rack.rubyforge.org/doc/classes/Rack/Builder.html">Rack::Builder</a> DSL-ben
használt +use+ metóduséval (az említett DSL-t leginkább rackup állományokban
használják). Hogy egy példát említsünk, a <code>use</code> metódus elfogad
változókat és blokkokat egyaránt, akár kombinálva is ezeket:</p>
-<pre class="highlight ruby"> <span class="n">use</span> <span class="no">Rack</span><span class="o">::</span><span class="no">Auth</span><span class="o">::</span><span class="no">Basic</span> <span class="k">do</span> <span class="o">|</span><span class="n">username</span><span class="p">,</span> <span class="n">password</span><span class="o">|</span>
- <span class="n">username</span> <span class="o">==</span> <span class="s1">'admin'</span> <span class="o">&amp;&amp;</span> <span class="n">password</span> <span class="o">==</span> <span class="s1">'titkos'</span>
- <span class="k">end</span>
-</pre>
+
+<div>
+<div class="CodeRay">
+ <div class="code"><pre> use <span style="color:#036;font-weight:bold">Rack</span>::<span style="color:#036;font-weight:bold">Auth</span>::<span style="color:#036;font-weight:bold">Basic</span> <span style="color:#080;font-weight:bold">do</span> |username, password|
+ username == <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">admin</span><span style="color:#710">'</span></span> &amp;&amp; password == <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">titkos</span><span style="color:#710">'</span></span>
+ <span style="color:#080;font-weight:bold">end</span>
+</pre></div>
+</div>
+</div>
+
<p>A Rack terjesztéssel egy csomó alap middleware komponens is érkezik,
amelyekkel a naplózás, URL útvonalak megadása, autentikáció és
munkamenet-kezelés könnyen megvalósítható. A Sinatra ezek közül elég
@@ -493,32 +702,38 @@
<p>Sinatra teszteket bármely Rack alapú tesztelő könyvtárral vagy
keretrendszerrel készíthetsz. Mi a <a href="http://gitrdoc.com/brynary/rack-test">Rack::Test</a>
könyvtárat ajánljuk:</p>
-<pre class="highlight ruby"> <span class="nb">require</span> <span class="s1">'my_sinatra_app'</span>
- <span class="nb">require</span> <span class="s1">'rack/test'</span>
-
- <span class="k">class</span> <span class="nc">MyAppTest</span> <span class="o">&lt;</span> <span class="no">Test</span><span class="o">::</span><span class="no">Unit</span><span class="o">::</span><span class="no">TestCase</span>
- <span class="kp">include</span> <span class="no">Rack</span><span class="o">::</span><span class="no">Test</span><span class="o">::</span><span class="no">Methods</span>
-
- <span class="k">def</span> <span class="nf">app</span>
- <span class="no">Sinatra</span><span class="o">::</span><span class="no">Application</span>
- <span class="k">end</span>
-
- <span class="k">def</span> <span class="nf">test_my_default</span>
- <span class="n">get</span> <span class="s1">'/'</span>
- <span class="n">assert_equal</span> <span class="s1">'Helló Világ!'</span><span class="p">,</span> <span class="n">last_response</span><span class="nf">.body</span>
- <span class="k">end</span>
-
- <span class="k">def</span> <span class="nf">test_with_params</span>
- <span class="n">get</span> <span class="s1">'/meet'</span><span class="p">,</span> <span class="ss">:name</span> <span class="o">=&gt;</span> <span class="s1">'Frici'</span>
- <span class="n">assert_equal</span> <span class="s1">'Helló Frici!'</span><span class="p">,</span> <span class="n">last_response</span><span class="nf">.body</span>
- <span class="k">end</span>
-
- <span class="k">def</span> <span class="nf">test_with_rack_env</span>
- <span class="n">get</span> <span class="s1">'/'</span><span class="p">,</span> <span class="p">{},</span> <span class="s1">'HTTP_USER_AGENT'</span> <span class="o">=&gt;</span> <span class="s1">'Songbird'</span>
- <span class="n">assert_equal</span> <span class="s2">"Songbird-öt használsz!"</span><span class="p">,</span> <span class="n">last_response</span><span class="nf">.body</span>
- <span class="k">end</span>
- <span class="k">end</span>
-</pre>
+
+<div>
+<div class="CodeRay">
+ <div class="code"><pre> require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">my_sinatra_app</span><span style="color:#710">'</span></span>
+ require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">rack/test</span><span style="color:#710">'</span></span>
+
+ <span style="color:#080;font-weight:bold">class</span> <span style="color:#B06;font-weight:bold">MyAppTest</span> &lt; <span style="color:#036;font-weight:bold">Test</span>::<span style="color:#036;font-weight:bold">Unit</span>::<span style="color:#036;font-weight:bold">TestCase</span>
+ include <span style="color:#036;font-weight:bold">Rack</span>::<span style="color:#036;font-weight:bold">Test</span>::<span style="color:#036;font-weight:bold">Methods</span>
+
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">app</span>
+ <span style="color:#036;font-weight:bold">Sinatra</span>::<span style="color:#036;font-weight:bold">Application</span>
+ <span style="color:#080;font-weight:bold">end</span>
+
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">test_my_default</span>
+ get <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/</span><span style="color:#710">'</span></span>
+ assert_equal <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Helló Világ!</span><span style="color:#710">'</span></span>, last_response.body
+ <span style="color:#080;font-weight:bold">end</span>
+
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">test_with_params</span>
+ get <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/meet</span><span style="color:#710">'</span></span>, <span style="color:#A60">:name</span> =&gt; <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Frici</span><span style="color:#710">'</span></span>
+ assert_equal <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Helló Frici!</span><span style="color:#710">'</span></span>, last_response.body
+ <span style="color:#080;font-weight:bold">end</span>
+
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">test_with_rack_env</span>
+ get <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/</span><span style="color:#710">'</span></span>, {}, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">HTTP_USER_AGENT</span><span style="color:#710">'</span></span> =&gt; <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Songbird</span><span style="color:#710">'</span></span>
+ assert_equal <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Songbird-öt használsz!</span><span style="color:#710">"</span></span>, last_response.body
+ <span style="color:#080;font-weight:bold">end</span>
+ <span style="color:#080;font-weight:bold">end</span>
+</pre></div>
+</div>
+</div>
+
<p>Megjegyzés: A beépített Sinatra::Test és Sinatra::TestHarness osztályok
a 0.9.2-es kiadástól kezdve elavultnak számítanak.</p>
@@ -535,24 +750,36 @@
<code>./public</code>
és <code>./views</code> könyvtár meglétét, naplózást, kivételkezelő oldalt stb.).
Itt jön a képbe a Sinatra::Base osztály:</p>
-<pre class="highlight ruby"> <span class="nb">require</span> <span class="s1">'sinatra/base'</span>
- <span class="k">class</span> <span class="nc">MyApp</span> <span class="o">&lt;</span> <span class="no">Sinatra</span><span class="o">::</span><span class="no">Base</span>
- <span class="n">set</span> <span class="ss">:sessions</span><span class="p">,</span> <span class="kp">true</span>
- <span class="n">set</span> <span class="ss">:foo</span><span class="p">,</span> <span class="s1">'bar'</span>
+<div>
+<div class="CodeRay">
+ <div class="code"><pre> require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">sinatra/base</span><span style="color:#710">'</span></span>
+
+ <span style="color:#080;font-weight:bold">class</span> <span style="color:#B06;font-weight:bold">MyApp</span> &lt; <span style="color:#036;font-weight:bold">Sinatra</span>::<span style="color:#036;font-weight:bold">Base</span>
+ set <span style="color:#A60">:sessions</span>, <span style="color:#069">true</span>
+ set <span style="color:#A60">:foo</span>, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">bar</span><span style="color:#710">'</span></span>
+
+ get <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
+ <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Helló Világ!</span><span style="color:#710">'</span></span>
+ <span style="color:#080;font-weight:bold">end</span>
+ <span style="color:#080;font-weight:bold">end</span>
+</pre></div>
+</div>
+</div>
- <span class="n">get</span> <span class="s1">'/'</span> <span class="k">do</span>
- <span class="s1">'Helló Világ!'</span>
- <span class="k">end</span>
- <span class="k">end</span>
-</pre>
<p>A MyApp osztály immár önálló Rack komponensként, mondjuk Rack middleware-ként
vagy alkalmazásként, esetleg Rails metal-ként is tud működni. Közvetlenül
használhatod (<code>use</code>) vagy futtathatod (<code>run</code>) az osztályodat egy rackup
konfigurációs állományban (<code>config.ru</code>), vagy egy szerverkomponenst
tartalmazó könyvtár vezérlésekor:</p>
-<pre class="highlight ruby"> <span class="no">MyApp</span><span class="nf">.run!</span> <span class="ss">:host</span> <span class="o">=&gt;</span> <span class="s1">'localhost'</span><span class="p">,</span> <span class="ss">:port</span> <span class="o">=&gt;</span> <span class="mi">9090</span>
-</pre>
+
+<div>
+<div class="CodeRay">
+ <div class="code"><pre> <span style="color:#036;font-weight:bold">MyApp</span>.run! <span style="color:#A60">:host</span> =&gt; <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">localhost</span><span style="color:#710">'</span></span>, <span style="color:#A60">:port</span> =&gt; <span style="color:#00D">9090</span>
+</pre></div>
+</div>
+</div>
+
<p>A Sinatra::Base gyermekosztályaiban elérhető metódusok egyúttal a felső
szintű DSL-en keresztül is hozzáférhetők. A legtöbb felső szintű
alkalmazás átalakítható Sinatra::Base alapú komponensekké két lépésben:</p>
@@ -576,8 +803,10 @@
<h2>Parancssori lehetőségek</h2>
<p>Sinatra alkalmazásokat közvetlenül futtathatunk:</p>
-<pre class="highlight text"> ruby myapp.rb [-h] [-x] [-e ENVIRONMENT] [-p PORT] [-s HANDLER]
-</pre>
+
+<pre><code> ruby myapp.rb [-h] [-x] [-e ENVIRONMENT] [-p PORT] [-s HANDLER]
+</code></pre>
+
<p>Az alábbi kapcsolókat ismeri fel a rendszer:</p>
<p>-h # segítség
@@ -593,24 +822,34 @@
készíts egy helyi másolatot és indítsd az alkalmazásodat úgy,
hogy a <code>sinatra/lib</code> könyvtár elérhető legyen a
<code>LOAD_PATH</code>-on:</p>
-<pre class="highlight text"> cd myapp
+
+<pre><code> cd myapp
git clone git://github.com/sinatra/sinatra.git
ruby -Isinatra/lib myapp.rb
-</pre>
+</code></pre>
+
<p>De hozzá is adhatod a <tt>sinatra/lib</tt> könyvtárat a <tt>LOAD_PATH</tt>-hoz
az alkalmazásodban:</p>
-<pre class="highlight ruby"> <span class="vg">$LOAD_PATH</span><span class="nf">.unshift</span> <span class="no">File</span><span class="nf">.dirname</span><span class="p">(</span><span class="kp">__FILE__</span><span class="p">)</span> <span class="o">+</span> <span class="s1">'/sinatra/lib'</span>
- <span class="nb">require</span> <span class="s1">'rubygems'</span>
- <span class="nb">require</span> <span class="s1">'sinatra'</span>
-
- <span class="n">get</span> <span class="s1">'/about'</span> <span class="k">do</span>
- <span class="s2">"A következő változatot futtatom "</span> <span class="o">+</span> <span class="no">Sinatra</span><span class="o">::</span><span class="no">VERSION</span>
- <span class="k">end</span>
-</pre>
+
+<div>
+<div class="CodeRay">
+ <div class="code"><pre> <span style="color:#d70">$LOAD_PATH</span>.unshift <span style="color:#036;font-weight:bold">File</span>.dirname(<span style="color:#069">__FILE__</span>) + <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/sinatra/lib</span><span style="color:#710">'</span></span>
+ require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">rubygems</span><span style="color:#710">'</span></span>
+ require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">sinatra</span><span style="color:#710">'</span></span>
+
+ get <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">/about</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
+ <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">A következő változatot futtatom </span><span style="color:#710">"</span></span> + <span style="color:#036;font-weight:bold">Sinatra</span>::<span style="color:#036;font-weight:bold">VERSION</span>
+ <span style="color:#080;font-weight:bold">end</span>
+</pre></div>
+</div>
+</div>
+
<p>A Sinatra frissítését később így végezheted el:</p>
-<pre class="highlight text"> cd myproject/sinatra
+
+<pre><code> cd myproject/sinatra
git pull
-</pre>
+</code></pre>
+
<a name='Tov%C3%A1bbi%20inform%C3%A1ci%C3%B3k'></a>
<h2>További információk</h2>
@@ -618,13 +857,14 @@
<li>
<a href="http://sinatra.github.com/">A projekt weboldala</a> - Kiegészítő dokumentáció,
hírek, hasznos linkek</li>
-<li>
+ <li>
<a href="http://sinatra.github.com/contributing.html">Közreműködés</a> - Hibát találtál?
Segítségre van szükséged? Foltot küldenél be?</li>
-<li>
+ <li>
<a href="http://sinatra.lighthouseapp.com">Lighthouse</a> - Hibakövetés és kiadások</li>
-<li><a href="http://twitter.com/sinatra">Twitter</a></li>
-<li><a href="http://groups.google.com/group/sinatrarb">Levelezőlista</a></li>
-<li>[IRC: #sinatra](irc://chat.freenode.net/#sinatra) a http://freenode.net címen</li>
+ <li><a href="http://twitter.com/sinatra">Twitter</a></li>
+ <li><a href="http://groups.google.com/group/sinatrarb">Levelezőlista</a></li>
+ <li>
+<a href="irc://chat.freenode.net/#sinatra">IRC: #sinatra</a> a http://freenode.net címen</li>
</ul>
</body></html>
View
622 _includes/README.jp.html
@@ -67,16 +67,20 @@
本文書は英語から翻訳したものであり、その内容が最新でない場合もあります。最新の情報はオリジナルの英語版を参照して下さい。</em></p>
<p><a href="http://ja.wikipedia.org/wiki/%E3%83%89%E3%83%A1%E3%82%A4%E3%83%B3%E5%9B%BA%E6%9C%89%E8%A8%80%E8%AA%9E">DSL</a>です。</p>
-<pre class="highlight text"># myapp.rb
+
+<pre><code># myapp.rb
require 'sinatra'
get '/' do
'Hello world!'
end
-</pre>
+</code></pre>
+
<p>gemをインストールして動かしてみる。</p>
-<pre class="highlight text">gem install sinatra
+
+<pre><code>gem install sinatra
ruby myapp.rb
-</pre>
+</code></pre>
+
<p><a href="http://localhost:4567">localhost:4567</a> を見る。</p>
<a name='%E3%83%AB%E3%83%BC%E3%83%88'></a>
@@ -84,7 +88,8 @@
<p>Sinatraでは、ルートはHTTPメソッドとURLマッチングパターンがペアになっています。
ルートはブロックに結び付けられています。</p>
-<pre class="highlight text">get '/' do
+
+<pre><code>get '/' do
.. 何か見せる ..
end
@@ -99,26 +104,32 @@
delete '/' do
.. 何か削除する ..
end
-</pre>
+</code></pre>
+
<p>ルートは定義された順番にマッチします。
リクエストに最初にマッチしたルートが呼び出されます。</p>
<p>ルートのパターンは名前付きパラメータを含むことができ、
<code>params</code>ハッシュで取得できます。</p>
-<pre class="highlight text">get '/hello/:name' do
+
+<pre><code>get '/hello/:name' do
# matches "GET /hello/foo" and "GET /hello/bar"
# params[:name] is 'foo' or 'bar'
"Hello #{params[:name]}!"
end
-</pre>
+</code></pre>
+
<p>また、ブロックパラメータで名前付きパラメータにアクセスすることもできます。</p>
-<pre class="highlight text">get '/hello/:name' do |n|
+
+<pre><code>get '/hello/:name' do |n|
"Hello #{n}!"
end
-</pre>
+</code></pre>
+
<p>ルートパターンはsplat(またはワイルドカード)を含むこともでき、
<code>params[:splat]</code> で取得できます。</p>
-<pre class="highlight text">get '/say/*/to/*' do
+
+<pre><code>get '/say/*/to/*' do
# matches /say/hello/to/world
params[:splat] # =&gt; ["hello", "world"]
end
@@ -127,36 +138,46 @@
# matches /download/path/to/file.xml
params[:splat] # =&gt; ["path/to/file", "xml"]
end
-</pre>
+</code></pre>
+
<p>ブロックパラーメータを使用した場合:</p>
-<pre class="highlight text">get '/download/*.*' do |path, ext|
+
+<pre><code>get '/download/*.*' do |path, ext|
[path, ext] # =&gt; ["path/to/file", "xml"]
end
-</pre>
+</code></pre>
+
<p>正規表現を使ったルート:</p>
-<pre class="highlight text">get %r{/hello/([\w]+)} do
+
+<pre><code>get %r{/hello/([\w]+)} do
"Hello, #{params[:captures].first}!"
end
-</pre>
+</code></pre>
+
<p>ブロックパラーメータを使用した場合:</p>
-<pre class="highlight text">get %r{/hello/([\w]+)} do |c|
+
+<pre><code>get %r{/hello/([\w]+)} do |c|
"Hello, #{c}!"
end
-</pre>
+</code></pre>
+
<a name='%E6%9D%A1%E4%BB%B6'></a>
<h3>条件</h3>
<p>ルートにはユーザエージェントのようなさまざまな条件を含めることができます。</p>
-<pre class="highlight text">get '/foo', :agent =&gt; /Songbird (\d\.\d)[\d\/]*?/ do
+
+<pre><code>get '/foo', :agent =&gt; /Songbird (\d\.\d)[\d\/]*?/ do
"You're using Songbird version #{params[:agent][0]}"
end
get '/foo' do
# Matches non-songbird browsers
end
-</pre>
+</code></pre>
+
<p>ほかに<code>host_name</code>と<code>provides</code>条件が利用可能です:</p>
-<pre class="highlight text">get '/', :host_name =&gt; /^admin\./ do
+
+<pre><code>get '/', :host_name =&gt; /^admin\./ do
"Admin Area, Access denied!"
end
@@ -167,9 +188,11 @@
get '/', :provides =&gt; ['rss', 'atom', 'xml'] do
builder :feed
end
-</pre>
+</code></pre>
+
<p>独自の条件を定義することも簡単にできます:</p>
-<pre class="highlight text">set(:probability) { |value| condition { rand &lt;= value } }
+
+<pre><code>set(:probability) { |value| condition { rand &lt;= value } }
get '/win_a_car', :probability =&gt; 0.1 do
"You won!"
@@ -178,7 +201,8 @@
get '/win_a_car' do
"Sorry, you lost."
end
-</pre>
+</code></pre>
+
<a name='%E6%88%BB%E3%82%8A%E5%80%A4'></a>
<h3>戻り値</h3>
@@ -190,21 +214,25 @@
妥当なオブジェクトであればどのようなオブジェクトでも返すことができます:</p>
<p>そのように、例えばストリーミングの例を簡単に実装することができます:</p>
-<pre class="highlight text">class Stream
+
+<pre><code>class Stream
def each
100.times { |i| yield "#{i}\n" }
end
end
get('/') { Stream.new }
-</pre>
+</code></pre>
+
<a name='%E9%9D%99%E7%9A%84%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB'></a>
<h2>静的ファイル</h2>
<p>静的ファイルは<code>./public</code>ディレクトリから配信されます。
<code>:public_folder</code>オプションを指定することで別の場所を指定することができます。</p>
-<pre class="highlight text">set :public_folder, File.dirname(__FILE__) + '/static'
-</pre>