gempage 0.0.2 → 0.0.3

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Y2E5NjhkNjVlZTI4MzEwODI0NjkyZWRmNWU5NjU3OTU2ZmZiZDE2NA==
4
+ YjljZGI2YmFmYjg2ZmU3M2YxM2I3Y2E0MWI2MGM4MmY4YzA3MDI3MA==
5
5
  data.tar.gz: !binary |-
6
- ZjRkMmI0YjQ0MzBjNTA5YmYyM2Y4MTNmZDg0N2UzYzk0NTFhZGZmNA==
6
+ YjcxYTAyYThiMTI5MTRlZTM2MTI3NzY3YmNmNDI2YThjY2MzNTZkMQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OGMzMmVjODA5ZTZkNjAwYTQ5OTQ3ODVhODkxNjhjMDI2OGE1ZmY4M2Q4Y2Uz
10
- YTBkOTk3NDBmMzcwYzAwNTJhZjE1MDE3ZGYzOGQyOTYwYmI0ZGFiMDdmMTgz
11
- ZDJkMzg3YzFlNjFjNTcwZDFlMGU4Y2EyNWNhYjU3MDNhYWJiNTA=
9
+ ZTRhYTRhMTM1NzczYWM2ZTkxYjk5N2E1ZDBlMzk0ODU2OWMxOTBhYmVmYTg1
10
+ MTE2NWUyMzBlNDc3MjE5NjY1Y2RhZWU3NTgzYjA4OTFkZTAyNGRiZGQ3OTcz
11
+ ZjdjYTk0ZDk5YzBkODgzOWM0M2U0M2E3YTI5OGNhOTJlYzZlNzk=
12
12
  data.tar.gz: !binary |-
13
- ZGMyMjBiNjI1NWIyOTI2NmVlYjIwNjFiNDdjNWM5YzdlY2NhNTk0ZGEwNWQz
14
- NzYzNzAzNzY3ZjI2YTVhYjk4ZjI0MTUyZWY1NTU2ZmJlMzU2YzA1YmMxMjg1
15
- YWM1ODhkZWE3OWU5ZjY3YTIyYjM4Mjk2OGIxMzRiZjQwMzUzNmU=
13
+ MWU5MDJhMDc0MDNjMzY1MTA1NGY4MDY3NmEwYjlkNjYwMTljYWVjYzY0Y2Uy
14
+ MjY3NzEyYmViNzY5NzFkYWI5ZTUwMWUwY2VhOGRkMjMzMjE2NGU5MGM5NDZm
15
+ YTgxZWZiMmQzMDIzZTEzNDgxZjdiMTNhY2YxZjI4YTg5MDFkM2I=
@@ -9,3 +9,20 @@ v0.0.2, 2013-10-24
9
9
  get set as default. Adding color setting to public/application.css during the generating
10
10
  phase to avoid having to set overrides. Refactored default versus custom color scheme code
11
11
  in generate.rb.
12
+
13
+ v0.0.3, 2013-10-29
14
+ -------------------
15
+
16
+ * [REFACTORING] Refactored for performance, readability, testability. Removal of unnecessary
17
+ parameters, redundant method calls and another couple levels of unnecessary hash rewriting.
18
+ Separated Importer functionality into two classes, GemfileProcessor and RubyGemInfo. Moved
19
+ grouping of gems into view, possible temporary move, and set view to use hash as is from
20
+ JSON.parse instead of expecting symbols as keys.
21
+ * [BUGFIX] Performance fixes! Benchmark.measure { Gempage.generate } for 6 gem groups and
22
+ 21 gems is now is at `0.060000 0.010000 0.070000 ( 6.475024)` versus
23
+ `0.410000 0.100000 0.510000 ( 49.683921)` in version 0.0.2.
24
+ * [FEATURE] Added some very rudimentary tests for the gemfile processor and ruby gem info
25
+ snagging part.
26
+ * [FEATURE] Missing gem (most likely in the case of vendored gems) and issues with snagging
27
+ gem info from rubygems.org now log their errors within the gempage. This is a rough draft of
28
+ a more informative reporting system.
@@ -1,4 +1,5 @@
1
1
  // Colors from: http://www.colourlovers.com/business/trends/branding/7880/Papeterie_Haute-Ville_Logo
