prawnto 0.0.5 → 0.1.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.
@@ -1,20 +1,44 @@
1
+ require "prawnto/available_features"
2
+
1
3
  module Prawnto
2
4
  module ActionControllerMixin
5
+ DEFAULT_PRAWNTO_OPTIONS = {:inline => true}
3
6
 
4
- DEFAULT_PRAWNTO_OPTIONS = {:inline=>true}
5
-
6
7
  def self.included(base)
7
8
  base.extend ClassMethods
8
9
  end
9
10
 
10
11
  module ClassMethods
12
+ if class_attribute_supported?
13
+ def self.extended(cls)
14
+ cls.send(:class_attribute, :prawn_options)
15
+ cls.send(:class_attribute, :prawnto_options)
16
+ end
17
+ else
18
+ def prawn_options=(options)
19
+ write_inheritable_hash(:prawn_options, options)
20
+ end
21
+
22
+ def prawn_options
23
+ read_inheritable_attribute(:prawn_options)
24
+ end
25
+
26
+ def prawnto_options=(options)
27
+ write_inheritable_hash(:prawnto_options, options)
28
+ end
29
+
30
+ def prawnto_options
31
+ read_inheritable_attribute(:prawnto_options)
32
+ end
33
+ end
34
+
11
35
  def prawnto(options)
12
36
  prawn_options, prawnto_options = breakdown_prawnto_options options
13
- write_inheritable_hash(:prawn, prawn_options)
14
- write_inheritable_hash(:prawnto, prawnto_options)
37
+ self.prawn_options = prawn_options
38
+ self.prawnto_options = prawnto_options
15
39
  end
16
-
17
- private
40
+
41
+ private
18
42
 
19
43
  def breakdown_prawnto_options(options)
20
44
  prawnto_options = options.dup
@@ -28,17 +52,15 @@ module Prawnto
28
52
  @prawnto_options.merge! options
29
53
  end
30
54
 
31
-
32
- private
55
+ private
33
56
 
34
57
  def compute_prawnto_options
35
58
  @prawnto_options ||= DEFAULT_PRAWNTO_OPTIONS.dup
36
59
  @prawnto_options[:prawn] ||= {}
37
- @prawnto_options[:prawn].merge!(self.class.read_inheritable_attribute(:prawn) || {}) {|k,o,n| o}
38
- @prawnto_options.merge!(self.class.read_inheritable_attribute(:prawnto) || {}) {|k,o,n| o}
60
+ @prawnto_options[:prawn].merge!(self.class.prawn_options || {}) { |k, o, n| o }
61
+ @prawnto_options.merge!(self.class.prawnto_options || {}) { |k, o, n| o }
39
62
  @prawnto_options
40
63
  end
41
-
42
64
  end
43
65
  end
44
66
 
@@ -0,0 +1,28 @@
1
+ unless defined? ::Rails::VERSION
2
+ module Rails
3
+ module VERSION
4
+ MAJOR = 2
5
+ MINOR = 0
6
+ TINY = 0
7
+ PRE = nil
8
+
9
+ STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
10
+ end
11
+ end
12
+ end
13
+
14
+ def base_class_for_template_handler_required?
15
+ ::Rails::VERSION::MAJOR < 3
16
+ end
17
+
18
+ def template_should_include_compilable?
19
+ ::Rails::VERSION::MAJOR < 3
20
+ end
21
+
22
+ def template_has_class_level_call_method?
23
+ ::Rails::VERSION::MAJOR > 3 || (::Rails::VERSION::MAJOR == 3 && ::Rails::VERSION::MINOR >= 1)
24
+ end
25
+
26
+ def class_attribute_supported?
27
+ ::Rails::VERSION::MAJOR >= 3
28
+ end
@@ -1,7 +1,9 @@
1
+ require "prawnto/available_features"
2
+
1
3
  module Prawnto
2
4
  module TemplateHandlers
3
- class Base < (::Rails::VERSION::MAJOR < 3 ? ::ActionView::TemplateHandler : ::Object)
4
- include ::ActionView::TemplateHandlers::Compilable if ::Rails::VERSION::MAJOR < 3
5
+ class Base < (base_class_for_template_handler_required? ? ::ActionView::TemplateHandler : ::Object)
6
+ include ::ActionView::TemplateHandlers::Compilable if template_should_include_compilable?
5
7
 
6
8
  def self.call(template)
7
9
  "_prawnto_compile_setup;" +
@@ -10,7 +12,7 @@ module Prawnto
10
12
  "pdf.render;"
11
13
  end
12
14
 
13
- if ::Rails::VERSION::MAJOR < 3 || (::Rails::VERSION::MAJOR == 3 && ::Rails::VERSION::MINOR < 1)
15
+ unless template_has_class_level_call_method?
14
16
  def compile(template)
15
17
  self.class.call(template)
16
18
  end
@@ -1,3 +1,3 @@
1
1
  module Prawnto
2
- VERSION = '0.0.5'
2
+ VERSION = '0.1.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prawnto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-02-24 00:00:00.000000000Z
14
+ date: 2012-02-27 00:00:00.000000000Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: prawn
18
- requirement: &15995880 !ruby/object:Gem::Requirement
18
+ requirement: &12515780 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ! '>='
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: '0'
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *15995880
26
+ version_requirements: *12515780
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rails
29
- requirement: &15995200 !ruby/object:Gem::Requirement
29
+ requirement: &12514940 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ! '>='
@@ -34,7 +34,7 @@ dependencies:
34
34
  version: '2.1'
35
35
  type: :runtime
36
36
  prerelease: false
37
- version_requirements: *15995200
37
+ version_requirements: *12514940
38
38
  description: Support .prawn templates as Prawn::Document content
39
39
  email:
40
40
  - smecsia@gmail.com
@@ -51,6 +51,7 @@ files:
51
51
  - lib/prawnto.rb
52
52
  - lib/prawnto/action_controller_mixin.rb
53
53
  - lib/prawnto/action_view_mixin.rb
54
+ - lib/prawnto/available_features.rb
54
55
  - lib/prawnto/railtie.rb
55
56
  - lib/prawnto/template_handler/compile_support.rb
56
57
  - lib/prawnto/template_handlers/base.rb