module Griddy::Sass::Script::Functions
Public Instance Methods
griddy(width, height, color)
click to toggle source
# File lib/griddy.rb, line 9 def griddy(width, height, color) assert_type width, :Number assert_type height, :Number assert_type color, :Color compiled_file = compile_file(width, height, color) base64_str = to_base64(compiled_file) Sass::Script::Value::String.new(base64_str) end
Private Instance Methods
compile_file(width, height, color)
click to toggle source
# File lib/griddy.rb, line 23 def compile_file(width, height, color) template = '<?xml version="1.0" encoding="utf-8"?><!DOCTYPE svg PUBLIC '+ '"-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1'+ '/DTD/svg11.dtd"><svg version="1.1" id="Border" xmlns="http://ww'+ 'w.w3.org/2000/svg"xmlns:xlink="http://www.w3.org/1999/xlink" x="0'+ 'px" y="0px"width="<%=width%>" height="<%=height%>" viewBox="0 0 10 '+ '10"><rect y="0" fill="none" stroke="<%=color%>" width="<%=width%>" '+ 'height="<%=height%>"/></svg>' erb_init = ERB.new(template) compiled_erb = erb_init.result(binding) end
to_base64(compiled)
click to toggle source
# File lib/griddy.rb, line 35 def to_base64(compiled) base64_prefix = 'url(data:image/svg+xml;base64,' base64_str = Base64.strict_encode64(compiled) base64_suffix = ')' base64_prefix + base64_str + base64_suffix end