2
+ // These are the defaults
2
3
 
3
4
  $midnight-blue: #113F8C;
4
5
  $forest-green: #32742C;
@@ -22,5 +23,6 @@ $rose: #FCCCD2;
22
23
  $slate: #6A8491;
23
24
  $green: #7DCE84;
24
25
 
25
- // Colors from a bunch of places
26
+ // Colors for system notices and page layout
26
27
 
28
+ $error_color: $red;
@@ -7,3 +7,11 @@
7
7
  color: $color;
8
8
  }
9
9
  }
10
+
11
+ @mixin gem-color-override($color) {
12
+ border: 3px solid $color !important;
13
+ color: $color !important;
14
+ a {
15
+ color: $color !important;
16
+ }
17
+ }
@@ -1,3 +1,6 @@
1
+ @import 'global/mixins';
2
+ @import 'global/colors';
3
+
1
4
  body {
2
5
  font: normal 15px/1.5 Verdana, Geneva, sans-serif;
3
6
  }
@@ -53,28 +56,35 @@ a {
53
56
  a {
54
57
  color: #616161;
55
58
  }
59
+ h4 {
60
+ font: bold 15px Verdana;
61
+ line-height: 1.2;
62
+ padding: 10px 0 5px 10px;
63
+ margin: 0;
64
+ }
65
+ h3 {
66
+ font: bold 14px Verdana;
67
+ line-height: 1.2;
68
+ padding: 0 0 5px 10px;
69
+ margin: 0;
70
+ }
56
71
  }
