Git Product home page Git Product logo

sinatra-contrib's Introduction

NOTE: This project has been merged upstream to sinatra/sinatra

The tree will be merged upstream, including commit history.

For specific file history, please refer to the pre-merge branch here.

To use this gem from the upstream repository, you can add the following to your Gemfile:

github 'sinatra/sinatra' do
  gem 'sinatra-contrib'
end

For more info check the official docs and api docs.

sinatra-contrib's People

Contributors

apotonick avatar ashleygwilliams avatar benders avatar dinduks avatar dtaniwaki avatar foca avatar gnandretta avatar kamui avatar kgrz avatar kytrinyx avatar lest avatar license2e avatar lukateras avatar micahredding avatar mono0x avatar ortuna avatar patriciomacadden avatar petedmarsh avatar r7kamura avatar rafmagana avatar rkh avatar shime avatar stjhimy avatar thibautsacreste avatar trevorbramble avatar udzura avatar undr avatar vipulnsward avatar willbailey avatar yesmeck avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sinatra-contrib's Issues

content_for? helper

...to check if a block is already defined. Rails has this, by the way, and it is quite useful in my experience.

Something like:

    def content_for?(key)
      content_blocks[key.to_sym].any?
    end

ContentFor ArgumentError: recursive array join

I tried out the ContentFor extension, but it seems to crash with an ArgumentError: recursive array join

It seems easy to reproduce, I created two files under /views:

\ test1.slim
= yield
== yield_content :test
\ test2.slim
p test2
- content_for :test do
  p test1

Then from my app.rb:

get "\test" do
  slim :test2, layout: :test1
end

Removing content_for or yield_content makes the page render without errors.

This is running on thin (1.5.0) through foreman.

register RespondWith is not inherited

require "sinatra/base"
require "sinatra/respond_with"
require "erb"

class Base < Sinatra::Base
  register Sinatra::RespondWith
end

class App < Base

  enable  :inline_templates
  enable  :raise_errors
  disable :show_exceptions

  get "/" do
    respond_with(:home)
  end
end

require "minitest/autorun"
require "rack/test"

class AppTest < MiniTest::Unit::TestCase
  include Rack::Test::Methods

  def app
    App
  end

  def test_respond_with_inheritance
    assert_raises(NoMethodError) { get("/") }
  end
end

__END__
@@home
<h1>hello, world!</h1>

Sinatra::JSON fails on timestamps

hi,

As mentioned in the title Sinatra::JSON doesn't really like time objects. To reproduce just do json ({:t => Time.now}) at any point. It will throw a TypeError can't convert nil into String. Wouldn't it be a more robust solution to simply use Ruby's JSON support?

Johnny.

Verbose logging extension

I'm working on a verbose logging extension (see https://github.com/sinatra/sinatra-contrib/blob/master/ideas.md).

I'm thinking in something like:

