Saucy
Dynamic Text Rendering Plugin for Rails. Like sIFR but without the hassle/flash/javascript.
- Automatic caching
- SEO friendly
- render any TTF font
Examples
<%= saucy_tag("Hi there") %>
<%= saucy_tag("I am red", :style => {:font => {:color => 'red' }}) %>
<%= saucy_tag("I am a red/blue sprite",
:style => {:font => {:color => 'red'}},
:highlight => {:font => {:color => 'blue'}}
) %>
Use
In a view:
<%= saucy_tag(text, options) %>
- text: your own text. Note it can contain newlines which will be interpreted as multiline text.
- options: html attributes to be inserted
Available options
- Style needs to be a hash – see the ‘Styles’ heading below {:style => {}}
- Highlight option is for sprites, the styles passed in override
- the styles that were passed in for :style. This can be used for hover or focus effects {:highlight => {}}
- The html style needs to be a hash
- The html class needs to be a array of classNames {:html => {:style => {}, :class => []}}
- Tag needs to be symbol (default is :a) {:tag => :p}
- Transparent needs to be a boolean –
- this defaults to true {:transparent => false}
Styles
The style has has several options and the default style is:
{
:background => "transparent",
:font => {
:size => 18,
:color => "#000",
:font => "arial",
:stretch => "normal"
},
:stroke => {
:width => 0,
:color => "#000",
:inner => true
},
:spacing => {
:letter => 0,
:word => 0
},
:rotate => 0,
:shadow => {
:color => "#000",
:opacity => 0.6,
:top => 2,
:left => 2,
:blur => 5.0,
:render => false
}
}
The style that’s passed in will be merged over the top of this.
Internet Explorer
Saucy will apply an AlphaFilter if you the background color is “transparent” (or absent since this is the default)
Fonts
Fonts are loaded from the /plugins/saucy/fonts directory.
Sprites
If you set an highlight style Saucy will render a sprite consisting of 2 images, the normal and the highlight. To set a sprite to be at the highlight style, simply set the top margin to 0. E.g. the following is for a hover effect:
You need to pass in a :highlight option which is in the same format as the :style option. The :highlight option overrides the :style option (you don’t need to pass in all the styles again).
Get Involved
- Discuss on the google group
- Saucy is hosted on Github: http://github.com/weepy/saucy/tree/master