sweetie 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.
Files changed (3) hide show
  1. data/bin/sweetie +7 -0
  2. data/lib/sweetie.rb +96 -0
  3. metadata +97 -0
data/bin/sweetie ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'sweetie'
4
+
5
+
6
+ Sweetie.change_config
7
+
data/lib/sweetie.rb ADDED
@@ -0,0 +1,96 @@
1
+ require "nokogiri"
2
+
3
+ class Sweetie
4
+
5
+ @@config = "../_config.yml"
6
+ @@dir = "_site"
7
+
8
+ def self.change_config
9
+ file = File.open(@@config)
10
+ text = ""
11
+ while line = file.gets
12
+ if line.match(/build:/)
13
+ text << "build: #{build_time}\n"
14
+ elsif line.match(/pages:/)
15
+ text << "pages: #{count_html_pages(@@dir)}\n"
16
+ elsif line.match(/images:/)
17
+ text << "images: #{count_all_images(@@dir)}\n"
18
+ elsif line.match(/links:/)
19
+ text << "links: #{count_all_links(@@dir)}\n"
20
+ else
21
+ text << line
22
+ end
23
+ end
24
+ file.close
25
+ File.open(@@config, 'w') do |file|
26
+ file.puts text
27
+ file.close
28
+ end
29
+ end
30
+
31
+ def self.count_link_of_one_page(page)
32
+ links = []
33
+ links = harvest('//a', page, links, 'a')
34
+ output_count(links)
35
+ end
36
+
37
+ def self.count_images_of_one_page(page)
38
+ images = []
39
+ images = harvest('//img', page, images, 'img')
40
+ output_count(images)
41
+ end
42
+
43
+ def self.count_html_pages(dir)
44
+ pages = []
45
+ traverse('//html', pages, 'html', dir)
46
+ output_count(pages)
47
+ end
48
+
49
+ def self.count_all_links(dir)
50
+ links = []
51
+ traverse('//a', links, 'a', dir)
52
+ output_count(links)
53
+ end
54
+
55
+ def self.count_all_images(dir)
56
+ images = []
57
+ traverse('//img', images, 'img', dir)
58
+ output_count(images)
59
+ end
60
+
61
+ def self.build_time
62
+ time = Time.now
63
+ "#{time.month}-#{time.day}-#{time.year}"
64
+ end
65
+
66
+ def self.traverse(pattern, ar, type, dir)
67
+ Dir.glob(dir+"/**/*") do |file|
68
+ next if file == '.' or file == '..' or file.include?("html~")
69
+ if file.match(/(.*).html/)
70
+ harvest(pattern, file, ar, type)
71
+ end
72
+ end
73
+ end
74
+
75
+ def self.harvest(pattern, html, ar, type)
76
+ file = File.open(html)
77
+ doc = Nokogiri::HTML(file)
78
+ doc.xpath(pattern).each do |node|
79
+ if type == "a"
80
+ ar << node.text
81
+ elsif type == "img" and ar.include?(node.to_s)
82
+ elsif type == "img"
83
+ ar << node.to_s
84
+ elsif type == "html"
85
+ ar << node
86
+ else
87
+ end
88
+ end
89
+ ar
90
+ end
91
+
92
+ def self.output_count(file)
93
+ file.uniq.count
94
+ end
95
+ end
96
+
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sweetie
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Matthias Guenther
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-07-02 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: nokogiri
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 11
29
+ segments:
30
+ - 1
31
+ - 4
32
+ - 6
33
+ version: 1.4.6
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 23
45
+ segments:
46
+ - 2
47
+ - 6
48
+ - 0
49
+ version: 2.6.0
50
+ type: :development
51
+ version_requirements: *id002
52
+ description: Sweetie count pages, images, links, and last-build time of a jekyll project
53
+ email: matthias.guenther@wikimatze.de
54
+ executables:
55
+ - sweetie
56
+ extensions: []
57
+
58
+ extra_rdoc_files: []
59
+
60
+ files:
61
+ - lib/sweetie.rb
62
+ - bin/sweetie
63
+ homepage: http://github.com/matthias-guenther/sweetie
64
+ licenses: []
65
+
66
+ post_install_message:
67
+ rdoc_options: []
68
+
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 3
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ requirements: []
90
+
91
+ rubyforge_project:
92
+ rubygems_version: 1.8.5
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: Count pages, images, links, and last-build time of a jekyll project
96
+ test_files: []
97
+