README.md in great_pretender-0.1.5 vs README.md in great_pretender-0.2.0

- old
+ new

@@ -13,11 +13,10 @@ - Supports nested mockup directories (e.g. `app/views/mockups/users/sessions/whatever.html.slim`) - Supports partials - Installs in 2 minutes as a Rails engine - Can be mixed in to other controllers for access control or whatever else you want to add - Configurable mockups folder name and default layout -- Dances with wolves ## Install Just add it to your Gemfile and go! @@ -73,17 +72,14 @@ 1. Create a controller that uses whatever inheritance you're interested in, and mix `GreatPretender::Controller` into it: ```ruby class Admin::MockupsController < Admin::ApplicationController - include GreatPretender::Controller before_action :require_admin_user! # or whatever - layout 'admin' # or whatever - end ``` 2. Manually add routes to the Great Pretender actions (`index` and `show`). **Please note** that the `show` action requires a `*splat`-style id: @@ -161,17 +157,27 @@ A lot of the time you'll want to emulate real data in your views. In those cases, Great Pretender supports the use of "Pretender" objects in `app/pretenders`. Pretender objects can be any class. They can accept a single argument in `initialize`, which will be the the mockup being rendered, **or** they can skip it entirely. -Any public method you add to a pretender object will be available to the view, just like helper methods. +An instance of every pretender will be available inside your templates. So for, e.g., a `user_pretender.rb` that defines: -### Load order +``` +class UserPretender + def name + "Gary Sinese" + end +end +``` -Pretenders, like layouts, are loaded based on the name of your mockup file. For example, a mockup named "users/login" would look for `app/pretenders/user(s)_pretender.rb` and `app/pretenders/login_pretender.rb`. **Please note** that plurally named templates will support a singular pretender, but singularly named templates will only load singular pretenders. +You would reference a `user` helper method (or `user_pretender` if `user` is already defined): -Pretenders are delegated to in order of most specific (`LoginPretender`) to least specific (`UserPretender`). So if `LoginPretender` and `UserPretender` both define method `name`, the `LoginPretender`'s implementation will be used. +```erb +<%= user.name %> <!-- Outputs "Gary Sinese" --> +or +<%= user_pretender.name %> <!-- Outputs same --> +``` ### Example Here's an example using the excellent [Faker gem](https://github.com/stympy/faker) (I leave it to you to figure out how you want to generate test data, but Faker is pretty awesome). @@ -179,32 +185,29 @@ ```ruby require "faker" class UserPretender - def login Faker::Internet.user_name end def email Faker::Internet.email end - end ``` #### `app/views/mockups/users/login.html.slim` ```slim header - | Welome back, #{login}! - | Your email is set to #{email} + | Welome back, #{user.login}! + | Your email is set to #{user.email} / The remainder of your login form mockup... ``` - ## The end! Thanks for using Great Pretender! I hope it helps you like it's helped us!