Radiant-如何增加定制的Radius Tag¶

1. 场景分析
我们希望把

     <r:box icon="happyface" title="Spiffy box title">
This is where the main content of our box will go. Lots
of HTML or radius tags can go here.
</r:box>



解析成

  <div class="box">
<h2>
<img src="/images/icons/happyface.png" />
Spiffy box title
</h2>
<div class="content">
This is where the main content of our box will go. Lots
of HTML or radius tags can go here.
</div>
</div>



<r:box /> 是没有定义的tag,需要我们自己定义。
2. 解决方案
1. 生成扩展extension -----custom_tags

  ./script/generate extension custom_tags


2. 测试先行-----编写specs
新建Lib目录,并在_custom_tags/spec/lib/custom_tags_spec.rb_

 require File.dirname(__FILE__) + '/../spec_helper'

describe 'CustomTags' do
dataset :pages

describe '<r:box>' do
it 'should render the correct HTML' do
tag = '<r:box icon="happyface" title="Test Title">Content</r:box>'

expected = %{<div class="box">
<h2>
<img src="/images/icons/happyface.png" />
Test Title
</h2>
<div class="content">
Content
</div>
</div>}

pages(:home).should render(tag).as(expected)
end
end
end


3. 修改custom_tags_extension.rb文件,在active方法中加入

 Page.send :include, CustomTags


4. 定义Radius Tag
vendor/extensions/custom_tags/lib/custom_tags.rb

 module CustomTags
include Radiant::Taggable

desc "Creates an HTML box with a title, icon and body content"
tag "box" do |tag|
""
end
end


5. 运行spec测试

cd vendor/extensions/custom_tags
rake spec


6. 结果如下

          .

Finished in 3.312051 seconds

1 example, 0 failures
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值