usefull_table 1.0.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 (28) hide show
  1. data/CHANGELOG.md +12 -0
  2. data/Gemfile +27 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +234 -0
  5. data/Rakefile +31 -0
  6. data/app/controllers/usefull_table/table_controller.rb +34 -0
  7. data/app/helpers/usefull_table_helper.rb +323 -0
  8. data/app/views/usefull_table/table/create.xlsx.maker +17 -0
  9. data/config/routes.rb +8 -0
  10. data/lib/generators/usefull_table/install/install_generator.rb +47 -0
  11. data/lib/generators/usefull_table/install/templates/config/locales/usefull_table.it.yml +42 -0
  12. data/lib/generators/usefull_table/install/templates/public/images/usefull_table_destroy.png +0 -0
  13. data/lib/generators/usefull_table/install/templates/public/images/usefull_table_download.png +0 -0
  14. data/lib/generators/usefull_table/install/templates/public/images/usefull_table_edit.png +0 -0
  15. data/lib/generators/usefull_table/install/templates/public/images/usefull_table_false.png +0 -0
  16. data/lib/generators/usefull_table/install/templates/public/images/usefull_table_show.png +0 -0
  17. data/lib/generators/usefull_table/install/templates/public/images/usefull_table_true.png +0 -0
  18. data/lib/generators/usefull_table/install/templates/public/stylesheets/usefull_table.css +101 -0
  19. data/lib/generators/usefull_table/scaffold/scaffold_generator.rb +12 -0
  20. data/lib/generators/usefull_table/scaffold/templates/lib/templates/erb/scaffold/index.html.erb +15 -0
  21. data/lib/generators/usefull_table/scaffold/templates/lib/templates/erb/scaffold/show.html.erb +12 -0
  22. data/lib/generators/usefull_table/scaffold/templates/lib/templates/rails/scaffold_controller/controller.rb +84 -0
  23. data/lib/usefull_table/engine.rb +17 -0
  24. data/lib/usefull_table/exceptions.rb +17 -0
  25. data/lib/usefull_table/table_builder.rb +522 -0
  26. data/lib/usefull_table/version.rb +3 -0
  27. data/lib/usefull_table.rb +13 -0
  28. metadata +123 -0
