DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Rendering A Tag Cloud Using A Dynarex-tagcloud File

  • submit to reddit
        Using a dynarex-tagcloud file used in conjunction with an S-Rscript RSF job a tag cloud can be rendered to HTML.

The following RSF job uses an XML file (dynarex-tagcloud) along with an XSL file to make the tag cloud:
<job id='to-html'>
  <script src=''/>

    require 'dynarex'
    require 'nokogiri'
    class TagCloud
      include Render

      def render(xml_url, xsl_url)
        dynarex = xml_url

        biggest_tag_size = dynarex.records.max_by {|x| x[:size].to_i}[:size].to_i

        r = dynarex.records
        biggest_tag_size = r.max_by {|x| x[:size].to_i}[:size].to_i
        r.each {|x| x[:gauge] = (10 / (biggest_tag_size / x[:size].to_f)).round}

        doc =
        element_xsl ='xsl_url').add_text(xsl_url)
        doc.root.elements['summary'].add_element element_xsl
        css_url = '/do/tagcloud/tagcloud-css'
        element_css ='css').add_text(css_url)
        doc.root.elements['summary'].add_element element_css          
        render_to_guide(:doc => doc)
    xml_url = params[:xml]
    xml_url ||= ''
    xsl_url = params[:xsl]
    xsl_url ||= ''
    tagcloud =
    tagcloud.render xml_url, xsl_url

Observed: see <a href="">screenshot of programming tag cloud</a> []

Here's the XML file used

Note: The dynarex-tagcloud layout simplifies the process of creating the tag cloud.