Wednesday, July 22, 2009

Annoyances

‹prev | My Chain | next›

Exploring through the site a bit, I notice that I need to default the output to UTF-8. All the data is stored in UTF-8. Things like em-dashes look OK when viewed directly in CouchDB:



But not so OK in Sinatra:



To set the default character encoding in Sinatra, use a before filter:
before do
content_type 'text/html', :charset => 'UTF-8'
end
With that, I have my em-dashes displaying OK:



I could have accomplished just as easily by adding a meta tag to the Haml template. It comes down to a personal preference for me. I rationalize it by thinking of data as a systemic consideration, not a presentation thing.

Next up, I take some to work through some of the issues that I am tracking. While fixing the search page, I notice that I am unable to search on multiple terms (e.g. "fish sticks"). This was caused by not URL encoding the search term when passing it off to couchdb-lucene. The example that I need to pass:
    it "should be able to search multiple terms" do
RestClient.should_receive(:get).
with(/q=foo\+bar/).
and_return('{"total_rows":30,"skip":0,"limit":20,"rows":[]}')

get "/recipes/search?q=foo+bar"
end
The code that makes this pass (using Rack::Utils.escape):
get '/recipes/search' do
@query = params[:q]

page = params[:page].to_i
skip = (page < 2) ? 0 : ((page - 1) * 20)

couchdb_url = "#{@@db}/_fti?limit=20" +
"&q=#{Rack::Utils.escape(@query)}" +
"&skip=#{skip}"

...
(commit)

I have two more minor issues in the tracker that need fixing, but everything else is looking good. After addressing those issues, it will finally be time to explore less to resolve my lack of CSS.

No comments:

Post a Comment