Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work with Sinatra #17

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

Conversation

a2ikm
Copy link
Contributor

@a2ikm a2ikm commented Mar 21, 2013

To enable ActiveDecorator in Sinatra, register it like:

require "active_decorator/sinatra"
register ActiveDecorator::Sinatra

Then ActiveDecorator::Sinatra reads ROOT/decorators/*_decorator.rb,
and decorates instance variables in scope and local variables passed
via render method with them.

The ROOT/decorators directory is used by default. If you want to use
another directory, you can set it as :decorators like:

require "active_decorator/sinatra"
set :decorators, "/path/to/your/decorators"
register ActiveDecorator::Sinatra

ActiveDecorator::Sinatra doesn't decorate following instance variables
by default:

@default_layout @env @params @preferred_extension
@request @response @template_cache

These are declared in an array named as
ActiveDecorator::Sinatra::DEFAULT_PROTECTED_INSTANCE_VARIABLES. If you
want to protect other instance variables, you can declare them as
:protected_instance_variables like:

require "active_decorator/sinatra"
set :protected_instance_variables, %w[@foo @bar]
register ActiveDecorator::Sinatra

Note that these set statements must be placed before the register
statement.

Specs for Sinatra run with the fllowing command:

`BUNDLER_GEMFILE=gemfiles/Gemfile-sinatra bundle exec rake spec:sinatra`

Sinatra doesn't support implicit object rendering (like render @author),
so features about this won't tested in the partial spec. This switching
is made with rails? method decrared in spec_helper.rb.

To enable ActiveDecorator in Sinatra, register it like:

    require "active_decorator/sinatra"
    register ActiveDecorator::Sinatra

Then ActiveDecorator::Sinatra reads `ROOT/decorators/*_decorator.rb`,
and decorates instance variables in `scope` and local variables passed
via `render` method with them.

The `ROOT/decorators` directory is used by default. If you want to use
another directory, you can set it as `:decorators` like:

    require "active_decorator/sinatra"
    set :decorators, "/path/to/your/decorators"
    register ActiveDecorator::Sinatra

ActiveDecorator::Sinatra doesn't decorate following instance variables
by default:

    @default_layout @env @params @preferred_extension
    @request @response @template_cache

These are declared in an array named as
`ActiveDecorator::Sinatra::DEFAULT_PROTECTED_INSTANCE_VARIABLES`. If you
want to protect other instance variables, you can declare them as
`:protected_instance_variables` like:

    require "active_decorator/sinatra"
    set :protected_instance_variables, %w[@foo @bar]
    register ActiveDecorator::Sinatra

Note that these `set` statements must be placed before the `register`
statement.
It runs with the fllowing command:

  `BUNDLER_GEMFILE=gemfiles/Gemfile-sinatra bundle exec rake spec:sinatra`

Sinatra doesn't support implicit object rendering (like `render @author`),
so features about this won't tested in the partial spec. This switching
is made with `rails?` method decrared in spec_helper.rb.
activesupport gem isn't installed with Sinatra by default.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant