html导入dj,GitHub - djberg96/html-table: An interface for generating HTML tables with Ruby, with some ...

Description

An interface for generating HTML Tables with Ruby.

Installation

gem install html-table

Synopsis

require 'html/table'

include HTML

# Explicit syntax

table = HTML::Table.new{ |t|

t.border = 1

t.bgcolor = "red"

}

# Implicit syntax

table = HTML::Table.new do

border 1

bgcolor 'red'

end

table.push Table::Row.new{ |r|

r.align = "left"

r.bgcolor = "green"

r.content = ["foo","bar","baz"]

}

row = Table::Row.new{ |r|

r.align = "right"

r.bgcolor = "blue"

r.content = "hello world"

}

table[1] = row

puts table.html

Output:

foobarbaz
hello world

See the 'examples' directory under 'doc' for more examples.

Mixins

Table is a subclass of Array, and therefore mixes in Enumerable. The

+push+, +unshift+ and []= methods have been modified. See below for details.

Table also mixes in AttributeHandler which provides methods for adding

attributes to each of the tag types. See attributes.rdoc for more details.

Notes

A Table consists of Table::Row, Table::Caption, Table::ColGroup,

Table::Body, Table::Foot, Table::Head and Table::Row objects.

Table::Row objects in turn consist of Table::Row::Data and

Table::Row::Header objects.

Table::ColGroup objects consist of Table::ColGroup::Col

objects.

Table::Head, Table::Body and Table::Foot objects consist

of Table::Row objects.

String attributes are quoted. Numeric attributes are not.

Some attributes have type checking. Some check for valid arguments. In

the latter case, it is case-insensitive. See the documentation on

specific methods for more details.

Using a non-standard extension (e.g. "background") will emit a

NonStandardExtensionWarning. See the documentation for structured_warnings

for more information on how to control these.

Known Bugs

None that I'm aware of. Please report bugs on the project page at:

Future Plans

None at this time.

Acknowledgements

Anthony Peacock, for giving me ideas with his HTML::Table Perl module.

Holden Glova and Culley Harrelson for API suggestions and comments.

License

Apache-2.0

Copyright

(C) 2003-2021 Daniel J. Berger

All Rights Reserved

Warranty

This package is provided "as is" and without any express or

implied warranties, including, without limitation, the implied

warranties of merchantability and fitness for a particular purpose.

Author

Daniel J. Berger

Developer's Notes

Some people might be a little annoyed with the fact that I use a

strongtyping library. I'm not a big fan of strong typing myself.

So, why did I do this?

Normally when creating code, you setup your own rules as far as what is

allowed as an argument. You publish the API, set up a good set of tests,

and don't bother worrying about types because you figure people can read

the API and won't go out of their way to break it. You certainly don't

worry about it yourself because you're used to dynamic languages and find

that you don't need the strong typing training wheels after all, right?

However, HTML tables have a predefined set of rules as far as what content

is valid, and where it's placed in order to be HTML compliant. For

example, if a caption is included, it should be at the 'top' of your table

syntax, you can only have one foot section, and so on. I therefore chose to

enforce these conventions and rules in Ruby via a module. I could have

lived without it, and instead chose to do a plethora of "kind_of?" checks,

but the strongtyping lib is simply more convenient all around.

UPDATE: I originally used Ryan Pavlik's strongtyping library as a dependency.

As of version 1.6.0 I now simply include a pure Ruby version with this library.

This makes it easier to work with JRuby and eliminates a dependency.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值