bubbler 0.0.1

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.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MGY2NjEyN2Q5N2FjZDUyNDkzMjZkODU2MTFmYThlNmJmNTIxZTE4MA==
5
+ data.tar.gz: !binary |-
6
+ M2QyZmEyMjhkZjZlYTY3Yzk0MDBiNWY3OWJmYjRkMWZiZDE4Nzk5Nw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MzdmMTY4MTZjOGUwMGFmMTljMjNmNzQwOTljMjE2ZGY1ZmY1YmY1Y2NkNmNh
10
+ ODZhYzdkYWJiZDMxMzUxOTFkNTY1Zjg5NDIyMmM5ODk1ZTA4N2JlNjNjMGMw
11
+ ZGUzYzQyNDBjMTdhOTIzZGI3OWU5ZTZiZWI0MWI3MGQ0NjY3Yjk=
12
+ data.tar.gz: !binary |-
13
+ ZTg3YjFmYzI2ZGQ2NGFhNDhjYmQ2MWI2MTU5NTA2YjY3ZGQ3YzFlMzcxZTlk
14
+ ZWEyNGQ1NWNlMDJlMzc2ZWM0Y2JkNmRlYTNhZmE5NjVmODc4YmY1ZmZmMDM0
15
+ YjkzY2JkMTYxNWU1YWRjNTQ3ZGMyODIxN2ZkZDA5NzFjZWI4YWE=
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bubbler.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Matias Keveri
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Bubbler
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'bubbler'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install bubbler
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env ruby
2
+ require "bubbler"
3
+ require "bubbler/default_template"
4
+ require "bubbler/example_config"
5
+ require "json"
6
+ require "slop"
7
+
8
+ opts = Slop.parse(help: true) do
9
+ banner "Creates bubble chart of file line counts.\nUsage: bubbler [options]"
10
+ on :c, :config=, "Config file path (default: ./config.json)"
11
+ on :f, :format=, "Output format (default is file). Choices: html, json"
12
+ on :e, :examples=, "Generates example files: config.json, default.mustache", argument: :optional
13
+ end
14
+
15
+
16
+ def arguments config_path
17
+ config = JSON.load( IO.read(config_path) )
18
+ template = IO.read(config["template"]) if File.exists?(config["template"])
19
+ template ||= "default"
20
+ { config: config, template: template }
21
+ end
22
+
23
+ def create_data config_path, opts
24
+ args = arguments(config_path)
25
+ case opts[:format]
26
+ when "json"
27
+ STDOUT.write Bubbler.json(args)
28
+ when "html"
29
+ STDOUT.write Bubbler.html(args)
30
+ else
31
+ Bubbler.create_html_file(args)
32
+ puts "index.html file created into current directory."
33
+ end
34
+ end
35
+
36
+ def create_examples
37
+ File.write("example_config.json", EXAMPLE_CONFIG)
38
+ File.write("default_template.mustache", DEFAULT_TEMPLATE)
39
+ end
40
+
41
+ if opts.help?
42
+ puts opts
43
+ elsif opts.examples?
44
+ create_examples
45
+ puts "Example files created into current directory."
46
+ else
47
+ config_path = opts[:config].nil? ? "config.json" : opts[:config]
48
+ if !File.exists?(config_path)
49
+ puts "Invalid config file path!"
50
+ else
51
+ create_data(config_path, opts)
52
+ end
53
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bubbler/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bubbler"
8
+ spec.version = Bubbler::VERSION
9
+ spec.authors = ["Matias Keveri"]
10
+ spec.email = ["matias@keveri.fi"]
11
+ spec.description = %q{Creates HTML page with bubble charts of file sizes.
12
+ Can also output raw html or json data.}
13
+ spec.summary = %q{Creates bubble charts.}
14
+ spec.homepage = "https://rubygems.org/gems/bubbler"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files`.split($/)
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rake", "~> 10.1"
24
+ spec.add_development_dependency "json", "~> 1.8"
25
+ spec.add_development_dependency "slop", "~> 3.5"
26
+ spec.add_development_dependency "mustache", "~> 0.99"
27
+ end
@@ -0,0 +1,28 @@
1
+ require "bubbler/version"
2
+ require "bubbler/bubble_data_collector"
3
+ require "bubbler/page"
4
+
5
+ module Bubbler
6
+
7
+ def self.create_html_file args
8
+ File.write("index.html", html(args))
9
+ end
10
+
11
+ def self.html args
12
+ graphs = graphs_from_config(args[:config])
13
+ Page.html(graphs: graphs, file: "index.html", template: args[:template])
14
+ end
15
+
16
+ def self.json args
17
+ graphs_from_config(args[:config]).to_json
18
+ end
19
+
20
+ private
21
+
22
+ def self.graphs_from_config config
23
+ config["graphs"].map do |g|
24
+ BubbleDataCollector.new_from_json(g, config["app_folder"]).create_graph
25
+ end
26
+ end
27
+
28
+ end
@@ -0,0 +1,17 @@
1
+ class Bubble
2
+
3
+ def initialize args
4
+ @name = args[:name]
5
+ @path = args[:path]
6
+ @line_count = args[:line_count]
7
+ end
8
+
9
+ def to_json options={}
10
+ self.as_d3_hash.to_json
11
+ end
12
+
13
+ def as_d3_hash
14
+ { name: @name, path: @path, value: @line_count }
15
+ end
16
+
17
+ end
@@ -0,0 +1,41 @@
1
+ require_relative "bubble_graph"
2
+
3
+ class BubbleDataCollector
4
+
5
+ def initialize args
6
+ @group = args[:group]
7
+ @path = args[:path]
8
+ @match = args[:match]
9
+ @recursive = args.fetch(:recursive, false)
10
+ end
11
+
12
+ def self.new_from_json json, base_path
13
+ base_path << '/' if base_path[-1] != '/'
14
+ new(group: json["group"], path: base_path + json["path"],
15
+ match: json["match"], recursive: json["recursive"])
16
+ end
17
+
18
+ def create_graph
19
+ files = collect_files(@path, @match, @recursive)
20
+ bubbles = create_bubbles_from_files(files, @path)
21
+ BubbleGraph.new(name: @group, data: bubbles)
22
+ end
23
+
24
+ private
25
+
26
+ def create_bubbles_from_files files, path
27
+ files.map do |f|
28
+ lc = count_lines(path + f)
29
+ Bubble.new(name: File.basename(f), path: f, line_count: lc)
30
+ end
31
+ end
32
+
33
+ def collect_files path, match, recursive
34
+ finder = recursive ? "**/#{match}" : match
35
+ Dir.chdir(path) { Dir[finder] }
36
+ end
37
+
38
+ def count_lines file
39
+ %x{sed -n '=' #{file} | wc -l}.to_i
40
+ end
41
+ end
@@ -0,0 +1,19 @@
1
+ require_relative "bubble"
2
+
3
+ class BubbleGraph
4
+ attr_reader :name, :data
5
+
6
+ def initialize args
7
+ @name = args[:name]
8
+ @data = args[:data]
9
+ end
10
+
11
+ def to_json options={}
12
+ self.as_d3_hash.to_json
13
+ end
14
+
15
+ def as_d3_hash
16
+ { children: @data }
17
+ end
18
+
19
+ end
@@ -0,0 +1,76 @@
1
+ DEFAULT_TEMPLATE = %q(
2
+ <!DOCTYPE html>
3
+ <meta charset="utf-8">
4
+
5
+ <style>
6
+ text {
7
+ font: 10px monospace;
8
+ }
9
+ h1 {
10
+ color: white;
11
+ font: 3em monospace;
12
+ text-align: center;
13
+ }
14
+ body {
15
+ background-color: #333;
16
+ }
17
+ </style>
18
+
19
+ <body>
20
+ {{#names}}
21
+ <div id="{{id}}"><h1>{{text}}</h1></div>
22
+ {{/names}}
23
+ </body>
24
+
25
+ <script>
26
+ {{#graphs}}
27
+ var {{name}} = {{{json}}}
28
+ {{/graphs}}
29
+ </script>
30
+
31
+ <script src="http://d3js.org/d3.v3.min.js"></script>
32
+
33
+ <script>
34
+ function create_bubble(graph_id, graph_data) {
35
+ var diameter = 960,
36
+ color = d3.scale.category20c();
37
+
38
+ var bubble = d3.layout.pack()
39
+ .sort(null)
40
+ .size([diameter, diameter])
41
+ .padding(1.5);
42
+
43
+ var svg = d3.select(graph_id).append("svg")
44
+ .attr("width", diameter)
45
+ .attr("height", diameter)
46
+ .attr("class", "bubble");
47
+
48
+ var node = svg.selectAll(".node")
49
+ .data(bubble.nodes(graph_data)
50
+ .filter(function(d) { return !d.children; }))
51
+ .enter().append("g")
52
+ .attr("class", "node")
53
+ .attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; });
54
+
55
+ node.append("title")
56
+ .text(function(d) { return d.path + ": " + d.value + " lines"; });
57
+
58
+ node.append("circle")
59
+ .attr("r", function(d) { return d.r; })
60
+ .style("fill", function(d) { return color(d.name); });
61
+
62
+ node.append("text")
63
+ .attr("dy", ".3em")
64
+ .style("text-anchor", "middle")
65
+ .text(function(d) { return d.name.substring(0, d.r / 3); });
66
+
67
+ d3.select(self.frameElement).style("height", diameter + "px");
68
+ }
69
+ </script>
70
+
71
+ <script>
72
+ {{#names}}
73
+ create_bubble("#{{id}}", {{id}});
74
+ {{/names}}
75
+ </script>
76
+ )
@@ -0,0 +1,24 @@
1
+ EXAMPLE_CONFIG = %q(
2
+ {
3
+ "app_folder": "/Users/matiaskeveri/Dev/Ruby/Rails/pomolle/",
4
+ "template": "default",
5
+ "graphs": [
6
+ {
7
+ "group": "models",
8
+ "path": "app/models/",
9
+ "match": "*.rb",
10
+ "recursive": true
11
+ },
12
+ {
13
+ "group": "controllers",
14
+ "path": "app/controllers/",
15
+ "match": "*.rb"
16
+ },
17
+ {
18
+ "group": "helpers",
19
+ "path": "app/helpers/",
20
+ "match": "*.rb"
21
+ }
22
+ ]
23
+ }
24
+ )
@@ -0,0 +1,36 @@
1
+ require "mustache"
2
+ require_relative "default_template"
3
+
4
+ class Page < Mustache
5
+ attr_reader :names, :graphs
6
+
7
+ def initialize args
8
+ @names = graph_names(args[:graphs])
9
+ @graphs = graph_data(args[:graphs])
10
+ end
11
+
12
+ def self.html args
13
+ page = new(args)
14
+ page.template = find_template(args.fetch(:template, "default"))
15
+ page.render
16
+ end
17
+
18
+ private
19
+
20
+ def graph_names graphs
21
+ graphs.map { |g| { text: g.name.upcase, id: g.name } }
22
+ end
23
+
24
+ def graph_data graphs
25
+ graphs.map { |g| { name: g.name, json: g.to_json } }
26
+ end
27
+
28
+ def self.find_template template
29
+ template == "default" ? default_template : template
30
+ end
31
+
32
+ def self.default_template
33
+ DEFAULT_TEMPLATE
34
+ end
35
+
36
+ end
@@ -0,0 +1,3 @@
1
+ module Bubbler
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bubbler
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Matias Keveri
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.1'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: slop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '3.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '3.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mustache
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '0.99'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '0.99'
83
+ description: ! "Creates HTML page with bubble charts of file sizes.\n Can also output
84
+ raw html or json data."
85
+ email:
86
+ - matias@keveri.fi
87
+ executables:
88
+ - bubbler
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - .gitignore
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/bubbler
98
+ - bubbler.gemspec
99
+ - lib/bubbler.rb
100
+ - lib/bubbler/bubble.rb
101
+ - lib/bubbler/bubble_data_collector.rb
102
+ - lib/bubbler/bubble_graph.rb
103
+ - lib/bubbler/default_template.rb
104
+ - lib/bubbler/example_config.rb
105
+ - lib/bubbler/page.rb
106
+ - lib/bubbler/version.rb
107
+ homepage: https://rubygems.org/gems/bubbler
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ! '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.2.2
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Creates bubble charts.
131
+ test_files: []
132
+ has_rdoc: