Sha256: a50a3faf7c226be68618002aba964a551113cfeb1c19ac009785959fb3e1d562

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

$:.unshift( "../lib" )
require 'capcode'
require 'capcode/render/markaby'
require 'rubygems'
require 'graphviz'
require 'base64'

def hello( path )
  g = GraphViz::new( "G" ) { |g|
    g.hello << g.world
    g.bonjour - g.monde
    g.hola > g.mundo
    g.holla >> g.welt
  }
  
  r = nil
  if path.nil?
    r = g.output( :png => String )
  else
    r = g.output( :png => String, :path => "/#{path}" )
  end
  
  return r
end

module Capcode
  class Index < Route '/'
    def get
      render :markaby => :index
    end
  end
    
  class Image < Route '/image/(.*)'
    def get(path)
      r = hello( path )

      render :content_type => "image/png", :text => r
    end
  end
  
  class Inline < Route '/inline/(.*)'
    def get(path)
      @image = Base64.b64encode(hello(path))
      
      render :markaby => :inline
    end
  end
end

module Capcode::Views
  def glop
    html do
      body do
        yield
      end
    end
  end
  
  def index
    h1 "Image :"
    img :src => URL(Capcode::Image)
  end
  
  def inline
    h1 "Inline image :"
    img :src => "data:image/png;base64,#{@image}"
  end
end

Capcode.run( )

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
Capcode-0.8.9 examples/render-image.rb
Capcode-0.8.8 examples/render-image.rb
Capcode-0.8.7 examples/render-image.rb