Sha256: eb3295c2cd253155fd9fdcf1e54e47fffafcf07a9469c490f2d4696cf19e604b

Contents?: true

Size: 1.06 KB

Versions: 10

Compression:

Stored size: 1.06 KB

Contents

$:.unshift( "../lib" )
require 'capcode'
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.encode64(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

10 entries across 10 versions & 1 rubygems

Version Path
Capcode-1.0.0 examples/render-image.rb
Capcode-0.9.9 examples/render-image.rb
Capcode-0.9.8 examples/render-image.rb
Capcode-0.9.7 examples/render-image.rb
Capcode-0.9.6 examples/render-image.rb
Capcode-0.9.5 examples/render-image.rb
Capcode-0.9.4 examples/render-image.rb
Capcode-0.9.3 examples/render-image.rb
Capcode-0.9.2 examples/render-image.rb
Capcode-0.9.1 examples/render-image.rb