mountain-goat 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/Gemfile +3 -0
  2. data/Gemfile.lock +31 -0
  3. data/History.md +4 -0
  4. data/LICENSE +20 -0
  5. data/POST_INSTALL +14 -0
  6. data/README.md +128 -0
  7. data/Rakefile +24 -0
  8. data/init.rb +4 -0
  9. data/install.rb +53 -0
  10. data/lib/mountain_goat/controllers/mountain_goat/mountain_goat_controller.rb +6 -0
  11. data/lib/mountain_goat/controllers/mountain_goat/mountain_goat_converts_controller.rb +107 -0
  12. data/lib/mountain_goat/controllers/mountain_goat/mountain_goat_metric_variants_controller.rb +80 -0
  13. data/lib/mountain_goat/controllers/mountain_goat/mountain_goat_metrics_controller.rb +108 -0
  14. data/lib/mountain_goat/controllers/mountain_goat/mountain_goat_rallies_controller.rb +3 -0
  15. data/lib/mountain_goat/metric_tracking.rb +241 -0
  16. data/lib/mountain_goat/models/ci_meta.rb +9 -0
  17. data/lib/mountain_goat/models/convert.rb +70 -0
  18. data/lib/mountain_goat/models/convert_meta_type.rb +19 -0
  19. data/lib/mountain_goat/models/cs_meta.rb +9 -0
  20. data/lib/mountain_goat/models/metric.rb +10 -0
  21. data/lib/mountain_goat/models/metric_variant.rb +22 -0
  22. data/lib/mountain_goat/models/rally.rb +32 -0
  23. data/lib/mountain_goat/switch_variant.rb +32 -0
  24. data/lib/mountain_goat/version.rb +3 -0
  25. data/lib/mountain_goat/views/mountain_goat/layouts/mountain_goat.html.erb +53 -0
  26. data/lib/mountain_goat/views/mountain_goat/mountain_goat_converts/_convert_form.html.erb +26 -0
  27. data/lib/mountain_goat/views/mountain_goat/mountain_goat_converts/_convert_meta_type_form.html.erb +27 -0
  28. data/lib/mountain_goat/views/mountain_goat/mountain_goat_converts/edit.html.erb +13 -0
  29. data/lib/mountain_goat/views/mountain_goat/mountain_goat_converts/index.html.erb +33 -0
  30. data/lib/mountain_goat/views/mountain_goat/mountain_goat_converts/new.html.erb +13 -0
  31. data/lib/mountain_goat/views/mountain_goat/mountain_goat_converts/show.html.erb +59 -0
  32. data/lib/mountain_goat/views/mountain_goat/mountain_goat_metric_variants/_metric_variant_form.html.erb +27 -0
  33. data/lib/mountain_goat/views/mountain_goat/mountain_goat_metric_variants/edit.html.erb +13 -0
  34. data/lib/mountain_goat/views/mountain_goat/mountain_goat_metric_variants/index.html.erb +35 -0
  35. data/lib/mountain_goat/views/mountain_goat/mountain_goat_metric_variants/new.html.erb +15 -0
  36. data/lib/mountain_goat/views/mountain_goat/mountain_goat_metric_variants/show.html.erb +14 -0
  37. data/lib/mountain_goat/views/mountain_goat/mountain_goat_metrics/_metric_form.html.erb +26 -0
  38. data/lib/mountain_goat/views/mountain_goat/mountain_goat_metrics/edit.html.erb +13 -0
  39. data/lib/mountain_goat/views/mountain_goat/mountain_goat_metrics/index.html.erb +29 -0
  40. data/lib/mountain_goat/views/mountain_goat/mountain_goat_metrics/new.html.erb +14 -0
  41. data/lib/mountain_goat/views/mountain_goat/mountain_goat_metrics/show.html.erb +59 -0
  42. data/lib/mountain_goat.rb +19 -0
  43. data/migrations/20090716093747_create_metric_tracking_tables.rb +85 -0
  44. data/mountain-goat.gemspec +26 -0
  45. metadata +141 -0
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :gemcutter
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,31 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mountain-goat (0.0.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.1.2)
10
+ mocha (0.9.10)
11
+ rake
12
+ rack (1.2.1)
13
+ rack-test (0.5.6)
14
+ rack (>= 1.0)
15
+ rake (0.8.7)
16
+ rspec (2.2.0)
17
+ rspec-core (~> 2.2)
18
+ rspec-expectations (~> 2.2)
19
+ rspec-mocks (~> 2.2)
20
+ rspec-core (2.2.1)
21
+ rspec-expectations (2.2.0)
22
+ diff-lcs (~> 1.1.2)
23
+ rspec-mocks (2.2.0)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ mountain-goat!
30
+ rack-test (>= 0.5.6)
31
+ rspec (~> 2.2.0)
data/History.md ADDED
@@ -0,0 +1,4 @@
1
+ 2011-7-6
2
+ ==================
3
+ * Initial commit
4
+ * Added History.md
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 hayesgm
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/POST_INSTALL ADDED
@@ -0,0 +1,14 @@
1
+ ******************************************************************
2
+
3
+ Install wkhtmltopdf:
4
+
5
+ 1. Install by hand (recomended):
6
+
7
+ https://github.com/jdpace/PDFKit/wiki/Installing-WKHTMLTOPDF
8
+
9
+ 2. Try using the wkhtmltopdf-binary gem (mac + linux i386)
10
+
11
+ gem install wkhtmltopdf-binary
12
+
13
+
14
+ ******************************************************************
data/README.md ADDED
@@ -0,0 +1,128 @@
1
+ # PDFKit
2
+
3
+ Create PDFs using plain old HTML+CSS. Uses [wkhtmltopdf](http://github.com/antialize/wkhtmltopdf) on the backend which renders HTML using Webkit.
4
+
5
+ ## Install
6
+
7
+ ### PDFKit
8
+
9
+ gem install pdfkit
10
+
11
+ ### wkhtmltopdf
12
+
13
+ 1. Install by hand (recomended):
14
+
15
+ https://github.com/jdpace/PDFKit/wiki/Installing-WKHTMLTOPDF
16
+
17
+ 2. Try using the wkhtmltopdf-binary gem (mac + linux i386)
18
+
19
+ gem install wkhtmltopdf-binary
20
+
21
+ *Note:* The automated installer has been removed.
22
+
23
+ ## Usage
24
+
25
+ # PDFKit.new takes the HTML and any options for wkhtmltopdf
26
+ # run `wkhtmltopdf --extended-help` for a full list of options
27
+ kit = PDFKit.new(html, :page_size => 'Letter')
28
+ kit.stylesheets << '/path/to/css/file'
29
+
30
+ # Git an inline PDF
31
+ pdf = kit.to_pdf
32
+
33
+ # Save the PDF to a file
34
+ file = kit.to_file('/path/to/save/pdf')
35
+
36
+ # PDFKit.new can optionally accept a URL or a File.
37
+ # Stylesheets can not be added when source is provided as a URL of File.
38
+ kit = PDFKit.new('http://google.com')
39
+ kit = PDFKit.new(File.new('/path/to/html'))
40
+
41
+ # Add any kind of option through meta tags
42
+ PDFKit.new('<html><head><meta name="pdfkit-page_size" content="Letter")
43
+
44
+ ## Configuration
45
+
46
+ If you're on Windows or you installed wkhtmltopdf by hand to a location other than /usr/local/bin you will need to tell PDFKit where the binary is. You can configure PDFKit like so:
47
+
48
+ # config/initializers/pdfkit.rb
49
+ PDFKit.configure do |config|
50
+ config.wkhtmltopdf = '/path/to/wkhtmltopdf'
51
+ config.default_options = {
52
+ :page_size => 'Legal',
53
+ :print_media_type => true
54
+ }
55
+ end
56
+
57
+ ## Middleware
58
+
59
+ PDFKit comes with a middleware that allows users to get a PDF view of any page on your site by appending .pdf to the URL.
60
+
61
+ ### Middleware Setup
62
+
63
+ **Non-Rails Rack apps**
64
+
65
+ # in config.ru
66
+ require 'pdfkit'
67
+ use PDFKit::Middleware
68
+
69
+ **Rails apps**
70
+
71
+ # in application.rb(Rails3) or environment.rb(Rails2)
72
+ require 'pdfkit'
73
+ config.middleware.use PDFKit::Middleware
74
+
75
+ **With PDFKit options**
76
+
77
+ # options will be passed to PDFKit.new
78
+ config.middleware.use PDFKit::Middleware, :print_media_type => true
79
+
80
+ **With conditions to limit routes that can be generated in pdf**
81
+
82
+ # conditions can be regexes (either one or an array)
83
+ config.middleware.use PDFKit::Middleware, {}, :only => %r[^/public]
84
+ config.middleware.use PDFKit::Middleware, {}, :only => [%r[^/invoice], %r[^/public]]
85
+
86
+ # conditions can be strings (either one or an array)
87
+ config.middleware.use PDFKit::Middleware, {}, :only => '/public'
88
+ config.middleware.use PDFKit::Middleware, {}, :only => ['/invoice', '/public']
89
+
90
+ ## Troubleshooting
91
+
92
+ * **Single thread issue:** In development environments it is common to run a
93
+ single server process. This can cause issues when rendering your pdf
94
+ requires wkhtmltopdf to hit your server again (for images, js, css).
95
+ This is because the resource requests will get blocked by the initial
96
+ request and the initial request will be waiting on the resource
97
+ requests causing a deadlock.
98
+
99
+ This is usually not an issue in a production environment. To get
100
+ around this issue you may want to run a server with multiple workers
101
+ like Passenger or try to embed your resources within your HTML to
102
+ avoid extra HTTP requests.
103
+
104
+ * **Resources aren't included in the PDF:** Images, CSS, or Javascript
105
+ does not seem to be downloading correctly in the PDF. This is due
106
+ to the fact that wkhtmltopdf does not know where to find those files.
107
+ Make sure you are using absolute paths (start with forward slash) to
108
+ your resources. If you are using PDFKit to generate pdfs from a raw
109
+ HTML source make sure you use complete paths (either file paths or
110
+ urls including the domain).
111
+
112
+ ## TODO
113
+ - add amd64 support in --install-wkhtmltopdf
114
+
115
+ ## Note on Patches/Pull Requests
116
+
117
+ * Fork the project.
118
+ * Setup your development environment with: gem install bundler; bundle install
119
+ * Make your feature addition or bug fix.
120
+ * Add tests for it. This is important so I don't break it in a
121
+ future version unintentionally.
122
+ * Commit, do not mess with rakefile, version, or history.
123
+ (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)
124
+ * Send me a pull request. Bonus points for topic branches.
125
+
126
+ ## Copyright
127
+
128
+ Copyright (c) 2010 Jared Pace. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'bundler'
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ require 'rspec/core/rake_task'
7
+ RSpec::Core::RakeTask.new(:spec) do |spec|
8
+ end
9
+
10
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
11
+ spec.rcov = true
12
+ end
13
+
14
+ task :default => :spec
15
+
16
+ require 'rake/rdoctask'
17
+ Rake::RDocTask.new do |rdoc|
18
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
19
+
20
+ rdoc.rdoc_dir = 'rdoc'
21
+ rdoc.title = "Mountain Goat #{version}"
22
+ rdoc.rdoc_files.include('README*')
23
+ rdoc.rdoc_files.include('lib/**/*.rb')
24
+ end
data/init.rb ADDED
@@ -0,0 +1,4 @@
1
+
2
+ require File.join([File.dirname(__FILE__), 'lib/mountain_goat'])
3
+
4
+ #ActionView::Helpers
data/install.rb ADDED
@@ -0,0 +1,53 @@
1
+ # Install hook code here
2
+
3
+ require 'ftools'
4
+
5
+ # keep everything inside fo this scope
6
+ class InstallMetricTrackingTables
7
+
8
+ def initialize
9
+ show_banner
10
+ check_system_cosistency
11
+ copy_migration_files
12
+ end
13
+
14
+ def here
15
+ File.dirname(__FILE__)
16
+ end
17
+
18
+ def sources
19
+ Dir.glob(File.join([here, 'migrations', '*.*']))
20
+ end
21
+
22
+ def target
23
+ File.join([here, '..', '..', '..', 'db', 'migrate'])
24
+ end
25
+
26
+ def validate_file_existance(file)
27
+ abort "File not found: #{target}" unless File.exist? file
28
+ end
29
+
30
+ def show_banner
31
+ puts '
32
+ ** Copying migrations to your application
33
+ '
34
+ end
35
+
36
+ def check_system_cosistency
37
+ validate_file_existance(target)
38
+ sources.each { |file| validate_file_existance(file) }
39
+ end
40
+
41
+ def copy_migration_files
42
+ sources.each do |file|
43
+ File.copy(file, target)
44
+ puts "
45
+ Source : #{file}
46
+ Target : #{target}
47
+ "
48
+ end
49
+ end
50
+
51
+ end
52
+
53
+ InstallMetricTrackingTables.new
@@ -0,0 +1,6 @@
1
+ class MountainGoatController < ActionController::Base
2
+
3
+ self.view_paths.push File.join([File.dirname(__FILE__), '../../views/mountain_goat/'])
4
+
5
+ layout 'mountain_goat'
6
+ end
@@ -0,0 +1,107 @@
1
+ class MountainGoatConvertsController < MountainGoatController
2
+
3
+ # GET /converts
4
+ # GET /converts.xml
5
+ def index
6
+ @converts = Convert.all
7
+
8
+ respond_to do |format|
9
+ format.html # index.html.erb
10
+ format.xml { render :xml => @converts }
11
+ end
12
+ end
13
+
14
+ # GET /converts/1
15
+ # GET /converts/1.xml
16
+ def show
17
+ @convert = Convert.find(params[:id])
18
+
19
+ @results_per_day = []
20
+ created_at = @convert.created_at
21
+ running_date = Time.utc( created_at.year, created_at.month, created_at.day )
22
+
23
+ while running_date < Time.zone.now
24
+ @results_per_day.push({ :date => running_date.to_i * 1000, :val => @convert.rallies.find( :all, :conditions => { :created_at => running_date..(running_date + 60 * 60 * 24) } ).count })
25
+ running_date += 60 * 60 * 24
26
+ end
27
+
28
+ @results_by_cmt = {}
29
+ @results_by_cmt_titles = {}
30
+
31
+ @convert.convert_meta_types.each do |cmt|
32
+ @results_by_cmt[cmt.id] = []
33
+ @results_by_cmt_titles[cmt.id] = {}
34
+ i = 0
35
+ cmt.meta.all(:select => "data, count(*) as count", :group => "data").each do |meta|
36
+ next if meta.data.nil?
37
+ if cmt.meta_type == 'cs_meta'
38
+ @results_by_cmt[cmt.id].push( { :name => i, :val => meta.count } )
39
+ @results_by_cmt_titles[cmt.id].merge!({ i => meta.data })
40
+ else
41
+ @results_by_cmt[cmt.id].push( { :name => meta.data, :val => meta.count } )
42
+ end
43
+
44
+ i += 1
45
+ end
46
+ end
47
+
48
+ respond_to do |format|
49
+ format.html # show.html.erb
50
+ format.xml { render :xml => @convert }
51
+ end
52
+ end
53
+
54
+ # GET /converts/new
55
+ # GET /converts/new.xml
56
+ def new
57
+ @convert = Convert.new
58
+
59
+ respond_to do |format|
60
+ format.html # new.html.erb
61
+ format.xml { render :xml => @convert }
62
+ end
63
+ end
64
+
65
+ # GET /converts/1/edit
66
+ def edit
67
+ @convert = Convert.find(params[:id])
68
+ end
69
+
70
+ # POST /converts
71
+ # POST /converts.xml
72
+ def create
73
+ @convert = Convert.new(params[:convert])
74
+
75
+ if @convert.save
76
+ flash[:notice] = 'Convert was successfully created.'
77
+ redirect_to mountain_goat_convert_url :id => @convert.id
78
+ else
79
+ render :action => "new"
80
+ end
81
+ end
82
+
83
+ # PUT /converts/1
84
+ # PUT /converts/1.xml
85
+ def update
86
+ @convert = Convert.find(params[:id])
87
+
88
+ if @convert.update_attributes(params[:convert])
89
+ flash[:notice] = 'Convert was successfully updated.'
90
+ redirect_to mountain_goat_convert_url :id => @convert.id
91
+ else
92
+ render :action => "edit"
93
+ end
94
+ end
95
+
96
+ # DELETE /converts/1
97
+ # DELETE /converts/1.xml
98
+ def destroy
99
+ @convert = Convert.find(params[:id])
100
+ @convert.destroy
101
+
102
+ respond_to do |format|
103
+ format.html { redirect_to mountain_goat_converts_url }
104
+ format.xml { head :ok }
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,80 @@
1
+ class MountainGoatMetricVariantsController < MountainGoatController
2
+
3
+ # GET /metric_variants
4
+ # GET /metric_variants.xml
5
+ def index
6
+ @metric_variants = MetricVariant.all
7
+
8
+ respond_to do |format|
9
+ format.html # index.html.erb
10
+ format.xml { render :xml => @metric_variants }
11
+ end
12
+ end
13
+
14
+ # GET /metric_variants/1
15
+ # GET /metric_variants/1.xml
16
+ def show
17
+ @metric_variant = MetricVariant.find(params[:id])
18
+
19
+ respond_to do |format|
20
+ format.html # show.html.erb
21
+ format.xml { render :xml => @metric_variant }
22
+ end
23
+ end
24
+
25
+ # GET /metric_variants/new
26
+ # GET /metric_variants/new.xml
27
+ def new
28
+ @metric = Metric.find( params[:mountain_goat_metric_id] )
29
+ @metric_variant = MetricVariant.new( :metric_id => @metric.id )
30
+
31
+ respond_to do |format|
32
+ format.html # new.html.erb
33
+ format.xml { render :xml => @metric_variant }
34
+ end
35
+ end
36
+
37
+ # GET /metric_variants/1/edit
38
+ def edit
39
+ @metric_variant = MetricVariant.find(params[:id])
40
+ end
41
+
42
+ # POST /metric_variants
43
+ # POST /metric_variants.xml
44
+ def create
45
+ @metric = Metric.find( params[:metric_variant][:metric_id] )
46
+ @metric_variant = MetricVariant.new(params[:metric_variant])
47
+
48
+ if @metric_variant.save
49
+ flash[:notice] = 'Metric variant was successfully created.'
50
+ redirect_to mountain_goat_metric_url :id => @metric_variant.metric.id
51
+ else
52
+ render :action => "new"
53
+ end
54
+ end
55
+
56
+ # PUT /metric_variants/1
57
+ # PUT /metric_variants/1.xml
58
+ def update
59
+ @metric_variant = MetricVariant.find(params[:id])
60
+
61
+ if @metric_variant.update_attributes(params[:metric_variant])
62
+ flash[:notice] = 'Metric variant was successfully updated.'
63
+ redirect_to mountain_goat_metric_url :id => @metric_variant.metric.id
64
+ else
65
+ render :action => "edit"
66
+ end
67
+ end
68
+
69
+ # DELETE /metric_variants/1
70
+ # DELETE /metric_variants/1.xml
71
+ def destroy
72
+ @metric_variant = MetricVariant.find(params[:id])
73
+ @metric_variant.destroy
74
+
75
+ respond_to do |format|
76
+ format.html { redirect_to mountain_goat_metric_variants_url }
77
+ format.xml { head :ok }
78
+ end
79
+ end
80
+ end