wizport 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
@@ -6,19 +6,13 @@
|
|
6
6
|
require "stringio"
|
7
7
|
module Wizport
|
8
8
|
module Html
|
9
|
-
class Document
|
9
|
+
class Document < Element
|
10
10
|
def initialize(&block)
|
11
11
|
@html = StringIO.new
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
def text(txt)
|
17
|
-
Wizport::Html::Text.new(self,txt)
|
18
|
-
end
|
19
|
-
|
20
|
-
def table(rows = [], &block)
|
21
|
-
Wizport::Html::Table.new(self, rows, &block)
|
12
|
+
#,:style => "border:1px solid red;width:96%"
|
13
|
+
tag 'div', :class => 'rpt' do
|
14
|
+
block.arity<1 ? self.instance_eval(&block) : block.call(self) if block_given?
|
15
|
+
end
|
22
16
|
end
|
23
17
|
|
24
18
|
def write(txt)
|
@@ -26,17 +20,23 @@ module Wizport
|
|
26
20
|
end
|
27
21
|
|
28
22
|
def to_html
|
29
|
-
@html << '</div>'
|
30
23
|
@html.string
|
31
24
|
end
|
32
25
|
|
33
|
-
def
|
26
|
+
def save(file)
|
27
|
+
File.open(file, 'w') { |file| file.write(to_html) }
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
34
31
|
|
32
|
+
def text(txt,options)
|
33
|
+
Wizport::Html::Text.new(self,txt,options)
|
35
34
|
end
|
36
35
|
|
37
|
-
def
|
38
|
-
|
36
|
+
def table(rows = [], &block)
|
37
|
+
Wizport::Html::Table.new(self, rows, &block)
|
39
38
|
end
|
39
|
+
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
@@ -9,6 +9,33 @@ module Wizport
|
|
9
9
|
def initialize(html)
|
10
10
|
@html = html
|
11
11
|
end
|
12
|
+
|
13
|
+
def tag(name, *args) #text = nil, options = {})
|
14
|
+
text = nil
|
15
|
+
options = {}
|
16
|
+
case args.size
|
17
|
+
when 1
|
18
|
+
if args.first.is_a?(Hash)
|
19
|
+
options = args.first
|
20
|
+
else
|
21
|
+
text = args.first
|
22
|
+
end
|
23
|
+
when 2
|
24
|
+
text = args.first
|
25
|
+
options = args.last
|
26
|
+
end
|
27
|
+
@html.write '<'
|
28
|
+
@html.write name
|
29
|
+
options.each do |k, v|
|
30
|
+
@html.write " #{k}='#{v}'"
|
31
|
+
end
|
32
|
+
@html.write '>'
|
33
|
+
@html.write text if text
|
34
|
+
yield if block_given?
|
35
|
+
@html.write '</'
|
36
|
+
@html.write name
|
37
|
+
@html.write '>'
|
38
|
+
end
|
12
39
|
end
|
13
40
|
end
|
14
41
|
end
|
@@ -6,43 +6,37 @@
|
|
6
6
|
module Wizport
|
7
7
|
module Html
|
8
8
|
class Table < Element
|
9
|
-
def initialize(html,rows = [],options = {}
|
9
|
+
def initialize(html, rows = [], options = {}, &block)
|
10
10
|
super html
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
#{style:'border:1px solid red;'}
|
12
|
+
tag 'table' do
|
13
|
+
tag 'tbody' do
|
14
|
+
rows.each do |row|
|
15
|
+
add_row row, :headed => options[:headed]
|
16
|
+
end
|
17
|
+
block.arity<1 ? self.instance_eval(&block) : block.call(self) if block_given?
|
18
|
+
end
|
14
19
|
end
|
15
|
-
block.arity<1 ? self.instance_eval(&block) : block.call(self) if block_given?
|
16
|
-
@html.write '</tbody></table>'
|
17
20
|
end
|
18
21
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
private
|
23
|
+
|
24
|
+
def add_row(columns, options = {})
|
25
|
+
name = options[:headed] ? 'thread' : 'tr'
|
26
|
+
tag name do
|
27
|
+
columns.each do |column|
|
28
|
+
add_cell column
|
29
|
+
end
|
26
30
|
end
|
27
|
-
@html.write '</'
|
28
|
-
@html.write tag_name
|
29
|
-
@html.write '>'
|
30
31
|
end
|
31
32
|
|
32
33
|
def add_cell(column)
|
34
|
+
content = column
|
33
35
|
if column.is_a?(Hash)
|
34
|
-
|
35
|
-
rowspan = column[:rowspan]
|
36
|
-
column = column[:content]
|
37
|
-
@html.write '<td'
|
38
|
-
@html.write " colspan='#{colspan}'" if colspan
|
39
|
-
@html.write " rowspan='#{rowspan}'" if rowspan
|
40
|
-
@html.write '>'
|
36
|
+
tag 'td', column.delete(:content), column #.merge({style:'border:1px solid red;'})
|
41
37
|
else
|
42
|
-
|
38
|
+
tag 'td', content #, {style:'border:1px solid red;'}
|
43
39
|
end
|
44
|
-
@html.write column
|
45
|
-
@html.write '</td>'
|
46
40
|
end
|
47
41
|
end
|
48
42
|
end
|
@@ -6,14 +6,11 @@
|
|
6
6
|
module Wizport
|
7
7
|
module Html
|
8
8
|
class Text < Element
|
9
|
-
|
9
|
+
#options = {color:red, 'font-size':24, 'text-align' = left }
|
10
|
+
def initialize(html,txt,options = {})
|
10
11
|
super html
|
11
|
-
|
12
|
-
@html.write txt
|
13
|
-
@html.write '</p>'
|
12
|
+
tag 'p', txt, {:style => options.collect {|k, v| "#{k}:#{v}"}.join(';')}.delete_if {|k,v| v == nil || v == ''}
|
14
13
|
end
|
15
|
-
|
16
|
-
|
17
14
|
end
|
18
15
|
end
|
19
16
|
end
|
data/lib/wizport/version.rb
CHANGED
@@ -5,10 +5,11 @@ require "../../../../spec/spec_helper"
|
|
5
5
|
describe Wizport::Html::Document do
|
6
6
|
|
7
7
|
it "should do something" do
|
8
|
-
html = Wizport::Html::Document.new
|
9
|
-
|
10
|
-
|
8
|
+
html = Wizport::Html::Document.new do
|
9
|
+
text "报表",'text-align' => :center
|
10
|
+
table [[1,2,3]] do
|
11
11
|
add_row [4,{content:'ss',colspan:2}]
|
12
|
+
end
|
12
13
|
end
|
13
14
|
|
14
15
|
p html.to_html
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wizport
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|