Top Level Namespace

Defined Under Namespace

Modules: CanvasShape, RVGShape, SVG Classes: Browser, CanvasBrowser, ElementEllipse, ElementLine, ElementRect, ElementSvg, ElementText, RenderSvg, ShapeBase, SvgEnvironment

Instance Method Summary collapse

Instance Method Details

#build_templates(t) ⇒ Object



1
2
3
4
5
6
7
8
9
# File 'lib/template_builder.rb', line 1

def build_templates(t)
  a = []
  t.gsub!(/\#\{/,'\#\\{')
  t.scan(/@@ (\w+)/){ a << [$1,$']}        
  code = a.map {|x| i = x[1] =~ /@@/; r = i.nil? ? x[1] : x[1][0,i] ; [x[0], r] }
  template_code = code.map {|f,c| "@@templates[:%s] = \"%s\"" % [f, c.gsub(/"/,'\\"')]}
  instance_eval(template_code.join("\n"))
  instance_eval("template :layout do \"%s\" end" % @@templates[:layout].strip) if @@templates.has_key? :layout
end

#render_canvas(template_name) ⇒ Object



1
2
3
4
5
6
7
8
9
# File 'lib/canvas_enclosure.rb', line 1

def render_canvas(template_name)
  url = "http://rorbuilder.info/r/heroku/erb/canvas.erb"
  t = open(url, "UserAgent" => "Sinatra-Rscript").read
  build_templates(t)

  @@templates[template_name] = yield.strip
  @content_type = 'text/xml'
  erb @@templates[template_name]
end