table2li 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +105 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/examples/formal.html +21 -0
- data/examples/no-th.html +12 -0
- data/examples/simple.html +17 -0
- data/exe/table2li +39 -0
- data/lib/table2li.rb +5 -0
- data/lib/table2li/version.rb +3 -0
- data/table2li.gemspec +26 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f68dc6b06246b06ef37325695cc5ed9a2c9e3081
|
4
|
+
data.tar.gz: cddd7b5193c883265e476436d4361783fa62bb0f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3a8993955793d13222781d5a87a64f26327d36ae3195e49f675a3ead758b4ba9cbd483a124d4441758e0860d0df42cf179964807b0d40b60640df8f7b4ab5264
|
7
|
+
data.tar.gz: bc17782d4be18cdb412b525d27090a6c956d9e4cf382a312871666ded4a84b32d7bc28b17e9f54d76cfa121482336d0dabeaf37e3e7eb1b82df2ff7604f706ea
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Masafumi Yokoyama <myokoym@gmail.com>
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
# Table2li
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/table2li.svg)](http://badge.fury.io/rb/table2li)
|
4
|
+
|
5
|
+
A HTML to HTML converter. Converts from table to list.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
$ gem install table2li
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
$ table2li table.html
|
14
|
+
|
15
|
+
Or
|
16
|
+
|
17
|
+
$ cat table.html | table2li
|
18
|
+
|
19
|
+
## Exapmle
|
20
|
+
|
21
|
+
### There header
|
22
|
+
|
23
|
+
From:
|
24
|
+
|
25
|
+
<table>
|
26
|
+
<thead>
|
27
|
+
<tr>
|
28
|
+
<th>id</th>
|
29
|
+
<th>name</th>
|
30
|
+
<th>description</th>
|
31
|
+
</tr>
|
32
|
+
</thead>
|
33
|
+
<tbody>
|
34
|
+
<tr>
|
35
|
+
<td>2</td>
|
36
|
+
<td>Ai</td>
|
37
|
+
<td>Me.</td>
|
38
|
+
</tr>
|
39
|
+
<tr>
|
40
|
+
<td>5</td>
|
41
|
+
<td>Go</td>
|
42
|
+
<td>You.</td>
|
43
|
+
</tr>
|
44
|
+
</tbody>
|
45
|
+
</table>
|
46
|
+
|
47
|
+
To:
|
48
|
+
|
49
|
+
<ul>
|
50
|
+
<li>1<ul><li>id<ul><li>2</li></ul>
|
51
|
+
</li></ul>
|
52
|
+
<ul><li>name<ul><li>Ai</li></ul>
|
53
|
+
</li></ul>
|
54
|
+
<ul><li>description<ul><li>Me.</li></ul>
|
55
|
+
</li></ul>
|
56
|
+
</li>
|
57
|
+
<li>2<ul><li>id<ul><li>5</li></ul>
|
58
|
+
</li></ul>
|
59
|
+
<ul><li>name<ul><li>Go</li></ul>
|
60
|
+
</li></ul>
|
61
|
+
<ul><li>description<ul><li>You.</li></ul>
|
62
|
+
</li></ul>
|
63
|
+
</li>
|
64
|
+
</ul>
|
65
|
+
|
66
|
+
### No header
|
67
|
+
|
68
|
+
From:
|
69
|
+
|
70
|
+
<table>
|
71
|
+
<tr>
|
72
|
+
<td>2</td>
|
73
|
+
<td>Ai</td>
|
74
|
+
<td>Me.</td>
|
75
|
+
</tr>
|
76
|
+
<tr>
|
77
|
+
<td>5</td>
|
78
|
+
<td>Go</td>
|
79
|
+
<td>You.</td>
|
80
|
+
</tr>
|
81
|
+
</table>
|
82
|
+
|
83
|
+
To:
|
84
|
+
|
85
|
+
<ul>
|
86
|
+
<li>1<ul><li>2</li></ul>
|
87
|
+
<ul><li>Ai</li></ul>
|
88
|
+
<ul><li>Me.</li></ul>
|
89
|
+
</li>
|
90
|
+
<li>2<ul><li>5</li></ul>
|
91
|
+
<ul><li>Go</li></ul>
|
92
|
+
<ul><li>You.</li></ul>
|
93
|
+
</li>
|
94
|
+
</ul>
|
95
|
+
|
96
|
+
## Development
|
97
|
+
|
98
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
99
|
+
|
100
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
101
|
+
|
102
|
+
## Contributing
|
103
|
+
|
104
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/myokoym/table2li.
|
105
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "table2li"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
<table>
|
2
|
+
<thead>
|
3
|
+
<tr>
|
4
|
+
<th>id</th>
|
5
|
+
<th>name</th>
|
6
|
+
<th>description</th>
|
7
|
+
</tr>
|
8
|
+
</thead>
|
9
|
+
<tbody>
|
10
|
+
<tr>
|
11
|
+
<td>2</td>
|
12
|
+
<td>Ai</td>
|
13
|
+
<td>Me.</td>
|
14
|
+
</tr>
|
15
|
+
<tr>
|
16
|
+
<td>5</td>
|
17
|
+
<td>Go</td>
|
18
|
+
<td>You.</td>
|
19
|
+
</tr>
|
20
|
+
</tbody>
|
21
|
+
</table>
|
data/examples/no-th.html
ADDED
data/exe/table2li
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "nokogiri"
|
4
|
+
|
5
|
+
source = Nokogiri::HTML.parse(ARGF.read)
|
6
|
+
|
7
|
+
header = source.xpath('//tr/th').map do |th|
|
8
|
+
th.inner_text
|
9
|
+
end
|
10
|
+
|
11
|
+
fragment = Nokogiri::HTML.fragment("")
|
12
|
+
|
13
|
+
builder = Nokogiri::HTML::Builder.with(fragment) do |doc|
|
14
|
+
doc.ul {
|
15
|
+
source.xpath('//tr[td]').each_with_index do |tr, i|
|
16
|
+
doc.li {
|
17
|
+
doc.text i + 1
|
18
|
+
tr.xpath('td').each_with_index do |td, i|
|
19
|
+
doc.ul {
|
20
|
+
doc.li {
|
21
|
+
if header[i]
|
22
|
+
doc.text header[i]
|
23
|
+
doc.ul {
|
24
|
+
doc.li {
|
25
|
+
doc.text td.inner_text
|
26
|
+
}
|
27
|
+
}
|
28
|
+
else
|
29
|
+
doc.text td.inner_text
|
30
|
+
end
|
31
|
+
}
|
32
|
+
}
|
33
|
+
end
|
34
|
+
}
|
35
|
+
end
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
puts fragment.to_html
|
data/lib/table2li.rb
ADDED
data/table2li.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'table2li/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "table2li"
|
8
|
+
spec.version = Table2li::VERSION
|
9
|
+
spec.authors = ["Masafumi Yokoyama"]
|
10
|
+
spec.email = ["myokoym@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A HTML to HTML converter. Converts from table to list. }
|
13
|
+
spec.description = spec.summary
|
14
|
+
spec.homepage = "https://github.com/myokoym/table2li"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_runtime_dependency "nokogiri"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: table2li
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Masafumi Yokoyama
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.11'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.11'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description: A HTML to HTML converter. Converts from table to list.
|
56
|
+
email:
|
57
|
+
- myokoym@gmail.com
|
58
|
+
executables:
|
59
|
+
- table2li
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/console
|
69
|
+
- bin/setup
|
70
|
+
- examples/formal.html
|
71
|
+
- examples/no-th.html
|
72
|
+
- examples/simple.html
|
73
|
+
- exe/table2li
|
74
|
+
- lib/table2li.rb
|
75
|
+
- lib/table2li/version.rb
|
76
|
+
- table2li.gemspec
|
77
|
+
homepage: https://github.com/myokoym/table2li
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.5.0
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: A HTML to HTML converter. Converts from table to list.
|
101
|
+
test_files: []
|
102
|
+
has_rdoc:
|