是否存在用于编写rails视图助手甚至视图的gem?如果没有,这个宝石的出发点是什么?
div class: 'header' do h1 { 'Hello World' } a href: 'http://google.com', class: 'button' do 'Google' end end
受最近的javascript前端库如何使用纯javascript函数实现基于组件的视图的启发,例如:React,Vue.js等.
也许Markaby会帮助你,让你通过Ruby生成HTML.
官方文档中的一个例子:
require 'markaby' mab = Markaby::Builder.new mab.html do head { title "Boats.com" } body do h1 "Boats.com has great deals" ul do li "$49 for a canoe" li "$39 for a raft" li "$29 for a huge boot that floats and can fit 5 people" end end end puts mab.to_s
Arbre将完成这项工作.它是从广泛使用的ActiveAdmin gem 中提取的,作为满足此类需求的独立解决方案.
项目自述文件中的一个简单示例:
html = Arbre::Context.new do h2 "Why is Arbre awesome?" ul do li "The DOM is implemented in ruby" li "You can create object oriented views" li "Templates suck" end end puts html.to_s # =>
将呈现以下内容:
Why is Arbre awesome?
- The DOM is implemented in ruby
- You can create object oriented views
- Templates suck