Ruby 2.1 with erubis Template Engine

一笑奈何 提交于 2019-12-01 11:14:52

问题


We are looking for fastest template engine for rendering of views.

As i understand erubis is the fastest template engine in ruby.

My usecase is render templates through script.

Looking at the gem official page it's latest release was in 2011. Not sure if the community is active. https://rubygems.org/gems/erubis/versions

Does anyone use ruby 2.1 with erubis template engine?

Is it recommended to use erubis with ruby 2.1?

Thanks Abhay


回答1:


I ran benchmark between ERB and erubis rendering with below code snippet.

erubis_render_time =  Benchmark.realtime {

  template_content = File.read("#{Rails.root}/app/views/web/email_templates/erubis_benchmark_test.erb")
  1000.times do |j|
    email_body = Erubis::Eruby.new(template_content).result({welcome_mail_cta: "Shop Now", welcome_mail_string: "Welcome. Your account is activated"})
  end
}


template_path = "/web/email_templates/benchmark_test"
erb_render_time = Benchmark.realtime {
1000.times do |j|
  email_body = ActionController::Base.new.send(:render_to_string,
                                              :template => template_path,
                                              :layout => false,
                                              :locals => {:data => {welcome_mail_cta: "Shop Now",
                                                                    welcome_mail_string: "Welcome. Your account is activated"
                                                    }
                                                          }
                                              )
end
}

As per above benchmark suite Erubis is 10-15 times faster then ERB rendering.



来源:https://stackoverflow.com/questions/27620228/ruby-2-1-with-erubis-template-engine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!