table_setter_generator 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.
Files changed (37) hide show
  1. data/.document +5 -0
  2. data/.gitignore +21 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +21 -0
  5. data/Rakefile +63 -0
  6. data/USAGE +2 -0
  7. data/VERSION.yml +5 -0
  8. data/documentation/css/styles.css +62 -0
  9. data/documentation/images/proplogo.png +0 -0
  10. data/documentation/index.html.erb +29 -0
  11. data/index.html +46 -0
  12. data/lib/table_setter_generator.rb +3 -0
  13. data/table_setter_generator.gemspec +79 -0
  14. data/table_setter_generator.rb +105 -0
  15. data/templates/table.rb +2 -0
  16. data/templates/table_controller.rb +28 -0
  17. data/templates/ts/config.ru +33 -0
  18. data/templates/ts/public/favicon.ico +0 -0
  19. data/templates/ts/public/images/th_arrow_asc.gif +0 -0
  20. data/templates/ts/public/images/th_arrow_desc.gif +0 -0
  21. data/templates/ts/public/javascripts/application.js +32 -0
  22. data/templates/ts/public/javascripts/jquery.tablesorter.js +852 -0
  23. data/templates/ts/public/javascripts/jquery.tablesorter.multipagefilter.js +111 -0
  24. data/templates/ts/public/javascripts/jquery.tablesorter.pager.js +183 -0
  25. data/templates/ts/public/stylesheets/stylesheet.css +74 -0
  26. data/templates/ts/tables/example.yml +21 -0
  27. data/templates/ts/tables/example_faceted.yml +27 -0
  28. data/templates/ts/tables/example_formatted.csv +1 -0
  29. data/templates/ts/tables/example_formatted.yml +27 -0
  30. data/templates/ts/tables/example_local.csv +5806 -0
  31. data/templates/ts/tables/example_local.yml +27 -0
  32. data/templates/ts/views/404.erb +4 -0
  33. data/templates/ts/views/500.erb +4 -0
  34. data/templates/ts/views/index.erb +8 -0
  35. data/templates/ts/views/layout.erb +35 -0
  36. data/templates/ts/views/table.erb +79 -0
  37. metadata +110 -0
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Jeff Larson
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,21 @@
1
+ =
2
+
3
+
4
+ TableSetterGenerator is a rails generator that will add TableSetter functionality to your rails app.
5
+
6
+
7
+ Docs:
8
+
9
+ http://propublica.github.com/table-setter-generator
10
+
11
+ Install:
12
+
13
+ gem install table_setter_generator
14
+
15
+ Usage (in your Rails application's directory):
16
+
17
+ script/generate table_setter
18
+
19
+
20
+
21
+
@@ -0,0 +1,63 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "table_setter_generator"
8
+ gem.summary = %Q{A Rails Generator for TableSetter}
9
+ gem.description = %Q{Generate a hackable version of TableSetter}
10
+ gem.email = "jeff.larson@propublica.org"
11
+ gem.homepage = "http://github.com/propublica/table-setter-generator"
12
+ gem.authors = ["Jeff Larson"]
13
+ gem.add_dependency "table_setter", ">= 0.1.2"
14
+ gem.add_dependency "rails", ">= 2.3.5"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/**/test_*.rb'
26
+ test.verbose = true
27
+ end
28
+
29
+ begin
30
+ require 'rcov/rcovtask'
31
+ Rcov::RcovTask.new do |test|
32
+ test.libs << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+ rescue LoadError
37
+ task :rcov do
38
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39
+ end
40
+ end
41
+
42
+ task :test => :check_dependencies
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "table-setter-generator #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
55
+
56
+
57
+ desc "render documentation for gh-pages"
58
+ task :gh do
59
+ require 'erb'
60
+ File.open("index.html", "w") do |f|
61
+ f.write ERB.new(File.open("documentation/index.html.erb").read).result
62
+ end
63
+ end
data/USAGE ADDED
@@ -0,0 +1,2 @@
1
+ To install the required routes and files for a TableSetter Rails app run:
2
+ script/generate table_setter
@@ -0,0 +1,5 @@
1
+ ---
2
+ :minor: 1
3
+ :patch: 0
4
+ :build:
5
+ :major: 0
@@ -0,0 +1,62 @@
1
+ body {
2
+ font-family: Garamond, Baskerville, "Baskerville Old Face", "Hoefler Text", "Times New Roman", serif;
3
+ font-size: 16px;
4
+ line-height:20px;
5
+ width: 600px;
6
+ margin-left:auto;
7
+ margin-right:auto;
8
+ background: #efefef;
9
+ }
10
+ a.propublica{
11
+ position:absolute;
12
+ background: transparent url(../images/proplogo.png) no-repeat -40px -20px;
13
+ top: 0;
14
+ left: 0;
15
+ width: 160px;
16
+ height: 141px;
17
+ }
18
+
19
+
20
+ .dir, .file{
21
+ padding-left: 25px;
22
+ background: transparent url(../images/folder.png) no-repeat 3px 0px;
23
+ margin-top: .25em;
24
+ margin-bottom: .25em;
25
+
26
+ }
27
+
28
+ .file{
29
+ background: transparent url(../images/text-x-generic.png) no-repeat 6px 3px;
30
+ }
31
+
32
+ pre {
33
+ font-family: Monaco, Courier, monospace;
34
+ font-size: 12px;
35
+ line-height: 16px;
36
+ padding:0.5em 1em;
37
+ overflow: auto;
38
+ border-left: 4px solid #143D8D;
39
+ margin-left: 1em;
40
+ }
41
+ a {
42
+ color: #143D8D;
43
+ text-decoration: none;
44
+ font-weight: bold;
45
+ }
46
+ ul {
47
+ margin:0 1em;
48
+ padding:0;
49
+ list-style: none;
50
+ }
51
+ li {
52
+ margin:0;
53
+ padding:0;
54
+ }
55
+ strong {
56
+ font-family: Monaco, Courier, monospace;
57
+ font-weight: normal;
58
+ background: #dadee5;
59
+ border: 1px solid #aaa;
60
+ padding: 1px 2px;
61
+ font-size: 12px;
62
+ }
@@ -0,0 +1,29 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
5
+ <title>TableSetterGenerator</title>
6
+ <link rel="stylesheet" type="text/css" href="documentation/css/styles.css" />
7
+ </head>
8
+
9
+ <body>
10
+ <a href="http://www.propublica.org" class="propublica">&nbsp;</a>
11
+ <h1>TableSetterGenerator <small>&ndash; Version: <%=
12
+ config = YAML.load(File.read('VERSION.yml'))
13
+ "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
14
+ %></small></h1>
15
+
16
+ <p><a href="http://github.com/propublica/table-setter-generator">TableSetterGenerator</a> is a rails generator that will add <a href="http://github.com/propublica/table-setter">TableSetter</a> functionality to your rails app.</p>
17
+ <h2>Installation</h2>
18
+ <p>To install the generator run:</p>
19
+ <pre>
20
+ gem install table table_setter_generator</pre>
21
+ <p>and then generate the required files in your rails application's directory:</p>
22
+ <pre>
23
+ script/generate table_setter</pre>
24
+ <h2>Usage</h2>
25
+ <p>For a detailed walkthrough on how <strong>TableSetter</strong> works you should consult the <a href="http://propublica.github.com/table-setter">TableSetter</a> documentation. In Rails the routes, controller and views are in the usual places. The <strong>TableSetter</strong> <a href="http://propublica.github.com/table-setter/#thefile">configuration files</a> are in <strong>config/tables</strong> directory.</p>
26
+ <h2><a name="license" href="#toc">License</a></h2>
27
+ <pre><%= File.open("LICENSE").read %></pre>
28
+ </body>
29
+ </html>
@@ -0,0 +1,46 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
5
+ <title>TableSetterGenerator</title>
6
+ <link rel="stylesheet" type="text/css" href="documentation/css/styles.css" />
7
+ </head>
8
+
9
+ <body>
10
+ <a href="http://www.propublica.org" class="propublica">&nbsp;</a>
11
+ <h1>TableSetterGenerator <small>&ndash; Version: 0.1.0</small></h1>
12
+
13
+ <p><a href="http://github.com/propublica/table-setter-generator">TableSetterGenerator</a> is a rails generator that will add <a href="http://github.com/propublica/table-setter">TableSetter</a> functionality to your rails app.</p>
14
+ <h2>Installation</h2>
15
+ <p>To install the generator run:</p>
16
+ <pre>
17
+ gem install table table_setter_generator</pre>
18
+ <p>and then generate the required files in your rails application's directory:</p>
19
+ <pre>
20
+ script/generate table_setter</pre>
21
+ <h2>Usage</h2>
22
+ <p>For a detailed walkthrough on how <strong>TableSetter</strong> works you should consult the <a href="http://propublica.github.com/table-setter">TableSetter</a> documentation. In Rails the routes, controller and views are in the usual places. The <strong>TableSetter</strong> <a href="http://propublica.github.com/table-setter/#thefile">configuration files</a> are in <strong>config/tables</strong> directory.</p>
23
+ <h2><a name="license" href="#toc">License</a></h2>
24
+ <pre>Copyright (c) 2009 Jeff Larson
25
+
26
+ Permission is hereby granted, free of charge, to any person obtaining
27
+ a copy of this software and associated documentation files (the
28
+ "Software"), to deal in the Software without restriction, including
29
+ without limitation the rights to use, copy, modify, merge, publish,
30
+ distribute, sublicense, and/or sell copies of the Software, and to
31
+ permit persons to whom the Software is furnished to do so, subject to
32
+ the following conditions:
33
+
34
+ The above copyright notice and this permission notice shall be
35
+ included in all copies or substantial portions of the Software.
36
+
37
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
38
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
39
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
40
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
41
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
42
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
43
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
44
+ </pre>
45
+ </body>
46
+ </html>
@@ -0,0 +1,3 @@
1
+ class TableSetterGenerator
2
+ # move along nothing to see here
3
+ end
@@ -0,0 +1,79 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{table_setter_generator}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jeff Larson"]
12
+ s.date = %q{2010-03-10}
13
+ s.description = %q{Generate a hackable version of TableSetter}
14
+ s.email = %q{jeff.larson@propublica.org}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "USAGE",
26
+ "VERSION.yml",
27
+ "documentation/css/styles.css",
28
+ "documentation/images/proplogo.png",
29
+ "documentation/index.html.erb",
30
+ "index.html",
31
+ "lib/table_setter_generator.rb",
32
+ "table_setter_generator.gemspec",
33
+ "table_setter_generator.rb",
34
+ "templates/table.rb",
35
+ "templates/table_controller.rb",
36
+ "templates/ts/config.ru",
37
+ "templates/ts/public/favicon.ico",
38
+ "templates/ts/public/images/th_arrow_asc.gif",
39
+ "templates/ts/public/images/th_arrow_desc.gif",
40
+ "templates/ts/public/javascripts/application.js",
41
+ "templates/ts/public/javascripts/jquery.tablesorter.js",
42
+ "templates/ts/public/javascripts/jquery.tablesorter.multipagefilter.js",
43
+ "templates/ts/public/javascripts/jquery.tablesorter.pager.js",
44
+ "templates/ts/public/stylesheets/stylesheet.css",
45
+ "templates/ts/tables/example.yml",
46
+ "templates/ts/tables/example_faceted.yml",
47
+ "templates/ts/tables/example_formatted.csv",
48
+ "templates/ts/tables/example_formatted.yml",
49
+ "templates/ts/tables/example_local.csv",
50
+ "templates/ts/tables/example_local.yml",
51
+ "templates/ts/views/404.erb",
52
+ "templates/ts/views/500.erb",
53
+ "templates/ts/views/index.erb",
54
+ "templates/ts/views/layout.erb",
55
+ "templates/ts/views/table.erb"
56
+ ]
57
+ s.homepage = %q{http://github.com/propublica/table-setter-generator}
58
+ s.rdoc_options = ["--charset=UTF-8"]
59
+ s.require_paths = ["lib"]
60
+ s.rubygems_version = %q{1.3.5}
61
+ s.summary = %q{A Rails Generator for TableSetter}
62
+
63
+ if s.respond_to? :specification_version then
64
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
65
+ s.specification_version = 3
66
+
67
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
68
+ s.add_runtime_dependency(%q<table_setter>, [">= 0.1.2"])
69
+ s.add_runtime_dependency(%q<rails>, [">= 2.3.5"])
70
+ else
71
+ s.add_dependency(%q<table_setter>, [">= 0.1.2"])
72
+ s.add_dependency(%q<rails>, [">= 2.3.5"])
73
+ end
74
+ else
75
+ s.add_dependency(%q<table_setter>, [">= 0.1.2"])
76
+ s.add_dependency(%q<rails>, [">= 2.3.5"])
77
+ end
78
+ end
79
+
@@ -0,0 +1,105 @@
1
+ require 'table_setter'
2
+ class TableSetterGenerator < Rails::Generator::Base
3
+ def manifest
4
+ record do |m|
5
+
6
+ # Model
7
+ m.directory "app/models/"
8
+ m.file "table.rb", "app/models/table.rb"
9
+
10
+
11
+ # Views
12
+ m.directory "app/views/table/"
13
+ m.file "ts/views/index.erb", "app/views/table/index.erb"
14
+ m.file "ts/views/table.erb", "app/views/table/table.erb"
15
+
16
+ # Layout
17
+ m.directory "app/views/layouts/"
18
+ m.file "ts/views/layout.erb", "app/views/layouts/table.erb"
19
+
20
+ # Static Assets
21
+ m.directory "public/javascripts/"
22
+ ["application.js", "jquery.tablesorter.js",
23
+ "jquery.tablesorter.multipagefilter.js", "jquery.tablesorter.pager.js"].each do |js|
24
+ m.file "ts/public/javascripts/#{js}", "public/javascripts/#{js}"
25
+ end
26
+
27
+ m.directory "public/stylesheets"
28
+ m.file "ts/public/stylesheets/stylesheet.css",
29
+ "public/stylesheets/stylesheet.css"
30
+
31
+ m.directory "public/images"
32
+ ["th_arrow_asc.gif", "th_arrow_desc.gif"].each do |image|
33
+ m.file "ts/public/images/#{image}", "public/images/#{image}"
34
+ end
35
+
36
+ # TableSetter Config Files
37
+ m.directory "config/tables"
38
+ ["example.yml", "example_faceted.yml", "example_formatted.csv",
39
+ "example_formatted.yml", "example_local.csv", "example_local.yml"].each do |table|
40
+ m.file "ts/tables/#{table}", "config/tables/#{table}"
41
+ end
42
+
43
+ # Local Installs
44
+ m.directory "app/controllers/"
45
+ m.file "table_controller.rb", "app/controllers/table_controller.rb"
46
+
47
+ # File changes
48
+ m.route! 'map.table ":slug/:page", :controller => :table, :action => :table, :requirements => { :page => /\d+/}, :page => nil'
49
+ m.route! "map.expire ':slug/expire', :controller => :table, :action => :expire"
50
+ m.route! "map.root :controller => :table, :action => :index"
51
+
52
+
53
+ m.config! "config.gem 'table_setter'"
54
+ m.config! "config.frameworks -= [ :active_record, :active_resource, :action_mailer ]"
55
+
56
+
57
+ # Environment
58
+ m.gsub_file "config/environment.rb", /(\z)/m do |match|
59
+ "\n" + 'TableSetter.configure "#{RAILS_ROOT}/config/"'
60
+ end
61
+
62
+
63
+ # Sinatra to Rails
64
+ m.gsub_file "app/views/layouts/table.erb", /(javascript_script_tag)/m do |match|
65
+ "javascript_include_tag"
66
+ end
67
+
68
+ m.gsub_file "app/views/layouts/table.erb", /(\/javascripts\/|\/stylesheets\/)/m do |match|
69
+ ""
70
+ end
71
+
72
+ m.gsub_file "app/views/table/table.erb", /(#{Regexp.escape '<%= url_for "/#{table.slug}/#{table.prev_page}/" if !table.prev_page.nil? %>'})/m do |match|
73
+ '<%= url_for(table_path :slug => table.slug, :page => table.prev_page) if !table.prev_page.nil? %>'
74
+ end
75
+
76
+ m.gsub_file "app/views/table/table.erb", /(#{Regexp.escape '<%= url_for "/#{table.slug}/#{table.next_page}/" if !table.next_page.nil? %>'})/m do |match|
77
+ '<%= url_for(table_path :slug => table.slug, :page => table.next_page) if !table.next_page.nil? %>'
78
+ end
79
+
80
+ m.gsub_file "app/views/table/index.erb",
81
+ /(#{Regexp.escape '<%= url_for "/#{table.slug}/" %>'})/ do |match|
82
+ '<%= url_for(table_path :slug => table.slug) %>'
83
+ end
84
+ end
85
+ end
86
+ end
87
+
88
+
89
+ Rails::Generator::Commands::Create.class_eval do
90
+ def config!(string)
91
+ insert_string! "config/environment.rb", string,
92
+ "Rails::Initializer.run do |config|"
93
+ end
94
+
95
+ def route!(string)
96
+ insert_string! "config/routes.rb", string,
97
+ "ActionController::Routing::Routes.draw do |map|"
98
+ end
99
+
100
+ def insert_string!(file, string, insert_after)
101
+ gsub_file file, /(#{Regexp.escape(insert_after)})/mi do |match|
102
+ "#{match}\n #{string}"
103
+ end
104
+ end
105
+ end