thinreports-preview 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a55e80015ff54b760e983537f4b7e45cb88129e1
4
+ data.tar.gz: aff317964571a72f735f92798033eb0785ffa095
5
+ SHA512:
6
+ metadata.gz: 879b041b325bfe56eb6f97a5eb8b882b7c79ab948f8eb70a10a2382ad9016c1dde41ad742098f1900d6f629a65e1450af5bc5a5cad4bfcc4a6e3357d1d940325
7
+ data.tar.gz: 0ae443d1a4d7092b81cfefcae37c98232660735d450375ad355aa549c73bfc8981fd30d15f48f7050a4fd2bc09714eeefdc2502b3e1a816e199d993ff159eaf4
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor
11
+ *.bundle
12
+ *.so
13
+ *.o
14
+ *.a
15
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in thinreports-preview.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Naoto SHINGAKI
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,37 @@
1
+ # Thinreports::Preview
2
+
3
+ Thinreports::Preview ia Thinporets Preview Library
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'thinreports-preview', git: "https://github.com/naoto/thnreports-preview.git"
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ ## Usage
18
+
19
+ Options
20
+
21
+ - `-t`,`--target` is thinreports template. default `./template/`
22
+ - `-o`,`--output` is pdf output directory. default `./generate`
23
+ - `-l`,`--list_loop` is List Loop Count. default `1`
24
+
25
+ Execute
26
+
27
+ ```shell
28
+ $ bundle exec ruby bin/thnreports-preview -t /path/to/file.tlf -o /output/direcitory
29
+ ```
30
+
31
+ Library
32
+
33
+ ```ruby
34
+ require 'thnrepornts/preview'
35
+
36
+ Thinreports::Preview::Generater.new('/path/to/file.tlf').generate('/output/directory')
37
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'thinreports/preview'
4
+
5
+ Thinreports::Preview.run(ARGV)
data/generate/.gitkeep ADDED
File without changes
@@ -0,0 +1,44 @@
1
+ module Thinreports::Preview
2
+ class Generater
3
+
4
+ def initialize(file)
5
+ @file = file
6
+ end
7
+
8
+ def generate(output, list_loop)
9
+ name = File.basename(@file, '.*')
10
+ shapes = ::ThinReports::Layout.new(@file).format.shapes
11
+ ::ThinReports::Report.generate_file("#{output}/#{name}.pdf", :layout => @file) do
12
+ start_new_page
13
+ shapes.each do |k,v|
14
+ case shapes[k].type
15
+ when 's-list'
16
+ tlist = Tlist.new(shapes[k].instance_variable_get("@config"))
17
+
18
+ list(tlist.name).events.on :footer_insert do |e|
19
+ tlist.footer.each do |key,val|
20
+ e.section.item(key).value(val.preview_text)
21
+ end
22
+ end
23
+
24
+ list_loop.times do |i|
25
+ list(tlist.name).add_row do |row|
26
+ tlist.header.each do |key,item|
27
+ row.item(key).value(item.preview_text)
28
+ end
29
+ tlist.items.each do |key, item|
30
+ row.item(key).value(item.preview_text)
31
+ end
32
+ end
33
+ end
34
+
35
+ when 's-tblock'
36
+ tblock = Tblock.new(shapes[k].instance_variable_get("@config"))
37
+ page.values(tblock.name => tblock.preview_text)
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,20 @@
1
+ require 'optparse'
2
+
3
+ module Thinreports::Preview
4
+ class Option < Hash
5
+
6
+ def initialize(args)
7
+ super nil
8
+
9
+ self[:output] = './generate'
10
+ self[:list_loop] = 1
11
+
12
+ op = OptionParser.new
13
+ op.on('-t', '--target VAL') { |v| self[:target] = v }
14
+ op.on('-o', '--output VAL') { |v| self[:output] = v }
15
+ op.on('-l', '--list-loop VAL') { |v| self[:list_loop] = v.to_i }
16
+ op.parse!(args)
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,22 @@
1
+ module Thinreports::Preview
2
+ class Tblock
3
+
4
+ def initialize(config)
5
+ @config = config
6
+ end
7
+
8
+ def name
9
+ @config["id"].to_sym
10
+ end
11
+
12
+ def preview_text(char = 'X')
13
+ char * word_lenght
14
+ end
15
+
16
+ private
17
+ def word_lenght
18
+ (@config["box"]["width"] / @config["svg"]["attrs"]["font-size"].to_i).ceil
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,45 @@
1
+ module Thinreports::Preview
2
+ class Tlist
3
+
4
+ def initialize(config)
5
+ @config = config
6
+ end
7
+
8
+ def name
9
+ @config["id"].to_sym
10
+ end
11
+
12
+ def items
13
+ list = {}
14
+ @config["sections"][:detail].shapes.each do |k,v|
15
+ list[k] = instance(v)
16
+ end
17
+ list
18
+ end
19
+
20
+ def header
21
+ list = {}
22
+ @config["sections"][:header].shapes.each do |k,v|
23
+ list[k] = instance(v)
24
+ end
25
+ list
26
+ end
27
+
28
+ def footer
29
+ list = {}
30
+ @config["sections"][:footer].shapes.each do |k,v|
31
+ list[k] = instance(v)
32
+ end
33
+ list
34
+ end
35
+
36
+ private
37
+ def instance(obj)
38
+ case obj.type
39
+ when 's-tblock'
40
+ Tblock.new(obj.instance_variable_get("@config"))
41
+ end
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,5 @@
1
+ module Thinreports
2
+ module Preview
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ require "thinreports/preview/version"
2
+
3
+ module Thinreports
4
+ module Preview
5
+ # Your code goes here...
6
+ require 'thinreports/preview/option'
7
+ require 'thinreports/preview/generater'
8
+ require 'thinreports/preview/tblock'
9
+ require 'thinreports/preview/tlist'
10
+
11
+ require 'thinreports'
12
+
13
+ def self.run(args)
14
+ option = Option.new(args)
15
+ if option[:target].nil?
16
+ Dir.glob('./template/*.tlf').each do |f|
17
+ Thinreports::Preview::Generater.new(f).generate(option[:output], option[:list_loop])
18
+ end
19
+ else
20
+ Thinreports::Preview::Generater.new(option[:target]).generate(option[:output], option[:list_loop])
21
+ end
22
+ end
23
+ end
24
+ end
data/template/.gitkeep ADDED
File without changes
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'thinreports/preview/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "thinreports-preview"
8
+ spec.version = Thinreports::Preview::VERSION
9
+ spec.authors = ["Naoto SHINGAKI"]
10
+ spec.email = ["n.shingaki@gmail.com"]
11
+ spec.summary = %q{Thinreports Preview}
12
+ spec.description = %q{Thinreports Preview}
13
+ spec.homepage = "https://github.com/naoto/thinreports-preview"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+
24
+ spec.add_development_dependency 'thinreports'
25
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thinreports-preview
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Naoto SHINGAKI
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thinreports
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Thinreports Preview
56
+ email:
57
+ - n.shingaki@gmail.com
58
+ executables:
59
+ - thinreports-preview
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - bin/thinreports-preview
69
+ - generate/.gitkeep
70
+ - lib/thinreports/preview.rb
71
+ - lib/thinreports/preview/generater.rb
72
+ - lib/thinreports/preview/option.rb
73
+ - lib/thinreports/preview/tblock.rb
74
+ - lib/thinreports/preview/tlist.rb
75
+ - lib/thinreports/preview/version.rb
76
+ - template/.gitkeep
77
+ - thinreports-preview.gemspec
78
+ homepage: https://github.com/naoto/thinreports-preview
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.2.2
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Thinreports Preview
102
+ test_files: []