Project

cambelt

0.01
No commit activity in last 3 years
No release in over 3 years
This gem makes it simple to embed images within your code with a nice Ruby DSL.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

Cambelt - Image Placeholders

Cambelt is a service that allows you to generate free image placeholders, simply and easily. If you would like to learn more about the service itself, have a look at http://cambelt.co for more information.

Quickstart

To install Cambelt on your machine you can type:

gem install cambelt

or use

gem 'cambelt'

in your Gemfile.

Cambelt detects if you are running Ruby on Rails, and if so adds a placeholder_image_tag() method to ActionView, allowing you to do:

<%= placeholder_image_tag %>

in your views and get a nice placeholder back! For your convenience this is also aliased to a simple call of:

<%= placeholder %>

Configuring Cambelt

This gem currently only interfaces with the basic free Cambelt service, which gives a limited number of configuration options that you can set as defaults. When you make a call to placeholder_image_tag(), Cambelt checks for these defaults to create the image, but allows you to pass in a hash of values to override any of them.

To configure Cambelt in Rails, you can run the following generator to create a Cambelt initializer file:

$ rails g cambelt:install

Then you can edit this file to customise your default settings. If you are not using Rails, then the command to configure Cambelt is the same as in the initializer, and is presented below:

Cambelt.configure do |config|
    width = 640
    height = 360
    font = "Questrial"
    font_size = 48
    text = "Sample Text"
    bg_color = "#cccccc"
    fg_color = "#333333"
end

These are the default settings that are provided, so if you are happy with those you don't actually need to call Cambelt.configure() at all. Each of these methods is overridable on any given call to placeholder_image_tag(), and to do this you supply a hash as the first parameter:

placeholder_image_tag(:text => "I love Cambelt!")

Finally, you can supply a second hash to the method which contains html attributes that your want your image tag to have, so:

placeholder_image_tag({:text => "I love Cambelt!"}, {:class => "cambelt_is_classy"})

will give you the following:

<img src="http://cambelt.co/640x360/I+love+Cambelt!?font=Questrial&font_size=48&color=cccccc,333333" class="cambelt_is_classy" />

Simple, isn't it?