sosedoff/xml-sitemap — Issue #10: uninitialized constant XmlSitemap::RenderEngine::CGI
Author: strife25
Created: 2011-10-22 15:02:50+00:00
State: open

I am writing a Sinatra web app and I am using the following code to generate a site map:

```ruby
get '/sitemap.xml' do
map = XmlSitemap::Map.new('johnryding.com') do |m|
m.add(:url => '/')
m.add(:url => '/about')
m.add(:url => '/projects', :period => :monthly)
m.add(:url => '/setup', :period => :monthly)
end

headers['Content-Type'] = 'text/xml'
map.render
end
```

However, when I point my browser to /sitemap.xml, I get the following error:

```
NameError - uninitialized constant XmlSitemap::RenderEngine::CGI:
/Library/Ruby/Gems/1.8/gems/xml-sitemap-1.2.1/lib/xml-sitemap/render_engine.rb:57:in `render_string'
/Library/Ruby/Gems/1.8/gems/xml-sitemap-1.2.1/lib/xml-sitemap/render_engine.rb:55:in `each'
/Library/Ruby/Gems/1.8/gems/xml-sitemap-1.2.1/lib/xml-sitemap/render_engine.rb:55:in `render_string'
/Library/Ruby/Gems/1.8/gems/xml-sitemap-1.2.1/lib/xml-sitemap/map.rb:102:in `render'
web/johnryding.rb:68:in `GET /sitemap.xml'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.1/lib/sinatra/base.rb:1211:in `call'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.1/lib/sinatra/base.rb:1211:in `compile!'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.1/lib/sinatra/base.rb:772:in `[]'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.1/lib/sinatra/base.rb:772:in `route!'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.1/lib/sinatra/base.rb:788:in `route_eval'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.1/lib/sinatra/base.rb:772:in `route!'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.1/lib/sinatra/base.rb:821:in `process_route'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.1/lib/sinatra/base.rb:819:in `catch'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.1/lib/sinatra/base.rb:819:in `process_route'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.1/lib/sinatra/base.rb:771:in `route!'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.1/lib/sinatra/base.rb:770:in `each'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.1/lib/sinatra/base.rb:770:in `route!'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.1/lib/sinatra/base.rb:886:in `dispatch!'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.1/lib/sinatra/base.rb:706:in `call!'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.1/lib/sinatra/base.rb:871:in `invoke'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.1/lib/sinatra/base.rb:871:in `catch'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.1/lib/sinatra/base.rb:871:in `invoke'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.1/lib/sinatra/base.rb:706:in `call!'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.1/lib/sinatra/base.rb:692:in `call'
/Library/Ruby/Gems/1.8/gems/rack-protection-1.1.4/lib/rack/protection/xss_header.rb:22:in `call'
/Library/Ruby/Gems/1.8/gems/rack-protection-1.1.4/lib/rack/protection/path_traversal.rb:16:in `call'
/Library/Ruby/Gems/1.8/gems/rack-protection-1.1.4/lib/rack/protection/json_csrf.rb:17:in `call'
/Library/Ruby/Gems/1.8/gems/rack-protection-1.1.4/lib/rack/protection/base.rb:47:in `call'
/Library/Ruby/Gems/1.8/gems/rack-protection-1.1.4/lib/rack/protection/xss_header.rb:22:in `call'
/Library/Ruby/Gems/1.8/gems/rack-1.3.4/lib/rack/logger.rb:15:in `call'
/Library/Ruby/Gems/1.8/gems/rack-1.3.4/lib/rack/commonlogger.rb:20:in `call'
/Library/Ruby/Gems/1.8/gems/rack-1.3.4/lib/rack/head.rb:9:in `call'
/Library/Ruby/Gems/1.8/gems/rack-1.3.4/lib/rack/methodoverride.rb:24:in `call'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.1/lib/sinatra/showexceptions.rb:21:in `call'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.1/lib/sinatra/base.rb:1334:in `call'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.1/lib/sinatra/base.rb:1403:in `synchronize'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.1/lib/sinatra/base.rb:1334:in `call'
/Library/Ruby/Gems/1.8/gems/rack-1.3.4/lib/rack/handler/webrick.rb:59:in `service'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:162:in `start'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:92:in `each'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:23:in `start'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
/Library/Ruby/Gems/1.8/gems/rack-1.3.4/lib/rack/handler/webrick.rb:13:in `run'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.1/lib/sinatra/base.rb:1295:in `run!'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.1/lib/sinatra/main.rb:25
web/johnryding.rb:123
```

It looks like line lib/xml-sitemap/render_engine:57 is giving the problem by trying to access the **CGI** constant:

```ruby
item_string += " #{CGI::escapeHTML(item.target)}\n"
```