`
CaiDeHen
  • 浏览: 89826 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

#118 Liquid

阅读更多
Liquid is a safe way to provide a powerful template language to the site's users. See how in this episode.

<!-- pages/show.html.erb -->
<%= liquidize @page.content, 'page' => @page %>

# environment.rb
config.gem 'liquid'

# application_helper.rb
def liquidize(content, arguments)
  RedCloth.new(Liquid::Template.parse(content).render(arguments, :filters => [LiquidFilters])).to_html
end

# lib/liquid_filters.rb
module LiquidFilters
  include ActionView::Helpers::NumberHelper
  
  def currency(price)
    number_to_currency(price)
  end
end

# category.rb
liquid_methods :name

# page.rb
liquid_methods :products

def products
  Product.all
end

# product.rb
liquid_methods :name, :price, :category
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics