README.md in revelry_content-0.0.0 vs README.md in revelry_content-0.0.1

- old
+ new

@@ -1,7 +1,178 @@ -# revelry_content +RevelryContent +=== -Coming soon. -Not in that way that people say "coming soon" as some sort of teaser. -Coming soon as in the code exists already. -We're actively prepping it to go in this repo. -Something substantive should show up here within a few days, maybe a couple weeks at most. +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 +<%= editable_text(lookup, t, user) %> +``` + +`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. + +`t` is the content key of the content, which is just a unique string for each piece of changeable content. + +`user` is the user to give to the authorization policy. With devise, this is often `current_user`. + +So for, an editable homepage headline, with the standard lookup and +`current_user` as the user, you would invoke the helper like this: + +```erb +<%= editable_text(@revelry_contents_content, 'home.headline', current_user, default_text: 'Lorem ipsum') %> +``` + +### Editable images + +Editable images work in a similar manner to editable text: + +```erb +<%= editable_image(@revelry_contents_content, 'home.image', current_user, default_url: 'http://placehold.it/200x200') %> +``` + +# 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 +<RevelryContent.EditableText canEdit={ true } content={ RevelryContent.Content.home.headline } /> +``` + +or + +```coffeescript +<RevelryContent.EditableImage canEdit={ true } content={ RevelryContent.Content.home.image } /> +``` + +[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 +<RevelryContent.TopBar /> +``` + +and + +```coffeescript +<RevelryContent.EditModeButton /> +``` + +These do not require any props.