@@ -0,0 +1,17 @@
1
+ #You have package = AXLSX::Package.new exposed
2
+
3
+ #Configuring Styles
4
+
5
+ excel = export_for(@object, @params)
6
+
7
+ package.workbook do |wb|
8
+ styles = wb.styles
9
+ title = styles.add_style(:b => true)
10
+
11
+ wb.add_worksheet do |sheet|
12
+ sheet.add_row excel.shift, :style => title
13
+ excel.each do |row|
14
+ sheet.add_row row
15
+ end
16
+ end
17
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,8 @@
1
+ # CURRENT FILE :: config/routes.rb
2
+ Rails.application.routes.draw do
3
+ namespace :usefull_table do
4
+ #resources :table, :only =>[:create]
5
+ match "table/create" => "table#create", :via => :post
6
+ match "table/update/:id" => "table#update", :via => :post
7
+ end
8
+ end
@@ -0,0 +1,47 @@
1
+ require 'rails/generators'
2
+ module UsefullTable
3
+ class InstallGenerator < Rails::Generators::Base
4
+ desc "Install generator for UsefullTable gem"
5
+ source_root File.expand_path("../templates", __FILE__)
6
+
7
+ def copy_config
8
+ directory "config"
9
+ end
10
+
11
+ def copy_public
12
+ directory "public"
13
+ end
14
+
15
+ #~ def copy_icons
16
+ #~ icons = ["acts_as_monitor_green.png", "acts_as_monitor_red.png", "acts_as_monitor_yellow.png", "acts_as_monitor_loading.gif"]
17
+ #~ icons.each do |icon|
18
+ #~ destination = "public/images/" + icon
19
+ #~ copy_file icon, destination
20
+ #~ end
21
+ #~ end
22
+
23
+ #~ def copy_locales
24
+ #~ file = "acts_as_monitor.it.yml"
25
+ #~ destination = "config/locales/" + file
26
+ #~ copy_file file, destination
27
+ #~ end
28
+
29
+ #~ def copy_javascripts
30
+ #~ copy_file "acts_as_monitor_javascript.js", "public/javascripts/acts_as_monitor_javascript.js"
31
+ #~ end
32
+
33
+ #~ def copy_stylesheet
34
+ #~ copy_file "acts_as_monitor.css", "public/stylesheets/acts_as_monitor.css"
35
+ #~ end
36
+
37
+
38
+ #~ def print_usage
39
+ #~ usage = <<-START
40
+ #~ Add acts_as_monitor to model to monitor
41
+ #~ Add a private method warn_*? and error_*? to define warning and error status
42
+ #~ Use monitor_tag(model_instance) in your view
43
+ #~ START
44
+ #~ puts(usage)
45
+ #~ end
46
+ end
47
+ end
@@ -0,0 +1,42 @@
1
+ #Ricordarsi di metterlo nei template da copiare con il generatore...
2
+ it:
3
+ usefull_table:
4
+ submit_excel: Excel
5
+ header_error: Errore
6
+ body_error: Errore
7
+ confirm: "Sei sicuro?"
8
+
9
+ #Localize monitor flag when exporting to_a (xlsx, xls, pdf)
10
+ monitor:
11
+ green: Ok
12
+ yellow: Problemi
13
+ red: Errori
14
+ title: "Stato"
15
+
16
+ icons:
17
+ show: "usefull_table_show.png"
18
+ edit: "usefull_table_edit.png"
19
+ destroy: "usefull_table_destroy.png"
20
+ download: "usefull_table_download.png"
21
+ ok: "usefull_table_true.png"
22
+ ko: "usefull_table_false.png"
23
+ time:
24
+ formats:
25
+ usefull_table_time: "%H:%M"
26
+ usefull_table_datetime: "%d/%m/%Y %H:%M"
27
+ usefull_table_date: "%d/%m/%Y"
28
+
29
+ date:
30
+ formats:
31
+ usefull_table_date: "%d/%m/%Y"
32
+
33
+ number:
34
+ currency:
35
+ format:
36
+ format: "%n %u"
37
+ unit: "€"
38
+ separator: ","
39
+ delimiter: "."
40
+ precision: 2
41
+ significant: false
42
+ strip_insignificant_zeros: false
@@ -0,0 +1,101 @@
1
+ /*Export*/
2
+ div.usefull_table_export input[type='submit']{
3
+ background: orange;
4
+ border-width: 1px;
5
+ margin-top: 3px;
6
+ margin-bottom: 3px;
7
+ }
8
+
9
+ /*Paginator */
10
+ div.usefull_table_paginator {
11
+ width: 100%;
12
+ background: white;
13
+ cursor: default;
14
+ border: 2px solid #dddddd;
15
+ }
16
+
17
+ /* self-clearing method: */
18
+ .usefull_table_paginator span{
19
+ margin:0;
20
+ padding:0;
21
+ border:0;
22
+ margin:0;
23
+ padding:0;
24
+ border:0;
25
+ font-size:100%;
26
+ font:inherit;
27
+ vertical-align:baseline;
28
+ display: inline;
29
+ float: left;}
30
+ .usefull_table_paginator a, .usefull_table_paginator, .usefull_table_paginator em {
31
+ padding: 0.1em 0.2em;
32
+ display: inline;
33
+ float: left;
34
+ margin-right: 1px; }
35
+ .usefull_table_paginator .disabled {
36
+ color: #999999;
37
+ border: 1px solid #dddddd; }
38
+ .usefull_table_paginator .current {
39
+ font-style: normal;
40
+ font-weight: bold;
41
+ background: #2e6ab1;
42
+ color: white;
43
+ border: 1px solid #2e6ab1; }
44
+ .usefull_table_paginator a {
45
+ text-decoration: none;
46
+ color: #105cb6;
47
+ border: 1px solid #9aafe5; }
48
+ .usefull_table_paginator a:hover, .usefull_table_paginator a:focus {
49
+ color: #000033;
50
+ border-color: #000033; }
51
+ .usefull_table_paginator .page_info {
52
+ background: #2e6ab1;
53
+ color: white;
54
+ padding: 0;
55
+ width: 100%;
56
+ margin-bottom: 0.3em;
57
+ text-align: center; }
58
+ .usefull_table_paginator .page_info b {
59
+ color: #000033;
60
+ background: #6aa6ed;
61
+ padding: 0.1em 0.25em; }
62
+ .usefull_table_paginator:after {
63
+ content: ".";
64
+ display: block;
65
+ height: 0;
66
+ clear: both;
67
+ visibility: hidden; }
68
+ * html .usefull_table_paginator {
69
+ height: 1%; }
70
+ *:first-child + html .usefull_table_paginator {
71
+ overflow: hidden; }
72
+
73
+ /* Table*/
74
+ div.usefull_table table {
75
+ border-collapse:collapse;
76
+ border-spacing:0;
77
+ margin-bottom:1.4em;
78
+ width:100%;}
79
+ div.usefull_table tbody tr.first_row {
80
+ background:#C3D934;}
81
+ div.usefull_table tbody tr.odd {
82
+ background-color: #FFFFFF;}
83
+ div.usefull_table tbody tr.even {
84
+ background-color: #E5ECF9;}
85
+ div.usefull_table td, .usefull_table th {
86
+ padding:2px 4px;
87
+ text-align:left;
88
+ margin:0;
89
+ vertical-align:middle;
90
+ float:none !important;
91
+ max-width:500px;
92
+ border-collapse: collapse;}
93
+ div.usefull_table th {
94
+ font-weight:bold;
95
+ border:0 none;}
96
+ div.usefull_table td {
97
+ border-bottom:1px solid red;
98
+ text-overflow:ellipsis;
99
+ overflow:hidden;
100
+ white-space:nowrap;
101
+ font-weight:normal;}
@@ -0,0 +1,12 @@
1
+ require 'rails/generators'
2
+ module UsefullTable
3
+ class ScaffoldGenerator < Rails::Generators::Base
4
+ desc "Install generator for UsefullTable gem"
5
+ source_root File.expand_path("../templates", __FILE__)
6
+
7
+ def copy_templates
8
+ directory "lib"
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ <h1>Listing <%= plural_table_name %></h1>
2
+
3
+ <%%= table_for @<%= plural_table_name %>, @search do |t| %>
4
+ <%% t.status %>
5
+ <%% t.show :url => Proc.new {|<%= singular_table_name %>| <%= singular_table_name %> } %>
6
+ <%% t.edit :url => Proc.new {|<%= singular_table_name %>| edit_<%= singular_table_name %>_path(<%= singular_table_name %>) } %>
7
+ <%% t.destroy :url => Proc.new {|<%= singular_table_name %>| <%= singular_table_name %> } %>
8
+ <% attributes.each do |attribute| -%>
9
+ <%% t.col :<%= attribute.name %> %>
10
+ <% end -%>
11
+ <%% end %>
12
+
13
+
14
+
15
+ <%%= link_to 'New <%= human_name %>', new_<%= singular_table_name %>_path %>
@@ -0,0 +1,12 @@
1
+ <p id="notice"><%%= notice %></p>
2
+
3
+ <% attributes.each do |attribute| -%>
4
+ <p>
5
+ <strong><%= attribute.human_name %>:</strong>
6
+ <%%= @<%= singular_table_name %>.<%= attribute.name %> %>
7
+ </p>
8
+
9
+ <% end -%>
10
+
11
+ <%%= link_to 'Edit', edit_<%= singular_table_name %>_path(@<%= singular_table_name %>) %> |
12
+ <%%= link_to 'Back', <%= index_helper %>_path %>
@@ -0,0 +1,84 @@
1
+ class <%= controller_class_name %>Controller < ApplicationController
2
+ # GET <%= route_url %>
3
+ # GET <%= route_url %>.xml
4
+ def index
5
+ @search = <%=class_name%>.search(params[:search])
6
+ @<%= plural_table_name %> = @search.paginate(:page => params[:page])
7
+
8
+ respond_to do |format|
9
+ format.html # index.html.erb
10
+ format.xml { render :xml => @<%= plural_table_name %> }
11
+ end
12
+ end
13
+
14
+ # GET <%= route_url %>/1
15
+ # GET <%= route_url %>/1.xml
16
+ def show
17
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
18
+
19
+ respond_to do |format|
20
+ format.html # show.html.erb
21
+ format.xml { render :xml => @<%= singular_table_name %> }
22
+ end
23
+ end
24
+
25
+ # GET <%= route_url %>/new
26
+ # GET <%= route_url %>/new.xml
27
+ def new
28
+ @<%= singular_table_name %> = <%= orm_class.build(class_name) %>
29
+
30
+ respond_to do |format|
31
+ format.html # new.html.erb
32
+ format.xml { render :xml => @<%= singular_table_name %> }
33
+ end
34
+ end
35
+
36
+ # GET <%= route_url %>/1/edit
37
+ def edit
38
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
39
+ end
40
+
41
+ # POST <%= route_url %>
42
+ # POST <%= route_url %>.xml
43
+ def create
44
+ @<%= singular_table_name %> = <%= orm_class.build(class_name, "params[:#{singular_table_name}]") %>
45
+
46
+ respond_to do |format|
47
+ if @<%= orm_instance.save %>
48
+ format.html { redirect_to(@<%= singular_table_name %>, :notice => '<%= human_name %> was successfully created.') }
49
+ format.xml { render :xml => @<%= singular_table_name %>, :status => :created, :location => @<%= singular_table_name %> }
50
+ else
51
+ format.html { render :action => "new" }
52
+ format.xml { render :xml => @<%= orm_instance.errors %>, :status => :unprocessable_entity }
53
+ end
54
+ end
55
+ end
56
+
57
+ # PUT <%= route_url %>/1
58
+ # PUT <%= route_url %>/1.xml
59
+ def update
60
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
61
+
62
+ respond_to do |format|
63
+ if @<%= orm_instance.update_attributes("params[:#{singular_table_name}]") %>
64
+ format.html { redirect_to(@<%= singular_table_name %>, :notice => '<%= human_name %> was successfully updated.') }
65
+ format.xml { head :ok }
66
+ else
67
+ format.html { render :action => "edit" }
68
+ format.xml { render :xml => @<%= orm_instance.errors %>, :status => :unprocessable_entity }
69
+ end
70
+ end
71
+ end
72
+
73
+ # DELETE <%= route_url %>/1
74
+ # DELETE <%= route_url %>/1.xml
75
+ def destroy
76
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
77
+ @<%= orm_instance.destroy %>
78
+
79
+ respond_to do |format|
80
+ format.html { redirect_to(<%= index_helper %>_url) }
81
+ format.xml { head :ok }
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,17 @@
1
+ module UsefullTable
2
+ class Engine < Rails::Engine
3
+
4
+ config.autoload_paths += Dir["#{config.root}/lib/**/"]
5
+
6
+ initializer 'usefull_table.helper' do |app|
7
+ ActiveSupport.on_load(:action_controller) do
8
+ include UsefullTableHelper
9
+ end
10
+ ActiveSupport.on_load(:action_view) do
11
+ include UsefullTableHelper
12
+ end
13
+
14
+ end
15
+ end
16
+
17
+ end
@@ -0,0 +1,17 @@
1
+ #Populate the module with the custom exceptions
2
+ module UsefullTable
3
+ class CustomError < StandardError
4
+ def initialize(*args)
5
+ @options = args.extract_options!
6
+ super
7
+ end
8
+
9
+ def message
10
+ @options.merge!({:default => "Error : #{@options.inspect}"})
11
+ #I18n.t("#{self.class.name.gsub(/::/,'.')}", :default => "Error : #{@options.inspect}", @options)
12
+ I18n.t("#{self.class.name.gsub(/::/,'.')}", @options )
13
+ end
14
+ end
15
+
16
+ class MissingBlock < CustomError ; end
17
+ end