== Sinatra/1.4.2 has taken the stage on 4567 for development with backup from Thin
>> Thin web server (v1.5.1 codename Straight Razor)
>> Maximum connections set to 1024
>> Listening on localhost:4567, CTRL+C to stop
I, [2013-03-28T17:46:04.715636 #4427]  INFO -- : passing through static!
I, [2013-03-28T17:46:04.715986 #4427]  INFO -- : passing through a before filter
I, [2013-03-28T17:46:04.716031 #4427]  INFO -- : passing through a before filter
I, [2013-03-28T17:46:04.716086 #4427]  INFO -- : passing through route!
I, [2013-03-28T17:46:04.716170 #4427]  INFO -- : passing through a after filter
I, [2013-03-28T17:46:04.716201 #4427]  INFO -- : passing through a after filter
127.0.0.1 - - [28/Mar/2013 17:46:04] "GET / HTTP/1.1" 200 11 0.0121
I, [2013-03-28T17:46:04.855699 #4427]  INFO -- : passing through static!
I, [2013-03-28T17:46:04.855918 #4427]  INFO -- : passing through a before filter
I, [2013-03-28T17:46:04.855991 #4427]  INFO -- : passing through a before filter
I, [2013-03-28T17:46:04.856076 #4427]  INFO -- : passing through route!
I, [2013-03-28T17:46:04.856140 #4427]  INFO -- : passing through route!
I, [2013-03-28T17:46:04.856543 #4427]  INFO -- : passing through a after filter
I, [2013-03-28T17:46:04.856585 #4427]  INFO -- : passing through a after filter
127.0.0.1 - - [28/Mar/2013 17:46:04] "GET /favicon.ico HTTP/1.1" 404 448 0.0018

Does someone have any extra idea for this extension?

Sinatra::Namespace does not prefix redirect() nor url()

I would expect the redirects to be prefixed like the routes.

namespace '/admin' do
    get '/a' do
        redirect '/b'  # is not redirecting to '/admin/b' but to '/b'
    end

    get '/a' do
        redirect to('/b')  # is not redirecting to '/admin/b' but to '/b'
    end
 end

:prefixed_redirects raises an error

namespace '/admin' do
    enable :prefixed_redirects
    get '/somewhere'
 end

 # => may not set prefixed_redirects (ArgumentError)

I don't know where this should be fixed

module Sinatra::Namespace::NamespacedMethods
    prefixed :to
end

didn't help either.

respond_with: intermittent failure to assign local variables

I have the following controller code:

get '/' do
respond_with :'collections/index', collections: Collection.all
end

Every nth refresh I get the following error, indicating that the variable collections is not assigned. I can confirm that the database is being hit for Collection.all. Unicorn is throwing an error. I looked around and could find similar references. I am running 1.9.3. I don't know if this is a compatibility issue or something Unicorn-specific.

1/22/12 10:16:21.722 PM org.bogomips.unicorn    NameError - undefined local variable or method `collections' for #<Collections:0x007fcfad4754a8>:
1/22/12 10:16:21.722 PM org.bogomips.unicorn        /usr/local/www/foo.bar/views/collections/index.slim:10:in `block in singletonclass'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/views/collections/index.slim:in `instance_eval'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/views/collections/index.slim:in `singletonclass'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/views/collections/index.slim:65534:in `__tilt_70264952098100'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/tilt-           1.3.3/lib/tilt/template.rb:140:in `call'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/tilt-    1.3.3/lib/tilt/template.rb:140:in `cached_evaluate'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/tilt-1.3.3/lib/tilt/template.rb:127:in `evaluate'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/tilt-1.3.3/lib/tilt/template.rb:76:in `render'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:636:in `render'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:590:in `slim'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/sinatra-contrib-1.3.1/lib/sinatra/respond_with.rb:142:in `block in respond_with'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/sinatra-contrib-1.3.1/lib/sinatra/respond_with.rb:113:in `call'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/sinatra-contrib-1.3.1/lib/sinatra/respond_with.rb:113:in `block in finish'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/sinatra-contrib-1.3.1/lib/sinatra/respond_with.rb:112:in `each'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/sinatra-contrib-1.3.1/lib/sinatra/respond_with.rb:112:in `finish'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/sinatra-contrib-1.3.1/lib/sinatra/respond_with.rb:154:in `respond_with'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/collections.rb:36:in `block in <class:Collections>'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:1212:in `call'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:1212:in `block in compile!'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:785:in `[]'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:785:in `block (3 levels) in route!'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:801:in `route_eval'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:785:in `block (2 levels) in route!'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:822:in `block in process_route'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:820:in `catch'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:820:in `process_route'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:784:in `block in route!'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:783:in `each'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:783:in `route!'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:886:in `dispatch!'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:719:in `block in call!'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:871:in `block in invoke'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:871:in `catch'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:871:in `invoke'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:719:in `call!'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:705:in `call'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/rack-ssl-enforcer-0.2.4/lib/rack/ssl-enforcer.rb:36:in `call'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/rack-protection-1.2.0/lib/rack/protection/xss_header.rb:22:in `call'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/rack-protection-1.2.0/lib/rack/protection/path_traversal.rb:16:in `call'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/rack-protection-1.2.0/lib/rack/protection/json_csrf.rb:17:in `call'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/rack-protection-1.2.0/lib/rack/protection/base.rb:47:in `call'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/rack-protection-1.2.0/lib/rack/protection/xss_header.rb:22:in `call'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/rack-1.4.0/lib/rack/nulllogger.rb:9:in `call'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/rack-1.4.0/lib/rack/head.rb:9:in `call'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:1334:in `block in call'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:1416:in `synchronize'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:1334:in `call'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/rack-1.4.0/lib/rack/builder.rb:134:in `call'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/rack-1.4.0/lib/rack/urlmap.rb:64:in `block in call'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/rack-1.4.0/lib/rack/urlmap.rb:49:in `each'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/rack-1.4.0/lib/rack/urlmap.rb:49:in `call'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/warden-1.1.0/lib/warden/manager.rb:35:in `block in call'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/warden-1.1.0/lib/warden/manager.rb:34:in `catch'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/warden-1.1.0/lib/warden/manager.rb:34:in `call'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/rack-cache-1.1/lib/rack/cache/context.rb:132:in `forward'
1/22/12 10:16:21.723 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/rack-cache-1.1/lib/rack/cache/context.rb:241:in `fetch'
1/22/12 10:16:21.724 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/rack-cache-1.1/lib/rack/cache/context.rb:181:in `lookup'
1/22/12 10:16:21.724 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/rack-cache-1.1/lib/rack/cache/context.rb:65:in `call!'
1/22/12 10:16:21.724 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/rack-cache-1.1/lib/rack/cache/context.rb:50:in `call'
1/22/12 10:16:21.724 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/rack-1.4.0/lib/rack/session/abstract/id.rb:205:in `context'
1/22/12 10:16:21.724 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/rack-1.4.0/lib/rack/session/abstract/id.rb:200:in `call'
1/22/12 10:16:21.724 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/rack-1.4.0/lib/rack/methodoverride.rb:21:in `call'
1/22/12 10:16:21.724 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/unicorn-4.1.1/lib/unicorn/http_server.rb:528:in `process_client'
1/22/12 10:16:21.724 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/unicorn-4.1.1/lib/unicorn/http_server.rb:600:in `worker_loop'
1/22/12 10:16:21.724 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/unicorn-4.1.1/lib/unicorn/http_server.rb:485:in `spawn_missing_workers'
1/22/12 10:16:21.724 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/unicorn-4.1.1/lib/unicorn/http_server.rb:135:in `start'
1/22/12 10:16:21.724 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/gems/unicorn-4.1.1/bin/unicorn:121:in `<top (required)>'
1/22/12 10:16:21.724 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/bin/unicorn:19:in `load'
1/22/12 10:16:21.724 PM org.bogomips.unicorn        /usr/local/www/foo.bar/vendor/bundle/ruby/1.9.1/bin/unicorn:19:in `<main>'

Separate Sinatra::Streaming (or lazy depend on eventmachine)

Hello,

This request might sound weird, but sinatra-contrib gem dependency on eventmachine causes issues with Ruby 1.9.x (1.9.2 and 1.9.3) under Windows.

Users trying to use Sinatra::Reloader during development add sinatra-contrib gem, which depends on eventmachine >= 0

This results in attempt to install latest stable gem (0.12.10) which has known issues under Windows (ala: does not compile).

After lurking on the internet for answers, end installing eventmachine 1.0.0.beta.4.1 (using --pre during gem install) but for some, under some weird circumstances with Bundler, dependencies are not met and it attempts to install eventmachine 0.12.10, again resulting in failure.

I believe is caused by installation on different GEM_PATH than GEM_HOME, but need more investigation.

May I suggest change sinatra/streaming.rb requires and remove runtime dependency on eventmachine?

require 'sinatra/base'
begin
  require 'eventmachine'
rescue LoadError
  abort 'EventMachine is required to use Sinatra::Streaming. Please `gem install eventmachine` first.'
end
require 'backports'

Thank you

Sinatra::Namespace doesn't seem to work

First off, I'm sorry I can't give you more context or (even better) provide a pull request. I haven't had any luck getting any more detail or information about what's going on and understanding the source for the namespace module is a little beyond me (I've tried :/).

That said, I can't seem to get namespace to work at all outside of a contrived, single Ruby file. I have a main controller file that does a require of another file with this:

# Gemfile
gem 'sinatra'
gem 'sinatra-flash', require: 'sinatra/flash'
gem 'sinatra-contrib', require: 'sinatra/contrib'

# controller.rb
Dir.glob('./**/*.rb') do |file|
  require file.gsub(/\.rb/, '')
end

get '/' do
  erb 'pages/home'
end

# sessions.rb
namespace '/login' do
  get do
    "oh hey"
  end
end

When I go to '/login' I get a "Sinatra doesn't know that ditty" 404. I'm on Sinatra 1.3.2, Sinatra-contrib 1.3.1 on Ruby 1.9.3-p125.

content_for w/ slim

I'm not sure if I should be posting this here or on the Slim repo, but content_for is broken using this templating engine.

Test Case

app.rb:

require 'slim'
require 'haml'
require 'sinatra/base'
require 'sinatra/content_for'

class Main < Sinatra::Base

  helpers Sinatra::ContentFor

  get '/' do
    slim :test
  end

end

views/layout.slim:

html
  head
    meta charset='utf8'
    title test
  body
    == yield
    == yield_content :test

views/test.slim

- content_for :test do
  test content

h1 page title

h2 page subtitle

... the block return isn't working correctly, it sends the entire template. Using = content_for works, but since that returns a proc, it prints #[<Proc... on the page where you've defined the content block.

1.3.2 isn’t tagged

The current release on Rubygems is version 1.3.2, but there is no corresponding git tag in the repo.

Can we have the tag pushed?

Reloading of Inline templates is not working

The title says it all. The minimal code for trying it out is here: http://paste.pocoo.org/show/491320

Update: Seems it's all a matter of set(:inline_templates, file) being triggered when requiring sinatra before the hooks are in place. Requiring sinatra/reloader (which requires sinatra/base) before requiring sinatra solves the issue, however I wonder if it should be that way....

#31 still exists

[#31]

require 'sinatra/base' # as per comment https://github.com/sinatra/sinatra-contrib/issues/23#issuecomment-2791295
require 'sinatra/reloader'

class MyServer < ::Sinatra::Base
  register Sinatra::Reloader
  enable :reloader

  get '/' do
    "hello"
  end
end

MyServer.run!

Still causes an error after I changed "hello" to "hello world".

>> Listening on 0.0.0.0:4567, CTRL+C to stop
RuntimeError - no acceptor:
    /home/raincole/.rvm/gems/ruby-1.9.3-p125/gems/eventmachine-0.12.10/lib/eventmachine.rb:572:in `start_tcp_server'
    /home/raincole/.rvm/gems/ruby-1.9.3-p125/gems/eventmachine-0.12.10/lib/eventmachine.rb:572:in `start_server'
    /home/raincole/.rvm/gems/ruby-1.9.3-p125/gems/thin-1.3.1/lib/thin/backends/tcp_server.rb:16:in `connect'
    /home/raincole/.rvm/gems/ruby-1.9.3-p125/gems/thin-1.3.1/lib/thin/backends/base.rb:53:in `block in start'

I'm using 1.3.2.

Sinatra::Namespace does not bubble errors

In this example:

class TestApp < Sinatra::Base
  register Sinatra::Namespace

  error 500 do
    'root error page'
  end

  get '/bar' do
    halt 500
  end

  namespace '/foo' do
    get '/bar' do
      halt 500
    end
  end

  run! if app_file == $0
end

Accessing /bar renders root error page, yet accessing /foo/bar does not.

It would be nice if halts would bubble up the namespaces until they were handled by an appropriate error block.

ContentFor & Encoding::CompatibilityError

Having an issue when using UTF8 chars in both layout and child templates with contrib's ContentFor.
Example:

app.rb:

require 'rubygems'
require 'sinatra/base'
require 'sinatra/content_for'

class App < Sinatra::Base
  register Sinatra::ContentFor

  set :views, File.dirname(__FILE__) + '/views'

  get '/' do
    erb :index
  end
end

index.erb:

<% content_for :body do %><% end %>

layout.erb:

<h1>The – Header</h1>
<%= yield_content :body %>

When the is present in both the layout and child template, I get the Encoding::CompatibilityError incompatible character encodings: UTF-8 and US-ASCII error. If only one (or none) of the templates has the , it renders fine. Both templates are separate files saved in UTF8 encoding, and adding the magic comment #encoding: utf-8 doesn't help.

Additionally, if I use the SinatraContentFor2 gem, the same scenario works without an issue. Is there some 1.9.2 incompatibility in the current implementation?

Martin

Logic correction for ConfigFile#config_for_env(hash)

Original Logic

if hash.respond_to? :keys and hash.keys.all? { |k| environments.include? k.to_s }
    hash = hash[environment.to_s] || hash[environment.to_sym]
end

Problem

This doesn't allow me (for example) to create a common: &common_settings block to include in my environments via YAML alias *common_settings because the logic is looking to see if the set of keys in the YAML file are ALL included in the set of environments. Since the set of environments doesn't include common, the logic fails and never loads the environment-specific settings. The solution is simple, though. Reverse the logic -- don't look for all keys in environments, look for all environments in keys.

Corrected Logic

if hash.respond_to? :keys and environments.all? { |e| hash.keys.collect(&:to_s).include? e.to_s }
    hash = hash[environment.to_s] || hash[environment.to_sym]
end

Now, I can use any additional setting block in my YAML file and my environment-specific settings will all load (provided they're all defined in the config file).

respond_with mutates template cache results, crashing subsequent requests

Running sinatra 1.3.3 and sinatra-contrib 1.3.1, with slim template, in production environment, using the following route:

get '/' do
  respond_with :index
end

If I reload after making my first request my application starts raising errors, claiming too many arguments to render. I believe this is because of template_cache is modified after every request at line 141 in the current release: https://github.com/sinatra/sinatra-contrib/blob/v1.3.1/lib/sinatra/respond_with.rb#L141

It fetches something from the template cache, and adds on locals to the cached template arguments for every request.

Using = instead of == in conditional

There's a bug in respond_with.rb:

sinatra-contrib-1.3.1/lib/sinatra/respond_with.rb:148 warning: Found '=' in conditional, should be '=='.

I'll fork and make a pull request soon.

sinatra-reloader doesn't play nicely with filters defined in multiple files

Sinatra runs filters in the order that they are defined. If you define your filters in multiple files, then typically you just need to make sure that they are required in the correct order and then you're golden. However, with sinatra-reloader, if you modify a file which defines a filter and it is reloaded, that filter will now be run at the end of the filters.

Concrete example: suppose you have before filters A and B defined in a.rb and b.rb, respectively. They assume that they are run in that order (A then B) and so a.rb is required before b.rb. If you modify a.rb, it will be reloaded and now when you make a request, B will be run before A.

Is there a known workaround for this or a good approach for mitigating this kind of problem in development?

Encoding issue in capture (erb)

This is based on issue #17 (see the original issue for a full description):

Having an issue when using UTF8 chars in both layout and child templates with contrib's ContentFor.

The erb templates have trouble capturing UTF-8 encoded content. This might also be relevant to other encodings.

This received a workaround in pull request #21.

This needs to be investigated more closely to find the root cause of the issue.

Deprecate Sinatra::Reloader

See: http://travis-ci.org/#!/TrevorBramble/sinatra-contrib/jobs/852727

This appears to actually be a spec failure due to how we're writing and loading temporary app files for these specs; a simple example app with sinatra/reloader required don't fall over.

Failure output extract:

51  1) Sinatra::Reloader automatically registers the reloader in the subclasses
52     Failure/Error: get('/foo').body.should == 'bar'
53       expected: "bar"
54            got: "foo" (using ==)
55     # ./spec/reloader_spec.rb:438:in `__script__'
56     # kernel/common/eval19.rb:45:in `instance_eval'
57     # kernel/bootstrap/array19.rb:18:in `map'
58     # kernel/bootstrap/array19.rb:18:in `map'

sinatra/content-for renders twice?

Hi!

I don't really know how to tell what's happening with sinatra/content_for, so I'll just put the code here:

#views/layout.slim
doctype 5
html
  head
    title 
      | Personal Page
      - title = yield_content(:title)
      - unless title.empty?
        |  - 
        =title
  body
    #wrapper
      == yield

When I go to localhost:4567 it renders this file:

#views/index.slim
- content_for :title do 
  | CV

h1 Hello World!

So I think this sould work, but that's what I get:

<!DOCTYPE html>
<html>
<head>
  <title>
    Personal Page - &lt;h1&gt;Hello World!&lt;&#47;h1&gt;CV
  </title>
</head>
<body>
  <div id="wrapper">
    <h1>Hello World!</h1>
    CV
  </div>
</body>
</html>

Which is obviously wrong, because all the content_for parts are rendered twice... Any idea about how to solve it?

Thanks! :)

(you have an example on https://github.com/mrc2407/personal_page/tree/443c3bc78ab4656629967dd5d6e9e979a0388a18)

add docs

This might be split into multiple issues.

Idea: glues for popular gems

A lot of people are averse to the idea of using Sinatra because they like the conveniences that Rails gives them. Perhaps sinatra-contrib can make some of those features available in an easy-to-include way.

For instance:

  • include Compass support in any Sinatra project by simply doing register Sinatra::CompassSupport, which will patch the SASS/SCSS options to take Compass files in consideration.
  • include Sequel support through register Sinatra::SequelSupport -- there's a sinatra-sequel gem right now that is unmaintained and isn't even compatible with MySQL or new Sequel migrations.
  • include I18n support with a simple plugin, as well. This will automatically provide helpers (like t) and read localization YAML files in config/.
  • include Sprockets support with a simple plugin, too. Same with ActiveRecord(?), etc

Would the sinatra-contrib team be interested in these? If I (or other people) were to work on these things, what would the chances of them being merged into the project?

Is loading a config file considered an error?

Just wondering the logic behind using $stderr.puts "loading config file '#{file}'" if logging? and why it doesn't use $stdout or look for logger? It seems like a hack that breaks the whole point of having $stdout and $stderr.

Sinatra::Namespace doesn't respect some settings?

In my main configure block I use:

set :haml, :format => :html5, :ugly => true

When I use the 'haml' helper to render a page for a normal (non-namespaced) route handler, it appears as I'd expect - with the HTML5 doctype and the ugly formatting. But when I use the 'haml' helper in a namespaced route handler, it appears that neither of these options are being respected.

I can work around this by doing haml :template, :format => :html5, :ugly => true in every namespaced route handler, which isn't exactly clean. I've tried using a set :haml line with the same options inside my namespace, but then I get a "may not set haml" error.

Sinatra::Reloader appears broken for modular app

I can't get Sinatra::Reloader to work with a modular app. Example:


require 'sinatra/base' # as per comment https://github.com/sinatra/sinatra-contrib/issues/23#issuecomment-2791295
require 'sinatra/reloader'

class MyServer < ::Sinatra::Base
  register Sinatra::Reloader
  enable :reloader

  get '/' do
    "hello"
  end
end

MyServer.run!

I can start the app and display a page on "localhost:4565/", but when I edit the file and change "hello" to "hello you", it throws a a RuntimeError exception when I attempt to reload the page.


RuntimeError - no acceptor:
    /home/lsiden/.rvm/gems/ruby-1.9.2-p290@accounts/gems/eventmachine-0.12.10/lib/eventmachine.rb:572:in `start_tcp_server'
    /home/lsiden/.rvm/gems/ruby-1.9.2-p290@accounts/gems/eventmachine-0.12.10/lib/eventmachine.rb:572:in `start_server'
    /home/lsiden/.rvm/gems/ruby-1.9.2-p290@accounts/gems/thin-1.3.1/lib/thin/backends/tcp_server.rb:16:in `connect'
    /home/lsiden/.rvm/gems/ruby-1.9.2-p290@accounts/gems/thin-1.3.1/lib/thin/backends/base.rb:53:in `block in start'
    /home/lsiden/.rvm/gems/ruby-1.9.2-p290@accounts/gems/thin-1.3.1/lib/thin/backends/base.rb:59:in `call'
    /home/lsiden/.rvm/gems/ruby-1.9.2-p290@accounts/gems/thin-1.3.1/lib/thin/backends/base.rb:59:in `start'
    /home/lsiden/.rvm/gems/ruby-1.9.2-p290@accounts/gems/thin-1.3.1/lib/thin/server.rb:159:in `start'
    /home/lsiden/.rvm/gems/ruby-1.9.2-p290@accounts/gems/rack-1.4.0/lib/rack/handler/thin.rb:13:in `run'
    /home/lsiden/.rvm/gems/ruby-1.9.2-p290@accounts/gems/sinatra-1.3.2/lib/sinatra/base.rb:1295:in `run!'
    /home/lsiden/projects/accounts/try/try.rb:13:in `<top (required)>'

Sinatra::Extension does not register routes

I realized Sinatra::Extension#method_missing is never called for get, post and alike.

Therefore the method does not get recorded and the routes never set up. Instead of method_missing I'm ending up in define_method of Sinatra::Delegator#get. I'm a little puzzled I must confess?

However, in the documentation it says

"Sinatra::Extension is a mixin that provides some syntactic sugar for your extensions. It allows you to call directly inside your extension module almost any Sinatra::Base method. This means you can use get to define a route, before to define a before filter, set to define a setting, a so on."

Perhaps changes to Sinatra not reflected in sinatra-contrib/extension?

Error building native extension on Windows 7

I have the latest version of DevKit and ran the command gem install sinatra-reloader. Here is the output I go when building the native extension:

Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
ERROR:  Error installing sinatra-reloader:
        ERROR: Failed to build gem native extension.

        C:/Ruby192/bin/ruby.exe extconf.rb
checking for rb_trap_immediate in ruby.h,rubysig.h... no
checking for rb_thread_blocking_region()... yes
checking for inotify_init() in sys/inotify.h... no
checking for __NR_inotify_init in sys/syscall.h... no
checking for writev() in sys/uio.h... no
checking for rb_thread_check_ints()... yes
checking for rb_time_new()... yes
checking for windows.h... yes
checking for winsock.h... yes
checking for main() in -lkernel32... yes
checking for main() in -lrpcrt4... yes
checking for main() in -lgdi32... yes
checking for main() in -lssl... no
creating Makefile

make
C:/Ruby192/bin/ruby -e "puts 'EXPORTS', 'Init_rubyeventmachine'"  > rubyeventmachine-i386-mingw32.def
g++ -I. -IC:/Ruby192/include/ruby-1.9.1/i386-mingw32 -I/C/Ruby192/include/ruby-1.9.1/ruby/backward -I/C/Ruby192/include/
ruby-1.9.1 -I. -DBUILD_FOR_RUBY -DHAVE_RB_THREAD_BLOCKING_REGION -DHAVE_TBR -DHAVE_RB_THREAD_CHECK_INTS -DHAVE_RB_TIME_N
EW -DOS_WIN32 -DHAVE_WINDOWS_H -DHAVE_WINSOCK_H -DWITHOUT_SSL -DHAVE_MAKE_PAIR    -O3 -g -Wextra -Wno-unused-parameter -
Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long   -o binder.o -c binder.c
pp
In file included from project.h:137:0,
                 from binder.cpp:20:
binder.h:35:34: warning: type qualifiers ignored on function return type
In file included from project.h:138:0,
                 from binder.cpp:20:
em.h:91:47: warning: type qualifiers ignored on function return type
em.h:92:76: warning: type qualifiers ignored on function return type
em.h:93:56: warning: type qualifiers ignored on function return type
em.h:95:57: warning: type qualifiers ignored on function return type
em.h:96:60: warning: type qualifiers ignored on function return type
em.h:97:58: warning: type qualifiers ignored on function return type
em.h:98:55: warning: type qualifiers ignored on function return type
em.h:99:36: warning: type qualifiers ignored on function return type
em.h:101:47: warning: type qualifiers ignored on function return type
em.h:106:42: warning: type qualifiers ignored on function return type
em.h:123:45: warning: type qualifiers ignored on function return type
em.h:132:36: warning: type qualifiers ignored on function return type
In file included from project.h:145:0,
                 from binder.cpp:20:
eventmachine.h:45:61: warning: type qualifiers ignored on function return type
eventmachine.h:46:112: warning: type qualifiers ignored on function return type
eventmachine.h:47:69: warning: type qualifiers ignored on function return type
eventmachine.h:49:73: warning: type qualifiers ignored on function return type
eventmachine.h:62:75: warning: type qualifiers ignored on function return type
eventmachine.h:63:74: warning: type qualifiers ignored on function return type
eventmachine.h:64:77: warning: type qualifiers ignored on function return type
eventmachine.h:65:41: warning: type qualifiers ignored on function return type
In file included from project.h:145:0,
                 from binder.cpp:20:
eventmachine.h:99:60: warning: type qualifiers ignored on function return type
eventmachine.h:100:58: warning: type qualifiers ignored on function return type
eventmachine.h:102:60: warning: type qualifiers ignored on function return type
eventmachine.h:105:41: warning: type qualifiers ignored on function return type
g++ -I. -IC:/Ruby192/include/ruby-1.9.1/i386-mingw32 -I/C/Ruby192/include/ruby-1.9.1/ruby/backward -I/C/Ruby192/include/
ruby-1.9.1 -I. -DBUILD_FOR_RUBY -DHAVE_RB_THREAD_BLOCKING_REGION -DHAVE_TBR -DHAVE_RB_THREAD_CHECK_INTS -DHAVE_RB_TIME_N
EW -DOS_WIN32 -DHAVE_WINDOWS_H -DHAVE_WINSOCK_H -DWITHOUT_SSL -DHAVE_MAKE_PAIR    -O3 -g -Wextra -Wno-unused-parameter -
Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long   -o cmain.o -c cmain.cpp

In file included from project.h:137:0,
                 from cmain.cpp:20:
binder.h:35:34: warning: type qualifiers ignored on function return type
In file included from project.h:138:0,
                 from cmain.cpp:20:
em.h:91:47: warning: type qualifiers ignored on function return type
em.h:92:76: warning: type qualifiers ignored on function return type
em.h:93:56: warning: type qualifiers ignored on function return type
em.h:95:57: warning: type qualifiers ignored on function return type
em.h:96:60: warning: type qualifiers ignored on function return type
em.h:97:58: warning: type qualifiers ignored on function return type
em.h:98:55: warning: type qualifiers ignored on function return type
em.h:99:36: warning: type qualifiers ignored on function return type
em.h:101:47: warning: type qualifiers ignored on function return type
em.h:106:42: warning: type qualifiers ignored on function return type
em.h:123:45: warning: type qualifiers ignored on function return type
em.h:132:36: warning: type qualifiers ignored on function return type
In file included from project.h:145:0,
                 from cmain.cpp:20:
eventmachine.h:45:61: warning: type qualifiers ignored on function return type
eventmachine.h:46:112: warning: type qualifiers ignored on function return type
eventmachine.h:47:69: warning: type qualifiers ignored on function return type
eventmachine.h:49:73: warning: type qualifiers ignored on function return type
eventmachine.h:62:75: warning: type qualifiers ignored on function return type
eventmachine.h:63:74: warning: type qualifiers ignored on function return type
eventmachine.h:64:77: warning: type qualifiers ignored on function return type
eventmachine.h:65:41: warning: type qualifiers ignored on function return type
In file included from project.h:145:0,
                 from cmain.cpp:20:
eventmachine.h:99:60: warning: type qualifiers ignored on function return type
eventmachine.h:100:58: warning: type qualifiers ignored on function return type
eventmachine.h:102:60: warning: type qualifiers ignored on function return type
eventmachine.h:105:41: warning: type qualifiers ignored on function return type
cmain.cpp:98:71: warning: type qualifiers ignored on function return type
cmain.cpp:109:122: warning: type qualifiers ignored on function return type
cmain.cpp:119:79: warning: type qualifiers ignored on function return type
cmain.cpp:129:83: warning: type qualifiers ignored on function return type
cmain.cpp:260:85: warning: type qualifiers ignored on function return type
cmain.cpp:270:84: warning: type qualifiers ignored on function return type
cmain.cpp:280:88: warning: type qualifiers ignored on function return type
cmain.cpp:290:51: warning: type qualifiers ignored on function return type
cmain.cpp:300:70: warning: type qualifiers ignored on function return type
cmain.cpp:320:55: warning: type qualifiers ignored on function return type
cmain.cpp:546:70: warning: type qualifiers ignored on function return type
cmain.cpp:669:68: warning: type qualifiers ignored on function return type
cmain.cpp: In function 'int evma_send_file_data_to_connection(long unsigned int, const char*)':
cmain.cpp:752:6: error: cannot convert 'stat*' to '_stati64*' for argument '2' to 'int _fstati64(int, _stati64*)'
make: *** [cmain.o] Error 1

Reloader doesn't work when sinatra is mounted into Rails application.

Reloader doesn't work when sinatra is mounted into Rails application.

App is mounted this way: mount Api2.new, :at => "/api2"

require 'sinatra/base'
require 'sinatra/reloader'

class Api2 < Sinatra::Base

  configure :development do
    register Sinatra::Reloader
  end

  configure :production do

  end

  get '/hello' do
    "hello 2"
  end
end

Changes will cause "Routing Error"

yield_content not keeping original encoding?

Hi,

I am using content_for in my application. In one of my documents I am using the following character in one of my erb files: '×'.

I have the following declarations in my app:

    Encoding.default_external = Encoding::UTF_8
    Encoding.default_internal = Encoding::UTF_8

All my documents are utf-8. My locale is the following:

LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

Using erb to output stuff seems to be working ok, for example (just for hand-debugging):

<% content_for :messages_and_contents do |file| %>
  <%=erb :'parts/messages'%>
  <%p erb(:'parts/messages').encoding.to_s%>
  <%=erb file%>
  <%p erb(file).encoding.to_s%>
<% end %>

Both output strings to the console give me UTF-8.

Using yield_content seems to break things. For example:

yield_content(:messages_and_contents,file)

...The output string for yield_content is US-ASCII.

Is something wrong on my side or is yield_content at fault here?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.