Project

snippetize

0.0
No commit activity in last 3 years
No release in over 3 years
Ruby gem allowing you to include re-usable code and partials in html or plain text fields.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

active_support
>= 0
>= 0
>= 0
 Project Readme

Snippetize

Snippetize allows you to include partials in html or plain text fields. Stay dry and reuse your partials using shortcode. Use it for including forms, videos, maps or simply preformated html snippets.

Why

If you want users to be able to add partials without editing html.

So this:

    Article.new(content: "<div class='widget'>I need my awesome widget that displays everywhere on the site.</div>")

Becomes:

    Article.new(content: "{{widget}}")

Installation

Add this line to your application's Gemfile:

gem 'snippetize'

And then execute:

$ bundle

Or install it yourself as:

$ gem install snippetize

Defaults

All partials will be taken from a snippets folder in views. For instance, {{awesome_widget}} assumes you have the following file:

app/views/snippets/_awesome_widget.html.erb

Usage

Insert the name of the partial within double brackets {{}}

text = "<div class='widget'>{{awesome_widget}}</div>"

Call snippetize and pass it your string

snippetize(text).html_safe

The result could look like this:

"<div class='widget'><div class='my-awesome-widget'>This lives in my partial.</div></div>"

You can also pass variables to you partial like you would normaly to a partial

text = "<div class='widget'>{{awesome_widget, count: 2, category: test}}</div>"

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Test your changes (rspec spec)
  4. Commit your changes (git commit -am 'Add some feature')
  5. Push to the branch (git push origin my-new-feature)
  6. Create new Pull Request