Giter VIP home page Giter VIP logo

shortcodes's Introduction

Shortcodes

Wordpress style shortcodes for your Ruby CMS.

A simple ruby gem that will parse your cms content for wordpress style shortcodes.

Installation

Add this line to your application's Gemfile:

gem 'shortcodes'

Then require the shortcodes you intend on using.

To automatically load all built-in shortcodes use:

# Gemfile
gem 'shortcodes', require: 'shortcodes/all'

To only load specified shortcodes do not use require: 'shortcodes/all', and instead require only the shortcodes you intend to use. In rails, you can do this in an initialize like so:

# config/initializers/shortcodes.rb
require 'shortcodes/youtube'

Usage

Shortcodes.shortcode(content)

Built-in Shortcodes

Youtube

Example:

[youtube url="https://www.youtube.com/watch?v=Gzj723LkRJY#t=3m21s"]

Attributes:

  • url - required
  • width, height - optional. defaults to 560x315

Wufoo

Copying and pasting the Wufoo Wordpress shortcode should work.

Example:

[wufoo username="awesome_user" formhash="a04909c" autoresize="true" height="961" header="show" ssl="true"]

Custom shortcodes

Either create an object that responds to call, or subclass Shortcodes::Handler and implement render. Register the shortcode using Shortcodes.register\_shortcode. Example:

require 'shortcodes/handler'

class MyShortcode < Shortcodes::Handler
  def render
    "Attributes can be accessed with <tt>#attributes</tt>: <pre>#{attributes.inspect}</pre>"
  end
end

Shortcodes.register_shortcode('my-shortcode', MyShortcode)

Also see lib/shortcodes/youtube.rb for a good real-world example.

Please PR new shortcodes!

If you write a custom that might be useful to other people, please submit a pull-request!

Contributing

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

shortcodes's People

Contributors

amiel avatar nathancarnes avatar

Stargazers

fujitora avatar Zack Katz avatar

Watchers

 avatar  avatar Monica Pierce avatar Nicole Champagne avatar James Cloos avatar Josh Parrish avatar

shortcodes's Issues

Support for block/container tags

Are there any plans to support block/container shortcodes which can contain other shortcodes? For example:

[timeline title="My true love gave to me..."]
  [event date="25/12/2013" description="A Partridge in a Pear Tree"]
  [event date="26/12/2013" description="2 Turtle Doves"]
  [event date="27/12/2013" description="3 French Hens"]
  [event date="28/12/2013" description="4 Calling Birds"]
  [event date="29/12/2013" description="5 Golden Rings"]
[/timeline]

Just a suggestion, I think it would be really useful.

Initializer required in Rails

In Rails, shortcodes/all.rb (which references the youtube.rb and wufoo.rb shortcodes) doesn't get loaded by default, so you have to create an initializer in your application called something like config/initializers/shortcodes.rb containing:

require 'shortcodes/wufoo'
require 'shortcodes/youtube'

If you create your own shortcodes (e.g. lib/shortcodes/custom.rb - you can use youtube.rb as a starting point for developing your own shortcode), remember to reference it in the initializer:

require 'shortcodes/custom'

Hope that helps someone else. Great gem by the way, thanks!

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.