crayfish 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,6 +26,10 @@ module Crayfish
26
26
  private
27
27
 
28
28
  def options
29
+ self.options
30
+ end
31
+
32
+ def self.options
29
33
  { :inline => true, :prawn => {} }
30
34
  end
31
35
 
@@ -53,6 +53,8 @@ module Crayfish
53
53
  def paint template,raw=false
54
54
  begin
55
55
  html = raw ? template : eval(template)
56
+ return html if @options[:html]
57
+
56
58
  Html.new(self,@pdf).draw(html)
57
59
  rescue => e
58
60
  no = 0
@@ -29,9 +29,14 @@ module Crayfish
29
29
  attr_reader :options
30
30
 
31
31
  def initialize(controller)
32
- @options = controller.send :options || {}
33
-
34
- controller.response.content_type ||= Mime::PDF
32
+ controller_options = controller.send(:options) || {}
33
+ @options = Crayfish::ActionController.options.merge(Hash[*controller_options.map{ |k,v| [k.to_sym,v] }.flatten])
34
+
35
+ if options[:html]
36
+ controller.response.content_type ||= Mime::HTML
37
+ else
38
+ controller.response.content_type ||= Mime::PDF
39
+ end
35
40
 
36
41
  inline = options[:inline] ? 'inline' : 'attachment'
37
42
  filename = options[:filename] ? "filename=#{options[:filename]}" : nil
@@ -21,5 +21,5 @@
21
21
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
 
23
23
  module Crayfish
24
- VERSION = "0.1.0"
24
+ VERSION = "0.2.0"
25
25
  end
@@ -49,6 +49,10 @@ class CrayfishTest < ActiveSupport::TestCase
49
49
  def headers
50
50
  response.headers
51
51
  end
52
+
53
+ def options
54
+ Crayfish::ActionController.options
55
+ end
52
56
  end
53
57
 
54
58
  class ActionView
data/test/pdf_test.rb ADDED
@@ -0,0 +1,44 @@
1
+ # Copyright (c) 2012 Bingoentreprenøren AS
2
+ # Copyright (c) 2012 Patrick Hanevold
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+
23
+ require 'test_helper'
24
+
25
+ class PDFTest < ActiveSupport::TestCase
26
+
27
+ test 'merge options' do
28
+ response = mock('Response')
29
+ response.expects(:content_type).returns(nil)
30
+ response.expects(:content_type=).with(Mime::PDF)
31
+
32
+ headers = mock('Headers')
33
+ headers.expects(:[]=).with('Content-Disposition', 'inline')
34
+
35
+ controller = stub('Controller')
36
+ controller.stubs(:options).returns(:controller => :options)
37
+ controller.stubs(:response).returns(response)
38
+ controller.stubs(:headers).returns(headers)
39
+
40
+ pdf = Crayfish::Rails::PDF.new(controller)
41
+ assert_equal pdf.options, :inline=>true, :prawn=>{}, :controller=>:options
42
+ end
43
+
44
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crayfish
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-15 00:00:00.000000000Z
12
+ date: 2012-04-11 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70322535618780 !ruby/object:Gem::Requirement
16
+ requirement: &70342194319800 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70322535618780
24
+ version_requirements: *70342194319800
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: prawn
27
- requirement: &70322535617400 !ruby/object:Gem::Requirement
27
+ requirement: &70342194318480 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70322535617400
35
+ version_requirements: *70342194318480
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: nokogiri
38
- requirement: &70322535615140 !ruby/object:Gem::Requirement
38
+ requirement: &70342194315580 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70322535615140
46
+ version_requirements: *70342194315580
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: sqlite3
49
- requirement: &70322535613040 !ruby/object:Gem::Requirement
49
+ requirement: &70342194313980 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70322535613040
57
+ version_requirements: *70342194313980
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: mocha
60
- requirement: &70322535611060 !ruby/object:Gem::Requirement
60
+ requirement: &70342194311060 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70322535611060
68
+ version_requirements: *70342194311060
69
69
  description: Crayfish - PDF templating for Rails
70
70
  email:
71
71
  - patrick.hanevold@gmail.com
@@ -116,6 +116,7 @@ files:
116
116
  - test/dummy/public/favicon.ico
117
117
  - test/dummy/script/rails
118
118
  - test/html_test.rb
119
+ - test/pdf_test.rb
119
120
  - test/test_helper.rb
120
121
  homepage: http://github.com/patrickhno
121
122
  licenses: []
@@ -131,7 +132,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
131
132
  version: '0'
132
133
  segments:
133
134
  - 0
134
- hash: -1624713932211142251
135
+ hash: 122081209892541250
135
136
  required_rubygems_version: !ruby/object:Gem::Requirement
136
137
  none: false
137
138
  requirements:
@@ -140,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
141
  version: '0'
141
142
  segments:
142
143
  - 0
143
- hash: -1624713932211142251
144
+ hash: 122081209892541250
144
145
  requirements: []
145
146
  rubyforge_project:
146
147
  rubygems_version: 1.8.15
@@ -180,4 +181,5 @@ test_files:
180
181
  - test/dummy/public/favicon.ico
181
182
  - test/dummy/script/rails
182
183
  - test/html_test.rb
184
+ - test/pdf_test.rb
183
185
  - test/test_helper.rb