active_scaffold_export 0.9.4
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/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/README.markdown +65 -0
- data/active_scaffold_export.gemspec +37 -0
- data/frontends/default/images/export.png +0 -0
- data/frontends/default/stylesheets/export-stylesheet-ie.css +6 -0
- data/frontends/default/stylesheets/export-stylesheet.css +27 -0
- data/frontends/default/views/_export.csv.erb +17 -0
- data/frontends/default/views/_export_form_body.html.erb +28 -0
- data/frontends/default/views/_show_export.html.erb +7 -0
- data/frontends/default/views/show_export.html.erb +5 -0
- data/init.rb +1 -0
- data/install.rb +31 -0
- data/lib/active_scaffold/actions/export.rb +114 -0
- data/lib/active_scaffold/config/export.rb +76 -0
- data/lib/active_scaffold/helpers/export_helpers.rb +60 -0
- data/lib/active_scaffold/helpers/view_helpers_override.rb +17 -0
- data/lib/active_scaffold_export.rb +25 -0
- data/lib/active_scaffold_export/config/core.rb +17 -0
- metadata +113 -0
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 MojoTech, LLC
|
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.markdown
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
active_scaffold_export
|
2
|
+
======================
|
3
|
+
|
4
|
+
Active Scaffold plugin for CSV exports.
|
5
|
+
|
6
|
+
Introduction
|
7
|
+
------------
|
8
|
+
|
9
|
+
This Active Scaffold plugin provides a configurable CSV 'Export'
|
10
|
+
action for Active Scaffold controllers.
|
11
|
+
|
12
|
+
Installation
|
13
|
+
------------
|
14
|
+
|
15
|
+
You can use active_scaffold_export with the latest Rails 3, but you'll
|
16
|
+
need to also install the vhochstein port of active_scaffold.
|
17
|
+
|
18
|
+
$ rails plugin install git://github.com/vhochstein/active_scaffold.git
|
19
|
+
|
20
|
+
In your Gemfile:
|
21
|
+
|
22
|
+
gem "active_scaffold_export"
|
23
|
+
|
24
|
+
Features
|
25
|
+
--------
|
26
|
+
|
27
|
+
* Uses FasterCSV for CSV generation
|
28
|
+
* Works with Rails 3 (thanks vhochstein!)
|
29
|
+
* Scales to many, many records (thanks Alexander Malysh!)
|
30
|
+
* Let the user pick which columns to export.
|
31
|
+
* Download full lists or just a single page.
|
32
|
+
* Don't like commas? No problem, uses your favorite delimiter!
|
33
|
+
* Don't need no stinkin' headers? Drop 'em.
|
34
|
+
|
35
|
+
Usage
|
36
|
+
-----
|
37
|
+
|
38
|
+
active_scaffold :users do |config|
|
39
|
+
actions.add :export # this is required, all other configuration is optional
|
40
|
+
|
41
|
+
export.columns = [ :id, :email, :created_at ] # uses list columns by default
|
42
|
+
export.allow_full_download = false # defaults to true
|
43
|
+
export.show_form = true # whether to show customization form or not, default to true
|
44
|
+
export.force_quotes = true # defaults to false
|
45
|
+
export.default_deselected_columns = [ :created_at ] # optional
|
46
|
+
export.default_delimiter = ';' # defaults to ','
|
47
|
+
export.default_skip_header = true # defaults to false
|
48
|
+
export.default_full_download = false # defaults to true
|
49
|
+
end
|
50
|
+
|
51
|
+
Note on Patches/Pull Requests
|
52
|
+
-----------------------------
|
53
|
+
|
54
|
+
* Fork the project.
|
55
|
+
* Make your feature addition or bug fix.
|
56
|
+
* Add tests for it. This is important so I don't break it in a
|
57
|
+
future version unintentionally.
|
58
|
+
* Commit, do not mess with rakefile, version, or history.
|
59
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
60
|
+
* Send me a pull request. Bonus points for topic branches.
|
61
|
+
|
62
|
+
Copyright
|
63
|
+
---------
|
64
|
+
|
65
|
+
Copyright (c) 2010 Mojo Tech, LLC. See LICENSE for details.
|
@@ -0,0 +1,37 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = %q{active_scaffold_export}
|
3
|
+
s.version = "0.9.4"
|
4
|
+
|
5
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
6
|
+
s.authors = ["Mojo Tech, LLC", "see commits"]
|
7
|
+
s.description = %q{This Active Scaffold plugin provides a configurable CSV 'Export' action for Active Scaffold controllers}
|
8
|
+
s.email = %q{chris@mojotech.com}
|
9
|
+
s.extra_rdoc_files = [
|
10
|
+
"README.markdown"
|
11
|
+
]
|
12
|
+
s.files = `git ls-files`.split("\n")
|
13
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
15
|
+
s.require_paths = ["lib"]
|
16
|
+
|
17
|
+
s.homepage = %q{http://github.com/mojotech/active_scaffold_export}
|
18
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
s.rubygems_version = %q{1.3.7}
|
21
|
+
s.summary = %q{Active Scaffold plugin for CSV exports}
|
22
|
+
|
23
|
+
if s.respond_to? :specification_version then
|
24
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
25
|
+
s.specification_version = 3
|
26
|
+
|
27
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
28
|
+
s.add_runtime_dependency(%q<fastercsv>, [">= 0"])
|
29
|
+
else
|
30
|
+
s.add_dependency(%q<fastercsv>, [">= 0"])
|
31
|
+
end
|
32
|
+
else
|
33
|
+
s.add_dependency(%q<fastercsv>, [">= 0"])
|
34
|
+
end
|
35
|
+
s.add_dependency("active_scaffold")
|
36
|
+
end
|
37
|
+
|
Binary file
|
@@ -0,0 +1,27 @@
|
|
1
|
+
.active-scaffold-header div.actions a.show_export {
|
2
|
+
background-image: url(../../../images/active_scaffold/default/export.png);
|
3
|
+
background-position: 1px 50%;
|
4
|
+
background-repeat: no-repeat;
|
5
|
+
padding-left: 19px;
|
6
|
+
}
|
7
|
+
.active-scaffold div.show_export-view h3 {
|
8
|
+
font-weight: bold;
|
9
|
+
}
|
10
|
+
.active-scaffold div.show_export-view div.separator {
|
11
|
+
clear: both;
|
12
|
+
padding: .5em;
|
13
|
+
}
|
14
|
+
.active-scaffold div.show_export-view div.options div.separator {
|
15
|
+
padding: 0;
|
16
|
+
}
|
17
|
+
.active-scaffold div.show_export-view div.options div.checkbox-wrapper {
|
18
|
+
margin-bottom: .5em;
|
19
|
+
}
|
20
|
+
.active-scaffold div.show_export-view div div.checkbox-wrapper {
|
21
|
+
min-width: 20%;
|
22
|
+
margin-bottom: .25em;
|
23
|
+
float: left;
|
24
|
+
}
|
25
|
+
.active-scaffold div.show_export-view label #delimiter {
|
26
|
+
font-family: monospace;
|
27
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<%
|
2
|
+
fcsv_options = {
|
3
|
+
:row_sep => "\n",
|
4
|
+
:col_sep => params[:delimiter],
|
5
|
+
:force_quotes => @export_config.force_quotes,
|
6
|
+
:headers => @export_columns.collect { |column| format_export_column_header_name(column) }
|
7
|
+
}
|
8
|
+
|
9
|
+
data = FasterCSV.generate(fcsv_options) do |csv|
|
10
|
+
csv << fcsv_options[:headers] unless params[:skip_header] == 'true'
|
11
|
+
@records.each do |record|
|
12
|
+
csv << @export_columns.collect { |column|
|
13
|
+
get_export_column_value(record, column)
|
14
|
+
}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
-%><%= data.html_safe -%>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
<% export_config = active_scaffold_config.export %>
|
2
|
+
<div class="columns checkbox-list">
|
3
|
+
<% export_config.columns.each do |column| -%>
|
4
|
+
<div class="column checkbox-wrapper">
|
5
|
+
<%= content_tag(:label, check_box_tag("export_columns[#{column.name}]", 1, !export_config.default_deselected_columns.include?(column.name)) + " #{column.label}".html_safe) %>
|
6
|
+
</div>
|
7
|
+
<% end -%>
|
8
|
+
|
9
|
+
</div>
|
10
|
+
<div class="separator"></div>
|
11
|
+
<h3><%=as_('Options')%></h3>
|
12
|
+
<div class="options checkbox-list">
|
13
|
+
<div class="option checkbox-wrapper">
|
14
|
+
<%= content_tag(:label, check_box_tag('skip_header', 1, export_config.default_skip_header) + " #{as_('Omit Header')}".html_safe) %>
|
15
|
+
</div>
|
16
|
+
<div class="option checkbox-wrapper">
|
17
|
+
<%= content_tag(:label, text_field_tag('delimiter', export_config.default_delimiter, :size => 1, :maxlength => 1) + " #{as_('Delimiter')}".html_safe) %>
|
18
|
+
</div>
|
19
|
+
<div class="separator"></div>
|
20
|
+
<div class="option checkbox-wrapper">
|
21
|
+
<%= content_tag(:label, radio_button_tag('full_download', false, !export_config.default_full_download) + " #{as_('This Page')}".html_safe) if export_config.allow_full_download %>
|
22
|
+
</div>
|
23
|
+
<div class="option checkbox-wrapper">
|
24
|
+
<%= content_tag(:label, radio_button_tag('full_download', true, export_config.default_full_download) + " #{as_('All Pages')}".html_safe) if export_config.allow_full_download %>
|
25
|
+
</div>
|
26
|
+
|
27
|
+
</div>
|
28
|
+
<div class="separator"></div>
|
@@ -0,0 +1,7 @@
|
|
1
|
+
<%= render :partial => "base_form", :locals => {:xhr => false,
|
2
|
+
:form_action => :export,
|
3
|
+
:url_options => params_for(:action => :export, :format => 'csv'),
|
4
|
+
:method => :get,
|
5
|
+
:cancel_link => true,
|
6
|
+
:headline => as_('Columns to Export'),
|
7
|
+
:body_partial => 'export_form_body'} %>
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'active_scaffold_export'
|
data/install.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Workaround a problem with script/plugin and http-based repos.
|
2
|
+
# See http://dev.rubyonrails.org/ticket/8189
|
3
|
+
Dir.chdir(Dir.getwd.sub(/vendor.*/, '')) do
|
4
|
+
|
5
|
+
##
|
6
|
+
## Copy over asset files (javascript/css/images) from the plugin directory to public/
|
7
|
+
##
|
8
|
+
|
9
|
+
def copy_files(source_path, destination_path, directory)
|
10
|
+
source, destination = File.join(directory, source_path), File.join(Rails.root, destination_path)
|
11
|
+
FileUtils.mkdir(destination) unless File.exist?(destination)
|
12
|
+
FileUtils.cp_r(Dir.glob(source+'/*.*'), destination)
|
13
|
+
end
|
14
|
+
|
15
|
+
directory = File.dirname(__FILE__)
|
16
|
+
|
17
|
+
copy_files("/public", "/public", directory)
|
18
|
+
|
19
|
+
available_frontends = Dir[File.join(directory, 'frontends', '*')].collect { |d| File.basename d }
|
20
|
+
[ :stylesheets, :javascripts, :images].each do |asset_type|
|
21
|
+
path = "/public/#{asset_type}/active_scaffold"
|
22
|
+
copy_files(path, path, directory)
|
23
|
+
|
24
|
+
available_frontends.each do |frontend|
|
25
|
+
source = "/frontends/#{frontend}/#{asset_type}/"
|
26
|
+
destination = "/public/#{asset_type}/active_scaffold/#{frontend}"
|
27
|
+
copy_files(source, destination, directory)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
module ActiveScaffold::Actions
|
2
|
+
module Export
|
3
|
+
def self.included(base)
|
4
|
+
base.before_filter :export_authorized?, :only => [:export]
|
5
|
+
base.before_filter :init_session_var
|
6
|
+
|
7
|
+
as_export_plugin_path = File.join(ActiveScaffold::Config::Export.plugin_directory, 'frontends', 'default' , 'views')
|
8
|
+
|
9
|
+
base.add_active_scaffold_path as_export_plugin_path
|
10
|
+
end
|
11
|
+
|
12
|
+
def init_session_var
|
13
|
+
session[:search] = params[:search] if !params[:search].nil? || params[:commit] == as_('Search')
|
14
|
+
end
|
15
|
+
|
16
|
+
# display the customization form or skip directly to export
|
17
|
+
def show_export
|
18
|
+
export_config = active_scaffold_config.export
|
19
|
+
respond_to do |wants|
|
20
|
+
wants.html do
|
21
|
+
render(:partial => 'show_export', :layout => true)
|
22
|
+
end
|
23
|
+
wants.js do
|
24
|
+
render(:partial => 'show_export', :layout => false)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# if invoked directly, will use default configuration
|
30
|
+
def export
|
31
|
+
export_config = active_scaffold_config.export
|
32
|
+
if params[:export_columns].nil?
|
33
|
+
export_columns = {}
|
34
|
+
export_config.columns.each { |col|
|
35
|
+
export_columns[col.name.to_sym] = 1
|
36
|
+
}
|
37
|
+
options = {
|
38
|
+
:export_columns => export_columns,
|
39
|
+
:full_download => export_config.default_full_download.to_s,
|
40
|
+
:delimiter => export_config.default_delimiter,
|
41
|
+
:skip_header => export_config.default_skip_header.to_s
|
42
|
+
}
|
43
|
+
params.merge!(options)
|
44
|
+
end
|
45
|
+
|
46
|
+
# this is required if you want this to work with IE
|
47
|
+
if request.env['HTTP_USER_AGENT'] =~ /msie/i
|
48
|
+
response.headers['Pragma'] = "public"
|
49
|
+
response.headers['Cache-Control'] = "no-cache, must-revalidate, post-check=0, pre-check=0"
|
50
|
+
response.headers['Expires'] = "0"
|
51
|
+
end
|
52
|
+
|
53
|
+
response.headers['Content-type'] = 'text/csv'
|
54
|
+
response.headers['Content-Disposition'] = "attachment; filename=#{export_file_name}"
|
55
|
+
|
56
|
+
@export_columns = export_config.columns.reject { |col| params[:export_columns][col.name.to_sym].nil? }
|
57
|
+
includes_for_export_columns = @export_columns.collect{ |col| col.includes }.flatten.uniq.compact
|
58
|
+
self.active_scaffold_includes.concat includes_for_export_columns
|
59
|
+
@export_config = export_config
|
60
|
+
|
61
|
+
# start streaming output
|
62
|
+
self.response_body = proc { |response, output|
|
63
|
+
find_items_for_export do |records|
|
64
|
+
@records = records
|
65
|
+
str = render_to_string :partial => 'export', :layout => false
|
66
|
+
output.write(str)
|
67
|
+
params[:skip_header] = 'true' # skip header on the next run
|
68
|
+
end
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
72
|
+
protected
|
73
|
+
# The actual algorithm to do the export
|
74
|
+
def find_items_for_export(&block)
|
75
|
+
find_options = { :sorting =>
|
76
|
+
active_scaffold_config.list.user.sorting.nil? ?
|
77
|
+
active_scaffold_config.list.sorting : active_scaffold_config.list.user.sorting,
|
78
|
+
:pagination => true
|
79
|
+
}
|
80
|
+
params[:search] = session[:search]
|
81
|
+
do_search rescue nil
|
82
|
+
params[:segment_id] = session[:segment_id]
|
83
|
+
do_segment_search rescue nil
|
84
|
+
|
85
|
+
if params[:full_download] == 'true'
|
86
|
+
find_options.merge!({
|
87
|
+
:per_page => 10000,
|
88
|
+
:page => 1
|
89
|
+
})
|
90
|
+
find_page(find_options).pager.each do |page|
|
91
|
+
yield page.items
|
92
|
+
end
|
93
|
+
else
|
94
|
+
find_options.merge!({
|
95
|
+
:per_page => active_scaffold_config.list.user.per_page,
|
96
|
+
:page => active_scaffold_config.list.user.page
|
97
|
+
})
|
98
|
+
yield find_page(find_options).items
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
# The default name of the downloaded file.
|
103
|
+
# You may override the method to specify your own file name generation.
|
104
|
+
def export_file_name
|
105
|
+
"#{self.controller_name}.csv"
|
106
|
+
end
|
107
|
+
|
108
|
+
# The default security delegates to ActiveRecordPermissions.
|
109
|
+
# You may override the method to customize.
|
110
|
+
def export_authorized?
|
111
|
+
authorized_for?(:action => :read)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module ActiveScaffold::Config
|
2
|
+
class Export < ActiveScaffold::Config::Form
|
3
|
+
self.crud_type = :read
|
4
|
+
|
5
|
+
def initialize(core_config)
|
6
|
+
@core = core_config
|
7
|
+
end
|
8
|
+
|
9
|
+
# global level configuration
|
10
|
+
# --------------------------
|
11
|
+
# the ActionLink for this action
|
12
|
+
cattr_accessor :link
|
13
|
+
@@link = ActiveScaffold::DataStructures::ActionLink.new('show_export', :label => :export, :type => :collection, :security_method => :export_authorized?)
|
14
|
+
|
15
|
+
# configures where the plugin itself is located. there is no instance version of this.
|
16
|
+
cattr_accessor :plugin_directory
|
17
|
+
@@plugin_directory = File.expand_path(__FILE__).match(%{(^.*)/lib/active_scaffold/config/export.rb})[1]
|
18
|
+
|
19
|
+
|
20
|
+
# instance-level configuration
|
21
|
+
# ----------------------------
|
22
|
+
|
23
|
+
attr_writer :link
|
24
|
+
def link
|
25
|
+
@link ||= if show_form
|
26
|
+
self.class.link.clone
|
27
|
+
else
|
28
|
+
ActiveScaffold::DataStructures::ActionLink.new('export', :label => :export, :type => :collection, :inline => false, :security_method => :export_authorized?)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
attr_writer :show_form, :allow_full_download, :force_quotes, :default_full_download, :default_delimiter, :default_skip_header, :default_deselected_columns
|
33
|
+
def show_form
|
34
|
+
self.show_form = @core.export_show_form if @show_form.nil?
|
35
|
+
@show_form
|
36
|
+
end
|
37
|
+
def allow_full_download
|
38
|
+
self.allow_full_download = @core.export_allow_full_download if @allow_full_download.nil?
|
39
|
+
@allow_full_download
|
40
|
+
end
|
41
|
+
def force_quotes
|
42
|
+
self.force_quotes = @core.export_force_quotes if @force_quotes.nil?
|
43
|
+
@force_quotes
|
44
|
+
end
|
45
|
+
def default_full_download
|
46
|
+
self.default_full_download = @core.export_default_full_download if @default_full_download.nil?
|
47
|
+
@default_full_download
|
48
|
+
end
|
49
|
+
def default_delimiter
|
50
|
+
self.default_delimiter = @core.export_default_delimiter if @default_delimiter.nil?
|
51
|
+
@default_delimiter
|
52
|
+
end
|
53
|
+
def default_skip_header
|
54
|
+
self.default_skip_header = @core.export_default_skip_header if @default_skip_header.nil?
|
55
|
+
@default_skip_header
|
56
|
+
end
|
57
|
+
def default_deselected_columns
|
58
|
+
self.default_deselected_columns = [] if @default_deselected_columns.nil?
|
59
|
+
@default_deselected_columns
|
60
|
+
end
|
61
|
+
|
62
|
+
# provides access to the list of columns specifically meant for this action to use
|
63
|
+
def columns
|
64
|
+
self.columns = @core.columns._inheritable unless @columns
|
65
|
+
@columns
|
66
|
+
end
|
67
|
+
def columns=(val)
|
68
|
+
@columns = ActiveScaffold::DataStructures::ActionColumns.new(*val)
|
69
|
+
@columns.action = self
|
70
|
+
end
|
71
|
+
|
72
|
+
def multipart?
|
73
|
+
false
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module ActiveScaffold
|
2
|
+
module Helpers
|
3
|
+
# Helpers that assist with the rendering of a Export Column
|
4
|
+
module ExportHelpers
|
5
|
+
## individual columns can be overridden by defining
|
6
|
+
# a helper method <column_name>_export_column(record)
|
7
|
+
# You can customize the output of all columns by
|
8
|
+
# overriding the following helper methods:
|
9
|
+
# format_export_column(raw_value)
|
10
|
+
# format_singular_association_export_column(association_record)
|
11
|
+
# format_plural_association_export_column(association_records)
|
12
|
+
def get_export_column_value(record, column)
|
13
|
+
if export_column_override? column
|
14
|
+
send(export_column_override(column), record)
|
15
|
+
else
|
16
|
+
raw_value = record.send(column.name)
|
17
|
+
|
18
|
+
if column.association.nil? or column_empty?(raw_value)
|
19
|
+
format_export_column(raw_value)
|
20
|
+
else
|
21
|
+
case column.association.macro
|
22
|
+
when :has_one, :belongs_to
|
23
|
+
format_singular_association_export_column(raw_value)
|
24
|
+
when :has_many, :has_and_belongs_to_many
|
25
|
+
format_plural_association_export_column(raw_value)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def export_column_override(column)
|
32
|
+
"#{column.name.to_s.gsub('?', '')}_export_column" # parse out any question marks (see issue 227)
|
33
|
+
end
|
34
|
+
|
35
|
+
def export_column_override?(column)
|
36
|
+
respond_to?(export_column_override(column))
|
37
|
+
end
|
38
|
+
|
39
|
+
def format_export_column(raw_value)
|
40
|
+
format_value(raw_value)
|
41
|
+
end
|
42
|
+
|
43
|
+
def format_singular_association_export_column(association_record)
|
44
|
+
format_value(association_record.to_label)
|
45
|
+
end
|
46
|
+
|
47
|
+
def format_plural_association_export_column(association_records)
|
48
|
+
firsts = association_records.first(4).collect { |v| v.to_label }
|
49
|
+
firsts[4] = "…" if firsts.length == 4
|
50
|
+
format_value(firsts.join(','))
|
51
|
+
end
|
52
|
+
|
53
|
+
## This helper can be overridden to change the way that the headers
|
54
|
+
# are formatted. For instance, you might want column.name.to_s.humanize
|
55
|
+
def format_export_column_header_name(column)
|
56
|
+
column.name.to_s
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Need to open the AS module carefully due to Rails 2.3 lazy loading
|
2
|
+
ActiveScaffold::Helpers::ViewHelpers.module_eval do
|
3
|
+
# Add the export plugin includes
|
4
|
+
|
5
|
+
# Provides stylesheets to include with +stylesheet_link_tag+
|
6
|
+
def active_scaffold_stylesheets_with_export(frontend = :default)
|
7
|
+
active_scaffold_stylesheets_without_export.to_a << ActiveScaffold::Config::Core.asset_path("export-stylesheet.css", frontend)
|
8
|
+
end
|
9
|
+
alias_method_chain :active_scaffold_stylesheets, :export
|
10
|
+
|
11
|
+
# Provides stylesheets for IE to include with +stylesheet_link_tag+
|
12
|
+
def active_scaffold_ie_stylesheets_with_export(frontend = :default)
|
13
|
+
active_scaffold_ie_stylesheets_without_export.to_a << ActiveScaffold::Config::Core.asset_path("export-stylesheet-ie.css", frontend)
|
14
|
+
end
|
15
|
+
alias_method_chain :active_scaffold_ie_stylesheets, :export
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'active_scaffold' rescue nil
|
2
|
+
# Make sure that ActiveScaffold has already been included
|
3
|
+
ActiveScaffold rescue throw "should have included ActiveScaffold plug in first. Please make sure that this plug-in comes alphabetically after the ActiveScaffold plug-in"
|
4
|
+
|
5
|
+
# Load our overrides
|
6
|
+
require "#{File.dirname(__FILE__)}/active_scaffold_export/config/core.rb"
|
7
|
+
require "#{File.dirname(__FILE__)}/active_scaffold/config/export.rb"
|
8
|
+
require "#{File.dirname(__FILE__)}/active_scaffold/actions/export.rb"
|
9
|
+
require "#{File.dirname(__FILE__)}/active_scaffold/helpers/view_helpers_override.rb"
|
10
|
+
require "#{File.dirname(__FILE__)}/active_scaffold/helpers/export_helpers.rb"
|
11
|
+
|
12
|
+
##
|
13
|
+
## Run the install script, too, just to make sure
|
14
|
+
## But at least rescue the action in production
|
15
|
+
##
|
16
|
+
Rails::Application.initializer("active_scaffold_export_install_assets") do
|
17
|
+
begin
|
18
|
+
require File.dirname(__FILE__) + '/../install'
|
19
|
+
rescue
|
20
|
+
raise $! unless Rails.env == 'production'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Register our helper methods
|
25
|
+
ActionView::Base.send(:include, ActiveScaffold::Helpers::ExportHelpers)
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Need to open the AS module carefully due to Rails 2.3 lazy loading
|
2
|
+
ActiveScaffold::Config::Core.class_eval do
|
3
|
+
# For some unobvious reasons, the class variables need to be defined
|
4
|
+
# *before* the cattr !!
|
5
|
+
@@export_show_form = true
|
6
|
+
@@export_allow_full_download = true
|
7
|
+
@@export_default_full_download = true
|
8
|
+
@@export_force_quotes = false
|
9
|
+
@@export_default_skip_header = false
|
10
|
+
@@export_default_delimiter = ','
|
11
|
+
cattr_accessor :export_show_form, :export_allow_full_download,
|
12
|
+
:export_force_quotes, :export_default_full_download,
|
13
|
+
:export_default_delimiter, :export_default_skip_header
|
14
|
+
|
15
|
+
ActionDispatch::Routing::ACTIVE_SCAFFOLD_CORE_ROUTING[:collection][:show_export] = :get
|
16
|
+
ActionDispatch::Routing::ACTIVE_SCAFFOLD_CORE_ROUTING[:collection][:export] = :get
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: active_scaffold_export
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 51
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 9
|
9
|
+
- 4
|
10
|
+
version: 0.9.4
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Mojo Tech, LLC
|
14
|
+
- see commits
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2010-11-18 00:00:00 -05:00
|
20
|
+
default_executable:
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
name: fastercsv
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 3
|
31
|
+
segments:
|
32
|
+
- 0
|
33
|
+
version: "0"
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: active_scaffold
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
version: "0"
|
48
|
+
type: :runtime
|
49
|
+
version_requirements: *id002
|
50
|
+
description: This Active Scaffold plugin provides a configurable CSV 'Export' action for Active Scaffold controllers
|
51
|
+
email: chris@mojotech.com
|
52
|
+
executables: []
|
53
|
+
|
54
|
+
extensions: []
|
55
|
+
|
56
|
+
extra_rdoc_files:
|
57
|
+
- README.markdown
|
58
|
+
files:
|
59
|
+
- Gemfile
|
60
|
+
- MIT-LICENSE
|
61
|
+
- README.markdown
|
62
|
+
- active_scaffold_export.gemspec
|
63
|
+
- frontends/default/images/export.png
|
64
|
+
- frontends/default/stylesheets/export-stylesheet-ie.css
|
65
|
+
- frontends/default/stylesheets/export-stylesheet.css
|
66
|
+
- frontends/default/views/_export.csv.erb
|
67
|
+
- frontends/default/views/_export_form_body.html.erb
|
68
|
+
- frontends/default/views/_show_export.html.erb
|
69
|
+
- frontends/default/views/show_export.html.erb
|
70
|
+
- init.rb
|
71
|
+
- install.rb
|
72
|
+
- lib/active_scaffold/actions/export.rb
|
73
|
+
- lib/active_scaffold/config/export.rb
|
74
|
+
- lib/active_scaffold/helpers/export_helpers.rb
|
75
|
+
- lib/active_scaffold/helpers/view_helpers_override.rb
|
76
|
+
- lib/active_scaffold_export.rb
|
77
|
+
- lib/active_scaffold_export/config/core.rb
|
78
|
+
has_rdoc: true
|
79
|
+
homepage: http://github.com/mojotech/active_scaffold_export
|
80
|
+
licenses: []
|
81
|
+
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options:
|
84
|
+
- --charset=UTF-8
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
hash: 3
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
version: "0"
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
hash: 3
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
version: "0"
|
105
|
+
requirements: []
|
106
|
+
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 1.3.7
|
109
|
+
signing_key:
|
110
|
+
specification_version: 3
|
111
|
+
summary: Active Scaffold plugin for CSV exports
|
112
|
+
test_files: []
|
113
|
+
|