usefull_extension 1.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.
data/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ ToDo
2
+ - Add Paperclip attachment support
3
+ - Add docx support
4
+
5
+ 1.0.0 (29 Jun 2012)
6
+ - First deploy
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "rails", "3.0.9"
4
+ gem "paperclip", '2.7.0'
5
+ gem "acts_as_xls"
6
+ gem "prawn"
7
+
8
+ group :development, :test do
9
+ gem "capybara", ">= 0.4.0"
10
+ gem "ruby-debug"
11
+ gem "sqlite3"
12
+ end
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
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.
data/README.rdoc ADDED
@@ -0,0 +1,82 @@
1
+ = UsefullExtension
2
+
3
+ Adds usefull extensions to your ruby application:
4
+ - Excel (xls and xlsx)
5
+ - Pdf
6
+
7
+ ==Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'usefull_extension'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install usefull_extension
20
+
21
+ ==Usage
22
+ The gem require acts_as_xls (https://github.com/skylord73/acts_as_xls) for xls and xlsx support and add pdf
23
+
24
+ ===Controler
25
+ in your controller you can write a render like this:
26
+
27
+ #app/controllers/users_controller.rb
28
+ def index
29
+ @users = User.all
30
+
31
+ respond_do |format
32
+ format.pdf { render :pdf => "index"}
33
+ end
34
+ end
35
+
36
+ or if you need a quick render, without any template you can write:
37
+ ...
38
+ format.xls { render :xls => @users}
39
+
40
+ the renderer will call to_xls method to the @users and return the file
41
+
42
+ Note: if you use render :xlsx or :pdf => @users you have to implement your own to_xlsx or to_pdf methods.
43
+
44
+ ===Views
45
+ you can use xls or xlsx templates as described in acts_as_xls https://github.com/skylord73/acts_as_xls, or a pdf template
46
+
47
+ the pdf the template expose the pdf variable you can use as descibed in Prawn site http://prawn.majesticseacreature.com/
48
+
49
+ #app/views/users/index.pdf.maker
50
+ pdf.text "Users inspected in pdf..."
51
+ @users.each { |user| pdf.text user.inspect}
52
+
53
+ then in your view simply link the page using the right format:
54
+
55
+ #app/views/users/index.html.erb
56
+ <%= link_to "pdf", users_path(:format => :pdf) %>
57
+
58
+ ===Options
59
+ You can pass all renderers common options, plus :filename => "my_file_name.xls" | "my_file_name.xlsx" to change the default filename (file.xls or file.xlsx)
60
+
61
+ ==Examples
62
+ You can watch the test/dummy application to find some working examples
63
+
64
+ ==Contributing
65
+
66
+ 1. Fork it
67
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
68
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
69
+ 4. Push to the branch (`git push origin my-new-feature`)
70
+ 5. Create new Pull Request
71
+
72
+ ==Thanks
73
+ I want to thanks:
74
+ - Daniel J. Berger, Hannes Wyss, GmbH, creators of the Spreadsheet gem that is the engine of the xls extension
75
+ - randym, creator of the Axlsx gem that powers the xlsx extension ( https://github.com/randym/axlsx )
76
+ - Gregory Brown, James Healy, Brad Ediger, Daniel Nelson, Jonathan Greenberg, creators of Prown ( http://prawn.majesticseacreature.com/ )
77
+
78
+
79
+
80
+ Extends acts_as_xls, adding pdf support in the same way
81
+
82
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,31 @@
1
+ # encoding: UTF-8
2
+ require 'rubygems'
3
+ begin
4
+ require 'bundler/setup'
5
+ require "bundler/gem_tasks"
6
+ rescue LoadError
7
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
8
+ end
9
+
10
+ require 'rake'
11
+ require 'rake/testtask'
12
+ require 'rdoc/task'
13
+
14
+
15
+
16
+ Rake::TestTask.new(:test) do |t|
17
+ t.libs << 'lib'
18
+ t.libs << 'test'
19
+ t.pattern = 'test/**/*_test.rb'
20
+ t.verbose = false
21
+ end
22
+
23
+ task :default => :test
24
+
25
+ Rake::RDocTask.new(:rdoc) do |rdoc|
26
+ rdoc.rdoc_dir = 'rdoc'
27
+ rdoc.title = 'UsefullExtension'
28
+ rdoc.options << '--line-numbers' << '--inline-source'
29
+ rdoc.rdoc_files.include('README.rdoc')
30
+ rdoc.rdoc_files.include('lib/**/*.rb')
31
+ end
@@ -0,0 +1,5 @@
1
+ module UsefullExtension
2
+ end
3
+
4
+ require "usefull_extension/engine"
5
+ require "usefull_extension/exceptions"
@@ -0,0 +1,33 @@
1
+ #require "acts_as_xls/xls"
2
+
3
+ module UsefullExtension
4
+ module Base
5
+ def self.included(base) # :nodoc:
6
+ base.send :extend, ClassMethods
7
+ base.send :include, InstanceMethods
8
+ end
9
+
10
+ #Instance methods for the mixin
11
+ module InstanceMethods
12
+ #def to_xls(options = {})
13
+ # ActsAsXls::Xls.to_xls(self,options)
14
+ #end
15
+ end
16
+
17
+ #ToDo
18
+ #*
19
+ #*
20
+
21
+ # Class methods for the mixin
22
+ module ClassMethods
23
+ #def new_from_xls(options = {})
24
+ # ActsAsXls::Xls.new_from_xls(self,options)
25
+ #end
26
+ end
27
+ end
28
+ end
29
+
30
+ require 'active_record'
31
+ ActiveRecord::Base.send :include, UsefullExtension::Base
32
+ ActiveRecord::Relation.send :include, UsefullExtension::Base
33
+ Array.send :include, UsefullExtension::Base
@@ -0,0 +1,20 @@
1
+ module UsefullExtension
2
+ class Engine < Rails::Engine
3
+
4
+ #initializer 'usefull_table.helper' do |app|
5
+ # ActiveSupport.on_load(:action_controller) do
6
+ # include UsefullTableHelper
7
+ # end
8
+ # ActiveSupport.on_load(:action_view) do
9
+ # include UsefullTableHelper
10
+ # end
11
+ #
12
+ #end
13
+ end
14
+ end
15
+
16
+ require 'paperclip'
17
+ require 'prawn'
18
+ require 'acts_as_xls'
19
+ require "usefull_extension/renderer"
20
+ require "usefull_extension/base"
@@ -0,0 +1,15 @@
1
+ module UsefullExtension
2
+ class CustomError < StandardError
3
+ def initialize(*args)
4
+ @options = args.extract_options!
5
+ super
6
+ end
7
+
8
+ def message
9
+ I18n.t("#{self.class.name.gsub(/::/,'.')}", @options)
10
+ end
11
+ end
12
+
13
+
14
+ end
15
+
@@ -0,0 +1,38 @@
1
+ require "action_controller"
2
+ require "action_view/template"
3
+
4
+ Mime::Type.register("application/pdf", :pdf) unless Mime::Type.lookup_by_extension(:pdf)
5
+
6
+ ActionController::Renderers.add :pdf do |obj, options|
7
+ options ||= {}
8
+ filename = options[:filename] || "file.pdf"
9
+ #Rails::logger.info("Renderer(xls) options=#{options.inspect}, obj=#{obj.inspect}")
10
+ if obj.respond_to?(:to_pdf)
11
+ #No template, must render obj
12
+ send_data obj.to_xls, :type => Mime::PDF, :filename => filename
13
+ else
14
+ send_file render_to_string(options[:template]), :type => Mime::PDF, :disposition => "attachment; filename=#{filename}"
15
+ end
16
+ end
17
+
18
+ module ActsAsXls
19
+ #Render a template like *.[xls|xlsx].maker
20
+ #the template is evaluated as a ruby expression.
21
+ #you can use package (xlsx) or book (xls) inside the template to create an excel file
22
+ #template return tempfile path that is rendered by the renderer.
23
+ module MAKER
24
+ module Proxy
25
+ def pdf
26
+ @pdf ||= Prawn::Document.new(:page_size => "A4", :margin => [10.28,10,10,10])
27
+ end
28
+
29
+ def render_pdf
30
+ @pdf.render_file @temp.path if @pdf
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+ end
37
+
38
+ #ActionView::Template.register_template_handler :maker, UsefullExtension::MAKER
@@ -0,0 +1,4 @@
1
+ module UsefullExtension
2
+ VERSION = "1.0.1"
3
+ end
4
+
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: usefull_extension
3
+ version: !ruby/object:Gem::Version
4
+ hash: 21
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 1
10
+ version: 1.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Andrea Bignozzi
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-06-29 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - "="
26
+ - !ruby/object:Gem::Version
27
+ hash: 21
28
+ segments:
29
+ - 3
30
+ - 0
31
+ - 9
32
+ version: 3.0.9
33
+ type: :runtime
34
+ name: rails
35
+ prerelease: false
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - "="
42
+ - !ruby/object:Gem::Version
43
+ hash: 19
44
+ segments:
45
+ - 2
46
+ - 7
47
+ - 0
48
+ version: 2.7.0
49
+ type: :runtime
50
+ name: paperclip
51
+ prerelease: false
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ type: :runtime
64
+ name: acts_as_xls
65
+ prerelease: false
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ type: :runtime
78
+ name: prawn
79
+ prerelease: false
80
+ version_requirements: *id004
81
+ description: Extend Rails capabilities of importing and exporting excel, pdf and other extension
82
+ email:
83
+ - skylord73@gmail.com
84
+ executables: []
85
+
86
+ extensions: []
87
+
88
+ extra_rdoc_files: []
89
+
90
+ files:
91
+ - lib/usefull_extension/engine.rb
92
+ - lib/usefull_extension/exceptions.rb
93
+ - lib/usefull_extension/base.rb
94
+ - lib/usefull_extension/version.rb
95
+ - lib/usefull_extension/renderer.rb
96
+ - lib/usefull_extension.rb
97
+ - MIT-LICENSE
98
+ - Rakefile
99
+ - Gemfile
100
+ - README.rdoc
101
+ - CHANGELOG.md
102
+ has_rdoc: true
103
+ homepage:
104
+ licenses: []
105
+
106
+ post_install_message:
107
+ rdoc_options: []
108
+
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ hash: 3
117
+ segments:
118
+ - 0
119
+ version: "0"
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ hash: 3
126
+ segments:
127
+ - 0
128
+ version: "0"
129
+ requirements: []
130
+
131
+ rubyforge_project:
132
+ rubygems_version: 1.3.7
133
+ signing_key:
134
+ specification_version: 3
135
+ summary: Extend Rails capabilities of importing and exporting excel, pdf and other extension
136
+ test_files: []
137
+