prawnto 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,8 @@
1
+ *.gem
2
+ .bundle
3
+ /.idea
4
+ Gemfile.lock
5
+ pkg/*
6
+ .DS_Store
7
+ **/*.swp
8
+ reference_pdfs
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in prawnto.gemspec
4
+ gemspec
data/Rakefile CHANGED
@@ -1,48 +1 @@
1
- require 'rake'
2
- require 'rake/testtask'
3
- require 'rake/rdoctask'
4
- require 'rake/gempackagetask'
5
-
6
- desc 'Default: run unit tests.'
7
- task :default => :test
8
-
9
- #desc 'Test the prawnto plugin.'
10
- #Rake::TestTask.new(:test) do |t|
11
- #t.libs << 'lib'
12
- #t.pattern = 'test/**/*_test.rb'
13
- #t.verbose = true
14
- #end
15
-
16
- desc 'Generate documentation for the prawnto plugin.'
17
- Rake::RDocTask.new(:rdoc) do |rdoc|
18
- rdoc.rdoc_dir = 'rdoc'
19
- rdoc.title = 'Prawnto'
20
- rdoc.options << '--line-numbers' << '--inline-source'
21
- rdoc.rdoc_files.include('README')
22
- rdoc.rdoc_files.include('lib/**/*.rb')
23
- end
24
-
25
- PKG_FILES = FileList[ '[a-zA-Z]*', 'lib/**/*', 'test/*', 'rails/*' ]
26
-
27
- require 'lib/prawnto.rb'
28
- spec = Gem::Specification.new do |s|
29
- s.name = "prawnto"
30
- s.version = Prawnto::VERSION
31
- s.author = "smecsia"
32
- s.email = "smecsia@gmail.com"
33
- #s.homepage = ""
34
- s.platform = Gem::Platform::RUBY
35
- s.summary = "Prawnto rails plugin implemented as a gem (see prawnto)"
36
- s.add_dependency('rails', '>=2.1')
37
- s.add_dependency('prawn')
38
- s.files = PKG_FILES.to_a
39
- s.require_path = "lib"
40
- s.has_rdoc = true
41
- s.extra_rdoc_files = ["README"]
42
- end
43
-
44
- desc 'Turn this plugin into a gem.'
45
- Rake::GemPackageTask.new(spec) do |pkg|
46
- pkg.gem_spec = spec
47
- end
48
-
1
+ require "bundler/gem_tasks"
@@ -1,31 +1,30 @@
1
- $:.unshift(File.dirname(__FILE__)) unless
2
- $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
-
4
- module Prawnto
5
- VERSION='0.0.4'
6
- autoload :ActionControllerMixin, 'prawnto/action_controller_mixin'
7
- autoload :ActionViewMixin, 'prawnto/action_view_mixin'
8
- module TemplateHandlers
9
- autoload :Base, 'prawnto/template_handlers/base'
10
- autoload :Dsl, 'prawnto/template_handlers/dsl'
11
- autoload :Raw, 'prawnto/template_handlers/raw'
12
- end
13
-
14
- module TemplateHandler
15
- autoload :CompileSupport, 'prawnto/template_handler/compile_support'
16
- end
17
-
18
- class << self
19
- def enable
20
- ActionController::Base.send :include, Prawnto::ActionControllerMixin
21
- ActionView::Base.send :include, Prawnto::ActionViewMixin
22
- Mime::Type.register "application/pdf", :pdf
23
- ActionView::Template.register_template_handler 'prawn', Prawnto::TemplateHandlers::Base
24
- ActionView::Template.register_template_handler 'prawn_dsl', Prawnto::TemplateHandlers::Dsl
25
- ActionView::Template.register_template_handler 'prawn_xxx', Prawnto::TemplateHandlers::Raw
26
- end
27
- end
28
-
29
- require "prawnto/railtie"
30
- end
31
-
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ module Prawnto
5
+ autoload :ActionControllerMixin, 'prawnto/action_controller_mixin'
6
+ autoload :ActionViewMixin, 'prawnto/action_view_mixin'
7
+ module TemplateHandlers
8
+ autoload :Base, 'prawnto/template_handlers/base'
9
+ autoload :Dsl, 'prawnto/template_handlers/dsl'
10
+ autoload :Raw, 'prawnto/template_handlers/raw'
11
+ end
12
+
13
+ module TemplateHandler
14
+ autoload :CompileSupport, 'prawnto/template_handler/compile_support'
15
+ end
16
+
17
+ class << self
18
+ def enable
19
+ ActionController::Base.send :include, Prawnto::ActionControllerMixin
20
+ ActionView::Base.send :include, Prawnto::ActionViewMixin
21
+ Mime::Type.register "application/pdf", :pdf
22
+ ActionView::Template.register_template_handler 'prawn', Prawnto::TemplateHandlers::Base
23
+ ActionView::Template.register_template_handler 'prawn_dsl', Prawnto::TemplateHandlers::Dsl
24
+ ActionView::Template.register_template_handler 'prawn_xxx', Prawnto::TemplateHandlers::Raw
25
+ end
26
+ end
27
+
28
+ require "prawnto/railtie"
29
+ end
30
+
@@ -1,9 +1,6 @@
1
1
  module Prawnto
