wizport 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -1,5 +1,5 @@
1
- *.gem
2
- .bundle
3
- Gemfile.lock
4
- pkg/*
5
- .idea/
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .idea/
data/Gemfile CHANGED
@@ -1,4 +1,9 @@
1
- source "http://rubygems.org"
2
-
3
- # Specify your gem's dependencies in wizport.gemspec
4
- gemspec
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in wizport.gemspec
4
+ gemspec
5
+
6
+ #gem 'rspec'
7
+ gem 'bson_ext'
8
+ gem 'mongoid'
9
+
data/Rakefile CHANGED
@@ -1 +1 @@
1
- require "bundler/gem_tasks"
1
+ require "bundler/gem_tasks"
data/lib/wizport.rb CHANGED
@@ -1,5 +1,24 @@
1
- require "wizport/version"
2
-
3
- module Wizport
4
- # Your code goes here...
5
- end
1
+ require "prawn"
2
+
3
+ require "wizport/version"
4
+
5
+ require "wizport/document/pdf"
6
+
7
+ require "wizport/visitor"
8
+ require "wizport/document/Rtf/element"
9
+ require "wizport/document/Rtf/plaintext"
10
+ require "wizport/document/Rtf/command"
11
+ require "wizport/document/Rtf/group"
12
+ require "wizport/document/Rtf/text"
13
+ require "wizport/document/rtf"
14
+
15
+ require "wizport/builder/pdf"
16
+ require "wizport/builder/rtf"
17
+
18
+ require "wizport/engine/mongoid_source"
19
+ require "wizport/engine/column"
20
+ require "wizport/engine/section"
21
+ require "wizport/engine/report"
22
+ module Wizport
23
+ # Your code goes here...
24
+ end
@@ -0,0 +1,65 @@
1
+ # encoding: utf-8
2
+
3
+ # Wizport: A gem for creating reports by specifying columns, groups, styles, etc.
4
+ # Copyright 2012 by sgzhe@163.com
5
+
6
+ module Wizport
7
+ module Builder
8
+ class Pdf
9
+ def initialize(report)
10
+ @rpt = report
11
+ @pdf = Wizport::Document::Pdf.new
12
+ end
13
+
14
+ def header
15
+ @pdf.text @rpt.title
16
+ end
17
+
18
+ def grid
19
+ tbl = []
20
+ tbl << @rpt.columns.map {|c| c.title }
21
+ @rpt.source.all.each do |obj|
22
+ tbl << @rpt.columns.map {|c| obj.send(c.name)}
23
+ end
24
+ @pdf.table tbl
25
+ end
26
+
27
+ def section(section)
28
+ @tbl = []
29
+ @rpt.source.groups(section).each do |group|
30
+ section_header(section,group)
31
+ section_body(section,group)
32
+ section_footer(section,group)
33
+ end
34
+ @pdf.table @tbl
35
+ end
36
+
37
+ def section_header(section,group)
38
+ @tbl << ["#{section.title}:#{group}"]
39
+ end
40
+
41
+ def section_body(section,group)
42
+ rows = []
43
+ rows << @rpt.columns.map {|c| c.title }
44
+ objs = @rpt.source.filter({section.group => group})
45
+ objs.each do |obj|
46
+ rows << @rpt.columns.map {|c| obj.send(c.name)}
47
+ end
48
+ @tbl << [@pdf.make_table(rows)]
49
+ end
50
+
51
+ def section_footer(section,group)
52
+
53
+ end
54
+
55
+ def footer
56
+
57
+ end
58
+
59
+ def save(file)
60
+ @pdf.save(file)
61
+ end
62
+
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,56 @@
1
+ # encoding: utf-8
2
+
3
+ # Wizport: A gem for creating reports by specifying columns, groups, styles, etc.
4
+ # Copyright 2012 by sgzhe@163.com
5
+
6
+ module Wizport
7
+ module Builder
8
+ class Rtf
9
+ def initialize(report)
10
+ @rpt = report
11
+ @rtf = Wizport::Document::Rtf.new
12
+ end
13
+
14
+ def header
15
+ @rtf.text @rpt.title
16
+ end
17
+
18
+ def section(section)
19
+ @tbl = []
20
+ @rpt.source.groups(section).each do |group|
21
+ section_header(section, group)
22
+ section_body(section, group)
23
+ section_footer(section, group)
24
+ end
25
+ @rtf.table @tbl
26
+ end
27
+
28
+ def section_header(section, group)
29
+ @tbl << ["#{section.title}:#{group}"]
30
+ end
31
+
32
+ def section_body(section, group)
33
+ #rows = []
34
+ #rows << @rpt.columns.map { |c| c.title }
35
+ #objs = @rpt.source.filter({section.group => group})
36
+ #objs.each do |obj|
37
+ # rows << @rpt.columns.map { |c| obj.send(c.name) }
38
+ #end
39
+ #@tbl << [@rtf.make_table(rows)]
40
+ end
41
+
42
+ def section_footer(section, group)
43
+
44
+ end
45
+
46
+ def footer
47
+
48
+ end
49
+
50
+ def save(file)
51
+ @rtf.save(file)
52
+ end
53
+
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,58 @@
1
+ # encoding: utf-8
2
+
3
+ # Wizport: A gem for creating reports by specifying columns, groups, styles, etc.
4
+ # Copyright 2012 by sgzhe@163.com
5
+
6
+ module Wizport
7
+ module Rtf
8
+ class Cell
9
+ attr_accessor :col_span, :row_span
10
+ def initialize(data,row = nil)
11
+ @row = row
12
+ @index = @row.cells.size
13
+ @col_span = 1
14
+ @row_span = 1
15
+ @text = ""
16
+ if data.is_a?(Hash)
17
+ @col_span = data[:col_span] if data[:col_span]
18
+ @row_span = data[:row_span] if data[:row_span]
19
+ @text = data[:text]
20
+ else
21
+ @text = data
22
+ end
23
+
24
+ unless col_spanned?
25
+ @row.table.elements << Command.new(:celld)
26
+ @row.table.elements << Command.new(:clvmgf) if @row_span > 1
27
+ @row.table.elements << Command.new(:clvmrg) if row_spanned?
28
+ @row.table.elements << Command.new(:cellx, (@index+@col_span)*1000)
29
+ @row.table.elements << Plaintext.new(@text)
30
+ @row.table.elements << Command.new(:cell)
31
+ end
32
+
33
+ #@row.cellx_command Command.new(:clvmgf) if @row_span > 1
34
+ #@row.cellx_command Command.new(:clvmrg) if row_spanned?
35
+ #@row.cellx_command Command.new(:cellx, (@index+@col_span)*1000)
36
+ #@row.cellt_command Plaintext.new(@text)
37
+ #@row.cellt_command Command.new(:cell)
38
+ end
39
+
40
+ def col_spanned?
41
+ @index.times do |c|
42
+ return true if @row.cells[c].col_span + c > @index
43
+ end
44
+ return false
45
+ end
46
+
47
+ def row_spanned?
48
+ @row.index.times do |r|
49
+ return true if @row.table.rows[r].cells[@index].row_span + r > @row.index
50
+ end
51
+ return false
52
+ end
53
+
54
+
55
+
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ # Wizport: A gem for creating reports by specifying columns, groups, styles, etc.
4
+ # Copyright 2012 by sgzhe@163.com
5
+
6
+ module Wizport
7
+ module Rtf
8
+ class Command < Element
9
+ attr_accessor :name,:value
10
+
11
+ def initialize(name,value = nil)
12
+ @name = name
13
+ @value = value
14
+ end
15
+
16
+ def ctrl
17
+ @name.to_s + @value.to_s
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,83 @@
1
+ # encoding: utf-8
2
+
3
+ # Wizport: A gem for creating reports by specifying columns, groups, styles, etc.
4
+ # Copyright 2012 by sgzhe@163.com
5
+
6
+ require "../../visitor"
7
+ require "./element"
8
+ require "./plaintext"
9
+ require "./command"
10
+ require "./group"
11
+ require "./text"
12
+ require "./cell"
13
+ require "./row"
14
+ require "./table"
15
+ require "./rtf_builder"
16
+
17
+
18
+ module Wizport
19
+ module Rtf
20
+ class Document < Group
21
+ def initialize(file = nil, &block)
22
+ super()
23
+ elements << Command.new(:rtf, 1)
24
+ block.arity<1 ? self.instance_eval(&block) : block.call(self) if block_given?
25
+ save file if file
26
+ end
27
+
28
+ #styles = {align,font,font_size,color }
29
+ def text(txt, styles = {:align => :left})
30
+ elements << Text.new(txt,styles)
31
+ end
32
+
33
+ def table(rows = [],&block)
34
+ elements << Table.new(rows, &block)
35
+ end
36
+
37
+ def colors(colours = ['ffffff'])
38
+
39
+
40
+ end
41
+
42
+ def style(txt, styles)
43
+
44
+ end
45
+
46
+
47
+ def method_missing(id, *args, &block)
48
+ cmd id, *args, &block
49
+ end
50
+
51
+ def to_s
52
+
53
+ end
54
+
55
+ def to_rtf
56
+ builder = RtfBuilder.new
57
+ accept(builder)
58
+ builder.to_rtf
59
+ end
60
+
61
+ def save(file)
62
+ File.open(file, 'w') { |file| file.write(to_rtf) }
63
+ end
64
+
65
+ end
66
+ end
67
+ end
68
+
69
+ if __FILE__ == $0
70
+ d = Wizport::Rtf::Document.new('c:/file.rtf') do
71
+ text "我们", :align => :center, :size => 48
72
+ text "春风不度玉门关", :align => :left, :font => 24
73
+ table [[{text:'eee',row_span:2},'s',{text:'ww',col_span:2},'d'],[nil,'s','d','d']] do
74
+ row ['f','s','d','d']
75
+ end
76
+
77
+ end
78
+
79
+ #p d.to_rtf
80
+
81
+
82
+ end
83
+
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+
3
+ # Wizport: A gem for creating reports by specifying columns, groups, styles, etc.
4
+ # Copyright 2012 by sgzhe@163.com
5
+
6
+ module Wizport
7
+ module Rtf
8
+ class Element
9
+ include Wizport::Visitable
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+
3
+ # Wizport: A gem for creating reports by specifying columns, groups, styles, etc.
4
+ # Copyright 2012 by sgzhe@163.com
5
+
6
+
7
+ module Wizport
8
+ module Rtf
9
+ class Group < Element
10
+ attr_accessor :elements
11
+ def initialize()
12
+ @elements = []
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+
3
+ # Wizport: A gem for creating reports by specifying columns, groups, styles, etc.
4
+ # Copyright 2012 by sgzhe@163.com
5
+
6
+ module Wizport
7
+ module Rtf
8
+ class Plaintext < Element
9
+ attr_accessor :txt
10
+
11
+ def initialize(txt)
12
+ @txt = txt
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+
3
+ # Wizport: A gem for creating reports by specifying columns, groups, styles, etc.
4
+ # Copyright 2012 by sgzhe@163.com
5
+
6
+ module Wizport
7
+ module Rtf
8
+ class Row
9
+ attr_accessor :table, :cells, :index
10
+ def initialize(columns,tbl = nil)
11
+ @table = tbl
12
+ @cells = []
13
+ @index = @table.rows.size
14
+
15
+ @table.elements << Command.new(:trowd)
16
+ @table.elements << Command.new(:trautofit1)
17
+ @table.elements << Command.new(:intbl)
18
+ columns.each_index do |i|
19
+ @cellx_index = nil
20
+ @cellt_index = nil
21
+ @cells << Cell.new(columns[i],self)
22
+ end
23
+ @table.elements << Command.new(:row)
24
+ end
25
+
26
+ def cellx_command(cmd)
27
+ @cellx_index = @cellx_index || @table.elements.size
28
+ @table.elements.insert @cellx_index, cmd
29
+ @cellx_index += 1
30
+ end
31
+
32
+ def cellt_command(cmd)
33
+ @cellt_index = @cellt_index || @table.elements.size
34
+ @table.elements.insert @cellt_index, cmd
35
+ @cellt_index += 1
36
+ end
37
+
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+
3
+ # Wizport: A gem for creating reports by specifying columns, groups, styles, etc.
4
+ # Copyright 2012 by sgzhe@163.com
5
+
6
+ module Wizport
7
+ module Rtf
8
+ class RtfBuilder
9
+ include Wizport::Visitor
10
+
11
+ def initialize
12
+ @rtf = StringIO.new
13
+ end
14
+
15
+ visit Group do |element|
16
+ @rtf << '{'
17
+ element.elements.each do |el|
18
+ el.accept(self)
19
+ end if element.is_a?(Wizport::Rtf::Group)
20
+ @rtf << '}'
21
+ end
22
+
23
+ visit Command do |element|
24
+ @rtf << '\\'
25
+ @rtf << element.ctrl
26
+ end
27
+
28
+ visit Plaintext do |element|
29
+ @rtf << ' '
30
+ @rtf << element.txt
31
+ end
32
+
33
+ def to_rtf
34
+ @rtf.string
35
+ end
36
+
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,191 @@
1
+ # encoding: utf-8
2
+
3
+ # Wizport: A gem for creating reports by specifying columns, groups, styles, etc.
4
+ # Copyright 2012 by sgzhe@163.com
5
+
6
+ module Wizport
7
+ module Rtf
8
+ class Spec
9
+ class << self
10
+ attr_reader :map
11
+ end
12
+ @map = {
13
+ # --- rtf general ----
14
+ :document_rtf => "rtf",
15
+ :document_ver => 1,
16
+ :document_generator => "generator",
17
+
18
+ # --- encoding ----
19
+ :encoding_ansi => "ansi",
20
+ :encoding_mac => "mac",
21
+ :encoding_pc => "pc",
22
+ :encoding_pca => "pca",
23
+ :encoding_ansi_code_page => "ansicpg",
24
+
25
+ # --- font ----
26
+ :font_table => "fonttbl",
27
+ :default_font => "deff",
28
+ :font => "f",
29
+ :font_kind_nil => "fnil",
30
+ :font_kind_roman => "froman",
31
+ :font_kind_swiss => "fswiss",
32
+ :font_kind_modern => "fmodern",
33
+ :font_kind_script => "fscript",
34
+ :font_kind_decor => "fdecor",
35
+ :font_kind_tech => "ftech",
36
+ :font_kind_bidi => "fbidi",
37
+ :font_charset => "fcharset",
38
+ :font_pitch => "fprq",
39
+ :font_size => "fs",
40
+ :font_down => "dn",
41
+ :font_up => "up",
42
+ :font_subscript => "sub",
43
+ :font_superscript => "super",
44
+ :fontNo_super_sub => "nosupersub",
45
+
46
+ :theme_font_lo_major => "flomajor", # these are 'theme' fonts
47
+ :theme_font_hi_major => "fhimajor", # used in new font tables
48
+ :theme_font_db_major => "fdbmajor",
49
+ :theme_font_bi_major => "fbimajor",
50
+ :theme_font_lo_minor => "flominor",
51
+ :theme_font_hi_minor => "fhiminor",
52
+ :theme_font_db_minor => "fdbminor",
53
+ :theme_font_bi_minor => "fbiminor",
54
+ :default_font_size => 24,
55
+ :code_page => "cpg",
56
+
57
+ # --- color ----
58
+ :color_table => "colortbl",
59
+ :color_red => "red",
60
+ :color_green => "green",
61
+ :color_blue => "blue",
62
+ :color_foreground => "cf",
63
+ :color_background => "cb",
64
+ :color_background_word => "chcbpat",
65
+ :color_highlight => "highlight",
66
+
67
+ # --- header/footer ----
68
+ :header => "header",
69
+ :header_first => "headerf",
70
+ :header_left => "headerl",
71
+ :header_right => "headerr",
72
+ :footer => "footer",
73
+ :footer_first => "footerf",
74
+ :footer_left => "footerl",
75
+ :footer_right => "footerr",
76
+ :footnote => "footnote",
77
+
78
+ # --- character ----
79
+ :delimiter => ",",
80
+ :extension_destination => "*",
81
+ :tilde => "~",
82
+ :hyphen => "-",
83
+ :underscore => "_",
84
+
85
+ # --- special character ----
86
+ :page => "page",
87
+ :section => "sect",
88
+ :paragraph => "par",
89
+ :line => "line",
90
+ :tabulator => "tab",
91
+ :em_dash => "emdash",
92
+ :en_ash => "endash",
93
+ :em_space => "emspace",
94
+ :en_space => "enspace",
95
+ :qm_space => "qmspace",
96
+ :bulltet => "bullet",
97
+ :left_single_quote => "lquote",
98
+ :right_single_quote => "rquote",
99
+ :left_double_quote => "ldblquote",
100
+ :right_double_quote => "rdblquote",
101
+
102
+ # --- format ----
103
+ :plain => "plain",
104
+ :paragraph_defaults => "pard",
105
+ :section_defaults => "sectd",
106
+
107
+ :bold => "b",
108
+ :italic => "i",
109
+ :underLine => "ul",
110
+ :underLineNone => "ulnone",
111
+ :strike_through => "strike",
112
+ :hidden => "v",
113
+ :align_left => "ql",
114
+ :align_center => "qc",
115
+ :align_right => "qr",
116
+ :align_justify => "qj",
117
+
118
+ :styleSheet => "stylesheet",
119
+
120
+ # --- info ----
121
+ :info => "info",
122
+ :info_version => "version",
123
+ :info_revision => "vern",
124
+ :info_number_of_pages => "nofpages",
125
+ :info_number_of_words => "nofwords",
126
+ :info_NumberOfChars => "nofchars",
127
+ :info_Id => "id",
128
+ :info_Title => "title",
129
+ :info_Subject => "subject",
130
+ :info_Author => "author",
131
+ :info_Manager => "manager",
132
+ :info_Company => "company",
133
+ :info_Operator => "operator",
134
+ :info_Category => "category",
135
+ :info_Keywords => "keywords",
136
+ :info_Comment => "comment",
137
+ :info_DocumentComment => "doccomm",
138
+ :info_HyperLinkBase => "hlinkbase",
139
+ :info_CreationTime => "creatim",
140
+ :info_RevisionTime => "revtim",
141
+ :info_PrintTime => "printim",
142
+ :info_BackupTime => "buptim",
143
+ :info_Year => "yr",
144
+ :info_Month => "mo",
145
+ :info_Day => "dy",
146
+ :info_Hour => "hr",
147
+ :info_Minute => "min",
148
+ :info_Second => "sec",
149
+ :info_EditingTimeMinutes => "edmins",
150
+
151
+ # --- user properties ----
152
+ :user_Properties => ":user_props",
153
+ :user_PropertyType => "proptype",
154
+ :user_PropertyName => "propname",
155
+ :user_PropertyValue => "staticval",
156
+ :user_PropertyLink => "linkval",
157
+
158
+ # this table is from the RTF specification 1.9.1, page 40
159
+ :property_TypeInteger => 3,
160
+ :property_TypeRealNumber => 5,
161
+ :property_TypeDate => 64,
162
+ :property_TypeBoolean => 11,
163
+ :property_TypeText => 30,
164
+
165
+ # --- picture ----
166
+ :picture => "pict",
167
+ :picture_Wrapper => "shppict",
168
+ :picture_WrapperAlternative => "nonshppict",
169
+ :picture_FormatEmf => "emfblip",
170
+ :picture_FormatPng => "pngblip",
171
+ :picture_FormatJpg => "jpegblip",
172
+ :picture_FormatPict => "macpict",
173
+ :picture_FormatOs2Metafile => "pmmetafile",
174
+ :picture_FormatWmf => "wmetafile",
175
+ :picture_FormatWinDib => "dibitmap",
176
+ :picture_FormatWinBmp => "wbitmap",
177
+ :picture_Width => "picw",
178
+ :picture_Height => "pich",
179
+ :picture_WidthGoal => "picwgoal",
180
+ :picture_HeightGoal => "pichgoal",
181
+ :picture_WidthScale => "picscalex",
182
+ :picture_HeightScale => "picscaley",
183
+
184
+ # --- bullets/numbering ----
185
+ :paragraph_number_text => "pntext",
186
+ :list_number_text => "listtext"
187
+
188
+ }
189
+ end
190
+ end
191
+ end
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+
3
+ # Wizport: A gem for creating reports by specifying columns, groups, styles, etc.
4
+ # Copyright 2012 by sgzhe@163.com
5
+
6
+ module Wizport
7
+ module Rtf
8
+ class Table < Group
9
+ attr_accessor :rows, :cells
10
+
11
+ #options = {header:[],widths:[]}
12
+ def initialize(rows = [],options = {}, &block)
13
+ super()
14
+ @rows = []
15
+ #@cells = {}
16
+ rows.each do |cells|
17
+ row cells
18
+ end
19
+ block.arity<1 ? self.instance_eval(&block) : block.call(self) if block_given?
20
+ end
21
+
22
+ def row(cells = [], &block)
23
+ r = Row.new(cells,self, &block)
24
+ @rows << r
25
+
26
+ end
27
+
28
+ #def [](r,c)
29
+ # @cells["#{r},#{c}"]
30
+ #end
31
+ #
32
+ #def [](r,c,v)
33
+ # @cells["#{r},#{c}"] = v
34
+ #end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+
3
+ # Wizport: A gem for creating reports by specifying columns, groups, styles, etc.
4
+ # Copyright 2012 by sgzhe@163.com
5
+
6
+ module Wizport
7
+ module Rtf
8
+ class Text < Group
9
+ ALIGN_MAP = {left:'ql',center:'qc'}
10
+
11
+ def initialize(txt = '', styles = {})
12
+ super()
13
+ styles = {:align => :left,:size => 24}.merge(styles)
14
+ elements << Command.new(:pard)
15
+ elements << @align = Command.new(ALIGN_MAP[styles[:align]])
16
+ elements << @size = Command.new(:fs,styles[:size])
17
+ elements << @txt = Plaintext.new(txt)
18
+ elements << Command.new(:par)
19
+ end
20
+
21
+ def size=(value)
22
+ @size.value = value
23
+ end
24
+
25
+ def size
26
+ @size.value
27
+ end
28
+
29
+ def align=(value)
30
+ @align.name = ALIGN_MAP[styles[value]]
31
+ end
32
+
33
+ def align
34
+ ALIGN_MAP.invert[@align.name]
35
+ end
36
+
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+
3
+ # Wizport: A gem for creating reports by specifying columns, groups, styles, etc.
4
+ # Copyright 2012 by sgzhe@163.com
5
+
6
+ module Wizport
7
+ module Document
8
+ class Pdf
9
+ def initialize
10
+ @pdf = Prawn::Document.new
11
+ @pdf.font "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf"
12
+ end
13
+
14
+ def text(txt)
15
+ @pdf.text txt
16
+ end
17
+
18
+ def table(rows,options={}, &block)
19
+ @pdf.table(rows,options.merge({:width => @pdf.bounds.width}), &block)
20
+ end
21
+
22
+ def make_table(rows)
23
+ @pdf.make_table(rows,:width => @pdf.bounds.width)
24
+ end
25
+
26
+ def save(file)
27
+ @pdf.render_file(file)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+
3
+ # Wizport: A gem for creating reports by specifying columns, groups, styles, etc.
4
+ # Copyright 2012 by sgzhe@163.com
5
+
6
+ require 'rtf'
7
+ module Wizport
8
+ module Document
9
+ class Rtf
10
+ def initialize
11
+ @rtf = RTF::Document.new(RTF::Font.new(RTF::Font::ROMAN, 'Times New Roman'))
12
+ end
13
+
14
+ def text(txt)
15
+ @rtf.paragraph << txt
16
+ end
17
+
18
+ def table(rows)
19
+ r = rows.length
20
+ c = rows.first && rows.first.length
21
+ tbl = @rtf.table r, c
22
+ tbl[0][2] << "sss"
23
+ #rows.each_index do |row|
24
+ # rows[row].each_index do |col|
25
+ # tbl[row][col] << rows[row][col].to_s
26
+ # end
27
+ #end
28
+ tbl
29
+ end
30
+
31
+ def save(file)
32
+ File.open(file, 'w') { |file| file.write(@rtf.to_rtf) }
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+
3
+ # Wizport: A gem for creating reports by specifying columns, groups, styles, etc.
4
+ # Copyright 2012 by sgzhe@163.com
5
+
6
+ module Wizport
7
+ module Document
8
+ class Txt
9
+ def initialize()
10
+ @doc = []
11
+ end
12
+
13
+ def text(txt)
14
+ @doc << txt << "\n"
15
+ end
16
+
17
+ def table(rows)
18
+
19
+ end
20
+
21
+
22
+ end
23
+ end
24
+ end
25
+
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+
3
+ # Wizport: A gem for creating reports by specifying columns, groups, styles, etc.
4
+ # Copyright 2012 by sgzhe@163.com
5
+
6
+
7
+ module Wizport
8
+ class ActiveSource
9
+ def initialize(source)
10
+ @source = source
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ # Wizport: A gem for creating reports by specifying columns, groups, styles, etc.
4
+ # Copyright 2012 by sgzhe@163.com
5
+
6
+ module Wizport
7
+ class Column
8
+ TYPE = {default:0,image:1}
9
+ ALIGN = {}
10
+
11
+ attr_accessor :title, :name, :width, :clazz
12
+
13
+ def initialize(options = {})
14
+ @title = options.delete(:title) || ""
15
+ @name = options.delete(:name) || ""
16
+ @width = options.delete(:width) || 50
17
+ @clazz = options.delete(clazz) || Object
18
+
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ # Wizport: A gem for creating reports by specifying columns, groups, styles, etc.
4
+ # Copyright 2012 by sgzhe@163.com
5
+
6
+ class Director
7
+ def initialize(builder)
8
+
9
+ end
10
+ end
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+
3
+ # Wizport: A gem for creating reports by specifying columns, groups, styles, etc.
4
+ # Copyright 2012 by sgzhe@163.com
5
+
6
+
7
+ module Wizport
8
+ class MongoidSource
9
+ def initialize(source)
10
+ @source = source
11
+ end
12
+
13
+ def groups(section)
14
+ @source.distinct(section.group)
15
+ end
16
+
17
+ def filter(options)
18
+ options.blank? ? @source : @source.where(options)
19
+ end
20
+
21
+ def all
22
+ @source
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ # Wizport: A gem for creating reports by specifying columns, groups, styles, etc.
4
+ # Copyright 2012 by sgzhe@163.com
5
+
6
+ module Wizport
7
+ class Report
8
+ attr_accessor :title, :subtitle, :columns, :sections, :source
9
+
10
+ def initialize(options = {})
11
+ @title = options.delete(:title) || ""
12
+ @subtitle = options.delete(:subtitle) || ""
13
+ @columns = options.delete(:columns) || []
14
+ @sections = options.delete(:sections) || []
15
+ @source = Wizport::MongoidSource.new(options.delete(:source))
16
+
17
+ end
18
+
19
+ def column(options)
20
+ @columns << Wizport::Column.new(options)
21
+ end
22
+
23
+ def section(options)
24
+ @sections << Wizport::Section.new(options)
25
+
26
+ end
27
+
28
+ def add_column(column)
29
+ @columns << column
30
+ end
31
+
32
+ def build(format = :pdf)
33
+ builder = Wizport::Builder::Pdf.new(self)
34
+ builder.header
35
+ if sections.size > 0
36
+ sections.each do |section|
37
+ builder.section(section)
38
+ end
39
+ else
40
+ builder.grid
41
+ end
42
+ builder.footer
43
+ builder
44
+ end
45
+
46
+ def save(file)
47
+ build(:pdf).save(file)
48
+ end
49
+
50
+ end
51
+ end
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+
3
+ # Wizport: A gem for creating reports by specifying columns, groups, styles, etc.
4
+ # Copyright 2012 by sgzhe@163.com
5
+
6
+ module Wizport
7
+ class Section
8
+ attr_accessor :group, :title, :sub
9
+
10
+ def initialize(options)
11
+ @group = options[:group]
12
+ @title = options[:title]
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ class SqlSource
2
+ # To change this template use File | Settings | File Templates.
3
+ end
@@ -1,3 +1,3 @@
1
- module Wizport
2
- VERSION = "0.0.1"
3
- end
1
+ module Wizport
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+
3
+ # Wizport: A gem for creating reports by specifying columns, groups, styles, etc.
4
+ # Copyright 2012 by sgzhe@163.com
5
+
6
+ module Wizport
7
+ module Visitable
8
+ def accept(visitor)
9
+ visitor.visit_for self
10
+ end
11
+ end
12
+
13
+ module Visitor
14
+ def self.included(base)
15
+ base.extend(ClassMethods)
16
+ base.class_eval do
17
+ include InstanceMethods
18
+ end
19
+ end
20
+
21
+ module InstanceMethods
22
+ def visit_for(visitable)
23
+ visitable.class.ancestors.each do |ancestor|
24
+ method_name = "visit_#{ancestor.name}"
25
+ return send method_name, visitable if respond_to? method_name
26
+ end
27
+ raise "Can't handle #{visitable.class}"
28
+ end
29
+ end
30
+
31
+ module ClassMethods
32
+ def visit(*klasses, &block)
33
+ klasses.each do |klass|
34
+ define_method(:"visit_#{klass.name}", block)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'wizport' # and any other gems you need
5
+
6
+ RSpec.configure do |config|
7
+ # some (optional) config here
8
+ end
@@ -0,0 +1,15 @@
1
+ require "../../../../spec/spec_helper"
2
+
3
+
4
+ describe Wizport::Rtf::Text do
5
+
6
+ it "a instance of text" do
7
+ t = Wizport::Rtf::Text.new
8
+ t.size = 88
9
+ p t.elements
10
+
11
+ t.should_not nil
12
+
13
+
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+
3
+ # Wizport: A gem for creating reports by specifying columns, groups, styles, etc.
4
+ # Copyright 2012 by sgzhe@163.com
5
+
6
+ require "../../../spec/spec_helper"
7
+
8
+ describe Wizport::Document::Rtf do
9
+
10
+ it "a simple example of Rtf" do
11
+ rtf = Wizport::Document::Rtf.new
12
+ rtf.text "hello sgz"
13
+ rtf.table [[1,1,1,""],[1,1,1,2],[1,1,1,3]]
14
+ rtf.save('c:/r.rtf')
15
+
16
+ end
17
+ end
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+
3
+ # Wizport: A gem for creating reports by specifying columns, groups, styles, etc.
4
+ # Copyright 2012 by sgzhe@163.com
5
+
6
+ require "../../../spec/spec_helper"
7
+ require "mongoid"
8
+
9
+ Mongoid.configure do |config|
10
+ config.master = Mongo::Connection.new.db("godfather")
11
+ end
12
+
13
+ class Person
14
+ include Mongoid::Document
15
+ field :name
16
+ field :sex
17
+ field :tel
18
+ end
19
+
20
+ #Person.delete_all
21
+ #Person.create({name:"sgz1",sex:"男",tel:"1223121"})
22
+ #Person.create({name:"sgz2",sex:"男",tel:"852471"})
23
+ #Person.create({name:"sgz3",sex:"女",tel:"963952"})
24
+
25
+ describe Wizport::Report do
26
+
27
+ it "a simple example of report" do
28
+ rpt = Wizport::Report.new(:title => "人员性别统计表",:source => Person.all)
29
+ rpt.column({:title => "姓名",:name => :name})
30
+ rpt.column({:title => "性别",:name => :sex})
31
+ rpt.column({:title => "电话",:name => :tel})
32
+ rpt.section({:title => "性别",:group => :sex})
33
+ rpt.save('c:/rpt.pdf')
34
+ end
35
+
36
+ end
data/wizport.gemspec CHANGED
@@ -1,24 +1,26 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "wizport/version"
4
-
5
- Gem::Specification.new do |s|
6
- s.name = "wizport"
7
- s.version = Wizport::VERSION
8
- s.authors = ["songgz"]
9
- s.email = ["sgzhe@163.com"]
10
- s.homepage = ""
11
- s.summary = "A simple, extensible reporting system"
12
- s.description = "A simple, extensible reporting system"
13
-
14
- s.rubyforge_project = "wizport"
15
-
16
- s.files = `git ls-files`.split("\n")
17
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
- s.require_paths = ["lib"]
20
-
21
- # specify any dependencies here; for example:
22
- # s.add_development_dependency "rspec"
23
- # s.add_runtime_dependency "rest-client"
24
- end
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "wizport/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "wizport"
7
+ s.version = Wizport::VERSION
8
+ s.authors = ["songgz"]
9
+ s.email = ["sgzhe@163.com"]
10
+ s.homepage = ""
11
+ s.summary = "A simple, extensible reporting system"
12
+ s.description = "A simple, extensible reporting system"
13
+
14
+ s.rubyforge_project = "wizport"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ s.add_development_dependency "rspec"
23
+ s.add_runtime_dependency "prawn"
24
+ s.add_runtime_dependency "rtf"
25
+
26
+ end
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.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,56 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-17 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2012-05-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: prawn
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rtf
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
14
62
  description: A simple, extensible reporting system
15
63
  email:
16
64
  - sgzhe@163.com
@@ -22,7 +70,35 @@ files:
22
70
  - Gemfile
23
71
  - Rakefile
24
72
  - lib/wizport.rb
73
+ - lib/wizport/builder/pdf.rb
74
+ - lib/wizport/builder/rtf.rb
75
+ - lib/wizport/document/Rtf/cell.rb
76
+ - lib/wizport/document/Rtf/command.rb
77
+ - lib/wizport/document/Rtf/document.rb
78
+ - lib/wizport/document/Rtf/element.rb
79
+ - lib/wizport/document/Rtf/group.rb
80
+ - lib/wizport/document/Rtf/plaintext.rb
81
+ - lib/wizport/document/Rtf/row.rb
82
+ - lib/wizport/document/Rtf/rtf_builder.rb
83
+ - lib/wizport/document/Rtf/spec.rb
84
+ - lib/wizport/document/Rtf/table.rb
85
+ - lib/wizport/document/Rtf/text.rb
86
+ - lib/wizport/document/pdf.rb
87
+ - lib/wizport/document/rtf.rb
88
+ - lib/wizport/document/txt.rb
89
+ - lib/wizport/engine/active_source.rb
90
+ - lib/wizport/engine/column.rb
91
+ - lib/wizport/engine/director.rb
92
+ - lib/wizport/engine/mongoid_source.rb
93
+ - lib/wizport/engine/report.rb
94
+ - lib/wizport/engine/section.rb
95
+ - lib/wizport/engine/sql_source.rb
25
96
  - lib/wizport/version.rb
97
+ - lib/wizport/visitor.rb
98
+ - spec/spec_helper.rb
99
+ - spec/wizport/document/rtf/text_spec.rb
100
+ - spec/wizport/document/rtf_spec.rb
101
+ - spec/wizport/engine/report_spec.rb
26
102
  - wizport.gemspec
27
103
  homepage: ''
28
104
  licenses: []