Introduction
Introduction Statistics Contact Development Disclaimer Help
* refactored generators * added generator for packaged grafico - reportable - F…
Log
Files
Refs
README
---
commit 22696d597d2ae138a1edf78c37bcd03a0b28d736
parent d9af94a2252454b9881676a910c26f3c093282d1
Author: Marco Otte-Witte <[email protected]>
Date: Mon, 19 Apr 2010 16:56:44 +0200
* refactored generators
* added generator for packaged grafico
Diffstat:
M README.md | 16 ++++++++--------
A generators/reportable_assets/NOTES | 3 +++
A generators/reportable_assets/repor… | 32 +++++++++++++++++++++++++++…
A generators/reportable_assets/templ… | 4 ++++
A generators/reportable_assets/templ… | 80 +++++++++++++++++++++++++++…
M generators/reportable_migration/re… | 13 ++++++++++---
D generators/reportable_migration/te… | 0
D generators/reportable_migration/te… | 40 ---------------------------…
R generators/reportable_migration/te… | 0
M lib/saulabs/reportable/railtie.rb | 11 +++++++++--
M reportable.gemspec | 2 +-
11 files changed, 147 insertions(+), 54 deletions(-)
---
diff --git a/README.md b/README.md
@@ -64,13 +64,13 @@ To install Reportable for Rails 2.x, add it to your applica…
config.gem 'reportable', :lib => 'saulabs/reportable'
-and generate the migration that creates Reportable's cache table:
+and generate the migration that create reportable's cache table:
- ./script/generate reportable_migration create_reportable_cache
+ ./script/generate reportable_migration
-Run the generated migration as the last step:
+If you want to use reportable's JavaScript graph output format, you also have …
- rake db:migrate
+ ./script/generate reportable_assets
### Rails 3.0
@@ -78,13 +78,13 @@ To install Reportable for Rails 3.0, add it to your applica…
gem 'reportable', :require => 'saulabs/reportable'
-and generate the migration that creates Reportable's cache table:
+and generate the migration that create reportable's cache table (beware that r…
- ./script/generate reportable_migration
+ rails generate reportable_migration
-Run the generated migration as the last step:
+If you want to use reportable's JavaScript graph output format, you also have …
- rake db:migrate
+ rails generate reportable_assets
Plans
diff --git a/generators/reportable_assets/NOTES b/generators/reportable_assets/…
@@ -0,0 +1,3 @@
+
+ ** Beware that Grafico depends on Prototype.js!
+ ** Also don't forget to include Grafico as well as Prototype.js in your layo…
diff --git a/generators/reportable_assets/reportable_assets_generator.rb b/gene…
@@ -0,0 +1,32 @@
+if Saulabs::Reportable::IS_RAILS3
+
+ class ReportableAssetsGenerator < Rails::Generators::Base
+
+ include Rails::Generators::Actions
+
+ def create_grafico_file
+ empty_directory('public/javascripts')
+ copy_file(
+ File.join(File.dirname(__FILE__), 'templates', 'grafico.min.js'),
+ 'public/javascripts/grafico.min.js'
+ )
+ readme(File.join(File.dirname(__FILE__), 'templates', 'NOTES'))
+ end
+
+ end
+
+else
+
+ class ReportableAssetsGenerator < Rails::Generator::Base
+
+ def manifest
+ record do |m|
+ m.directory('public/javascripts')
+ m.file('grafico.min.js', 'public/javascripts/grafico.min.js')
+ m.readme('NOTES')
+ end
+ end
+
+ end
+
+end
diff --git a/generators/reportable_assets/templates/NOTES b/generators/reportab…
@@ -0,0 +1,4 @@
+
+ ** Beware that Grafico depends on Prototype.js!
+ ** Also don't forget to include Grafico as well as Prototype.js in your layo…
+
diff --git a/generators/reportable_assets/templates/grafico.min.js b/generators…
@@ -0,0 +1,80 @@
+var Grafico={Version:"0.9",Base:{},BaseGraph:{},Normaliser:{},LineGraph:{},Are…
+Grafico.Base=Class.create({normaliseData:function(a){return $A(a).collect(func…
+Grafico.Normaliser=Class.create({initialize:function(a,b){this.options={start_…
+this.min;a=this.same_values?this.min-this.step*5:this.round(a,1);if(this.min>0…
+(Math.log(a)/Math.LN10).round()-1)}});
+Grafico.BaseGraph=Class.create(Grafico.Base,{initialize:function(a,b,c){this.o…
+draw_axis:true,datalabels:"",hover_color:"",watermark:false,watermark_location…
+if(this.hasBaseLine()){this.flat_data.push(this.base_line);this.flat_data=this…
+this.options.labels=$A($R(1,this.data_size));Object.extend(this.options,this.c…
+this.y_padding=this.y_padding_top+this.y_padding_bottom;this.graph_width=this.…
+this.top_value=this.value_labels.last();this.grid_start_offset=-1;this.paper=n…
+this.globalBlockSet=this.paper.set();this.globalAreaLineSet=this.paper.set();t…
+return this.normalized_base_line},getNormalizedRealData:function(){if(this.nor…
+c=a.clientY+document.body.scrollTop-document.documentElement.scrollTop}return{…
+b)}.bind(this))},paddingLeftOffset:function(){if(this.options.show_vertical_la…
+this.drawGrid();this.options.watermark&&this.drawWatermark();this.options.show…
+a.options.datalabels[b[0]],a.element,c)}.bind(a))},drawWatermark:function(){va…
+b.src=a.src||a},drawGrid:function(){var a=this.paper.path().attr({stroke:this.…
+for(d=0;d<c;d++){if(this.options.hide_empty_label_grid===true&&this.options.la…
+1&&g.splice(0,this.options.odd_horizontal_offset)}if(this.options.stacked_fill…
+"stroke-width":this.options.stroke_width+"px"});$A(g).each(function(k,m){var n…
+this.options.draw_hovers){this.drawHover(j,d,e,b);this.globalHoverSet.toFront(…
+2.5-1,b=this.options.height-this.y_padding_bottom,c=this.paper.path().attr({st…
+this.x_padding_left,this.options.height-this.y_padding_bottom-a)},drawAxis:fun…
+10)-0.5,parseInt(this.y_padding_top,10))},makeValueLabels:function(a){for(var …
+Object.extend(k,f||{});a.each(function(m){if(this.options.draw_axis&&(this.opt…
+"",c=0;c<this.value_labels.length;c++)this.value_labels[c]+=b;this.drawMarkers…
+7)*-1],a)},drawHover:function(a,b,c,d){var e=this,f=this.options.stacked_fill|…
+stroke:g},200):a.animate({stroke:g},200);l=e.getMousePos(l);h[0].attr({x:l.x-j…
+h)})},function(){f==="fill"?a.animate({fill:d,stroke:d},200):a.animate({stroke…
+c.attrs.y+d.height-this.options.height;e.translate(0,b*-1-1);f&&f.translate(0,…
+b.height/2+c-1).lineTo(a.attrs.x,a.attrs.y+b.height/2+c*2).lineTo(a.attrs.x+c,…
+if(typeof Array.prototype.max==="undefined")Array.prototype.max=function(){ret…
+Array.prototype.remove=function(a,b){b=this.slice((b||a)+1||this.length);this.…
+Raphael.el.lineTo=function(a,b){this._last={x:a,y:b};return this.attr({path:th…
+Raphael.el.andClose=function(){return this.attr({path:this.attrs.path+"z"})};
+Grafico.LineGraph=Class.create(Grafico.BaseGraph,{chartDefaults:function(){ret…
+"circle")this.drawGraphMarkers(a,c,d,e,g,h);else this.options.markers==="value…
+b,c,d,e,f,g){a+=this.options.odd_horizontal_offset>1?this.options.odd_horizont…
+6,j=this.step,i=this.options.stacked?this.graph_height/9:this.graph_height/3;b…
+fill:this.options.hover_text_color,opacity:1});f=e.getBBox();c=this.drawRoundR…
+Grafico.AreaGraph=Class.create(Grafico.LineGraph,{chartDefaults:function(){ret…
+else this.options.markers==="value"&&this.drawGraphValueMarkers(a,c,d,e,g,h,j)…
+Grafico.StackGraph=Class.create(Grafico.AreaGraph,{chartDefaults:function(){re…
+Grafico.StreamGraph=Class.create(Grafico.StackGraph,{chartDefaults:function(){…
+false?b[d][c]:(d+1)*b[d][c];a[c]=this.options.stream_line_smoothing==false?-su…
+for(var d=a.collect(function(g){return g[1]}),e=0;e<d[0].length;e++)d[d.length…
+bestMarkerPositions:function(){if(this.best_marker_positions==undefined)this.b…
+fill:this.options.hover_text_color,opacity:1});c=b.getBBox();c=this.drawRoundR…
+Grafico.BarGraph=Class.create(Grafico.BaseGraph,{chartDefaults:function(){retu…
+this.bar_padding},calculateStep:function(){this.data_size=this.data_size===1?2…
+e=h&&a===f.length-1?h:d<0?j:e;f=this.paper.rect(c-this.bar_width/2,b,this.bar_…
+c=this.options.labels;if(this.options.label_max_size)for(var d=0;d<c.length;d+…
+0.5,parseInt(b,10)+0.5);b-=this.graph_height;a.moveTo(this.x_padding_left-0.5,…
+c=this.y_label_count;d=this.options.horizontalbar?this.graph_width/this.y_labe…
+a.moveTo(parseInt(this.x_padding_left+this.graph_width,10)-0.5,this.y_padding_…
+stroke:e,opacity:0});b.attr({"font-size":this.options.font_size,fill:this.opti…
+Grafico.StackedBarGraph=Class.create(Grafico.BarGraph,{chartDefaults:function(…
+b[c+1][d];return a},calculateCoords:function(a){var b=this.x_padding_left+this…
+i){this.drawPlot(i,h,j[0],j[1],b,g,d,e,f)}.bind(this));if(this.options.datalab…
+b=this.paper.rect(c-this.bar_width/2,b,this.bar_width,d).attr(f);d<0?b.attr({h…
+1.5,d);a.attr({fill:e,"stroke-width":0,stroke:e,opacity:0});b.attr({"font-size…
+200)})}});
+Grafico.HorizontalBarGraph=Class.create(Grafico.BarGraph,{chartDefaults:functi…
+b[b.length-1];return a/b*this.graph_width},longestLabel:function(){return $A(t…
+g=this.x_padding_left+f-0.5,h=this.options.bargraph_lastcolor,j=this.options.b…
+bargraph2.attr({fill:k,"stroke-width":0,stroke:k});p.push(bargraph2,n);i<0&&ba…
+e,this.graph_width,this.bar_width).attr({fill:k,"stroke-width":0,stroke:k,opac…
+stroke:k},200);o.animate({opacity:0},200)})}e+=this.step}.bind(this))},drawFoc…
+c=this.options.labels;if(this.options.label_max_size)for(var d=0;d<c.length;d+…
+7)*-1])},drawMeanLine:function(a){var b=this.paper.path().attr(this.options.me…
+Grafico.SparkLine=Class.create(Grafico.Base,{initialize:function(a,b,c){this.e…
+this.options.acceptable_range?this.paper.rect(0,this.options.height-this.norma…
+1,0.75).hex},normalise:function(a){var b=this.data.min()<0?this.data.max()-thi…
+b)}this.drawLines(this.options.color,a);this.options.highlight&&this.showHighl…
+1]+(b/2).round();var d=this.options.highlight.color||"#f00";if(typeof this.opt…
+Grafico.SparkBar=Class.create(Grafico.SparkLine,{calculateStep:function(){retu…
+showHighlight:function(){}});
+Grafico.SparkArea=Class.create(Grafico.SparkLine,{drawLines:function(a,b){var …
+i);h.lineTo(j,this.options.height-i)}.bind(this));g.lineTo(j,this.options.heig…
diff --git a/generators/reportable_migration/reportable_migration_generator.rb …
@@ -5,7 +5,10 @@ if Saulabs::Reportable::IS_RAILS3
include Rails::Generators::Migration
def create_migration
- migration_template File.join(File.dirname(__FILE__), 'templates', 'migra…
+ migration_template(
+ File.join(File.dirname(__FILE__), 'templates', 'migration-rails3.rb'),
+ 'db/migrate/create_reportable_cache.rb'
+ )
end
def self.next_migration_number(dirname)
@@ -20,14 +23,18 @@ if Saulabs::Reportable::IS_RAILS3
else
- class ReportableMigrationGenerator < Rails::Generator::NamedBase
+ class ReportableMigrationGenerator < Rails::Generator::Base
def manifest
record do |m|
- m.migration_template 'migration.erb', 'db/migrate'
+ m.migration_template('migration.rb', 'db/migrate')
end
end
+ def file_name
+ 'create_reportable_cache'
+ end
+
end
end
diff --git a/generators/reportable_migration/templates/migration-rails3.erb b/g…
diff --git a/generators/reportable_migration/templates/migration.erb b/generato…
@@ -1,40 +0,0 @@
-class <%= class_name %> < ActiveRecord::Migration
-
- def self.up
- create_table :reportable_cache, :force => true do |t|
- t.string :model_name, :null => false
- t.string :report_name, :null => false
- t.string :grouping, :null => false
- t.string :aggregation, :null => false
- t.string :conditions, :null => false
- t.float :value, :null => false, :default => 0
- t.datetime :reporting_period, :null => false
-
- t.timestamps
- end
-
- add_index :reportable_cache, [
- :model_name,
- :report_name,
- :grouping,
- :aggregation,
- :conditions
- ], :name => :name_model_grouping_agregation
- add_index :reportable_cache, [
- :model_name,
- :report_name,
- :grouping,
- :aggregation,
- :conditions,
- :reporting_period
- ], :unique => true, :name => :name_model_grouping_aggregation_period
- end
-
- def self.down
- remove_index :reportable_cache, :name => :name_model_grouping_agregation
- remove_index :reportable_cache, :name => :name_model_grouping_aggregation_…
-
- drop_table :reportable_cache
- end
-
-end
diff --git a/generators/reportable_migration/templates/migration-rails3.rb b/ge…
diff --git a/lib/saulabs/reportable/railtie.rb b/lib/saulabs/reportable/railtie…
@@ -7,12 +7,19 @@ module Saulabs
class Railtie < Rails::Railtie
+ GEM_ROOT = File.join(File.dirname(__FILE__), '..', '..', '..')
+
initializer 'saulabs.reportable.initialization' do
- require File.join(File.dirname(__FILE__), '..', '..', '..', 'rails', '…
+ require File.join(GEM_ROOT, 'rails', 'init')
end
generators do
- require File.join(File.dirname(__FILE__), '..', '..', '..', 'generator…
+ require File.join(GEM_ROOT, 'generators', 'reportable_migration', 'rep…
+ require File.join(GEM_ROOT, 'generators', 'reportable_assets', 'report…
+ end
+
+ rake_tasks do
+ load File.join(GEM_ROOT, 'tasks', 'reportable_tasks.rake')
end
end
diff --git a/reportable.gemspec b/reportable.gemspec
@@ -6,7 +6,7 @@ pkg_files = [
'Rakefile',
'MIT-LICENSE'
]
-pkg_files += Dir['generators/**/*.{rb,erb}']
+pkg_files += Dir['generators/**/*']
pkg_files += Dir['lib/**/*.rb']
pkg_files += Dir['rails/**/*.rb']
pkg_files += Dir['spec/**/*.{rb,yml,opts}']
You are viewing proxied material from jay.scot. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.