2
2
  module TemplateHandler
3
-
4
3
  class CompileSupport
5
- extend ActiveSupport::Memoizable
6
-
7
4
  attr_reader :options
8
5
 
9
6
  def initialize(controller)
@@ -25,16 +22,16 @@ module Prawnto
25
22
 
26
23
  # TODO: kept around from railspdf-- maybe not needed anymore? should check.
27
24
  def ie_request?
28
- @controller.request.env['HTTP_USER_AGENT'] =~ /msie/i
25
+ return @ie_request if instance_variable_defined?(:@ie_request)
26
+ @ie_request = @controller.request.env['HTTP_USER_AGENT'] =~ /msie/i
29
27
  end
30
- memoize :ie_request?
31
28
 
32
29
  # added to make ie happy with ssl pdf's (per naisayer)
33
30
  def ssl_request?
31
+ return @ssl_request if instance_variable_defined?(:@ssl_request)
34
32
  protocol = @controller.request.env['SERVER_PROTOCOL']
35
- protocol && protocol.downcase == "https"
33
+ @ssl_request = protocol && protocol.downcase == "https"
36
34
  end
37
- memoize :ssl_request?
38
35
 
39
36
  # TODO: kept around from railspdf-- maybe not needed anymore? should check.
40
37
  def set_pragma
@@ -1,14 +1,20 @@
1
1
  module Prawnto
2
2
  module TemplateHandlers
3
- class Base < ::ActionView::TemplateHandler
4
- include ::ActionView::TemplateHandlers::Compilable
5
-
6
- def compile(template)
3
+ class Base < (::Rails::VERSION::MAJOR < 3 ? ::ActionView::TemplateHandler : ::Object)
4
+ include ::ActionView::TemplateHandlers::Compilable if ::Rails::VERSION::MAJOR < 3
5
+
6
+ def self.call(template)
7
7
  "_prawnto_compile_setup;" +
8
- "pdf = Prawn::Document.new(@prawnto_options[:prawn]);" +
8
+ "pdf = Prawn::Document.new(@prawnto_options[:prawn]);" +
9
9
  "#{template.source}\n" +
10
10
  "pdf.render;"
11
11
  end
12
+
13
+ if ::Rails::VERSION::MAJOR < 3 || (::Rails::VERSION::MAJOR == 3 && ::Rails::VERSION::MINOR < 1)
14
+ def compile(template)
15
+ self.class.call(template)
16
+ end
17
+ end
12
18
  end
13
19
  end
14
20
  end
@@ -1,14 +1,16 @@
1
1
  module Prawnto
2
2
  module TemplateHandlers
3
3
  class Dsl < Base
4
-
5
- def compile(template)
6
- "_prawnto_compile_setup(true);" +
7
- "pdf = Prawn::Document.new(@prawnto_options[:prawn]);" +
8
- "pdf.instance_eval do; #{template.source}\nend;" +
9
- "pdf.render;"
4
+ def self.call(template)
5
+ <<-RUBY
6
+ _prawnto_compile_setup(true)
7
+ pdf = Prawn::Document.new(@prawnto_options[:prawn])
8
+ pdf.instance_eval do
9
+ #{template.source}
10
+ end
11
+ pdf.render
12
+ RUBY
10
13
  end
11
-
12
14
  end
13
15
  end
14
16
  end
