xlsxtream 1.1.0 → 1.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: 6c2e61534349014a46be7c2e6d6910c8b40b1e01
4
- data.tar.gz: 4d43327ab3fe0f3006021ed28caf375cb5767ddb
3
+ metadata.gz: 1d7ef18ac21a43cee29087458665fd3ff6511c62
4
+ data.tar.gz: 03bf65a93162886fbfcdebefb89191ea29a09744
5
5
  SHA512:
6
- metadata.gz: 6533bdf0887f634e5b3e3f85684bf67ddffd042afe2096a2f8a458df21089a202a080f393a7fe61131b62b7189e0c7fb6df1d4e6cd329cb5a397fa295b1541ac
7
- data.tar.gz: c7697cd9435b60986ab4f9be408e5fd8af20bf35257f3fb8ba317ddb9d4b62adede90fa090160c44ed7716c5896abac576286beebc4b95836c17d1cf434757c7
6
+ metadata.gz: '087c1ab2888d86144ce3872a5a74579b3d82eb07f672dd261b29c5513129a24eb81340b16fb0bb9f3e0843c39d7ae8d17e076bc2aff3b92ff569f617259e2351'
7
+ data.tar.gz: dbc340a4f04e01e975886d5e94c939e2a6879bc754a632bd334895545bf982944b0c6053014ab0ddd8d383ac36ee677c118046cdeff21dd090df68dbbdb0d547
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.0 (2017-10-30)
4
+
5
+ - Add support for customizing default font (#17)
6
+
3
7
  ## 1.1.0 (2017-10-23)
4
8
 
5
9
  - Add support for boolean values (#13)
data/README.md CHANGED
@@ -82,6 +82,14 @@ end
82
82
  xlsx.close
83
83
  # Close IO object
84
84
  io.close
85
+
86
+ # Changing the default font from Calibri, 12pt, Swiss
87
+ Xlsxtream::Workbook.new(io, :font => {
88
+ :name => 'Times New Roman',
89
+ :size => 10, # size in pt
90
+ :family => 'Roman' # Swiss, Modern, Script, Decorative
91
+ })
92
+
85
93
  ```
86
94
 
87
95
  ## Development
@@ -0,0 +1,3 @@
1
+ module Xlsxtream
2
+ class Error < StandardError; end
3
+ end
@@ -1,3 +1,3 @@
1
1
  module Xlsxtream
2
- VERSION = '1.1.0'.freeze
2
+ VERSION = '1.2.0'.freeze
3
3
  end
@@ -1,5 +1,6 @@
1
1
  # encoding: utf-8
2
2
  require "stringio"
3
+ require "xlsxtream/errors"
3
4
  require "xlsxtream/xml"
4
5
  require "xlsxtream/shared_string_table"
5
6
  require "xlsxtream/workbook"
@@ -10,6 +11,15 @@ require "xlsxtream/io/stream"
10
11
  module Xlsxtream
11
12
  class Workbook
12
13
 
14
+ FONT_FAMILY_IDS = {
15
+ '' => 0,
16
+ 'roman' => 1,
17
+ 'swiss' => 2,
18
+ 'modern' => 3,
19
+ 'script' => 4,
20
+ 'decorative' => 5
21
+ }.freeze
22
+
13
23
  class << self
14
24
 
15
25
  def open(data = nil, options = {})
@@ -98,6 +108,14 @@ module Xlsxtream
98
108
  end
99
109
 
100
110
  def write_styles
111
+ font_options = @options.fetch(:font, {})
112
+ font_size = font_options.fetch(:size, 12).to_s
113
+ font_name = font_options.fetch(:name, 'Calibri').to_s
114
+ font_family = font_options.fetch(:family, 'Swiss').to_s.downcase
115
+ font_family_id = FONT_FAMILY_IDS[font_family] or fail Error,
116
+ "Invalid font family #{font_family}, must be one of "\
117
+ + FONT_FAMILY_IDS.keys.map(&:inspect).join(', ')
118
+
101
119
  @io.add_file "xl/styles.xml"
102
120
  @io << XML.header
103
121
  @io << XML.strip(<<-XML)
@@ -108,9 +126,9 @@ module Xlsxtream
108
126
  </numFmts>
109
127
  <fonts count="1">
110
128
  <font>
111
- <sz val="12"/>
112
- <name val="Calibri"/>
113
- <family val="2"/>
129
+ <sz val="#{XML.escape_attr font_size}"/>
130
+ <name val="#{XML.escape_attr font_name}"/>
131
+ <family val="#{font_family_id}"/>
114
132
  </font>
115
133
  </fonts>
116
134
  <fills count="2">
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xlsxtream
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felix Bünemann
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-22 00:00:00.000000000 Z
11
+ date: 2017-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip
@@ -98,6 +98,7 @@ files:
98
98
  - bin/console
99
99
  - bin/setup
100
100
  - lib/xlsxtream.rb
101
+ - lib/xlsxtream/errors.rb
101
102
  - lib/xlsxtream/io/directory.rb
102
103
  - lib/xlsxtream/io/hash.rb
103
104
  - lib/xlsxtream/io/rubyzip.rb