RevelryContent
===
RevelryContent is a gem for managing admin-editable content within Rails applications.
# Installation
Add it to your gemfile.
Then run:
```bash
bundle install
rails g revelry_content:install
rake db:migrate
```
Mount the engine in your routes.rb file:
```ruby
mount RevelryContent::Engine => "/revelry_content"
```
Include RevelryContent::WithRevelryContent in any controllers which need to show editable
content. You probably want to include it in ApplicationController like so:
```ruby
class ApplicationController
include RevelryContent::WithRevelryContent
def index; end
end
```
And include the editor javascript:
```javascript
//= require revelry_content
```
Add include the editor stylesheet:
```css
/*
*= require revelry_content/application
*/
```
# Configuration
## Configuring authentication
```ruby
RevelryContent.configure do |config|
config.user_for_content do |controller|
# Your authentication logic here
controller.current_user
end
end
```
## Configuring authorization
You can set a block which takes two params `user` and `content` to handle authorization.
True is authorized, false is unauthorized.
```ruby
RevelryContent.configure do |config|
config.authorization_policy do |user|
# Your authorization logic here
user.admin?
end
end
```
## Configuring file uploads
RevelryContent uses [carrierwave](https://github.com/carrierwaveuploader/carrierwave) to store image uploads. You'll want to configure carrierwave appropriately for your app.
# Use in ERB Templates
RevelryContent provides helpers for setting up edit controls:
### Adding the RevelryContent menus and edit mode button
Add the `revelry_content/contents/menus` partial to the page to place the edit button and top bar on the page. The top bar will be invisible unless we are in edit mode.
```erb
<%= render 'revelry_content/contents/menus' %>
```
### Editable text
```erb
<%= revelry_content_text('home.title', default: 'Hello, World!') %>
```
`lookup` is a lookup hash of the available content. If you have included `RevelryContent::WithRevelryContent` in your controller, `@revelry_content_contents` is the default lookup with all content.
In this case `'home.headline'` is the content key of the content, which is just a unique string for each piece of changeable content.
The `default` param is what is shown if know one has set any content yet.
(Think brand-new sites.)
### Editable images
Editable images work in a similar manner to editable text:
```erb
<%= revelry_content_image('home.image', default: 'http://placehold.it/200x200') %>
```
Here, `home.image` is the content key for the image to display, and `default` provides a placeholder image URL.
# Using in JavaScript (including React)
## Making content available to JavaScript
You can configure RevelryContent to export all of your content into javascript.
```ruby
RevelryContent.configure do |config|
config.js_export = true
end
```
Then run the export task:
```shell
rake revelry_content:export_js
```
And include the exported js in your application.js:
```javascript
//= require revelry_content/content
```
and access it like this:
```javascript
RevelryContent.Content.home.headline
```
The JavaScript export will automatically update whenever content is updated.
## Adding Editable Sections with React
RevelryContent is built on React, so you can also directly invoke the React components:
```coffeescript
```
or
```coffeescript
```
[More details are availble here](https://github.com/revelrylabs/revelry_content/blob/master/react-components.md)
## Adding the top bar and buttons with React
```coffeescript
```
and
```coffeescript
```
These do not require any props.