rtf_rails 0.0.1

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.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "http://rubygems.org"
2
+ gem 'rails', '>=3.0.0'
3
+ gem 'rtf', '~> 0.3.3'
4
+
5
+ group :development do
6
+ gem "rdoc", "~> 3.12"
7
+ gem "bundler", "~> 1.1.rc"
8
+ gem "jeweler", "~> 1.8.3"
9
+ end
@@ -0,0 +1,96 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ actionmailer (3.2.1)
5
+ actionpack (= 3.2.1)
6
+ mail (~> 2.4.0)
7
+ actionpack (3.2.1)
8
+ activemodel (= 3.2.1)
9
+ activesupport (= 3.2.1)
10
+ builder (~> 3.0.0)
11
+ erubis (~> 2.7.0)
12
+ journey (~> 1.0.1)
13
+ rack (~> 1.4.0)
14
+ rack-cache (~> 1.1)
15
+ rack-test (~> 0.6.1)
16
+ sprockets (~> 2.1.2)
17
+ activemodel (3.2.1)
18
+ activesupport (= 3.2.1)
19
+ builder (~> 3.0.0)
20
+ activerecord (3.2.1)
21
+ activemodel (= 3.2.1)
22
+ activesupport (= 3.2.1)
23
+ arel (~> 3.0.0)
24
+ tzinfo (~> 0.3.29)
25
+ activeresource (3.2.1)
26
+ activemodel (= 3.2.1)
27
+ activesupport (= 3.2.1)
28
+ activesupport (3.2.1)
29
+ i18n (~> 0.6)
30
+ multi_json (~> 1.0)
31
+ arel (3.0.2)
32
+ builder (3.0.0)
33
+ erubis (2.7.0)
34
+ git (1.2.5)
35
+ hike (1.2.1)
36
+ i18n (0.6.0)
37
+ jeweler (1.8.3)
38
+ bundler (~> 1.0)
39
+ git (>= 1.2.5)
40
+ rake
41
+ rdoc
42
+ journey (1.0.3)
43
+ json (1.6.5)
44
+ mail (2.4.1)
45
+ i18n (>= 0.4.0)
46
+ mime-types (~> 1.16)
47
+ treetop (~> 1.4.8)
48
+ mime-types (1.17.2)
49
+ multi_json (1.1.0)
50
+ polyglot (0.3.3)
51
+ rack (1.4.1)
52
+ rack-cache (1.1)
53
+ rack (>= 0.4)
54
+ rack-ssl (1.3.2)
55
+ rack
56
+ rack-test (0.6.1)
57
+ rack (>= 1.0)
58
+ rails (3.2.1)
59
+ actionmailer (= 3.2.1)
60
+ actionpack (= 3.2.1)
61
+ activerecord (= 3.2.1)
62
+ activeresource (= 3.2.1)
63
+ activesupport (= 3.2.1)
64
+ bundler (~> 1.0)
65
+ railties (= 3.2.1)
66
+ railties (3.2.1)
67
+ actionpack (= 3.2.1)
68
+ activesupport (= 3.2.1)
69
+ rack-ssl (~> 1.3.2)
70
+ rake (>= 0.8.7)
71
+ rdoc (~> 3.4)
72
+ thor (~> 0.14.6)
73
+ rake (0.9.2.2)
74
+ rdoc (3.12)
75
+ json (~> 1.4)
76
+ rtf (0.3.3)
77
+ sprockets (2.1.2)
78
+ hike (~> 1.2)
79
+ rack (~> 1.0)
80
+ tilt (~> 1.1, != 1.3.0)
81
+ thor (0.14.6)
82
+ tilt (1.3.3)
83
+ treetop (1.4.10)
84
+ polyglot
85
+ polyglot (>= 0.3.1)
86
+ tzinfo (0.3.31)
87
+
88
+ PLATFORMS
89
+ ruby
90
+
91
+ DEPENDENCIES
92
+ bundler (~> 1.1.rc)
93
+ jeweler (~> 1.8.3)
94
+ rails (>= 3.0.0)
95
+ rdoc (~> 3.12)
96
+ rtf (~> 0.3.3)
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Alejandro Juarez Robles
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Walton Hoops
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,99 @@
1
+ = Rtf::Rails
2
+
3
+ Rtf::Rails provides a simple way of creating RTF views in Rails 3 using the rtf library.
4
+
5
+ To use Rtf::Rails simply add the line
6
+
7
+ gem 'rtf_rails'
8
+
9
+ to your Gemfile and then run
10
+
11
+ bundle install
12
+
13
+ That's it! You can now create views named
14
+
15
+ [action].rtf.rtf_rb
16
+
17
+ which will be used whenever the user requests a page with a 'rtf' extension
18
+
19
+ == Usage
20
+
21
+ === Basic Usage
22
+
23
+ Rtf::Rails is designed to provide only a very thin wrapper around Rtf itself. A Rtf::Rails view should consist of only a call to the function rtf_document and a block. This will create an instance of Rtf::Document and yield it to the block.
24
+ For a simple rtf view try:
25
+
26
+ views/.../simple.rtf.rtf_rb
27
+
28
+ rtf_document() do |rtf|
29
+ rtf << "Hello World"
30
+ end
31
+
32
+ This will create a simple PDF with only the text Hello World.
33
+
34
+ === Partials
35
+
36
+ While layouts do not yet work with Rtf::Rails, partials work fine. Rendering a partial is much like in a normal view. For example:
37
+
38
+ views/.../partial.rtf.rtf_rb
39
+
40
+ rtf_document do |rtf|
41
+ render "frontpage", :rtf => rtf
42
+ rtf << "something else"
43
+ end
44
+
45
+ views/.../_frontpage.rtf.rtf_rb
46
+
47
+ rtf << "frontpage action!!"
48
+
49
+
50
+ As you might expect this will result in a rtf with a leading page.
51
+
52
+ === Instance Variables
53
+
54
+ Like normal Rails views, instance variables assigned in the controller are made available in the view. For example:
55
+
56
+ home_controller.rb
57
+
58
+ class HomeController < ApplicationController
59
+ def index
60
+ @people=['Jane','John','Jack']
61
+ end
62
+ end
63
+
64
+ views/.../index.rtf.rtf_rb
65
+
66
+ rtf_document(:page_layout => :landscape) do |rtf|
67
+ @people.each {|person| rtf << person}
68
+ end
69
+
70
+ This will produce a rtf with Jane, John, and Jack all written on seperate lines.
71
+
72
+
73
+ === Force Saving
74
+
75
+ The :force_download option makes the browser display a 'save as' dialog rather than attempting to display the content in browser (this is achieved by setting the Content-Dispoition header).
76
+
77
+ views/.../saveas.rtf.rtf_rb
78
+
79
+ rtf_document(:force_download=>true) do |rtf|
80
+ rtf << "Hello World"
81
+ end
82
+
83
+ Finally is the :filename option. This allows you to override the default filename to something other than the name of the action.
84
+ Note: You should include the .rtf extension in the filename. Rtf::Rails will not do this for you.
85
+
86
+ views/.../filename.rtf.rtf_rb
87
+
88
+ rtf_document(:filename=>'Hello.rtf') do |rtf|
89
+ rtf << "Hello World"
90
+ end
91
+
92
+ This will result in the user being promted to download a file named 'Hello.rtf'.
93
+
94
+ == Gotchas
95
+
96
+ The one major gotcha at this point is that layouts do not work. Do not attempt to make an app/views/layouts/application.rtf.rtf_rb. All your rtf views will quit. This is something I hope to fix in a later release. In the meantime I recommend using custom classes like the one above to achieve a similair effect.
97
+
98
+
99
+ Copyright (c) 2012 MonsterLabs, released under the MIT license
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "rtf_rails"
18
+ gem.homepage = "http://github.com/monsterlabs/rtf_rails"
19
+ gem.has_rdoc = false
20
+ gem.extra_rdoc_files = ["README.rdoc"]
21
+ gem.license = "MIT"
22
+ gem.summary = %Q{Integrates RTF gem into Rails in a natural way}
23
+ gem.description = %Q{Rtf::Rails provides a simple way of creating RTF views in Rails 3 using the rtf library.}
24
+ gem.email = "alex@monsterlabs.com.mx"
25
+ gem.authors = ["Alejandro Juarez Robles"]
26
+ gem.add_dependency('rails', '>=3.0.0')
27
+ gem.add_dependency('rtf', '~> 0.3.3')
28
+ end
29
+ Jeweler::RubygemsDotOrgTasks.new
30
+
31
+ require 'rake/testtask'
32
+ Rake::TestTask.new(:test) do |test|
33
+ test.libs << 'lib' << 'test'
34
+ test.pattern = 'test/**/test_*.rb'
35
+ test.verbose = true
36
+ end
37
+
38
+
39
+ task :default => :test
40
+
41
+ require 'rdoc/task'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "rtf_rails #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'rtf_rails'
@@ -0,0 +1,39 @@
1
+ require 'rtf'
2
+ module Rtf
3
+ module Rails
4
+
5
+ module RtfHelper
6
+ def rtf_document(opts={})
7
+ download = opts.delete(:force_download)
8
+ filename = opts.delete(:filename)
9
+ rtf = RTF::Document.new(RTF::Font.new(RTF::Font::ROMAN, 'Times New Roman'))
10
+ yield rtf if block_given?
11
+
12
+ disposition(download, filename) if (download || filename)
13
+
14
+ rtf.to_rtf
15
+ end
16
+
17
+ def disposition(download, filename)
18
+ download = true if (filename && download == nil)
19
+ disposition = download ? "attachment;" : "inline;"
20
+ disposition += " filename=\"#{filename}\"" if filename
21
+ headers["Content-Disposition"] = disposition
22
+ end
23
+ end
24
+
25
+ class TemplateHandler
26
+ class_attribute :default_format
27
+ self.default_format = :rtf
28
+
29
+ def self.call(template)
30
+ "#{template.source.strip}"
31
+ end
32
+ end
33
+
34
+ end
35
+ end
36
+
37
+ Mime::Type.register_alias("application/rtf", :rtf) unless Mime::Type.lookup_by_extension(:rtf)
38
+ ActionView::Template.register_template_handler(:rtf_rb, Rtf::Rails::TemplateHandler)
39
+ ActionView::Base.send(:include, Rtf::Rails::RtfHelper)
@@ -0,0 +1 @@
1
+ require 'rtf_rails'
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'rtf_rails'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestRtfRails < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rtf_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alejandro Juarez Robles
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-02 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: &70231713158360 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70231713158360
25
+ - !ruby/object:Gem::Dependency
26
+ name: rtf
27
+ requirement: &70231713157880 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 0.3.3
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70231713157880
36
+ - !ruby/object:Gem::Dependency
37
+ name: rdoc
38
+ requirement: &70231713157400 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '3.12'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70231713157400
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: &70231713156920 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.1.rc
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70231713156920
58
+ - !ruby/object:Gem::Dependency
59
+ name: jeweler
60
+ requirement: &70231713156440 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 1.8.3
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70231713156440
69
+ - !ruby/object:Gem::Dependency
70
+ name: rails
71
+ requirement: &70231713155960 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: 3.0.0
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: *70231713155960
80
+ - !ruby/object:Gem::Dependency
81
+ name: rtf
82
+ requirement: &70231713155480 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ version: 0.3.3
88
+ type: :runtime
89
+ prerelease: false
90
+ version_requirements: *70231713155480
91
+ description: Rtf::Rails provides a simple way of creating RTF views in Rails 3 using
92
+ the rtf library.
93
+ email: alex@monsterlabs.com.mx
94
+ executables: []
95
+ extensions: []
96
+ extra_rdoc_files:
97
+ - README.rdoc
98
+ files:
99
+ - .document
100
+ - Gemfile
101
+ - Gemfile.lock
102
+ - LICENSE.txt
103
+ - MIT-LICENSE
104
+ - README.rdoc
105
+ - Rakefile
106
+ - VERSION
107
+ - init.rb
108
+ - lib/rtf_rails.rb
109
+ - rails/init.rb
110
+ - test/helper.rb
111
+ - test/test_rtf_rails.rb
112
+ homepage: http://github.com/monsterlabs/rtf_rails
113
+ licenses:
114
+ - MIT
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ segments:
126
+ - 0
127
+ hash: 4310985505342677727
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 1.8.10
137
+ signing_key:
138
+ specification_version: 3
139
+ summary: Integrates RTF gem into Rails in a natural way
140
+ test_files: []