Documentation

Ruby on Rails Integration

Use the following class for your Ruby on Rails integration.

require 'net/http'
class KitGUI
   
# replace with your own KitGUI CMS Account Key
    ACCOUNTKEY= "21a83010ca074a458feb07667692b083"
    @cache = ActiveSupport::Cache::MemoryStore.new
    def self.getContent(contentID, contentType,kitgui)
        matches = contentID.match(/^[a-zA-Z]+[a-zA-Z0-9\\-_]*$/)
        unless matches.nil?
            raise Exception.new('KitGUI content ID must begin with a letter ([A-Za-z]) and ' +
            '
may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_")')
        end
       
@editMode = (kitgui=="1")
        @cacheKey = "kitgui-" + contentID
        if !editMode
            @raw = @cache.read(@
cacheKey)
        end
        if !editMode.nil? || @raw.empty?
            @url = "http://s3.amazonaws.com/kitgui/clients/" + ACCOUNTKEY+  "/ids/" +
contentID + ".txt"
            @raw = Net::HTTP.get_response(URI.parse(@url)).body
            @cache.write(
@cacheKey,@raw)
        end
                unless editMode
                    return @raw
                else
                    return "<div style=\'display:inline-block\' class=\'kitgui-id-#{contentID} " +

                    "kitgui-content-type-#{contentType} '\>" + @raw + "</div>"
                end
                 
    end
end

To get content on your views, call KitGUI like so:

<%= raw KitGUI.getContent("your-content-id","INLINE",cookies[:kitgui])%>

It gets interesting when you pass in your content ID dynamically by using dyanamic URLs. Setting up templates quickly for infinite pages is very simple.

authored by Adnan Arshad (odesk handle "Adnan Arshad")