birt 0.1.8 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f3905ae31d2825e827dbd5782531b828df936781
4
- data.tar.gz: 9fb645709376d55d6be68d02331ed575fd1b185f
3
+ metadata.gz: 73de487306437a5f2436c45ea2eb0b09a14663a1
4
+ data.tar.gz: c68d43bb533f6f104b0280abfd76d108f2ecfdc9
5
5
  SHA512:
6
- metadata.gz: 0477ca0ffb713d2695a9b2c2c82b6e3f52da8af37e10615cb3db07257b721b792137697e8ed5b61fb169cfef1b678b34da9384799e730af5f9e380103d0fc641
7
- data.tar.gz: 2bf7fb221a9444fed9e60c472fa0eef0c6cd8acbc3f5dde55b0545bec564a742a7c99f6fa8f3609de12b1caa6a738a6b203d3b31704b690fe95267633a21c8c9
6
+ metadata.gz: 2a015056d3bbd6e78903784641929dd5bce22b214b20895214b6886478ab09e957192e54378eb5b80ac936b617a28c6ad9ae1830a4fc1336073a51962542729b
7
+ data.tar.gz: 87beae04b1ac18f60bb8f6febf4b9faefb6b751f03403632bbb0c97a429e1b8e838945fcaf164b0ef3648376331653437a2091bb3f4553cd62e09f6e5490717f
data/config/birt.yml ADDED
@@ -0,0 +1,9 @@
1
+ default: &default
2
+ datasource: rptdesign
3
+ adapter: mysql
4
+ development:
5
+ <<: *default
6
+ datasource: rails
7
+ production:
8
+ <<: *default
9
+ datasource: rails
@@ -0,0 +1,13 @@
1
+ default: &default
2
+ adapter: mysql2
3
+ encoding: utf8
4
+ pool: 5
5
+ username: root
6
+ password: sun
7
+ host: localhost
8
+ development:
9
+ <<: *default
10
+ database: spider
11
+ production:
12
+ <<: *default
13
+ database: spider
@@ -7,7 +7,7 @@ class Birt::Core::DataSource
7
7
  attr_accessor :password
8
8
  attr_accessor :database
9
9
 
10
- def initialize(xml_element)
10
+ def initialize(xml_element = nil)
11
11
  if xml_element
12
12
  self.name = xml_element.attribute(:name).value
13
13
  self.host = xml_element.get_elements("property[@name='odaURL']")[0].text
@@ -24,4 +24,7 @@ class Birt::Core::DataSource
24
24
  @port = port_database[0]
25
25
  @database = port_database[1]
26
26
  end
27
- end
27
+ def set_host(host)
28
+ @host = host
29
+ end
30
+ end
@@ -1,13 +1,7 @@
1
1
  class Birt::Core::Mysql
2
2
 
3
- def self.client(data_source)
4
- @client ||=Mysql2::Client.new(
5
- host: data_source.host,
6
- port: data_source.port,
7
- username: data_source.username,
8
- password: data_source.password,
9
- database: data_source.database
10
- )
3
+ def self.client(data_source = nil)
4
+ create_client(choose_data_source(data_source))
11
5
  end
12
6
 
13
7
  def self.query(data_source, query_text)
@@ -16,4 +10,40 @@ class Birt::Core::Mysql
16
10
  yield(results) if block_given?
17
11
  results
18
12
  end
19
- end
13
+ def self.create_client(data_source)
14
+ Mysql2::Client.new(
15
+ host: data_source.host,
16
+ port: data_source.port,
17
+ username: data_source.username,
18
+ password: data_source.password,
19
+ database: data_source.database
20
+ )
21
+ end
22
+ def self.rails_data_source
23
+ config_path = Rails.root ? File.join(Rails.root, "config", "database.yml") : './config/database.yml'
24
+ database_yml = File.open(config_path)
25
+ dbconfig = YAML::load(database_yml)
26
+ dbconfig = dbconfig[Rails.env] if defined? Rails
27
+ data_source = Birt::Core::DataSource.new do |item|
28
+ item.set_host dbconfig['host']
29
+ item.port = dbconfig['port'] ||= 3306
30
+ item.username = dbconfig['username']
31
+ item.password = dbconfig['password']
32
+ item.database = dbconfig['database']
33
+ end
34
+ data_source
35
+ end
36
+ def self.choose_data_source(data_source = nil)
37
+ return rails_data_source if data_source.nil?
38
+ config_path = Rails.root ? File.join(Rails.root, "config", "birt.yml") : './config/birt.yml'
39
+ if (File.exist?(config_path))
40
+ config = YAML.load(ERB.new(File.new(config_path).read).result)
41
+ config = config[Rails.env] if defined? Rails
42
+ end
43
+ if "rptdesign" == config["datasource"]
44
+ data_source
45
+ else
46
+ rails_data_source
47
+ end
48
+ end
49
+ end
@@ -40,7 +40,7 @@ class Birt::Core::RptDesign
40
40
 
41
41
  #数据源
42
42
  _root.each_element(xpath = '/report/data-sources/oda-data-source') do |item|
43
- p @data_sources[item.attribute(:name).value] = Birt::Core::DataSource.new(item)
43
+ @data_sources[item.attribute(:name).value] = Birt::Core::DataSource.new(item)
44
44
  end
45
45
 
46
46
  #数据集
@@ -72,4 +72,4 @@ class Birt::Core::RptDesign
72
72
  end
73
73
  end
74
74
 
75
- end
75
+ end
data/lib/birt/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Birt
2
- VERSION = "0.1.8"
2
+ VERSION = "0.2.0"
3
3
  module Core
4
4
 
5
5
  end
data/lib/birt.rb CHANGED
@@ -1,11 +1,12 @@
1
1
  require "birt/routing"
2
2
  require "birt/version"
3
+ require 'rails'
3
4
  require "birt/engine"
4
5
  require 'rexml/document'
5
6
  require 'base64'
6
7
  require 'pry'
7
8
  require 'mysql2'
8
- require 'rails'
9
+
9
10
 
10
11
 
11
12
  %w{ controllers helpers views}.each do |dir|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: birt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - saxer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-11 00:00:00.000000000 Z
11
+ date: 2015-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 4.2.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.2'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +108,20 @@ dependencies:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
110
  version: 0.3.18
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
97
125
  description: birt report
98
126
  email:
99
127
  - 15201280641@qq.com
@@ -114,6 +142,8 @@ files:
114
142
  - app/assets/stylesheets/birt/components/loading.scss
115
143
  - app/assets/stylesheets/birt/components/table.scss
116
144
  - app/views/birt/api/index.json.jbuilder
145
+ - config/birt.yml
146
+ - config/database.yml
117
147
  - config/routes.rb
118
148
  - lib/app/controllers/birt/api_controller.rb
119
149
  - lib/app/helpers/application_helper.rb