README.md in xpose-0.1.5 vs README.md in xpose-0.1.6

- old
+ new

@@ -1,17 +1,160 @@ # Xpose +[![Gem Version](https://img.shields.io/gem/v/xpose.svg)](https://rubygems.org/gems/xpose) + +## Presentation + +**Xpose** provides a set of helpers that help you write smaller, cleaner controllers. + ## Installation Add this line to your application's Gemfile: ```ruby gem 'xpose' ``` And then execute: - $ bundle +```shell +bundle install +``` + +## Basic usage + +Here is a basic scaffolded controller in Rails (comments removed): + +```ruby +class ArticlesController < ApplicationController + before_action :set_article, only: [:show, :edit, :update, :destroy] + + def index + @articles = Article.all + end + + def show + end + + def new + @article = Article.new + end + + def edit + end + + def create + @article = Article.new(article_params) + + respond_to do |format| + if @article.save + format.html { redirect_to @article, notice: 'Article was successfully created.' } + format.json { render :show, status: :created, location: @article } + else + format.html { render :new } + format.json { render json: @article.errors, status: :unprocessable_entity } + end + end + end + + def update + respond_to do |format| + if @article.update(article_params) + format.html { redirect_to @article, notice: 'Article was successfully updated.' } + format.json { render :show, status: :ok, location: @article } + else + format.html { render :edit } + format.json { render json: @article.errors, status: :unprocessable_entity } + end + end + end + + def destroy + @article.destroy + respond_to do |format| + format.html { redirect_to articles_url, notice: 'Article was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + def set_article + @article = Article.find(params[:id]) + end + + def article_params + params.require(:article).permit(:name, :content) + end +end +``` + +Here is the Xpose-friendly equivalent: + +```ruby +class ArticlesController < ApplicationController + expose :articles + expose :article + + def index + end + + def show + end + + def new + end + + def create + if article.save + redirect_to article, notice: 'Article was successfully created.' + else + render :new + end + end + + def edit + end + + def update + if article.update(article_params) + redirect_to article, notice: 'Article was successfully updated.' + else + render :edit + end + end + + def destroy + article.destroy + redirect_to articles_url, notice: 'Article was successfully destroyed.' + end + + private + + def article_params + params.require(:article).permit(:name) + end +end +``` + +## Helpers + +### expose + +`expose` provides powerful tools to help you minimize your controllers. + +Default values: +`expose :name, :infer, scope: :all, decorate: true, decorator: :infer` + +Examples: + +```ruby +expose :articles +expose :articles, scope: :visible +expose :article +expose :forthy_two, 42, decorate: false +expose :bob, "Bob", decorator: -> { |v| v.length } + +``` ## Usage TODO