Giter Club home page Giter Club logo

rails_join's Introduction

rails_join

Doing a ‘join` on an array containing html safe strings will produce an html unsafe string.

Rails provides a helper called ‘safe_join` that will always produce an html safe string.

This gem modifies ‘Array#join` so that it returns an html safe string when the first element is an html safe string. This is similar to `s1 + s2` returning an html safe string if and only if `s1` is html safe. If the first element is not an html safe string (or does not exist), then `Array#join` returns a normal string, as was previously the case. Again, this is similar to `s1 + s2` returning a normal string if `s1` is a normal string, even if `s2` is an html safe string.

links = [link_to("Home", "/"), link_to("Profile", "/profile")]
desired = links[0] + " > " + links[1]
joined  = links.join(" > ")
joined == desired # => false
joined.html_safe? # => false
require 'rails_join'
joined  = links.join(" > ")
joined == desired # => true
joined.html_safe? # => true

Installation

Simply add to your Gemfile:

gem "rails_join"

Run ‘bundle install` and you’re done.

Runs on all versions of Ruby and all versions of Rails >= 3.0

Why?

See: github.com/rails/rails/pull/3716

Copyright © 2012 Marc-Andre Lafortune. See LICENSE.txt for further details.

rails_join's People

Contributors

marcandre avatar

Stargazers

 avatar

Watchers

 avatar  avatar  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.