Platinum Partner

Use Base64 For Embedding Raster Data In Source File

When we create a simple script with gui, it should be nice to puts the icons in the source script,
so whe can diffuse the code without any packaging.

This code create a ruby source which declare some file-content coded in ASCII/.base64
In the source, he put get_icon_filename(name) which put content to a temporary file and return
the filename created :


# usage: ruby gene.rb ../angel.png  face_crying.png face_smile_big.png > icons64.rb
require 'base64'
require 'tmpdir'

str=< #{fname} / #{$icons[name].size}" if $DEBUG
  File.open(fname,"wb") { |f| f.write($icons[name].unpack('m')) } unless File.exists?(fname)
  fname
end
EEND

puts str

STDERR.puts "#{lvar.join(", ")} done size=#{str.size}."


This generate a code like :

require 'base64'
require 'tmpdir'
$icons={}

$icons['angel']=< #{fname} / #{$icons[name].size}" if $DEBUG
  File.open(fname,"wb") { |f| f.write($icons[name].unpack('m')) } unless File.exists?(fname)
  fname
end


Here a little Shoes app for use raster content

require 'green_shoes'

<< "contents of 'icons64.rb' here" >>

Shoes.app do
  stack {
	background "#A0A0B0".."#A0A0FF"
	$icons.keys.each { |name|
			para name
			image get_icon_filename(name)
	}
  }
end



Or a Ruiby app (see https://github.com/raubarede/Ruiby):


require_relative 'Ruiby/lib/ruiby.rb'
<< "contents of 'icons64.rb' here" >>

class X < Ruiby_gtk
	def component()
	  stack do
		$icons.keys.each do |n| 
			flow { 
                           slot(label(n))
                           slot(label("#"+get_icon_filename(n) )) 
			}
		end
	  end
	end
end
Ruiby.start { X.new("test",100,100) }


{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}