@@ -1,64 +1,63 @@
1
- module Prawnto
2
- module TemplateHandlers
3
- class Raw < Base
4
-
5
- def compile(template)
6
- #TODO: what's up with filename here? not used is it?
7
- source,filename = massage_template_source(template)
8
- "_prawnto_compile_setup;" +
9
- # (filename ? "@prawnto_options[:filename] = filename" : "") +
10
- source
11
- end
12
-
13
- # attr_reader :run_environment
14
-
15
- GENERATE_REGULAR_EXPRESSION = /^\s*Prawn\:\:Document\.generate(\(?)(.*?)(\,(.*))?(\s*\)?\s+do(.*?))$/m
16
- RENDER_FILE_REGULAR_EXPRESSION = /(\w+)\.render_file\(?(.*?)\)?\s*$/
17
-
18
- =begin
19
- def render(template)
20
- setup_run_environment
21
- pull_prawnto_options
22
- source,filename = massage_template_source(template)
23
- @prawnto_options[:filename] = filename if filename
24
- build_headers
25
- @run_environment.instance_eval(source, template.filename, 0) #run in anonymous class
26
- end
27
-
28
-
29
- protected
30
-
31
- def setup_run_environment
32
- @run_environment = Object.new
33
- end
34
-
35
- =end
36
- protected
37
- def massage_template_source(template)
38
- source = template.source.dup
39
- variable_name = '_pdf'
40
- filename = nil
41
-
42
- source.gsub! /^(\s*?)(\$LOAD_PATH)/, '\1#\2'
43
- source.gsub! /^(\s*?)(require\(?\s*['"]rubygems['"]\s*\)?\s*)$/, '\1#\2'
44
- source.gsub! /^(\s*?)(require\(?\s*['"]prawn['"]\s*\)?\s*)$/, '\1#\2'
45
-
46
- if (source =~ GENERATE_REGULAR_EXPRESSION)
47
- filename = $2
48
- source.sub! GENERATE_REGULAR_EXPRESSION, "#{variable_name} = Prawn::Document.new\\1\\4\\5"
49
- elsif (source =~ RENDER_FILE_REGULAR_EXPRESSION)
50
- variable_name = $1
51
- filename = $2
52
- source.sub! RENDER_FILE_REGULAR_EXPRESSION, '#\0'
53
- end
54
- source.gsub! /^(\s*)(class\s|def\s).*?\n\1end/m do |match|
55
- eval "class <<@run_environment; #{match}; end;"
56
- "\n" * match.count("\n")
57
- end
58
- source += "\n[#{variable_name}.render,#{filename}]\n"
59
- source
60
- end
61
-
62
- end
63
- end
64
- end
1
+ module Prawnto
2
+ module TemplateHandlers
3
+ class Raw < Base
4
+ def self.call(template)
5
+ #TODO: what's up with filename here? not used is it?
6
+ source,filename = massage_template_source(template)
7
+ "_prawnto_compile_setup;" +
8
+ # (filename ? "@prawnto_options[:filename] = filename" : "") +
9
+ source
10
+ end
11
+
12
+ # attr_reader :run_environment
13
+
14
+ GENERATE_REGULAR_EXPRESSION = /^\s*Prawn\:\:Document\.generate(\(?)(.*?)(\,(.*))?(\s*\)?\s+do(.*?))$/m
15
+ RENDER_FILE_REGULAR_EXPRESSION = /(\w+)\.render_file\(?(.*?)\)?\s*$/
16
+
17
+ =begin
18
+ def render(template)
19
+ setup_run_environment
20
+ pull_prawnto_options
21
+ source,filename = massage_template_source(template)
22
+ @prawnto_options[:filename] = filename if filename
23
+ build_headers
24
+ @run_environment.instance_eval(source, template.filename, 0) #run in anonymous class
25
+ end
26
+
27
+
28
+ protected
29
+
30
+ def setup_run_environment
31
+ @run_environment = Object.new
32
+ end
33
+
34
+ =end
35
+ protected
36
+ def self.massage_template_source(template)
37
+ source = template.source.dup
38
+ variable_name = '_pdf'
39
+ filename = nil
40
+
41
+ source.gsub! /^(\s*?)(\$LOAD_PATH)/, '\1#\2'
42
+ source.gsub! /^(\s*?)(require\(?\s*['"]rubygems['"]\s*\)?\s*)$/, '\1#\2'
43
+ source.gsub! /^(\s*?)(require\(?\s*['"]prawn['"]\s*\)?\s*)$/, '\1#\2'
44
+
45
+ if (source =~ GENERATE_REGULAR_EXPRESSION)
46
+ filename = $2
47
+ source.sub! GENERATE_REGULAR_EXPRESSION, "#{variable_name} = Prawn::Document.new\\1\\4\\5"
48
+ elsif (source =~ RENDER_FILE_REGULAR_EXPRESSION)
49
+ variable_name = $1
50
+ filename = $2
51
+ source.sub! RENDER_FILE_REGULAR_EXPRESSION, '#\0'
52
+ end
53
+ source.gsub! /^(\s*)(class\s|def\s).*?\n\1end/m do |match|
54
+ eval "class <<@run_environment; #{match}; end;"
55
+ "\n" * match.count("\n")
56
+ end
57
+ source += "\n[#{variable_name}.render,#{filename}]\n"
58
+ source
59
+ end
60
+
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,3 @@
1
+ module Prawnto
2
+ VERSION = '0.0.5'
3
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "prawnto/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "prawnto"
7
+ s.version = Prawnto::VERSION
8
+ s.authors = ["smecsia", "niquola", "bondarev"]
9
+ s.email = ["smecsia@gmail.com", "alexander.i.bondarev@gmail.com"]
10
+ s.homepage = "https://github.com/smecsia/prawnto"
11
+ s.summary = %q{Support .prawn templates as Prawn::Document content}
12
+ s.description = %q{Support .prawn templates as Prawn::Document content}
13
+
14
+ s.rubyforge_project = "prawnto"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ s.add_runtime_dependency "prawn"
24
+ s.add_runtime_dependency 'rails', '>=2.1'
25
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :prawnto do
3
+ # # Task goes here
4
+ # end
metadata CHANGED
@@ -1,111 +1,93 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: prawnto
3
- version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 0
9
- - 4
10
- version: 0.0.4
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - smecsia
9
+ - niquola
10
+ - bondarev
14
11
  autorequire:
15
12
  bindir: bin
16
13
  cert_chain: []
17
-
18
- date: 2010-11-10 00:00:00 +03:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: rails
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
14
+ date: 2012-02-24 00:00:00.000000000Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: prawn
18
+ requirement: &15995880 !ruby/object:Gem::Requirement
25
19
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 1
30
- segments:
31
- - 2
32
- - 1
33
- version: "2.1"
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
23
+ version: '0'
34
24
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: prawn
38
25
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
26
+ version_requirements: *15995880
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: &15995200 !ruby/object:Gem::Requirement
40
30
  none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 3
45
- segments:
46
- - 0
47
- version: "0"
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '2.1'
48
35
  type: :runtime
49
- version_requirements: *id002
50
- description:
51
- email: smecsia@gmail.com
36
+ prerelease: false
37
+ version_requirements: *15995200
38
+ description: Support .prawn templates as Prawn::Document content
39
+ email:
40
+ - smecsia@gmail.com
41
+ - alexander.i.bondarev@gmail.com
52
42
  executables: []
53
-
54
43
  extensions: []
55
-
56
- extra_rdoc_files:
44
+ extra_rdoc_files: []
45
+ files:
46
+ - .gitignore
47
+ - Gemfile
48
+ - MIT-LICENSE
57
49
  - README
58
- files:
59
50
  - Rakefile
60
- - README
61
- - MIT-LICENSE
62
- - lib/prawnto/template_handler/compile_support.rb
63
- - lib/prawnto/template_handlers/dsl.rb
64
- - lib/prawnto/template_handlers/raw.rb
65
- - lib/prawnto/template_handlers/base.rb
51
+ - lib/prawnto.rb
66
52
  - lib/prawnto/action_controller_mixin.rb
67
53
  - lib/prawnto/action_view_mixin.rb
68
54
  - lib/prawnto/railtie.rb
69
- - lib/prawnto.rb
55
+ - lib/prawnto/template_handler/compile_support.rb
56
+ - lib/prawnto/template_handlers/base.rb
57
+ - lib/prawnto/template_handlers/dsl.rb
58
+ - lib/prawnto/template_handlers/raw.rb
59
+ - lib/prawnto/version.rb
60
+ - pkg/prawnto-0.0.1.gem
61
+ - prawnto.gemspec
62
+ - rails/init.rb
63
+ - tasks/prawnto_tasks.rake
64
+ - test/action_controller_test.rb
70
65
  - test/base_template_handler_test.rb
71
- - test/template_handler_test_mocks.rb
72
- - test/raw_template_handler_test.rb
73
66
  - test/dsl_template_handler_test.rb
74
- - test/action_controller_test.rb
75
- - rails/init.rb
76
- has_rdoc: true
77
- homepage:
67
+ - test/raw_template_handler_test.rb
68
+ - test/template_handler_test_mocks.rb
69
+ homepage: https://github.com/smecsia/prawnto
78
70
  licenses: []
79
-
80
71
  post_install_message:
81
72
  rdoc_options: []
82
-
83
- require_paths:
73
+ require_paths:
84
74
  - lib
85
- required_ruby_version: !ruby/object:Gem::Requirement
75
+ required_ruby_version: !ruby/object:Gem::Requirement
86
76
  none: false
87
- requirements:
88
- - - ">="
89
- - !ruby/object:Gem::Version
90
- hash: 3
91
- segments:
92
- - 0
93
- version: "0"
94
- required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
82
  none: false
96
- requirements:
97
- - - ">="
98
- - !ruby/object:Gem::Version
99
- hash: 3
100
- segments:
101
- - 0
102
- version: "0"
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
103
87
  requirements: []
104
-
105
- rubyforge_project:
106
- rubygems_version: 1.3.7
88
+ rubyforge_project: prawnto
89
+ rubygems_version: 1.8.10
107
90
  signing_key:
108
91
  specification_version: 3
109
- summary: Prawnto rails plugin implemented as a gem (see prawnto)
92
+ summary: Support .prawn templates as Prawn::Document content
110
93
  test_files: []
111
-