Git Product home page Git Product logo

phrasing's Introduction

Phrasing!

Phrasing

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

Installation

Include the gem in your Gemfile

gem "phrasing"

Run the install script:

rake phrasing:install

This will create a migration file and a config file where you can edit the name of the route to see all the phrases.

Migrate your database

rake db:migrate

Setup

The rake task will also generate a PhrasingHelper.rb file in your app/helpers folder where you will need to implement your can_edit_phrases? method. Example:

module PhrasingHelper

  def can_edit_phrases?
    current_user.is_admin?
  end
  
end

Include the phrasing html initializer at the top of your body

= render 'phrasing/initializer'

Include the required javascript file (most often in your application.js file):

//= require phrasing

Include the required stylesheet file (most often in your application.css file):

//= require phrasing

How to use phrasing?

Start with adding your phrases simply by writting in your view file:

= phrase('my-first-phrase')

Apart from editing phrases (basically, Rails translations) you can also inline edit your models attributes, just use the same phrase method, with the first attribute being the record and the second one the records attribute:

= 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:

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

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

Phrasing.allow_update_on_all_models_and_attributes = true

Upgrading from version 2.x to 3.x

In versions 3.0.0 and above we have added the Phrasing Versioning System which requires an additional table, so if you are upgrading to a 3.x release, run rake phrasing:install to get the additional migration file, rake db:migrate and thats it.

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.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 
interpolation: { %min: 10 } # add variables to your translations just like w/ I18n

Authors

Copyright (c) 2013, Infinum

Phrasing relies heavily (or is built) on two other libraries: the Copycat gem and the ZenPen library. So thank you to the authors and all the contributors!

phrasing's People

Contributors

damirsvrtan avatar carr avatar

Watchers

Nolboo Kim avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.