axlsx_enhanced 0.1.2

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
+ SHA256:
3
+ metadata.gz: 78ae4908ae887f44e7165f416b8f44b5dd7f042ae728f1d70784611b03fda387
4
+ data.tar.gz: cb8bd047be9faf2044fdf907c9c385f9cf8b75e1e21c902b7618b31a6682d7f2
5
+ SHA512:
6
+ metadata.gz: f1e0f075cad1f2a27bc374525db110faa70cf4d755c8f9d444aba362de751e7699bdb9ab54cea7ab15a21d0d0b34aca6451162164828a1bf9c90704e2f093143
7
+ data.tar.gz: d836fe1d0d6f67a71d0ff33150cda310e15b80ad3d610ac5346e18b3e97a52150b28f1c2183ea68cd3c7fdd44ee9d76ebce241f5c959f15fbcb79e87d2b549ec
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ .DS_Store
14
+ .gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.16.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at TODO: Write your email address. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in axlsx_enhanced.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,58 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ axlsx_enhanced (0.1.1)
5
+ activesupport (~> 5.2)
6
+ axlsx (~> 2.0, >= 2.0.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (5.2.2)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 0.7, < 2)
14
+ minitest (~> 5.1)
15
+ tzinfo (~> 1.1)
16
+ axlsx (2.0.1)
17
+ htmlentities (~> 4.3.1)
18
+ nokogiri (>= 1.4.1)
19
+ rubyzip (~> 1.0.0)
20
+ concurrent-ruby (1.1.4)
21
+ diff-lcs (1.3)
22
+ htmlentities (4.3.4)
23
+ i18n (1.5.3)
24
+ concurrent-ruby (~> 1.0)
25
+ mini_portile2 (2.4.0)
26
+ minitest (5.11.3)
27
+ nokogiri (1.10.1)
28
+ mini_portile2 (~> 2.4.0)
29
+ rake (10.5.0)
30
+ rspec (3.8.0)
31
+ rspec-core (~> 3.8.0)
32
+ rspec-expectations (~> 3.8.0)
33
+ rspec-mocks (~> 3.8.0)
34
+ rspec-core (3.8.0)
35
+ rspec-support (~> 3.8.0)
36
+ rspec-expectations (3.8.2)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (~> 3.8.0)
39
+ rspec-mocks (3.8.0)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.8.0)
42
+ rspec-support (3.8.0)
43
+ rubyzip (1.0.0)
44
+ thread_safe (0.3.6)
45
+ tzinfo (1.2.5)
46
+ thread_safe (~> 0.1)
47
+
48
+ PLATFORMS
49
+ ruby
50
+
51
+ DEPENDENCIES
52
+ axlsx_enhanced!
53
+ bundler (~> 1.16)
54
+ rake (~> 10.0)
55
+ rspec (~> 3.0)
56
+
57
+ BUNDLED WITH
58
+ 1.16.2
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Oscar Rodríguez
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,147 @@
1
+ # AxlsxEnhanced
2
+
3
+ Provides a better way to serialize xlsx documents using axlsx gem. Enhances axlsx styling while building a spreadsheet by ruby code.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'axlsx_enhanced', '~> 0.1.2'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install axlsx_enhanced
20
+
21
+ ## Usage
22
+
23
+ ### Default usage
24
+
25
+ AxlsxEnhanced uses the same Axlsx syntax, and just injected some useful methods for building a worksheet:
26
+
27
+ ```ruby
28
+ document = Axlsx::Package.new do |p|
29
+ # Creates a new worksheet
30
+ # args:
31
+ # *(built-in Axlsx args)
32
+ # name: String, default: ""
33
+ # smart_styles: Array, default: AxlsxEnhanced::Helpers::Styles.defaults
34
+ p.workbook.smart_add_worksheet(name: 'Sheet 1') do |sheet|
35
+ # METHOD 1
36
+ ## Sets bold style for all cells
37
+ sheet.smart_add_row ["Cell 1", "Cell 2", "Cell 3"], style: :bold
38
+
39
+ # METHOD 2
40
+ ## Sets italic style for cell #1 and underline style for cell #2
41
+ sheet.smart_add_row ["Cell 1", "Cell 2"], style: [:italic, :underline]
42
+
43
+ # METHOD 3
44
+ ## Sets cell styles for specific cells in a row
45
+ row = sheet.smart_add_row ["Cell 1", "Cell 2", "Cell 3"]
46
+ ## Sets bold style for cell #1
47
+ row.cells[0].smart_style = :bold
48
+ ## Sets italic + underline style for cell #3
49
+ row.cells[2].smart_style = [:italic, :underline]
50
+ end
51
+
52
+ p.serialize('hello.xlsx')
53
+ end
54
+ ```
55
+
56
+ ### Styles
57
+
58
+ Styling worksheets are easier now after we created the following structure for it:
59
+
60
+ ```ruby
61
+ # Creates a style
62
+ style = {
63
+ name: :custom_style,
64
+ properties: {
65
+ b: true,
66
+ sz: 12,
67
+ fg_color: "FFFFFF",
68
+ bg_color: "004586",
69
+ alignment: {
70
+ horizontal: :center,
71
+ vertical: :center,
72
+ wrap_text: true
73
+ },
74
+ border: {
75
+ style: :thick,
76
+ color: "FFFF0000",
77
+ edges: [:top, :bottom]
78
+ }
79
+ }
80
+ }
81
+ ```
82
+
83
+ For more style properties examples see Axlsx properties examples [in here](https://github.com/randym/axlsx/blob/master/examples/example.rb).
84
+
85
+ ### Using the default style templates
86
+ You can use our default style templates while building a worksheet, to see all the available style names check out [this file](https://github.com/mldoscar/axlsx_enhanced/blob/master/lib/axlsx_enhanced/helpers/styles/defaults.rb).
87
+
88
+ ### Create your own style templates
89
+
90
+ Creating and reusing your own templates now is possible using `smart_styles` option when creating a worksheet as the example given below:
91
+
92
+ ```ruby
93
+ # Creates a custom template
94
+ my_template = [
95
+ {
96
+ name: :bold_italic,
97
+ properties: {
98
+ b: true,
99
+ i: true
100
+ }
101
+ },
102
+ {
103
+ name: :center_middle_text,
104
+ properties: {
105
+ alignment: {
106
+ horizontal: :center,
107
+ vertical: :center
108
+ }
109
+ }
110
+ }
111
+ ]
112
+ ```
113
+
114
+ After that, now we are able to use our custom template:
115
+
116
+ ```ruby
117
+ # Use the template in a worksheet
118
+ document = Axlsx::Package.new do |p|
119
+ p.workbook.smart_add_worksheet(name: 'Sheet 1', smart_styles: my_template) do |sheet|
120
+ sheet.smart_add_row ["Cell 1", "Cell 2", "Cell 3"], style: :bold_italic
121
+ end
122
+ p.serialize('hello.xlsx')
123
+ end
124
+ ```
125
+
126
+ **NOTE THAT** using your custom style templates will override our default style template. For combining our style template with yours you can merge the styles in a new variable and the use it for creating a spreadsheet:
127
+
128
+ ```ruby
129
+ combined_template = []
130
+
131
+ combined_template += my_template
132
+ combined_template += AxlsxEnhanced::Helpers::Styles.defaults
133
+ ```
134
+
135
+ ## Development
136
+
137
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
138
+
139
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
140
+
141
+ ## Contributing
142
+
143
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mldoscar/axlsx_enhanced. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
144
+
145
+ ## Code of Conduct
146
+
147
+ Everyone interacting in the AxlsxEnhanced project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/mldoscar/axlsx_enhanced/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,41 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "axlsx_enhanced/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "axlsx_enhanced"
8
+ spec.version = AxlsxEnhanced::VERSION
9
+ spec.authors = ["Oscar Rodriguez"]
10
+ spec.email = ["soporte@nicacode.com"]
11
+
12
+ spec.summary = %q{Provides better syntax and helpers for building xlsx documents with Axlsx gem}
13
+ spec.description = %q{Enhances axlsx styling while building a spreadsheet by ruby code}
14
+ spec.homepage = "https://github.com/mldoscar/axlsx_enhanced"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ # Specify which files should be added to the gem when it is released.
27
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
28
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
29
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
30
+ end
31
+ spec.bindir = "exe"
32
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ["lib"]
34
+
35
+ spec.add_development_dependency "bundler", "~> 1.16"
36
+ spec.add_development_dependency "rake", "~> 10.0"
37
+ spec.add_development_dependency "rspec", "~> 3.0"
38
+
39
+ spec.add_runtime_dependency "activesupport", "~> 5.2"
40
+ spec.add_runtime_dependency "axlsx", "~> 2.0", ">= 2.0.1"
41
+ end
data/bin/bundle ADDED
@@ -0,0 +1,105 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'bundle' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "rubygems"
12
+
13
+ m = Module.new do
14
+ module_function
15
+
16
+ def invoked_as_script?
17
+ File.expand_path($0) == File.expand_path(__FILE__)
18
+ end
19
+
20
+ def env_var_version
21
+ ENV["BUNDLER_VERSION"]
22
+ end
23
+
24
+ def cli_arg_version
25
+ return unless invoked_as_script? # don't want to hijack other binstubs
26
+ return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
27
+ bundler_version = nil
28
+ update_index = nil
29
+ ARGV.each_with_index do |a, i|
30
+ if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
31
+ bundler_version = a
32
+ end
33
+ next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
34
+ bundler_version = $1 || ">= 0.a"
35
+ update_index = i
36
+ end
37
+ bundler_version
38
+ end
39
+
40
+ def gemfile
41
+ gemfile = ENV["BUNDLE_GEMFILE"]
42
+ return gemfile if gemfile && !gemfile.empty?
43
+
44
+ File.expand_path("../../Gemfile", __FILE__)
45
+ end
46
+
47
+ def lockfile
48
+ lockfile =
49
+ case File.basename(gemfile)
50
+ when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
51
+ else "#{gemfile}.lock"
52
+ end
53
+ File.expand_path(lockfile)
54
+ end
55
+
56
+ def lockfile_version
57
+ return unless File.file?(lockfile)
58
+ lockfile_contents = File.read(lockfile)
59
+ return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
60
+ Regexp.last_match(1)
61
+ end
62
+
63
+ def bundler_version
64
+ @bundler_version ||= begin
65
+ env_var_version || cli_arg_version ||
66
+ lockfile_version || "#{Gem::Requirement.default}.a"
67
+ end
68
+ end
69
+
70
+ def load_bundler!
71
+ ENV["BUNDLE_GEMFILE"] ||= gemfile
72
+
73
+ # must dup string for RG < 1.8 compatibility
74
+ activate_bundler(bundler_version.dup)
75
+ end
76
+
77
+ def activate_bundler(bundler_version)
78
+ if Gem::Version.correct?(bundler_version) && Gem::Version.new(bundler_version).release < Gem::Version.new("2.0")
79
+ bundler_version = "< 2"
80
+ end
81
+ gem_error = activation_error_handling do
82
+ gem "bundler", bundler_version
83
+ end
84
+ return if gem_error.nil?
85
+ require_error = activation_error_handling do
86
+ require "bundler/version"
87
+ end
88
+ return if require_error.nil? && Gem::Requirement.new(bundler_version).satisfied_by?(Gem::Version.new(Bundler::VERSION))
89
+ warn "Activating bundler (#{bundler_version}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_version}'`"
90
+ exit 42
91
+ end
92
+
93
+ def activation_error_handling
94
+ yield
95
+ nil
96
+ rescue StandardError, LoadError => e
97
+ e
98
+ end
99
+ end
100
+
101
+ m.load_bundler!
102
+
103
+ if m.invoked_as_script?
104
+ load Gem.bin_path("bundler", "bundle")
105
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "axlsx_enhanced"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/htmldiff ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'htmldiff' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("diff-lcs", "htmldiff")
data/bin/ldiff ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'ldiff' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("diff-lcs", "ldiff")
data/bin/nokogiri ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'nokogiri' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("nokogiri", "nokogiri")
data/bin/rackup ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rackup' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rack", "rackup")
data/bin/rake ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rake' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rake", "rake")
data/bin/rspec ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rspec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rspec-core", "rspec")
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,21 @@
1
+ require "active_support/core_ext/object/blank"
2
+ require "active_support/core_ext/hash/deep_merge"
3
+ require "axlsx"
4
+
5
+ module AxlsxEnhanced
6
+ require "axlsx_enhanced/version"
7
+ require "axlsx_enhanced/helpers"
8
+ end
9
+
10
+ module Axlsx
11
+ # Inclussions
12
+ class Workbook
13
+ include AxlsxEnhanced::Helpers::Injections::Workbook
14
+ end
15
+ class Worksheet
16
+ include AxlsxEnhanced::Helpers::Injections::Worksheet
17
+ end
18
+ class Cell
19
+ include AxlsxEnhanced::Helpers::Injections::Cell
20
+ end
21
+ end
@@ -0,0 +1,12 @@
1
+ module AxlsxEnhanced
2
+ module Helpers
3
+ # Requirements
4
+ require File.expand_path(File.dirname(__FILE__)) + '/helpers/styles/defaults'
5
+ require File.expand_path(File.dirname(__FILE__)) + '/helpers/styles/style'
6
+ require File.expand_path(File.dirname(__FILE__)) + '/helpers/styles/style_collection'
7
+
8
+ require File.expand_path(File.dirname(__FILE__)) + '/helpers/injections/worksheet'
9
+ require File.expand_path(File.dirname(__FILE__)) + '/helpers/injections/workbook'
10
+ require File.expand_path(File.dirname(__FILE__)) + '/helpers/injections/cell'
11
+ end
12
+ end
@@ -0,0 +1,38 @@
1
+ module AxlsxEnhanced
2
+ module Helpers
3
+ module Injections
4
+ module Cell
5
+ def smart_style=(value)
6
+ return if value.nil?
7
+
8
+ # Get sheet and workbook
9
+ sheet = self.row.worksheet
10
+ book = sheet.workbook
11
+
12
+ if value.is_a? Array
13
+ # Iterate style if value is an Array
14
+ new_style = {}
15
+
16
+ value.each do |v|
17
+ # Find the specified style and merge it into the new style
18
+ s = sheet.smart_styles.find(v.to_sym)
19
+ new_style.deep_merge! s.properties
20
+ end
21
+ else
22
+ # Find the specified style
23
+ new_style = sheet.smart_styles.find(value).properties
24
+ end
25
+
26
+ # Add the style to the workbook
27
+ style_id = book.styles.add_style new_style
28
+
29
+ # Assign the style into the cell
30
+ self.style = style_id
31
+
32
+ # Return the style id
33
+ return style_id
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,20 @@
1
+ module AxlsxEnhanced
2
+ module Helpers
3
+ module Injections
4
+ module Workbook
5
+ def smart_add_worksheet(options)
6
+ # Create the worksheet
7
+ worksheet = self.add_worksheet(options)
8
+
9
+ # Assign smart styles if any is given, and clean options hash
10
+ worksheet.smart_styles = options[:smart_styles] || AxlsxEnhanced::Helpers::Styles.defaults
11
+ options.delete(:smart_styles)
12
+
13
+ # Perform a block yield if necessary
14
+ yield worksheet if block_given?
15
+ worksheet
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,71 @@
1
+ module AxlsxEnhanced
2
+ module Helpers
3
+ module Injections
4
+ module Worksheet
5
+ def smart_styles=(value)
6
+ @smart_styles = AxlsxEnhanced::Helpers::Styles::StyleCollection.new(self, value || [])
7
+ end
8
+
9
+ def smart_styles
10
+ return @smart_styles
11
+ end
12
+
13
+ def smart_add_separator
14
+ return self.add_row [nil]
15
+ end
16
+
17
+ def smart_add_row(array, args = {})
18
+ unless args[:style].blank?
19
+ if args[:style].is_a?(Array)
20
+ # Look for all smart styles and parse them into base styles
21
+ base_styles = []
22
+
23
+ args[:style].each do |item|
24
+ style_hash = {}
25
+
26
+ # Parse the item into an array
27
+ item_array = item.is_a?(Array) ? item : [item]
28
+
29
+ item_array.each do |style|
30
+ next if style.nil?
31
+
32
+ # Get smart style object
33
+ smart_style = self.smart_styles.find(style)
34
+
35
+ # Merge the smart style properties into the style hash
36
+ style_hash.deep_merge!(smart_style.properties)
37
+ end
38
+
39
+ # Extract heigh property if any
40
+ args[:height] ||= style_hash[:height] if style_hash[:height].present?
41
+
42
+ # Push a parsed base style into the array
43
+ base_styles.push self.styles.add_style(style_hash)
44
+ end
45
+ else
46
+ style_hash = {}
47
+
48
+ # Get smart style object
49
+ smart_style = self.smart_styles.find args[:style]
50
+
51
+ # Merge the smart style properties into the style hash
52
+ style_hash.deep_merge!(smart_style.properties)
53
+
54
+ # Extract heigh property if any
55
+ args[:height] ||= style_hash[:height] if style_hash[:height].present?
56
+
57
+ # Set a base style as a single Integer number
58
+ base_styles = self.styles.add_style(smart_style.properties)
59
+ end
60
+
61
+ # Re-write style args setting the base styles
62
+ args[:style] = base_styles
63
+ end
64
+
65
+ # Call original row creation method
66
+ return self.add_row(array, args)
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,90 @@
1
+ module AxlsxEnhanced
2
+ module Helpers
3
+ module Styles
4
+ def self.defaults
5
+ return [
6
+ # Text style
7
+ { name: :bold, properties: { b: true } },
8
+ { name: :italic, properties: { i: true } },
9
+ { name: :underline, properties: { u: true } },
10
+ { name: :strike, properties: { strike: true } },
11
+
12
+ # Horizontal alignment
13
+ { name: :halign_left, properties: { alignment: { horizontal: :left } } },
14
+ { name: :halign_center, properties: { alignment: { horizontal: :center } } },
15
+ { name: :halign_right, properties: { alignment: { horizontal: :right } } },
16
+
17
+ # Vertical alignment
18
+ { name: :valign_top, properties: { alignment: { vertial: :top } } },
19
+ { name: :valign_center, properties: { alignment: { vertial: :center } } },
20
+ { name: :valign_right, properties: { alignment: { vertial: :bottom } } },
21
+ { name: :wrap_text, properties: { alignment: { wrap_text: true } } },
22
+
23
+ # Borders
24
+ { name: :border_top_1, properties: { border: { style: :thin, color: 'FF000000', edges: [:top, :bottom, :left, :right] } } },
25
+ { name: :border_top_2, properties: { border: { style: :medium, color: 'FF000000', edges: [:top, :bottom, :left, :right] } } },
26
+
27
+ # Number formats
28
+ {
29
+ name: :number, properties: {
30
+ format_code: '#,##0.00'
31
+ }
32
+ },
33
+ {
34
+ name: :int_number, properties: {
35
+ format_code: '#,##0'
36
+ }
37
+ },
38
+
39
+ # Date formats
40
+ {
41
+ name: :date, properties: {
42
+ format_code: 'DD/MM/YYYY'
43
+ }
44
+ },
45
+
46
+ # Text colors
47
+ {
48
+ name: :red_text, properties: {
49
+ fg_color: 'FF0000'
50
+ }
51
+ },
52
+
53
+ # Custom presets
54
+ {
55
+ name: :report_title, properties: {
56
+ sz: 14,
57
+ b: true,
58
+ alignment: { vertical: :center, horizontal: :center },
59
+ height: 30
60
+ }
61
+ },
62
+ {
63
+ name: :report_subtitle, properties: {
64
+ sz: 12,
65
+ b: true,
66
+ alignment: { vertical: :center, horizontal: :center },
67
+ height: 20
68
+ }
69
+ },
70
+ {
71
+ name: :table_header, properties: {
72
+ b: true,
73
+ alignment: { vertical: :center, horizontal: :center },
74
+ height: 20,
75
+ bg_color: '2196F3', fg_color: 'FF'
76
+ }
77
+ },
78
+ {
79
+ name: :table_footer, properties: {
80
+ b: true,
81
+ alignment: { vertical: :center, horizontal: :center },
82
+ height: 20,
83
+ bg_color: '2196F3', fg_color: 'FF'
84
+ }
85
+ }
86
+ ]
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,26 @@
1
+ module AxlsxEnhanced
2
+ module Helpers
3
+ module Styles
4
+ class Style
5
+ attr_accessor :properties
6
+
7
+ def initialize(args = {})
8
+ self.name = args[:name]
9
+ self.properties = args[:properties]
10
+ end
11
+
12
+ def name=(value)
13
+ @name = value.to_sym
14
+ end
15
+
16
+ def name
17
+ return @name
18
+ end
19
+
20
+ def add_property(hash)
21
+ self.properties.deep_merge! hash
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,34 @@
1
+ module AxlsxEnhanced
2
+ module Helpers
3
+ module Styles
4
+ class StyleCollection
5
+ def initialize(worksheet, items = [])
6
+ @worksheet = worksheet
7
+ @collection = []
8
+
9
+ self.add(items)
10
+ end
11
+
12
+ def worksheet
13
+ return @worksheet
14
+ end
15
+
16
+ def collection
17
+ return @collection
18
+ end
19
+
20
+ def add(args)
21
+ items = args.is_a?(Array) ? args : [args]
22
+
23
+ items.each do |item|
24
+ self.collection.push AxlsxEnhanced::Helpers::Styles::Style.new(item)
25
+ end
26
+ end
27
+
28
+ def find(name)
29
+ return @collection.find { |x| x.name == name.to_sym }
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module AxlsxEnhanced
2
+ VERSION = "0.1.2"
3
+ end
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: axlsx_enhanced
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Oscar Rodriguez
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-01-31 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.2'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: axlsx
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: 2.0.1
79
+ type: :runtime
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - "~>"
84
+ - !ruby/object:Gem::Version
85
+ version: '2.0'
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 2.0.1
89
+ description: Enhances axlsx styling while building a spreadsheet by ruby code
90
+ email:
91
+ - soporte@nicacode.com
92
+ executables: []
93
+ extensions: []
94
+ extra_rdoc_files: []
95
+ files:
96
+ - ".gitignore"
97
+ - ".rspec"
98
+ - ".travis.yml"
99
+ - CODE_OF_CONDUCT.md
100
+ - Gemfile
101
+ - Gemfile.lock
102
+ - LICENSE
103
+ - README.md
104
+ - Rakefile
105
+ - axlsx_enhanced.gemspec
106
+ - bin/bundle
107
+ - bin/console
108
+ - bin/htmldiff
109
+ - bin/ldiff
110
+ - bin/nokogiri
111
+ - bin/rackup
112
+ - bin/rake
113
+ - bin/rspec
114
+ - bin/setup
115
+ - lib/axlsx_enhanced.rb
116
+ - lib/axlsx_enhanced/helpers.rb
117
+ - lib/axlsx_enhanced/helpers/injections/cell.rb
118
+ - lib/axlsx_enhanced/helpers/injections/workbook.rb
119
+ - lib/axlsx_enhanced/helpers/injections/worksheet.rb
120
+ - lib/axlsx_enhanced/helpers/styles/defaults.rb
121
+ - lib/axlsx_enhanced/helpers/styles/style.rb
122
+ - lib/axlsx_enhanced/helpers/styles/style_collection.rb
123
+ - lib/axlsx_enhanced/version.rb
124
+ homepage: https://github.com/mldoscar/axlsx_enhanced
125
+ licenses:
126
+ - MIT
127
+ metadata:
128
+ allowed_push_host: https://rubygems.org
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 2.7.7
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: Provides better syntax and helpers for building xlsx documents with Axlsx
149
+ gem
150
+ test_files: []