prat0318/json_resume

UTF-8 issues with mustache/ruby on Ubuntu when converting to any format.

GhassenJ opened this issue · 8 comments

/home/vagrant/.rvm/gems/ruby-2.1.2@global/gems/mustache-0.99.6/lib/mustache/template.rb:3842:in block in render': incompatible character encodings: ISO-8859-1 and UTF-8 (Encoding::CompatibilityError) from /home/vagrant/.rvm/gems/ruby-2.1.2@global/gems/mustache-0.99.6/lib/mustache/template.rb:3842:inmap'
from /home/vagrant/.rvm/gems/ruby-2.1.2@global/gems/mustache-0.99.6/lib/mustache/template.rb:3842:in render' from /home/vagrant/.rvm/gems/ruby-2.1.2@global/gems/mustache-0.99.6/lib/mustache/template.rb:43:inrender'
from /home/vagrant/.rvm/gems/ruby-2.1.2@global/gems/mustache-0.99.6/lib/mustache.rb:124:in render' from /home/vagrant/.rvm/gems/ruby-2.1.2@global/gems/mustache-0.99.6/lib/mustache.rb:85:inrender'
from /home/vagrant/.rvm/gems/ruby-2.1.2@global/gems/json_resume-1.0.2/bin/json_resume:167:in generate_file' from /home/vagrant/.rvm/gems/ruby-2.1.2@global/gems/json_resume-1.0.2/bin/json_resume:66:inconvert_to_html'
from /home/vagrant/.rvm/gems/ruby-2.1.2@global/gems/json_resume-1.0.2/bin/json_resume:29:in convert' from /home/vagrant/.rvm/gems/ruby-2.1.2@global/gems/thor-0.19.1/lib/thor/command.rb:27:inrun'
from /home/vagrant/.rvm/gems/ruby-2.1.2@global/gems/thor-0.19.1/lib/thor/invocation.rb:126:in invoke_command' from /home/vagrant/.rvm/gems/ruby-2.1.2@global/gems/thor-0.19.1/lib/thor.rb:359:indispatch'
from /home/vagrant/.rvm/gems/ruby-2.1.2@global/gems/thor-0.19.1/lib/thor/base.rb:440:in start' from /home/vagrant/.rvm/gems/ruby-2.1.2@global/gems/json_resume-1.0.2/bin/json_resume:176:in<top (required)>'
from /home/vagrant/.rvm/rubies/ruby-2.1.2/bin/json_resume:23:in load' from /home/vagrant/.rvm/rubies/ruby-2.1.2/bin/json_resume:23:in

'
from /home/vagrant/.rvm/gems/ruby-2.1.2@global/bin/ruby_executable_hooks:15:in eval' from /home/vagrant/.rvm/gems/ruby-2.1.2@global/bin/ruby_executable_hooks:15:in'

This is weird. I wonder how the encoding ISO-8859-1 is present on your system. Can you tell me the result of these two commands on your shell - ruby -e 'puts __ENCODING__.name' and echo $LC_CTYPE

ISO-8859-1 ... weird. Do I need to enforce UTF-8 in all of the ruby applications files?

add this variable by : export LC_CTYPE=en_US.UTF-8 on your terminal and try converting. Lets see if that helps. If not, does the response of the above two commands still remains the ISO one?

echo $LC_CTYPE now returns "en_US.UTF-8"
But, ruby -e 'puts ENCODING.name' is still ISO-8859-1.

ok, lets try this - export RUBYOPT='-E utf-8'

Taken from : http://stackoverflow.com/questions/5908774/set-global-default-encoding-for-ruby-1-9

Nothing changed.

Well, i am also on 2.1.2 and i reproduced the issue and changing RUBYOPT worked for me. I am not sure of any other solution as of now.

$ export RUBYOPT='-E ISO-8859-1'                                                                                           [17:38:40]
$ json_resume convert prateek_cv.json                                                                                       [17:38:50]
Generating the html type...
/Users/prat0318/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/mustache-0.99.6/lib/mustache/template.rb:3842:in `block in render': incompatible character encodings: ISO-8859-1 and UTF-8 (Encoding::CompatibilityError)
    from /Users/prat0318/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/mustache-0.99.6/lib/mustache/template.rb:3842:in `map'
    from /Users/prat0318/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/mustache-0.99.6/lib/mustache/template.rb:3842:in `render'
    from /Users/prat0318/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/mustache-0.99.6/lib/mustache/template.rb:43:in `render'
    from /Users/prat0318/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/mustache-0.99.6/lib/mustache.rb:124:in `render'
    from /Users/prat0318/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/mustache-0.99.6/lib/mustache.rb:85:in `render'
    from /Users/prat0318/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/json_resume-1.0.2/bin/json_resume:167:in `generate_file'
    from /Users/prat0318/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/json_resume-1.0.2/bin/json_resume:66:in `convert_to_html'
    from /Users/prat0318/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/json_resume-1.0.2/bin/json_resume:29:in `convert'
    from /Users/prat0318/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
    from /Users/prat0318/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
    from /Users/prat0318/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
    from /Users/prat0318/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
    from /Users/prat0318/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/json_resume-1.0.2/bin/json_resume:176:in `<top (required)>'
    from /Users/prat0318/.rbenv/versions/2.1.2/bin/json_resume:23:in `load'
    from /Users/prat0318/.rbenv/versions/2.1.2/bin/json_resume:23:in `<main>'

$ export RUBYOPT='-E utf-8'                                                                                                     [17:38:59]
$ json_resume convert prateek_cv.json                                                                                     [17:39:16]
Generating the html type...

Generated files present at /Users/prat0318/projects/json_resume/resume/page.html
Place /Users/prat0318/projects/json_resume/resume/ in /var/www/ to host.

Oh sorry, I was busy earlier and only checked ruby -e 'puts ENCODING.name'. It is now fine.
Thanks for your commitment.