57
-
58
- .documentation {
72
+ .icon {
59
73
  font-size: 30px;
60
74
  position: absolute;
61
75
  font-weight: bold;
76
+ }
77
+ .documentation {
62
78
  bottom: -28px;
63
79
  left: -18px;
64
80
  }
65
- .gem h4 {
66
- font: bold 15px Verdana;
67
- line-height: 1.2;
68
- padding: 10px 0 5px 10px;
69
- margin: 0;
70
- a {
71
- color: gray;
72
- }
73
- }
74
- .github {
75
- font-size: 30px;
76
- font-weight: bold;
77
- position: absolute;
81
+ .github, .error {
78
82
  bottom: -22px;
79
83
  right: -23px;
80
84
  }
85
+ .gem-color-error {
86
+ @include gem-color-override($error_color)
87
+ }
88
+ .error {
89
+ color: $error_color;
90
+ }
@@ -25,4 +25,5 @@ Gem::Specification.new do |s|
25
25
  s.add_development_dependency 'sass'
26
26
  s.add_development_dependency 'rake'
27
27
  s.add_development_dependency 'rspec'
28
+ s.add_development_dependency 'webmock'
28
29
  end
@@ -2,34 +2,42 @@ require "gempage/version"
2
2
 
3
3
  require 'erb'
4
4
  require 'fileutils'
5
+ require 'gempage/gemfile_processor'
6
+ require 'gempage/ruby_gem_info'
5
7
  require 'gempage/configuration'
6
- require 'gempage/import'
7
8
  Gempage.send :extend, Gempage::Configuration
8
9
 
9
10
  module Gempage
10
11
  class << self
11
12
 
12
13
  def generate(options = nil)
13
- format(grouped_result, options)
14
+ result ? format(options) : puts(output_message)
14
15
  end
15
16
 
16
17
  def result
17
18
  return @result if defined? @result
18
- Gempage::Import::Importer.new(gemfile_path).gem_list
19
+ @result = gem_listing ? merge_gem_and_info : false
19
20
  end
20
21
 
21
- def grouped_result
22
- return @grouped_result if defined? @grouped_result
23
- result.group_by{ |result| result[:category] }
22
+ def gem_listing
23
+ return @gem_listing if defined? @gem_listing
24
+ @gem_listing = Gempage::GemfileProcessor.new(gemfile_path).gem_list
24
25
  end
25
26
 
26
- def format(grouped_result, options)
27
- create_stylesheet('application', options)
28
- create_index(grouped_result)
29
- puts output_message(grouped_result, result)
27
+ def merge_gem_and_info
28
+ gem_listing.each_with_index do |listed_gem, index|
29
+ ruby_gem_json = Gempage::RubyGemInfo.new(listed_gem['name']).gem_json
30
+ gem_listing[index].merge!(ruby_gem_json)
31
+ end
32
+ end
33
+
34
+ def format(options)
35
+ create_index
36
+ create_stylesheet(options)
37
+ puts output_message
30
38
  end
31
39
 
32
- def create_index(result)
40
+ def create_index
33
41
  File.open(File.join(gempage_path, "index.html"), "w+") do |file|
34
42
  file.puts template('layout').result(binding)
35
43
  end
@@ -39,7 +47,7 @@ module Gempage
39
47
  ERB.new(File.read(File.join(File.dirname(__FILE__), '../views/', "#{name}.erb")))
40
48
  end
41
49
 
42
- def create_stylesheet(name, options)
50
+ def create_stylesheet(options)
43
51
  File.open(File.join(asset_gempage_path, "application.css"), "w+") do |file|
44
52
  file.puts File.readlines(File.join(File.dirname(__FILE__), "../public/application.css"))
45
53
  file.puts File.readlines(File.join(File.dirname(__FILE__), "../public/color-schemes/#{color_scheme_file(options)}.css"))
@@ -54,8 +62,13 @@ module Gempage
54
62
  File.exist?(File.join(File.dirname(__FILE__), "../public/color-schemes/#{file_name}.css"))
55
63
  end
56
64
 
57
- def output_message(grouped_result, result)
58
- "Gem list generated for #{grouped_result.length} gem groups and #{result.length} gems to #{gempage_path}."
65
+ def output_message
66
+ if result
67
+ category_count = result.group_by{ |result| result['category'] }.length
68
+ "Gem list generated for #{category_count} gem groups and #{result.length} gems to #{gempage_path}."
69
+ else
70
+ "There is no Gemfile to process, how odd..."
71
+ end
59
72
  end
60
73
 
61
74
  end
@@ -0,0 +1,58 @@
1
+ require 'fileutils'
2
+
3
+ module Gempage
4
+ class GemfileProcessor
5
+ attr_reader :gem_list
6
+
7
+ def initialize(gemfile_path)
8
+ @gemfile_path = gemfile_path
9
+ @gem_list = gem_list
10
+ end
11
+
12
+ def gem_list
13
+ process_gems(normalize_lines) if gemfile_lines
14
+ end
15
+
16
+ private
17
+
18
+ def gemfile_lines
19
+ return @gemfile_lines if defined? @gemfile_lines
20
+ @gemfile_lines = File.exists?(@gemfile_path) ? File.readlines(@gemfile_path) : false
21
+ end
22
+
23
+ def normalize_lines
24
+ # Strip white space, keep only lines starting with gem, group
25
+ # or end, normalize to single quotes, remove trailing comments
26
+ gemfile_lines.map { |x| x.strip.gsub(/"/,"'") }
27
+ .reject { |x| x.empty? || !x.match(/^(gem|group|end)/) }
28
+ .map { |x| x.gsub(/\s?#.*$/, '') }
29
+ end
30
+
31
+ # The heart of the system that parses through the Gemfile
32
+
33
+ def process_gems(data, group = 'all', gems = [])
34
+ data.each_with_index do |line, index|
35
+ if line.match(/^gem\s/)
36
+ gem_detail = gem_details(line, group)
37
+ gems << gem_detail if gem_detail
38
+ else
39
+ group = get_group(line)
40
+ return process_gems(data[(index + 1)..-1], group, gems) unless group == 'all'
41
+ end
42
+ end
43
+ gems
44
+ end
45
+
46
+ def get_group(line)
47
+ group = line.match(/^group\s+(.+)\sdo$/)
48
+ group ? group[1] : 'all'
49
+ end
50
+
51
+ def gem_details(line, group)
52
+ gem_pieces = line.match(/^gem\s'([\w|-]+)',?\s?(.*)/)
53
+ configuration = gem_pieces[2] && gem_pieces[2].strip.length != 0 ? gem_pieces[2] : nil
54
+ gem_pieces ? { 'name' => gem_pieces[1], 'category' => group, 'configuration' => configuration } : nil
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,58 @@
1
+ require 'json'
2
+
3
+ module Gempage
4
+ class RubyGemInfo
5
+
6
+ # The snagging gem details from RubyGems.org part of the system
7
+
8
+ attr_reader :gem_json
9
+
10
+ def initialize(gem_name)
11
+ @gem_name = gem_name
12
+ @gem_json = gem_json
13
+ end
14
+
15
+ def gem_json
16
+ process_uris(process_empty_strings(get_gem_json))
17
+ end
18
+
19
+ private
20
+
21
+ def get_gem_json
22
+ JSON.parse(response_body(rubygem_url))
23
+ end
24
+
25
+ def response_body(url)
26
+ begin
27
+ request = Net::HTTP.new URI(url).host
28
+ response = request.request_get URI(url).path
29
+ response.code.to_i == 200 ? response.body : rubygem_error(response.code.to_s)
30
+ rescue StandardError
31
+ rubygem_error
32
+ end
33
+ end
34
+
35
+ def rubygem_url
36
+ "https://rubygems.org/api/v1/gems/#{@gem_name}.json"
37
+ end
38
+
39
+ def rubygem_error(error_code = nil)
40
+ error_message = error_code ? error_code : "Issue with RubyGems"
41
+ '{ "error":"' + error_message + '" }'
42
+ end
43
+
44
+ def process_empty_strings(gem_json)
45
+ gem_json.each{ |key, value| gem_json[key] = nil if value.kind_of?(String) && value.strip.length == 0 }
46
+ end
47
+
48
+ def process_uris(gem_json)
49
+ gem_json['source_code_uri'] = get_source_code_uri(gem_json['source_code_uri'], gem_json['homepage_uri'])
50
+ gem_json
51
+ end
52
+
53
+ def get_source_code_uri(source_code_uri, homepage_uri)
54
+ !source_code_uri && homepage_uri && homepage_uri.match(/github\.com/) ? homepage_uri : source_code_uri
55
+ end
56
+
57
+ end
58
+ end
@@ -1,3 +1,3 @@
1
1
  module Gempage
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -49,25 +49,35 @@ a {
49
49
  color: #616161; }
50
50
  .gem a {
51
51
  color: #616161; }
52
+ .gem h4 {
53
+ font: bold 15px Verdana;
54
+ line-height: 1.2;
55
+ padding: 10px 0 5px 10px;
56
+ margin: 0; }
57
+ .gem h3 {
58
+ font: bold 14px Verdana;
59
+ line-height: 1.2;
60
+ padding: 0 0 5px 10px;
61
+ margin: 0; }
52
62
 
53
- .documentation {
63
+ .icon {
54
64
  font-size: 30px;
55
65
  position: absolute;
56
- font-weight: bold;
66
+ font-weight: bold; }
67
+
68
+ .documentation {
57
69
  bottom: -28px;
58
70
  left: -18px; }
59
71
 
60
- .gem h4 {
61
- font: bold 15px Verdana;
62
- line-height: 1.2;
63
- padding: 10px 0 5px 10px;
64
- margin: 0; }
65
- .gem h4 a {
66
- color: gray; }
67
-
68
- .github {
69
- font-size: 30px;
70
- font-weight: bold;
71
- position: absolute;
72
+ .github, .error {
72
73
  bottom: -22px;
73
74
  right: -23px; }
75
+
76
+ .gem-color-error {
77
+ border: 3px solid #e54028 !important;
78
+ color: #e54028 !important; }
79
+ .gem-color-error a {
80
+ color: #e54028 !important; }
81
+
82
+ .error {
83
+ color: #e54028; }
@@ -5,6 +5,7 @@ source 'https://rubygems.org'
5
5
  gem 'rails', '3.2.14'
6
6
 
7
7
  gem 'mysql2'
8
+ gem 'higgly'
8
9
  gem 'thin'
9
10
  gem 'resque'
10
11
  gem 'httparty'
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gempage::GemfileProcessor do
4
+ let (:processed_gemfile) {
5
+ [ {"name"=>"rails", "category"=>"all", "configuration"=>"'3.2.14'"},
6
+ {"name"=>"mysql2", "category"=>"all", "configuration"=>nil},
7
+ {"name"=>"higgly", "category"=>"all", "configuration"=>nil},
8
+ {"name"=>"thin", "category"=>"all", "configuration"=>nil},
9
+ {"name"=>"resque", "category"=>"all", "configuration"=>nil},
10
+ {"name"=>"httparty", "category"=>"all", "configuration"=>nil},
11
+ {"name"=>"json", "category"=>"all", "configuration"=>nil},
12
+ {"name"=>"sanitize", "category"=>"all", "configuration"=>nil},
13
+ {"name"=>"pg", "category"=>":production", "configuration"=>nil},
14
+ {"name"=>"turbo-sprockets-rails3", "category"=>":assets", "configuration"=>nil},
15
+ {"name"=>"uglifier", "category"=>":assets", "configuration"=>"'>= 1.0.3', :require => false"},
16
+ {"name"=>"sass-rails", "category"=>":assets", "configuration"=>" '~> 3.2.3'"},
17
+ {"name"=>"coffee-rails", "category"=>":assets", "configuration"=>"'~> 3.2.1'"},
18
+ {"name"=>"better_errors", "category"=>":development", "configuration"=>nil},
19
+ {"name"=>"binding_of_caller", "category"=>":development", "configuration"=>":require => false"},
20
+ {"name"=>"jazz_hands", "category"=>":development, :test", "configuration"=>nil},
21
+ {"name"=>"quiet_assets", "category"=>":development, :test", "configuration"=>nil},
22
+ {"name"=>"rspec-rails", "category"=>":test", "configuration"=>nil},
23
+ {"name"=>"rspec-mocks", "category"=>":test", "configuration"=>nil},
24
+ {"name"=>"email_spec", "category"=>":test", "configuration"=>nil},
25
+ {"name"=>"webmock", "category"=>":test", "configuration"=>nil}]
26
+ }
27
+
28
+ it 'should process a bunch of gems' do
29
+ gemfile_path = File.join(Gempage.root, '/spec/fixtures/Gemfile')
30
+ gem_listing = Gempage::GemfileProcessor.new(gemfile_path).gem_list
31
+ gem_listing.should eql(processed_gemfile)
32
+ end
33
+
34
+ it 'should return nil if there is no Gemfile' do
35
+ gemfile_path = File.join(Gempage.root, '/spec/fixtures/nonesuch_Gemfile')
36
+ gem_listing = Gempage::GemfileProcessor.new(gemfile_path).gem_list
37
+ gem_listing.should eql(nil)
38
+ end
39
+
40
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gempage::RubyGemInfo do
4
+ let (:orginal_json_no_empty_strings) {
5
+ { "name"=>"rails", "downloads"=>28773847, "version"=>"4.0.0",
6
+ "info"=>"Ruby on Rails is a full-stack web framework optimized for programmer happiness and sustainable productivity.",
7
+ "project_uri"=>"http://rubygems.org/gems/rails", "gem_uri"=>"http://rubygems.org/gems/rails-4.0.0.gem",
8
+ "homepage_uri"=>"http://www.rubyonrails.org", "wiki_uri"=>"http://wiki.rubyonrails.org",
9
+ "documentation_uri"=>"http://api.rubyonrails.org", "mailing_list_uri"=>"http://groups.google.com/group/rubyonrails-talk",
10
+ "source_code_uri"=>"http://github.com/rails/rails" }
11
+ }
12
+ let (:orginal_json_empty_strings) {
13
+ { "name"=>"httparty", "downloads"=>5888099, "version"=>"0.12.0",
14
+ "info"=>"Makes http fun! Also, makes consuming restful web services dead easy.",
15
+ "project_uri"=>"http://rubygems.org/gems/httparty", "gem_uri"=>"http://rubygems.org/gems/httparty-0.12.0.gem",
16
+ "homepage_uri"=>"http://jnunemaker.github.com/httparty", "wiki_uri"=>nil, "documentation_uri"=>nil,
17
+ "mailing_list_uri"=>nil, "source_code_uri"=>"http://github.com/jnunemaker/httparty" }
18
+ }
19
+ let (:rails_response_body) {
20
+ "{\"name\":\"rails\",\"downloads\":28773847,\"version\":\"4.0.0\",
21
+ \"info\":\"Ruby on Rails is a full-stack web framework optimized for programmer happiness and sustainable productivity.\",
22
+ \"project_uri\":\"http://rubygems.org/gems/rails\",\"gem_uri\":\"http://rubygems.org/gems/rails-4.0.0.gem\",
23
+ \"homepage_uri\":\"http://www.rubyonrails.org\",\"wiki_uri\":\"http://wiki.rubyonrails.org\",
24
+ \"documentation_uri\":\"http://api.rubyonrails.org\",\"mailing_list_uri\":\"http://groups.google.com/group/rubyonrails-talk\",
25
+ \"source_code_uri\":\"http://github.com/rails/rails\"}"
26
+ }
27
+
28
+ let (:httparty_response_body) {
29
+ "{\"name\":\"httparty\",\"downloads\":5888099,\"version\":\"0.12.0\",
30
+ \"info\":\"Makes http fun! Also, makes consuming restful web services dead easy.\",
31
+ \"project_uri\":\"http://rubygems.org/gems/httparty\",\"gem_uri\":\"http://rubygems.org/gems/httparty-0.12.0.gem\",
32
+ \"homepage_uri\":\"http://jnunemaker.github.com/httparty\",\"wiki_uri\":\"\",\"documentation_uri\":\"\",
33
+ \"mailing_list_uri\":\"\",\"source_code_uri\":\"http://github.com/jnunemaker/httparty\"}"
34
+ }
35
+
36
+ it "should returns json with gem information" do
37
+ stub_request(:any, "http://rubygems.org/api/v1/gems/rails.json").
38
+ with(:headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
39
+ to_return(:status => 200, :body => rails_response_body, :headers => {})
40
+ ruby_gem_json = Gempage::RubyGemInfo.new('rails').gem_json
41
+ ruby_gem_json.should eql(orginal_json_no_empty_strings)
42
+ end
43
+
44
+ it "should returns json with gem information empty strings converted to nils" do
45
+ stub_request(:any, "http://rubygems.org/api/v1/gems/httparty.json").
46
+ with(:headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
47
+ to_return(:status => 200, :body => httparty_response_body, :headers => {})
48
+ ruby_gem_json = Gempage::RubyGemInfo.new('httparty').gem_json
49
+ ruby_gem_json.should eql(orginal_json_empty_strings)
50
+ end
51
+
52
+ end
@@ -1 +1,2 @@
1
1
  require 'gempage'
2
+ require 'webmock/rspec'
@@ -4,12 +4,13 @@
4
4
  <meta charset="utf-8">
5
5
  <title>Gem Reference</title>
6
6
  <link href="./gempage/assets/<%= Gempage::VERSION %>/application.css" rel="stylesheet">
7
- <link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet">
7
+ <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.0/css/font-awesome.css" rel="stylesheet">
8
8
  </head>
9
9
  <body>
10
10
  <div class="content">
11
11
  <% class_lookup = []
12
- result.each do |group, ruby_gems|
12
+ grouped_result = result.group_by{ |result| result['category'] }
13
+ grouped_result.each do |group, ruby_gems|
13
14
  group_array = group.split(',').map(&:strip) %>
14
15
  <div class="gem-section">
15
16
  <div class="gem-group-heading">
@@ -22,25 +23,34 @@
22
23
  gem_style = "z-index:#{index};"
23
24
  gem_style += " top:#{(index * 5)}px; left:#{(index * 5)}px;"
24
25
  class_lookup << group_name unless class_lookup.include? group_name
25
- gem_color_id = class_lookup.find_index(group_name) + 1 %>
26
- <div class="gem gem-color-<%= gem_color_id %>" style="<%= gem_style %>" title="<%= rubygem[:info] %>">
26
+ gem_color_id = class_lookup.find_index(group_name) + 1
27
+ gem_class = "gem gem-color-#{gem_color_id}#{' gem-color-error' if rubygem['error']}" %>
28
+ <div class="<%= gem_class %>" style="<%= gem_style %>" title="<%= rubygem['info'] %>">
27
29
  <% if index == 0 %>
28
30
  <h4>
29
- <% if rubygem[:homepage_uri] %>
30
- <a href="<%= rubygem[:homepage_uri] %>" target="_blank"><%= rubygem[:name] %></a>
31
+ <% if rubygem['homepage_uri'] %>
32
+ <a href="<%= rubygem['homepage_uri'] %>" target="_blank"><%= rubygem['name'] %></a>
31
33
  <% else %>
32
- <%= rubygem[:name] %>
34
+ <%= rubygem['name'] %>
33
35
  <% end %>
34
36
  </h4>
37
+ <% if rubygem['error'] %>
38
+ <h3><%= rubygem['error'] %></h3>
39
+ <% end
40
+ end
41
+ if rubygem['documentation_uri'] %>
42
+ <div class="icon documentation">
43
+ <a href="<%= rubygem['documentation_uri'] %>" target="_blank"><i class="fa fa-book fa-3x"></i></a>
44
+ </div>
35
45
  <% end
36
- if rubygem[:documentation_uri] %>
37
- <div class="documentation">
38
- <a class="icon-book icon-3x" href="<%= rubygem[:documentation_uri] %>" target="_blank"></a>
46
+ if rubygem['source_code_uri'] %>
47
+ <div class="icon github">
48
+ <a href="<%= rubygem['source_code_uri'] %>" target="_blank"><i class="fa fa-github fa-3x"></i></a>
39
49
  </div>
40
50
  <% end
41
- if rubygem[:source_code_uri] %>
42
- <div class="github">
43
- <a class="icon-github icon-3x" href="<%= rubygem[:source_code_uri] %>" target="_blank"></a>
51
+ if rubygem['error'] %>
52
+ <div class="icon error">
53
+ <i class="fa fa-question-circle fa-3x"></i>
44
54
  </div>
45
55
  <% end %>
46
56
  </div>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gempage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jane S. Sebastian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-24 00:00:00.000000000 Z
11
+ date: 2013-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ! '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  description: A reference page for gems installed within a Rails application.
112
126
  email:
113
127
  - jane@betatetra.com
@@ -133,14 +147,16 @@ files:
133
147
  - gempage.gemspec
134
148
  - lib/gempage.rb
135
149
  - lib/gempage/configuration.rb
136
- - lib/gempage/import.rb
150
+ - lib/gempage/gemfile_processor.rb
151
+ - lib/gempage/ruby_gem_info.rb
137
152
  - lib/gempage/version.rb
138
153
  - public/application.css
139
154
  - public/color-schemes/default.css
140
155
  - public/color-schemes/pastels.css
141
156
  - public/color-schemes/random.css
142
157
  - spec/fixtures/Gemfile
143
- - spec/lib/importer_spec.rb
158
+ - spec/lib/gemfile_processor_spec.rb
159
+ - spec/lib/ruby_gem_info_spec.rb
144
160
  - spec/spec_helper.rb
145
161
  - views/layout.erb
146
162
  homepage: https://github.com/careful-with-that-axe
@@ -169,6 +185,7 @@ specification_version: 4
169
185
  summary: Work in progress yo.
170
186
  test_files:
171
187
  - spec/fixtures/Gemfile
172
- - spec/lib/importer_spec.rb
188
+ - spec/lib/gemfile_processor_spec.rb
189
+ - spec/lib/ruby_gem_info_spec.rb
173
190
  - spec/spec_helper.rb
174
191
  has_rdoc:
@@ -1,119 +0,0 @@
1
- require 'fileutils'
2
- require 'json'
3
-
4
- module Gempage::Import
5
- class Importer
6
-
7
- attr_reader :gem_list
8
-
9
- def initialize(gemfile_path)
10
- @gemfile_path = gemfile_path
11
- @gem_list = gem_list
12
- end
13
-
14
- def gem_list
15
- if gemfile_lines
16
- gems = process_gems(normalize(gemfile_lines))
17
- final_gems = []
18
- gems.each do |gem_listing|
19
- final_gems << add_rubygem_content(gem_listing) if find_gem(gem_listing[:name])
20
- end
21
- else
22
- puts "There is no Gemfile to process... how odd."
23
- end
24
- end
25
-
26
- private
27
-
28
- def gemfile_lines
29
- File.readlines(@gemfile_path) if File.exists? @gemfile_path
30
- end
31
-
32
- def normalize(gemfile)
33
- # Strip white space, keep only lines starting with gem, group
34
- # or end, normalize to single quotes, remove trailing comments
35
- gemfile.map { |x| x.strip.gsub(/"/,"'") }
36
- .reject { |x| x.empty? || !x.match(/^(gem|group|end)/) }
37
- .map { |x| x.gsub(/\s?#.*$/, '') }
38
- end
39
-
40
- def process_gems(data, group = 'all', gems = [])
41
- data.each_with_index do |line, index|
42
- if line.match(/^gem\s/)
43
- add_gem(gems, group, line)
44
- else
45
- if line.match(/^group/)
46
- group = get_group(line)
47
- return process_gems(data[(index + 1)..-1], group, gems)
48
- else line.match(/^end/)
49
- group = 'all'
50
- end
51
- end
52
- end
53
- gems
54
- end
55
-
56
- def get_group(line)
57
- group = line.match(/^group\s+(.+)\sdo$/)
58
- group ? group[1] : nil
59
- end
60
-
61
- def add_gem(gems, group, line)
62
- gems << gem_details(line, group) if gem_details(line, group)
63
- end
64
-
65
- def gem_details(line, group)
66
- gem_pieces = line.match(/^gem\s'([\w|-]+)',?\s?(.*)/)
67
- gem_pieces ? { name: gem_pieces[1], category: group, configuration: gem_pieces[2] } : nil
68
- end
69
-
70
- def find_gem(name)
71
- url = "https://rubygems.org/api/v1/gems/#{name}.json"
72
- JSON.parse(response_body(url)) if response_body(url)
73
- # set variable
74
- end
75
-
76
- def response_body(url)
77
- begin
78
- request = Net::HTTP.new URI(url).host
79
- response = request.request_get URI(url).path
80
- response.code.to_i == 200 ? response.body : false
81
- rescue StandardError
82
- false
83
- end
84
- end
85
-
86
- def add_rubygem_content(gem_listing)
87
- rubygem = find_gem(gem_listing[:name])
88
- documentation_uri = get_documentation_uri(rubygem['documentation_uri'], rubygem['homepage_uri'])
89
- source_code_uri = get_source_code_uri(rubygem['source_code_uri'], rubygem['homepage_uri'])
90
- homepage_uri = get_homepage_uri(rubygem['homepage_uri'])
91
- if rubygem
92
- gem_listing[:downloads] = rubygem['downloads']
93
- gem_listing[:version] = rubygem['version']
94
- gem_listing[:authors] = rubygem['authors']
95
- gem_listing[:info] = rubygem['info']
96
- gem_listing[:documentation_uri] = documentation_uri
97
- gem_listing[:source_code_uri] = source_code_uri
98
- gem_listing[:homepage_uri] = homepage_uri
99
- gem_listing
100
- else
101
- puts "None such #{name} gem... #{name} will not be in the Gem Reference"
102
- false
103
- end
104
- end
105
-
106
- def get_homepage_uri(homepage_uri)
107
- homepage_uri && homepage_uri != '' ? homepage_uri : nil
108
- end
109
-
110
- def get_documentation_uri(documentation_uri, source_code_uri)
111
- documentation_uri && documentation_uri != '' && documentation_uri != source_code_uri ? documentation_uri : nil
112
- end
113
-
114
- def get_source_code_uri(source_code_uri, homepage_uri)
115
- source_code_uri && source_code_uri != '' ? source_code_uri : nil
116
- !source_code_uri && homepage_uri && homepage_uri.match(/github\.com/) ? homepage_uri : source_code_uri
117
- end
118
- end
119
- end
@@ -1,14 +0,0 @@
1
- require 'spec_helper'
2
- require 'fixtures/gem_list_fixture'
3
-
4
- describe Gempage::Import::Importer do
5
-
6
- before :each do
7
- Gempage::Import::Importer.any_instance.stub(:puts) # Silencing display during tests
8
- gemfile_path = File.join(Gempage.root, '/spec/fixtures/Gemfile')
9
- @importer = Gempage::Import::Importer.new(gemfile_path)
10
- end
11
-
12
- xit 'should process a bunch of gems'
13
-
14
- end