Ruby on Rails automatic string extraction for translation - ruby-on-rails

I am trying to automatically extract strings from ruby views .erb files to config/lang/ files for example en.yml
Is there some updated alternative to this?
http://zigzag.github.io/2009/12/17/get-your-local-rails-application-ready-for-i18n.html
It is supposed to be a gem tool that will extract strings if used like this:
ready_for_i18n <you view path> <target path>

There is a number of gems that do this. One list of such gems is maintained on the i18n-tasks wiki:
Slimkeyfy extracts plain strings from Slim views and Rails Controllers.
haml-i18n-extractor
automates string extraction from HAML.
i15r for ERB and Haml.
i18n-html_extractor another extractor for ERB with an interactive mode.

Try i18n-tasks gem
$ i18n-tasks add-missing

Related

‘No such file or directory - pandoc’ when trying to use :markdown filter in haml-rails

I am trying to use the :markdown filter with haml-rails on Rails 5.0.2.
When I first tried to use Markdown in a HAML file, it said it needed pandoc-ruby as a dependency, so I added that to my Gemfile. However, now when I try to use :markdown inside my file, I am getting the following error:
You don’t need Pandoc here, that’s just the first markdown processor Tilt tries to use and reports if it can’t find any others. You do need some markdown processor though.
Your simplest fix would probably be to remove pandoc-ruby from your Gemfile and add a Ruby markdown processor (e.g. kramdown).
If you need more control over which processor Haml uses (e.g. if you want to use kramdown for Haml filters but have RedCarpet in your app for something else), try something like this in an initializer:
require 'tilt/kramdown'
module Haml::Filters
remove_filter("Markdown")
register_tilt_filter "Markdown", :template_class => Tilt::KramdownTemplate
end
If you do want to use Pandoc for rendering markdown then you need to make sure it’s installed, see Chris’ answer.
From its README:
PandocRuby is a wrapper for Pandoc, a Haskell library with command line tools for converting one markup format to another.
It requires Pandoc to be installed separately (emphasis added):
First, make sure to install Pandoc.
Next, add PandocRuby to your Gemfile
gem 'pandoc-ruby'

How to convert Rails whole application in erb to haml

I have one Rails application and all files are in erb format. Is there any quick way to convert whole application's erb file to haml.. without any conflict.
And also would like to know for the Reverse..
Thanks in advance. :)
For erb-to-haml
You can use from the command line html2haml
html2haml your_erb_file new_haml_file
If you want to convert all your files in one go, look at this article : http://shifteleven.com/articles/2008/06/08/converting-erb-to-haml-snippet
erb2haml gem will do the trick.. have a look to https://github.com/dhl/erb2haml
For haml-to-erb
I recommend you HAML2ERB service . It's really cool and generates valid ERB/HTML code! Tested on big HAML views (over 800 lines of markup) from the real production app. Project active :)
have a look to this also http://makandracards.com/makandra/544-convert-haml-to-erb

How to generate KML file in ruby?

I'd like to serve a dynamically generated KML file using ruby on rails. I made some research and I found kamel which looks great. The problem is that kame depends on ruby_kml gem which doesn't seem to be available anymore.
$ gem install kamel
ERROR: While executing gem ... (Gem::DependencyError)
Unable to resolve dependencies: kamel requires ruby_kml (~> 0.1.4)
Searching 'kml' on rubygems.org was unsuccessful.
So does someone know any alternative to achieve KML generation in ruby on rails?
KML is just another XML, you can easily make your own "writer" which parses recursively and formats whatever input is passed in as a parameter and generates a string that looks like valid KML/XML.
Recommended reading for the options and the XML layout:
https://developers.google.com/kml/documentation/kmlreference

sanitize and namespace

I have some "namespaced" custom tags(developed with radius gem) that i would like to use in my rails application. I'd like to use sanitize gem to prevent xss-attacks, but there are no descriptions how to configure namespace in sanitize. Is there any possible way?
The sanitize gem doesn't support namespaces. Briefly looking at the code for sanitize, neither the transform class that cleans elements nor the way it actually parses html gives Nokogiri (the xml parser underlying sanitize) the information it needs to be able to recognise and process namespaces), so without modifying sanitize to support this, it's not going to be possible.
You'll be able to see the tags without the prefixed-namespaces in sanitize, so if they all have custom names that don't collide with any other tags, you can specify those, but with sanitize as it is currently written, you can't filter namespace-specific tags.
As far as I know the sanitize gem just filters javascript and HTML from params in the controller. Perhaps its been extended since I last looked.
No, you can't namespace most gems. There are a few hacks to put wrappers around them with monkey patching. If needed I would google "ruby namespace collision" and you get something like this How to resolve Rails model namespace collision

Ruby PDF:Toolkit using pdftotext

I'm converting pdf files in my Ruby project. I'm using the pdf toolkit gem for this.
The documentation shows how you can use pdftotext
pdftotext(file,outfile = nil,&block)
In my project I am converting a PDF file without any arguments and can just do this:
PDF::Toolkit.pdftotext("file.pdf", "file.txt)
If I run it from the command line, I can preserve the layout by passing that param
pdftotext -layout file.pdf
What is the correct syntax to achieve this with PDF::Toolkit?
Thanks!
Figured out how to make it work so I'm answering my own question, but if there's a "proper way" to do this, I'd love to see how to do it.
Put the options in the second argument and the text file will be named file_name.txt
PDF::Toolkit.pdftotext("file_name.pdf","-layout" )

Resources