Edit phrases inline for your Ruby on Rails applications!
Ruby CSS JavaScript HTML
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
app Fix rails 5.2 bug May 15, 2018
config RESTFUL phrasing_phrase controller. Sep 21, 2014
lib Bump gem to 4.1.0 May 17, 2018
spec Fix failed test Feb 13, 2018
.gitignore Remove gitignore Feb 23, 2017
.travis.yml Remove travis Ruby 2.0.0 version build Nov 16, 2017
CHANGELOG.md Bump gem to 4.1.0 May 17, 2018
Gemfile Add button for download filtered yaml files Feb 12, 2018
MIT-LICENSE Code cleanup Oct 14, 2013
README-3.md
README.md Make gem compatible with Rails 5 May 17, 2018
Rakefile
Release_notes_version_4.md Remove JS cookie store Jul 19, 2016
phrasing.gemspec Remove JS cookie store Jul 19, 2016

README.md

Phrasing!

Build Status

Phrasing is a gem for live editing phrases (copy) on websites.

Installation

Include the gem in your Gemfile

gem "phrasing"

Bundle the Gemfile

bundle install

Run the install script which will create a migration file and a config file.

rails generate phrasing

Migrate your database

rake db:migrate

Setup

The rake task will also generate phrasing_helper.rb in your app/helpers folder. Here you will need to implement the can_edit_phrases? method. Use this to hook-up your existing user authentication system to work with Phrasing.

For example:

module PhrasingHelper
  def can_edit_phrases?
    current_user.is_admin?
  end
end

Include the phrasing html initializer right below the <body> tag in your application layout file.

<%= render 'phrasing/initializer' %>

Include the required javascript files:

//= require phrasing

Include the required javascript files:

//= require jquery
//= require jquery_ujs
//= require phrasing

Include the required stylesheet file:

*= require phrasing

How to use phrasing?

You can start adding new phrases by simply adding them in your view file:

<%= phrase('my-first-phrase') %>

Aside from editing phrases (basically, Rails translations) you can also edit model attributes inline. Use the same phrase method, with the first attribute being the record in question, and the second one the attribute you wish to make editable:

<%= phrase(@post, :title) %>

In the above example, @post is the record with a title attribute.

Security

Since Phrasing can be used to update any attribute in any table (using the model_phrase method), special care must be taken into consideration from a security standpoint.

By default, Phrasing doesn't allow updating of any attribute apart from PhrasingPhrase.value. To be able to work with other attributes, you need to whitelist them.

In the config/initializers/phrasing.rb file you can whitelist your model attributes like this:

config.white_list = ["Post.title", "Post.body"]

or you can whitelist all of them (not recommended) with:

config.allow_update_on_all_models_and_attributes = true

Turbolinks

If you're experiencing problems with Rails apps using Turbolinks, include the jQuery-turbolinks gem in your application and simply require it in the following order:

//= require jquery
//= require jquery_ujs
//= require jquery.turbolinks
//= require phrasing
//= require turbolinks

Phrasing Appearance

The phrase view helper can take the options hash as the last parameter. Features:

url: custom_url # point Phrasing to other actions in other controllers
inverse: true # change the hovered background and underline colors to better fit darker backgrounds
class: custom_class # add custom CSS classes to your phrases to change the appearance of phrases in your application
scope: 'homepage.footer' # add scopes just like you would w/ I18.n. If the first argument is 'test', than the key would be 'homepage.footer.test'

Credits

Phrasing is maintained and sponsored by Infinum.

Phrasing leverages parts of Copycat and ZenPen.

License

Phrasing is Copyright © 2013 Infinum. It is free software, and may be redistributed under the terms specified in the LICENSE file.