What are the advantages of using Builder over regular xml files? - ruby-on-rails

I have a Rails application which is using the Builder gem for writing easy to use XML files.
I am very much satisfied with the Builder gem but, as per my product architect's view, we should always use simple .xml files instead of using third party tools.
So, I need to give a solid justification to him explaining to him about the advantages of using Builder over regular XML files in our Rails application.
Can anyone give or guide me to a valid justification on the usage of Builder over regualr RXML/XML files in a Rails application?

If your xml files are static than he is correct and there is no benefit of friting them using any sort of xml template. If you are using it for dynamic content than you gain all of the benefit of template language such as sharing the code between templates, caching etc

He can be as high minded as he likes, but Builder 3.0 comes with any brand new rails 3 app. It's already in your gem bundle, why not utilize it? It's like saying ActiveRecord or JQuery shouldn't be used because we shouldn't rely on a third party tool. Since you're already using rails and all of the open source software that comes with it, what's wrong with Builder?
That being said, as Yuiry pointed out, the advantage is that builder is dynamic whereas a .xml is static.

Related

Removing empty nodes from an XML document created by a .builder template

I have a problem like What's the cleanest way to ignore empty nodes with Nokogiri::XML::Builder , except that my XML document is generated by a .builder template file using the builder gem.
I'm generating an XML document using the builder gem (and tilt) and I want to get rid of empty nodes.
The answer suggesting just iterating through each attribute and deciding whether to serialise each attribute or not isn't very suitable to my application, because there's quite a lot of logic involved in building the XML document.
The answer suggesting the use of Nokogiri::XML::Node#traverse doesn't look bad, but I suspect this approach isn't supported by the builder gem. The documentation for builder says
An Builder::XmlTree class to generate XML tree (i.e. DOM-like)
structures is also planned, but not yet implemented. Also, the events
builder is currently lagging the markup builder in features.
(I'm not sure if the quoted section is equivalent to Nokogiri::XML::Node#traverse, but it does at the least suggest that there's some functionality not available in Builder)
Also, searching for some sort of remove method doesn't get a match in the git repository.
The builder gem, as of 2017, is largely abandoned. The master branch last had a commit in June 2013, and there's only been a handful of commits in forks since then. Tilt's mention of maintenance only refers to the maintenance of integration between tilt and builder.
Are there any gems that support the .builder format other than the builder gem?
Do I have any alternatives other than adding a lot of if title or if feed conditionals to the .builder file, or once I've created the XML, feeding it through an unrelated XML parser?

How can I inject a dynamically generated image (barcode, as it happens) into a PDF document (I'm in rails if that matters)?

I'm aware of pdf-stamper, but I'm trying to avoid switching everything to jruby right now.
I just need to "stamp" an image that I generate within the rails app (a PDF417 barcode) into a form field in the PDF document (there's an FDF; it's a document template kinda thing).
I'm filling out the text-based fields by just shelling out to pdftk, so if there's a way to do it using pdftk, I'd be fine with that, but I've looked high and low for one without any luck.
How about using a barcode font? some alternatives too. I haven't used that one but there may be others available too
I know I'm late to the party, but the PDF417 Rubygem should do what you need. https://rubygems.org/gems/pdf417 will generate it and if you have chunky_png installed you can easily write out PNGs to a file.

Can an admin template be used in a Ruby on Rails web app?

I have been doing UI research and have come across admin templates at http://themeforest.net/. I was wondering how do you apply these onto a web app built on Rails. These templates look very similar to wordpress themes. Are they that easy to configure? Is it just as simple as setting up a link to the database to make the fields form capture data? I've been looking at this theme.
For admin templates I recommend using Active Admin. It's relatively easy to implement and gives you great admin screens with little effort.
Yes, You can. I'm trying to solve the same problem and so far I have a couple options:
1.) do it by hand, I've done this before, it works but takes a lot of time to truly understand how your theme is put together. First I would recommend using the included themes assets exactly as they are bundled with the theme. Don't assume that just because you have twitter-bootstrap-rails gem that the bootstrap classes in the theme will work. Link the assets statically and slowly extract out the static assets and replace them in the asset pipeline once you know they work.
2.) Use the strategy suggested in the install_theme gem (http://drnicwilliams.com/2009/10/06/install-any-html-themetemplate-into-your-rails-app/) the gem itself is not maintained any longer (i'm not sure about any forks), but the strategy is sound. Extract the core parts of the template into partials.
The short answer is yes, but there is no straight forward way to "import to rails"

ruby on rails 3.1 web design

May I ask you how to make rails web design more efficient?
Is compass plus blueprint the perfect match?
Is the current version of compass support rails3.1
Are there any other frameworks that will make rails web deign easier?
Thanks
Definitely a framework like compass is awesome, it includes a lot of helpers, and provides a good solid base.
For form-styling I would recommend using a gem like [formtastic][1], which not only greatly simplifies making forms, but also provides a standard css file. So all needed tags are then known (and can be overwritten if needed).
There a few alternatives to kickstart your application's layout:
twitter-bootstrap: it is plainly awesome and provides a great start (it does not play nice with formtastic, but works perfectly well with simple_form).
web-app-theme provides generators, and a set of templates to style your application quickly
activo is a template that is contained in web-app-theme, but can also be used standalone
Hope this helps.

Is Prince the best way to create PDFs in Ruby on Rails?

After several Google searches, it appears that the way to create PDFs in Rails from HTML and CSS (versus a new markup language) is to use Prince.
With licensing at $3800 for my non-big-commercial app, I'm wondering if this is, in fact, consensus or people have an alternative they can share the whats and hows.
You may check out prawn too. Tutorial can be found on railscasts.com.
This may fit the bill: http://code.google.com/p/wkhtmltopdf/
We tried tow solutions:
using latex generate pdf, there is ruby gem code rtex
using java library iText, use it you may need rjb which allow you using java lib directly in ruby code, just like jruby, but you don't need build all you application on jruby.
I create tons of different PDF files on the fly from various data sources using Rails, including finest layout. I create need to create them for presenting products to customers.
After having tried all the tools mentioned above, Prince is the best tool for this task.
Prince's rendering quality & CSS support (better than some browsers) is its main selling point. If you're only generating documents with simple layouts, stick with Prawn.

Resources