simple_spreadsheets 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,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MzRlYzFkMzk2MjA4MDVlYjJiZmZlN2RkMDc5YTU3YTgzZTRkNTNkNQ==
5
+ data.tar.gz: !binary |-
6
+ Nzg3Mzk5YTkzNWY1ZGEzMThkY2I4ZmNmNTQxZTFmOGQ1ZGY4M2FjNw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ N2U1YjVmNTcxOTIwNDg4ZTdlY2Y0NGYxZTlkMmE0YmI3ZWYxMjc4MzBmZWQ2
10
+ MTI4YTFmOWI4ZGRiYjBhMGIwMzJkMDdlMjAzY2M5ZTE1NWE1YjM1NzdiMjI5
11
+ NGIwZDc4N2MzZDg4NTgwNDU2MjdmYjhkMjFlMThiMDAyMjM3Y2E=
12
+ data.tar.gz: !binary |-
13
+ MjI1NjMzMWU4MGE5NWVjMTUyYjY3NWVmYjY4YjlmY2IxOGNlYmE2NzFiZDcx
14
+ MWRmNDAwNzZlZjU2YTY1YjExY2RjM2JiNWYzZTFhYTJhMTE2MmY5NDlmMmRk
15
+ ZTI4YWY4OTkxODQ2NDI1NzkyYWFiM2Y0NmY0YWNjZWJlOGE4Yjk=
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in simple_spreadsheets.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Jon Evans
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,108 @@
1
+ # SimpleSpreadsheets
2
+
3
+ Write Excel-friendly spreadsheets with ease!
4
+
5
+ ## Usage
6
+
7
+ First, add a helper that allows using `SimpleSpreadsheets` easily. Note that
8
+ this is not included by default so that you can easily customize the
9
+ interface, filename, etc. Here's an example:
10
+
11
+ ```ruby
12
+ def xls(title, &block)
13
+ filename = [title, file_timestamp].join("_")
14
+ response.headers['Content-Disposition'] = "attachment; filename=\"#{filename}.xls\""
15
+ SimpleSpreadsheets.render(title, &block).html_safe
16
+ end
17
+ ```
18
+
19
+ In your controller, specify that you respond to `xls`. Here's an example where
20
+ people can view a list of boats in their browser, or export the same list:
21
+
22
+ ```ruby
23
+ class BoatsController < ApplicationController
24
+ respond_to :html, :xls
25
+
26
+ def index
27
+ @search = search
28
+
29
+ respond_to do |format|
30
+ format.html { @boats = Boat.paginate(page: params[:page]) }
31
+ format.xls { @boats = Boat.all }
32
+ end
33
+ end
34
+ end
35
+ ```
36
+
37
+ Now, in `boats/index.xls.erb`, you can use `SimpleSpreadsheets` to render a
38
+ spreadsheet for all the boats:
39
+
40
+ ```erb
41
+ <%= xls("Boats") do |xls| %>
42
+ <% xls.row do |row| %>
43
+ <% row.string "Manufacturer" %>
44
+ <% row.string "Model" %>
45
+ <% row.string "Color" %>
46
+ <% row.string "Count" %>
47
+ <% end %>
48
+
49
+ <% @boats.each do |boat| %>
50
+ <% xls.row do |row| %>
51
+ <% row.string boat.manufacturer %>
52
+ <% row.string boat.model %>
53
+ <% row.string boat.color %>
54
+ <% row.number boat.count %>
55
+ <% end %>
56
+ <% end %>
57
+ <% end %>
58
+ ```
59
+
60
+ ## Testing
61
+
62
+ `simple_spreadsheets` comes bundled with a custom RSpec matcher that you can use
63
+ from your feature specs to ensure the response is valid xls. In your spec,
64
+
65
+ ```ruby
66
+ require 'simple_spreadsheets/rspec/matcher'
67
+ ```
68
+
69
+ Example usage:
70
+
71
+ ```ruby
72
+ scenario 'exporting to XLS' do
73
+ click_link('Download XLS')
74
+ expect(page).to be_valid_xls
75
+ end
76
+ ```
77
+
78
+ ## Installation
79
+
80
+ Add this line to your application's Gemfile:
81
+
82
+ ```ruby
83
+ gem 'simple_spreadsheets'
84
+ ```
85
+
86
+ And then execute:
87
+
88
+ $ bundle
89
+
90
+ Or install it yourself as:
91
+
92
+ $ gem install simple_spreadsheets
93
+
94
+ ## Contributing
95
+
96
+ 1. Fork it ( https://github.com/[my-github-username]/simple_spreadsheets/fork )
97
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
98
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
99
+ 4. Push to the branch (`git push origin my-new-feature`)
100
+ 5. Create a new Pull Request
101
+
102
+ ## About Foraker Labs
103
+
104
+ <img src="http://assets.foraker.com/foraker_logo.png" width="400" height="62">
105
+
106
+ This project is maintained by Foraker Labs. The names and logos of Foraker Labs are fully owned and copyright Foraker Design, LLC.
107
+
108
+ Foraker Labs is a Boulder-based Ruby on Rails and iOS development shop. Please reach out if we can [help build your product](http://www.foraker.com).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,12 @@
1
+ require "simple_spreadsheets/version"
2
+ require "simple_spreadsheets/rendering"
3
+ require "simple_spreadsheets/document"
4
+ require "active_support/core_ext"
5
+
6
+ module SimpleSpreadsheets
7
+ def self.render(name)
8
+ document = Document.new(name)
9
+ yield(document)
10
+ document.render
11
+ end
12
+ end
@@ -0,0 +1,70 @@
1
+ module SimpleSpreadsheets
2
+ class Document
3
+ include Rendering
4
+
5
+ def self.render(title)
6
+ instance = new(title)
7
+ yield instance
8
+ instance.render
9
+ end
10
+
11
+ def initialize(title)
12
+ @title = title
13
+ @rows = []
14
+ end
15
+
16
+ def row
17
+ row = Row.new
18
+ yield(row)
19
+ rows << row
20
+ end
21
+
22
+ private
23
+
24
+ attr_accessor :rows
25
+
26
+ def render_rows
27
+ rows.map(&:render).join("\n")
28
+ end
29
+
30
+ class Row
31
+ include Rendering
32
+
33
+ def initialize
34
+ @cells = []
35
+ end
36
+
37
+ def string(value)
38
+ append_cell("String", value)
39
+ end
40
+
41
+ def number(value)
42
+ append_cell("Number", value)
43
+ end
44
+
45
+ private
46
+
47
+ def append_cell(type, value)
48
+ cells << Cell.new(type, value)
49
+ end
50
+
51
+ attr_accessor :cells
52
+
53
+ def render_cells
54
+ cells.map(&:render).join("\n")
55
+ end
56
+
57
+ class Cell
58
+ include Rendering
59
+
60
+ def initialize(type, value)
61
+ @type, @value = type, value
62
+ end
63
+
64
+ private
65
+
66
+ attr_reader :type, :value
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,15 @@
1
+ module SimpleSpreadsheets
2
+ module Rendering
3
+ def render
4
+ ERB.new(template).result(binding)
5
+ end
6
+
7
+ def template
8
+ File.read(File.expand_path("../templates/#{template_file}.xml.erb", __FILE__))
9
+ end
10
+
11
+ def template_file
12
+ self.class.name.demodulize.downcase
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ module SimpleSpreadsheets
2
+ module Rspec
3
+ module Matcher
4
+ RSpec::Matchers.define :be_valid_xls do |expected|
5
+ match do |page|
6
+ parsed = Nokogiri::XML(page.body.sub("<?xml version=\"1.0\"?>", ""))
7
+ root = parsed.xpath('/*').first
8
+
9
+ parsed.errors.none? &&
10
+ root.name == "Workbook" &&
11
+ root.namespace.href == "urn:schemas-microsoft-com:office:spreadsheet"
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1 @@
1
+ <ss:Cell><ss:Data ss:Type="<%= type %>"><%= value %></ss:Data></ss:Cell>
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0"?>
2
+ <ss:Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
3
+ xmlns:o="urn:schemas-microsoft-com:office:office"
4
+ xmlns:x="urn:schemas-microsoft-com:office:excel"
5
+ xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
6
+ xmlns:html="http://www.w3.org/TR/REC-html40">
7
+ <ss:Worksheet ss:Name="Acceptances">
8
+ <ss:Table>
9
+ <%= render_rows %>
10
+ </ss:Table>
11
+ </ss:Worksheet>
12
+ </ss:Workbook>
@@ -0,0 +1 @@
1
+ <ss:Row><%= render_cells %></ss:Row>
@@ -0,0 +1,3 @@
1
+ module SimpleSpreadsheets
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'simple_spreadsheets/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "simple_spreadsheets"
8
+ spec.version = SimpleSpreadsheets::VERSION
9
+ spec.authors = ["Foraker Labs"]
10
+ spec.email = ["llc@foraker.com"]
11
+ spec.summary = %q{Easily render Excel-friendly spreadsheets.}
12
+ spec.description = %q{A gem for simply rendering xls.}
13
+ spec.homepage = ""
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.9"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_spreadsheets
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Foraker Labs
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-26 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.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
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
+ description: A gem for simply rendering xls.
42
+ email:
43
+ - llc@foraker.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/simple_spreadsheets.rb
54
+ - lib/simple_spreadsheets/document.rb
55
+ - lib/simple_spreadsheets/rendering.rb
56
+ - lib/simple_spreadsheets/rspec/matcher.rb
57
+ - lib/simple_spreadsheets/templates/cell.xml.erb
58
+ - lib/simple_spreadsheets/templates/document.xml.erb
59
+ - lib/simple_spreadsheets/templates/row.xml.erb
60
+ - lib/simple_spreadsheets/version.rb
61
+ - simple_spreadsheets.gemspec
62
+ homepage: ''
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.2.2
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Easily render Excel-friendly spreadsheets.
86
+ test_files: []