riif 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
1
  --color
2
- --format documentation
2
+ --format Fuubar
3
+
@@ -2,11 +2,14 @@
2
2
 
3
3
  ## NEXT (unreleased)
4
4
 
5
+ ## 0.2.0
6
+ * #4 - Add support to customize filename
7
+ * #5 - Separate different lists into groups
8
+
5
9
  ## 0.1.0
6
10
  * #2 - Implement Mixed document in one IIF file. (DSL had been changed)
7
11
 
8
12
  ## 0.0.1
9
-
10
13
  * Implement OTHERNAME
11
14
  * Implement TIMEACT
12
15
  * Implement TERMS
@@ -22,3 +25,4 @@
22
25
  * Implement EMP
23
26
  * Implement CUST
24
27
  * Implement TRNS and SPL
28
+
data/README.md CHANGED
@@ -19,6 +19,11 @@ Or install it yourself as:
19
19
 
20
20
  $ gem install riif
21
21
 
22
+
23
+ ## Limitation
24
+
25
+ You have to use `klass` for `class` and `_1099` for `1099`
26
+
22
27
  ## Usage
23
28
 
24
29
  ### With Rails
@@ -31,7 +36,7 @@ With a custom template handler, it works with Rails.
31
36
  class InvoicesController < ApplicationController
32
37
  def show
33
38
  respond_to do |format|
34
- format.iif
39
+ format.iif { render iif: render_to_string, filename: 'batman'}
35
40
  format.html
36
41
  end
37
42
  end
@@ -23,10 +23,7 @@ require 'riif/dsl/vtype'
23
23
  module Riif
24
24
  class IIF
25
25
  def initialize(&block)
26
- @output = {
27
- headers: [],
28
- rows: []
29
- }
26
+ @output = {}
30
27
  if block_given?
31
28
  instance_eval(&block)
32
29
  end
@@ -34,11 +31,14 @@ module Riif
34
31
 
35
32
  def output
36
33
  CSV.generate(col_sep: "\t") do |tsv|
37
- @output[:headers].uniq.each do |header|
38
- tsv << header
39
- end
40
- @output[:rows].each do |row|
41
- tsv << row
34
+
35
+ @output.each do |_, list|
36
+ list[:headers].uniq.each do |header|
37
+ tsv << header
38
+ end
39
+ list[:rows].each do |row|
40
+ tsv << row
41
+ end
42
42
  end
43
43
  end
44
44
  end
@@ -46,8 +46,10 @@ module Riif
46
46
  def method_missing(method_name, *args, &block)
47
47
  result = eval("::Riif::DSL::#{method_name.capitalize}").new.build(&block)
48
48
 
49
- @output[:headers].concat(result[:headers])
50
- @output[:rows].concat(result[:rows])
49
+ @output[method_name] ||= { headers: [], rows: [] }
50
+
51
+ @output[method_name][:headers].concat(result[:headers])
52
+ @output[method_name][:rows].concat(result[:rows])
51
53
  end
52
54
  end
53
55
  end
@@ -0,0 +1,15 @@
1
+ module Riif
2
+ module Rails
3
+ class Renderer
4
+ ActionController::Renderers.add :iif do |iif_string, options|
5
+ filename = options[:filename] || options[:template]
6
+ send_data(
7
+ iif_string,
8
+ filename: "#{filename}.iif",
9
+ type: Mime::IIF,
10
+ disposition: 'attachment'
11
+ )
12
+ end
13
+ end
14
+ end
15
+ end
@@ -10,6 +10,7 @@ module Riif
10
10
  end
11
11
 
12
12
  require 'riif/rails/template_handler'
13
+ require 'riif/rails/renderer'
13
14
  end
14
15
  end
15
16
  end
@@ -1,3 +1,3 @@
1
1
  module Riif
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -23,4 +23,5 @@ Gem::Specification.new do |gem|
23
23
  gem.add_development_dependency 'rspec-rails'
24
24
  gem.add_development_dependency 'awesome_print'
25
25
  gem.add_development_dependency 'combustion', '~> 0.3.1'
26
+ gem.add_development_dependency 'fuubar'
26
27
  end
@@ -6,9 +6,21 @@ describe InvoicesController do
6
6
  let(:expected) { File.read('spec/fixtures/rails/invoices.iif') }
7
7
 
8
8
  describe '#index' do
9
- it 'respond with rendered iif' do
9
+
10
+ before do
10
11
  get :index, format: 'iif'
