- 浏览: 202884 次
- 来自: ...
文章分类
最新评论
-
赤道螞蟻:
如果是數據庫有定時任務,定時更新表的數據。 表中數據變化時,主 ...
用socket.io实现WebSocket的一个简单例子 -
cwalet:
在世界的中心呼喚愛 写道提示找不到 expressnpm in ...
用socket.io实现WebSocket的一个简单例子 -
在世界的中心呼喚愛:
提示找不到 express
用socket.io实现WebSocket的一个简单例子 -
Anleb:
def m1(a)
puts 'invoke m1'
pu ...
Ruby的一些疑问 -
biyeah:
补充,任何类,只要实现to_proc方法,都可以与&结 ...
Ruby的一些疑问
http://markaby.rubyforge.org/
Markaby is a very short bit of code for writing HTML pages in pure Ruby. It is an alternative to ERb which weaves the two languages together. Also a replacement for templating languages which use primitive languages that blend with HTML.
Using Markaby as a Rails plugin
Write Rails templates in pure Ruby. Example layout:
Using Markaby as a Ruby class
Markaby is flaming easy to call from your Ruby classes.
Markaby::Builder.new does take two arguments for passing in variables and a helper object. You can also affix the block right on to the class.
See Markaby::Builder for all of that.
A Note About instance_eval
The Markaby::Builder class is different from the normal Builder class, since it uses instance_eval when running blocks. This cleans up the appearance of the Markaby code you write. If instance_eval was not used, the code would look like this:
So, the advantage is the cleanliness of your code. The disadvantage is that the block will run inside the Markaby::Builder object’s scope. This means that inside these blocks, self will be your Markaby::Builder object. When you use instance variables in these blocks, they will be instance variables of the Markaby::Builder object.
This doesn’t effect Rails users, but when used in regular Ruby code, it can be a bit disorienting. You are recommended to put your Markaby code in a module where it won’t mix with anything.
A Note About Rails Helpers
When used in Rails templates, the Rails helper object is passed into Markaby::Builder. When you call helper methods inside Markaby, the output from those methods will be output to the stream. This is incredibly handy, since most Rails helpers output HTML tags.
However, some methods are designed to give back a String which you can use elsewhere. Call the @helpers object with the method and you’ll get the String back and nothing will be output.
p "Total is: #{@helper.number_to_human_size @file_bytes}"
Conversely, you may call instance variables from your controller by using a method and its value will be returned, nothing will be output.
A Quick Tour
If you dive right into Markaby, it’ll probably make good sense, but you’re likely to run into a few kinks. Keep these pointers in mind and everything will be fine.
Element Classes
Element classes may be added by hooking methods onto container elements:
Which results in:
Element IDs
IDs may be added by the use of bang methods:
Which results in:
Markaby assumes XHTML 1.0 Transitional
Output defaults to XHTML 1.0 Transitional. To do XHTML 1.0 Strict, try this:
The capture Method
Want to catch a block of HTML as a string and play with it a bit? Use the capture method.
Commonly used to join HTML blocks together:
The tag! Method
If you need to force a tag at any time, call tag! with the tag name followed by the possible arguments and block. The CssProxy won’t work with this technique.
Credits
Markaby is a work of immense hope by Tim Fletcher and why the lucky stiff. Thankyou for giving it a whirl.
Markaby is inspired by the HTML library within cgi.rb. Hopefully it will turn around and take some cues.
Markaby is a very short bit of code for writing HTML pages in pure Ruby. It is an alternative to ERb which weaves the two languages together. Also a replacement for templating languages which use primitive languages that blend with HTML.
Using Markaby as a Rails plugin
Write Rails templates in pure Ruby. Example layout:
html do head do title 'Products: ' + action_name stylesheet_link_tag 'scaffold' end body do p flash[:notice], :style => "color: green" self << content_for_layout end end
Using Markaby as a Ruby class
Markaby is flaming easy to call from your Ruby classes.
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
Markaby::Builder.new does take two arguments for passing in variables and a helper object. You can also affix the block right on to the class.
See Markaby::Builder for all of that.
A Note About instance_eval
The Markaby::Builder class is different from the normal Builder class, since it uses instance_eval when running blocks. This cleans up the appearance of the Markaby code you write. If instance_eval was not used, the code would look like this:
mab = Markaby::Builder.new mab.html do mab.head { mab.title "Boats.com" } mab.body do mab.h1 "Boats.com has great deals" end end puts mab.to_s
So, the advantage is the cleanliness of your code. The disadvantage is that the block will run inside the Markaby::Builder object’s scope. This means that inside these blocks, self will be your Markaby::Builder object. When you use instance variables in these blocks, they will be instance variables of the Markaby::Builder object.
This doesn’t effect Rails users, but when used in regular Ruby code, it can be a bit disorienting. You are recommended to put your Markaby code in a module where it won’t mix with anything.
A Note About Rails Helpers
When used in Rails templates, the Rails helper object is passed into Markaby::Builder. When you call helper methods inside Markaby, the output from those methods will be output to the stream. This is incredibly handy, since most Rails helpers output HTML tags.
head do javascript_include_tag 'prototype' autodiscovery_link_tag end
However, some methods are designed to give back a String which you can use elsewhere. Call the @helpers object with the method and you’ll get the String back and nothing will be output.
p "Total is: #{@helper.number_to_human_size @file_bytes}"
Conversely, you may call instance variables from your controller by using a method and its value will be returned, nothing will be output.
# Inside imaginary ProductController def list @products = Product.find :all end # Inside app/views/product/list.mab products.each do |product| p product.title end
A Quick Tour
If you dive right into Markaby, it’ll probably make good sense, but you’re likely to run into a few kinks. Keep these pointers in mind and everything will be fine.
Element Classes
Element classes may be added by hooking methods onto container elements:
div.entry do h2.entryTitle 'Son of WebPage' div.entrySection %{by Anthony} div.entryContent 'Okay, once again, the idea here is ...' end
Which results in:
<div class="entry"> <h2 class="entryTitle">Son of WebPage</h2> <div class="entrySection">by Anthony</div> <div class="entryContent">Okay, once again, the idea here is ...</div> </div>
Element IDs
IDs may be added by the use of bang methods:
div.page! div.content! h1 "A Short Short Saintly Dog" end end
Which results in:
<div id="page"> <div id="content"> <h1>A Short Short Saintly Dog</h1> </div> </div>
Markaby assumes XHTML 1.0 Transitional
Output defaults to XHTML 1.0 Transitional. To do XHTML 1.0 Strict, try this:
xhtml_strict do # innerds end
The capture Method
Want to catch a block of HTML as a string and play with it a bit? Use the capture method.
Commonly used to join HTML blocks together:
div.menu! \ ['5.gets', 'bits', 'cult', 'inspect', '-h'].map do |category| capture { link_to category } end. join( " | " )
The tag! Method
If you need to force a tag at any time, call tag! with the tag name followed by the possible arguments and block. The CssProxy won’t work with this technique.
tag! :select, :id => "country_list" do countries.each do |country| tag! :option, country end end
Credits
Markaby is a work of immense hope by Tim Fletcher and why the lucky stiff. Thankyou for giving it a whirl.
Markaby is inspired by the HTML library within cgi.rb. Hopefully it will turn around and take some cues.
发表评论
-
在Rails中使用Pry
2012-02-07 06:43 2177Pry可看成是IRB的加强版。支持语法高亮等特点。 1、在Ge ... -
camping 一个小巧的ruby web framework
2012-02-04 04:01 1790https://github.com/camping/camp ... -
Ruby的一些疑问
2012-01-26 01:01 14351、网点看到一断程序, def m1(a) puts 'i ... -
RSpec测试框架
2012-01-10 12:59 2991#参考http://www.slideshare.net/ih ... -
[转]Ruby - DUP vs CLONE
2012-01-09 12:57 1834http://railsblogger.blogspot.co ... -
[转]eval, class_eval, instance_eval和binding
2012-01-09 12:10 1099http://www.cnblogs.com/rubylouv ... -
[转]Ruby中的binding
2012-01-09 11:50 1599http://kkito.cn/index.php/blog/ ... -
[转]Method visibility in Ruby
2012-01-04 12:37 1168From:http://weblog.jamisbuck.or ... -
[转]浅谈Ruby on Rails中的include和extend
2011-12-30 02:20 1057http://developer.51cto.com/art/ ... -
[转]Ruby中的Rake任务详述
2011-12-29 03:47 1769Trackback: http://tb.blog.csdn. ... -
[转]ruby中的闭包
2011-12-26 10:42 2770原文: http://kenbeit.com/po ... -
ruby技巧
2011-12-26 10:40 0ruby小技巧之 http://kenbeit.com/pos ... -
[转]Ruby中的多态
2011-12-20 11:56 0原文http://kkito.cn/index.php ... -
ruby中实现闭包
2011-12-20 09:10 957ruby中实现闭包很简单 如果一个方法中返回一个proced ... -
ruby中星号的使用
2011-12-20 05:54 1927ruby中星号的使用 1、数字乘法 2 * 3 = 6 2 ... -
[转]ruby的include与extend
2011-12-20 05:09 901原文http://www.cnblogs.com/rubylo ... -
[转]Ruby常用的内部变量
2011-12-20 03:59 952Ruby常用的内部变量 原文http://www.cnblog ... -
ruby与javascript面向对象编程的比较
2011-12-06 14:05 3351原文:http://howtonode.org/object- ... -
解决ruby中文乱码
2011-12-06 04:20 8012在文件头加上#encoding=UTF-8,示例: #enco ... -
[转帖]重新认识Ruby的多态和duck type
2011-12-05 11:56 985多态在Java中是如何定义的? 原文:http://devel ...
相关推荐
在编程领域,XML(eXtensible Markup Language)是一种用于存储和传输数据的标记语言,它具有结构化、可扩展性和平台无关性等优点。在C++编程中,处理XML文件通常需要借助特定的库来解析和操作XML文档。本文将深入...
This book is a condensed reference for HTML5 markup. It presents the essential HTML5 elements and attributes in a well-organized format that can be used as a handy reference. HTML5 Quick Markup ...
XML(eXtensible Markup Language)是一种用于标记数据的语言,广泛应用于数据交换、配置文件、文档存储等领域。在IT行业中,处理XML数据是常见的任务,而`MarkUp`类可能是为简化这一过程而设计的一个工具。 `...
在IT行业中,XML(eXtensible Markup Language)是一种用于存储和传输数据的标准化格式,尤其在软件开发中被广泛使用。VC++,全称Visual C++,是Microsoft开发的一款强大的C++集成开发环境,它提供了对XML的支持,...
XML(eXtensible Markup Language)作为一种数据交换和存储格式,被广泛应用于配置文件、数据传输、软件接口等场景。为了在VC中处理XML文档,我们可以利用第三方库,比如在本案例中提到的“markup”。 “markup”库...
XML(eXtensible Markup Language)是一种用于标记数据的通用标准,广泛用于数据交换和存储。RABL提供了一种简洁的方式定义XML结构,类似于JSON模板。 ```ruby object @item attribute :title node(:comments) do |...
"Markup"是C++中一个用于处理XML的类库,它提供了一种方便的方式来解析和操作XML文档。本文将深入探讨如何使用Markup库在C++中进行XML处理。 XML是一种自描述的、结构化的数据格式,其语法严格,易于机器解析和生成...
XML(eXtensible Markup Language)是一种用于标记数据的语言,广泛应用于数据交换、配置文件、文档存储等领域。在C++编程中,处理XML文件通常需要使用特定的库或类来实现。这里提到的"xml之Markup操作类.rar"提供了...
XML(eXtensible Markup Language)是一种用于存储和传输数据的标记语言,它以其结构化、自解释性和可扩展性而被广泛应用于软件开发、Web服务以及数据交换等领域。在处理XML文件时,经常会用到各种库或工具,其中一...
XML(eXtensible Markup Language)是一种用于标记数据的语言,广泛应用在数据交换、配置文件、文档存储等领域。本文将深入探讨一个名为"Markup"的简单易用的XML操作类库,该库以其轻量级、高效和易于使用的特性受到...
在IT行业中,XML(eXtensible Markup Language)是一种被广泛用于存储和传输数据的标记语言,它具有自解释性,结构清晰,易于人和机器阅读。C++,作为一门强大的编程语言,常用于开发高性能的应用程序,但在处理XML...
在本Demo中,我们重点探讨如何使用MFC中的Markup库来读写XML文件,这在很多场景下都是非常实用的,比如配置文件的存储、数据交换等。 XML(Extensible Markup Language)是一种自描述性的文本格式,常用于存储结构...
在IT领域,XML(eXtensible Markup Language)是一种用于标记数据的标准格式,它强调结构化数据的描述和存储。XML的设计目标是传输和存储数据,而非显示数据,因此它通常与样式表语言如CSS或XSLT结合使用来达到展示...
在IT行业中,XML(eXtensible Markup Language)是一种用于存储和传输数据的标准化格式,尤其在应用程序之间交换数据时非常常见。XML文件是自描述的,这意味着它们包含描述数据结构的信息,使得解析器能够理解并处理...
XML(eXtensible Markup Language)是一种用于标记数据的语言,广泛应用在软件开发、网络通信、数据存储等领域。本文将深入探讨“Markup_xml解析开源代码”的相关知识点,介绍TinyXML库,一个轻量级且易于使用的XML...
"Class-Markup-instructions.rar_Markup"这个压缩包文件提供了一个关于如何在C#或.NET环境中使用Markup类来操作XML的详细教程。这个教程可能涵盖了XML的基础知识,以及如何使用自定义的Markup类进行XML文件的读取和...
Markup.js, 强大的JavaScript模板 Markup.js-- 功能强大的JavaScript模板Markup.js 是一个简单而强大的JavaScript模板系统。为什么 Markup.js?Markup.js 将结构化数据转换为HTML标记或者其他文本格式的痛苦。 它
《Application=Code+Markup》是一本专注于Windows Presentation Foundation (WPF) 程序设计的中文书籍。WPF是微软.NET Framework的一部分,它为开发者提供了一种强大的方式来创建具有丰富用户界面的桌面应用程序。这...
City Geography Markup Language (CityGML) En-coding Standard an OGC Member approved international standard
markup, 我们用来渲染 README.your_favorite_markup的代码 GitHub标记这个库是存储库中的每个标记文件在 GitHub.com: 上呈现之前的第一步。这里库将原始标记转换为 HTML 。 请参见下面的支持标记标记格式列表。HTML...