12
+ end
13
+
14
+ it 'respond with rendered iif' do
11
15
  response.body.should eq expected
12
16
  end
17
+
18
+ it 'respond with QuickBooks content type' do
19
+ response.header['Content-Type'].should eq 'application/qbooks'
20
+ end
21
+
22
+ it 'respond with filename: batman.iif' do
23
+ response.header['Content-Disposition'].should =~ /filename="batman\.iif"/
24
+ end
13
25
  end
14
26
  end
@@ -1,9 +1,12 @@
1
+ !CUST NAME BADDR1 BADDR2 BADDR3 BADDR4 BADDR5 SADDR1 SADDR2 SADDR3 SADDR4 SADDR5 PHONE1 PHONE2 FAXNUM CONT1 CONT2 CTYPE TERMS TAXABLE LIMIT RESALENUM REP TAXITEM NOTEPAD SALUTATION COMPANYNAME FIRSTNAME MIDINIT LASTNAME CUSTFLD1 CUSTFLD2 CUSTFLD3 CUSTFLD4 CUSTFLD5 CUSTFLD6 CUSTFLD7 JOBDESC JOBTYPE JOBSTATUS JOBSTART JOBPROJEND JOBEND NOTE
2
+ CUST Batman Amoy
3
+ CUST Joker Amoy
1
4
  !BUD ACCNT PERIOD AMOUNT STARTDATE CLASS CUSTOMER
5
+ BUD Accounts Receivable MONTH foo 3/14/12
6
+ BUD Accounts Payable MONTH 123 3/15/12
2
7
  !TRNS TRNSID TRNSTYPE DATE ACCNT NAME CLASS AMOUNT DOCNUM MEMO CLEAR TOPRINT ADDR1 ADDR2 ADDR3 ADDR4 ADDR5 DUEDATE TERMS PAID SHIPDATE
3
8
  !SPL SPLID TRNSTYPE DATE ACCNT NAME CLASS AMOUNT DOCNUM MEMO CLEAR QNTY PRICE INVITEM PAYMETH TAXABLE REIMBEXP EXTRA
4
9
  !ENDTRNS
5
- BUD Accounts Receivable MONTH foo 3/14/12
6
- BUD Accounts Payable MONTH 123 3/15/12
7
10
  TRNS foo
8
11
  SPL joker
9
12
  SPL foobar
@@ -1,7 +1,7 @@
1
1
  class InvoicesController < ActionController::Base
2
2
  def index
3
3
  respond_to do |format|
4
- format.iif
4
+ format.iif { render iif: render_to_string, filename: 'batman'}
5
5
  end
6
6
  end
7
7
  end
@@ -7,6 +7,13 @@ describe Riif::IIF do
7
7
 
8
8
  let(:mixed) {
9
9
  Riif::IIF.new do
10
+ cust do
11
+ row do
12
+ name 'Batman'
13
+ baddr1 'Amoy'
14
+ end
15
+ end
16
+
10
17
  bud do
11
18
  row do
12
19
  accnt 'Accounts Receivable'
@@ -37,6 +44,13 @@ describe Riif::IIF do
37
44
  end
38
45
  end
39
46
  end
47
+
48
+ cust do
49
+ row do
50
+ name 'Joker'
51
+ baddr1 'Amoy'
52
+ end
53
+ end
40
54
  end
41
55
  }
42
56
 
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: riif
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jun Lin
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-10 00:00:00.000000000 Z
12
+ date: 2012-12-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  version_requirements: !ruby/object:Gem::Requirement
@@ -107,6 +107,22 @@ dependencies:
107
107
  - !ruby/object:Gem::Version
108
108
  version: 0.3.1
109
109
  none: false
110
+ - !ruby/object:Gem::Dependency
111
+ version_requirements: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ none: false
117
+ name: fuubar
118
+ type: :development
119
+ prerelease: false
120
+ requirement: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ none: false
110
126
  description: DSL to generate IIF file
111
127
  email:
112
128
  - linjunpop@gmail.com
@@ -143,6 +159,7 @@ files:
143
159
  - lib/riif/dsl/vend.rb
144
160
  - lib/riif/dsl/vtype.rb
145
161
  - lib/riif/iif.rb
162
+ - lib/riif/rails/renderer.rb
146
163
  - lib/riif/rails/template_handler.rb
147
164
  - lib/riif/railtie.rb
148
165
  - lib/riif/version.rb