sweetie 0.1.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (201) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +30 -0
  3. data/.gitignore +4 -1
  4. data/.rubocop.yml +16 -0
  5. data/Gemfile +6 -0
  6. data/README.md +292 -15
  7. data/Rakefile +3 -2
  8. data/lib/sweetie/bitbucket.rb +30 -0
  9. data/lib/sweetie/bitbucket_stati_helper.rb +247 -0
  10. data/lib/sweetie/conversion.rb +84 -103
  11. data/lib/sweetie/helper.rb +90 -0
  12. data/lib/sweetie/version.rb +5 -0
  13. data/lib/sweetie.rb +3 -4
  14. data/spec/fixtures/bitbucket/expected_repositories.txt +1 -0
  15. data/spec/fixtures/bitbucket/repositories.json +1 -0
  16. data/spec/fixtures/jekyll/_config.yml +4 -0
  17. data/spec/fixtures/jekyll/_config_repositories.yml +7 -0
  18. data/spec/fixtures/jekyll/_expected_config.yml +4 -0
  19. data/spec/{source → fixtures/jekyll}/site/404.html +0 -0
  20. data/spec/{source → fixtures/jekyll}/site/about.html +0 -0
  21. data/spec/{source → fixtures/jekyll}/site/archiv.html +0 -0
  22. data/spec/{source → fixtures/jekyll}/site/atom.xml +0 -0
  23. data/spec/{source → fixtures/jekyll}/site/colophon.html +0 -0
  24. data/spec/{source → fixtures/jekyll}/site/contact.html +0 -0
  25. data/spec/{source → fixtures/jekyll}/site/follow.html +0 -0
  26. data/spec/{source → fixtures/jekyll}/site/images/2_avatars.gif +0 -0
  27. data/spec/{source → fixtures/jekyll}/site/images/favicon.png +0 -0
  28. data/spec/{source → fixtures/jekyll}/site/images/images-global/matthias_guenther.jpg +0 -0
  29. data/spec/{source → fixtures/jekyll}/site/images/images-global/matthias_guenther_thumbnail_normal.jpg +0 -0
  30. data/spec/{source → fixtures/jekyll}/site/images/images-global/matthias_guenther_thumbnail_small.jpg +0 -0
  31. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/closebox.png +0 -0
  32. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-caption-fill.png +0 -0
  33. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-caption-l.png +0 -0
  34. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-caption-r.png +0 -0
  35. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-shadow1.png +0 -0
  36. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-shadow2.png +0 -0
  37. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-shadow3.png +0 -0
  38. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-shadow4.png +0 -0
  39. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-shadow5.png +0 -0
  40. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-shadow6.png +0 -0
  41. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-shadow7.png +0 -0
  42. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-shadow8.png +0 -0
  43. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-spin-1.png +0 -0
  44. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-spin-10.png +0 -0
  45. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-spin-11.png +0 -0
  46. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-spin-12.png +0 -0
  47. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-spin-2.png +0 -0
  48. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-spin-3.png +0 -0
  49. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-spin-4.png +0 -0
  50. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-spin-5.png +0 -0
  51. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-spin-6.png +0 -0
  52. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-spin-7.png +0 -0
  53. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-spin-8.png +0 -0
  54. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-spin-9.png +0 -0
  55. data/spec/{source → fixtures/jekyll}/site/images/rails3.jpg +0 -0
  56. data/spec/{source → fixtures/jekyll}/site/index.html +0 -0
  57. data/spec/{source → fixtures/jekyll}/site/robots.txt +0 -0
  58. data/spec/{source → fixtures/jekyll}/site/sitemap.xml +0 -0
  59. data/spec/{source → fixtures/jekyll}/site/why-i-use-jekyll-for-blogging.html +0 -0
  60. data/spec/fixtures/middleman/build/2012-01-meetup/index.html +238 -0
  61. data/spec/fixtures/middleman/build/2012-03-meetup/index.html +217 -0
  62. data/spec/fixtures/middleman/build/2012-05-meetup/index.html +214 -0
  63. data/spec/fixtures/middleman/build/2012-07-meetup/index.html +210 -0
  64. data/spec/fixtures/middleman/build/2012-08-workshop/index.html +228 -0
  65. data/spec/fixtures/middleman/build/2012-09-meetup/index.html +231 -0
  66. data/spec/fixtures/middleman/build/2012-10-workshop/index.html +227 -0
  67. data/spec/fixtures/middleman/build/2012-11-meetup/index.html +229 -0
  68. data/spec/fixtures/middleman/build/2012-unusual-december-meetup/index.html +186 -0
  69. data/spec/fixtures/middleman/build/2013-01-meetup/index.html +226 -0
  70. data/spec/fixtures/middleman/build/404/index.html +157 -0
  71. data/spec/fixtures/middleman/build/CNAME +1 -0
  72. data/spec/fixtures/middleman/build/april-2014-meetup/index.html +221 -0
  73. data/spec/fixtures/middleman/build/april-2015-meetup/index.html +204 -0
  74. data/spec/fixtures/middleman/build/april-2017-meetup/index.html +210 -0
  75. data/spec/fixtures/middleman/build/assets/favicons/android-chrome-144x144.png +0 -0
  76. data/spec/fixtures/middleman/build/assets/favicons/android-chrome-192x192.png +0 -0
  77. data/spec/fixtures/middleman/build/assets/favicons/android-chrome-36x36.png +0 -0
  78. data/spec/fixtures/middleman/build/assets/favicons/android-chrome-48x48.png +0 -0
  79. data/spec/fixtures/middleman/build/assets/favicons/android-chrome-72x72.png +0 -0
  80. data/spec/fixtures/middleman/build/assets/favicons/android-chrome-96x96.png +0 -0
  81. data/spec/fixtures/middleman/build/assets/favicons/apple-touch-icon-114x114.png +0 -0
  82. data/spec/fixtures/middleman/build/assets/favicons/apple-touch-icon-120x120.png +0 -0
  83. data/spec/fixtures/middleman/build/assets/favicons/apple-touch-icon-144x144.png +0 -0
  84. data/spec/fixtures/middleman/build/assets/favicons/apple-touch-icon-152x152.png +0 -0
  85. data/spec/fixtures/middleman/build/assets/favicons/apple-touch-icon-180x180.png +0 -0
  86. data/spec/fixtures/middleman/build/assets/favicons/apple-touch-icon-57x57.png +0 -0
  87. data/spec/fixtures/middleman/build/assets/favicons/apple-touch-icon-60x60.png +0 -0
  88. data/spec/fixtures/middleman/build/assets/favicons/apple-touch-icon-72x72.png +0 -0
  89. data/spec/fixtures/middleman/build/assets/favicons/apple-touch-icon-76x76.png +0 -0
  90. data/spec/fixtures/middleman/build/assets/favicons/apple-touch-icon-precomposed.png +0 -0
  91. data/spec/fixtures/middleman/build/assets/favicons/apple-touch-icon.png +0 -0
  92. data/spec/fixtures/middleman/build/assets/favicons/browserconfig.xml +12 -0
  93. data/spec/fixtures/middleman/build/assets/favicons/favicon-16x16.png +0 -0
  94. data/spec/fixtures/middleman/build/assets/favicons/favicon-32x32.png +0 -0
  95. data/spec/fixtures/middleman/build/assets/favicons/favicon-96x96.png +0 -0
  96. data/spec/fixtures/middleman/build/assets/favicons/favicon.ico +0 -0
  97. data/spec/fixtures/middleman/build/assets/favicons/manifest.json +41 -0
  98. data/spec/fixtures/middleman/build/assets/favicons/mstile-144x144.png +0 -0
  99. data/spec/fixtures/middleman/build/assets/favicons/mstile-150x150.png +0 -0
  100. data/spec/fixtures/middleman/build/assets/favicons/mstile-310x150.png +0 -0
  101. data/spec/fixtures/middleman/build/assets/favicons/mstile-310x310.png +0 -0
  102. data/spec/fixtures/middleman/build/assets/favicons/mstile-70x70.png +0 -0
  103. data/spec/fixtures/middleman/build/assets/favicons/safari-pinned-tab.svg +450 -0
  104. data/spec/fixtures/middleman/build/assets/images/launch_co_logo.png +0 -0
  105. data/spec/fixtures/middleman/build/assets/images/vimfest.png +0 -0
  106. data/spec/fixtures/middleman/build/assets/javascripts/application.js +12 -0
  107. data/spec/fixtures/middleman/build/assets/javascripts/jquery.utils.js +12 -0
  108. data/spec/fixtures/middleman/build/assets/javascripts/lib/validate.js +1 -0
  109. data/spec/fixtures/middleman/build/assets/stylesheets/application.css +5 -0
  110. data/spec/fixtures/middleman/build/assets/stylesheets/vendor/bootstrap.css +5 -0
  111. data/spec/fixtures/middleman/build/august-2013-meetup/index.html +208 -0
  112. data/spec/fixtures/middleman/build/blog/index.html +500 -0
  113. data/spec/fixtures/middleman/build/book-club-about-the-viml-primer/index.html +182 -0
  114. data/spec/fixtures/middleman/build/contact/index.html +155 -0
  115. data/spec/fixtures/middleman/build/data/vimberlin-2013-09_ctags/index.html +98 -0
  116. data/spec/fixtures/middleman/build/data/vimberlin-2013-09_vimprofiling/index.html +157 -0
  117. data/spec/fixtures/middleman/build/data/vimberlin-2014-01_vim_writing/index.html +70 -0
  118. data/spec/fixtures/middleman/build/december-2015-meetup/index.html +199 -0
  119. data/spec/fixtures/middleman/build/december-2016-meetup/index.html +224 -0
  120. data/spec/fixtures/middleman/build/february-2013-vim-beer-lin/index.html +190 -0
  121. data/spec/fixtures/middleman/build/february-2015-meetup/index.html +233 -0
  122. data/spec/fixtures/middleman/build/february-2016-meetup/index.html +271 -0
  123. data/spec/fixtures/middleman/build/feed.xml +2106 -0
  124. data/spec/fixtures/middleman/build/fonts/FontAwesome.otf +0 -0
  125. data/spec/fixtures/middleman/build/fonts/fontawesome-webfont.eot +0 -0
  126. data/spec/fixtures/middleman/build/fonts/fontawesome-webfont.svg +655 -0
  127. data/spec/fixtures/middleman/build/fonts/fontawesome-webfont.ttf +0 -0
  128. data/spec/fixtures/middleman/build/fonts/fontawesome-webfont.woff +0 -0
  129. data/spec/fixtures/middleman/build/fonts/fontawesome-webfont.woff2 +0 -0
  130. data/spec/fixtures/middleman/build/humans.txt +12 -0
  131. data/spec/fixtures/middleman/build/imprint/index.html +177 -0
  132. data/spec/fixtures/middleman/build/index.html +157 -0
  133. data/spec/fixtures/middleman/build/january-2014-meetup/index.html +257 -0
  134. data/spec/fixtures/middleman/build/january-2015-meetup/index.html +243 -0
  135. data/spec/fixtures/middleman/build/january-2016-meetup/index.html +202 -0
  136. data/spec/fixtures/middleman/build/january-2017-meetup/index.html +228 -0
  137. data/spec/fixtures/middleman/build/july-2015-meetup/index.html +207 -0
  138. data/spec/fixtures/middleman/build/june-2016-meetup/index.html +260 -0
  139. data/spec/fixtures/middleman/build/march-2-2017-meetup/index.html +201 -0
  140. data/spec/fixtures/middleman/build/march-2014-meetup/index.html +219 -0
  141. data/spec/fixtures/middleman/build/march-2016-meetup/index.html +221 -0
  142. data/spec/fixtures/middleman/build/march-2017-meetup/index.html +222 -0
  143. data/spec/fixtures/middleman/build/may-2013-meetup/index.html +234 -0
  144. data/spec/fixtures/middleman/build/may-2014-meetup/index.html +198 -0
  145. data/spec/fixtures/middleman/build/may-2015-meetup/index.html +202 -0
  146. data/spec/fixtures/middleman/build/may-2016-meetup/index.html +245 -0
  147. data/spec/fixtures/middleman/build/newsletter/index.html +171 -0
  148. data/spec/fixtures/middleman/build/november-2013-meetup/index.html +199 -0
  149. data/spec/fixtures/middleman/build/november-2015-meetup/index.html +402 -0
  150. data/spec/fixtures/middleman/build/november-2016-meetup/index.html +224 -0
  151. data/spec/fixtures/middleman/build/october-2013-meetup/index.html +210 -0
  152. data/spec/fixtures/middleman/build/october-2014-meetup/index.html +196 -0
  153. data/spec/fixtures/middleman/build/october-2016-meetup/index.html +222 -0
  154. data/spec/fixtures/middleman/build/robots.txt +6 -0
  155. data/spec/fixtures/middleman/build/september-2013-meetup/index.html +225 -0
  156. data/spec/fixtures/middleman/build/september-2014-meetup/index.html +211 -0
  157. data/spec/fixtures/middleman/build/sitemap.xml +297 -0
  158. data/spec/fixtures/middleman/build/vimfest-october-2015/index.html +303 -0
  159. data/spec/fixtures/middleman/config.rb +4 -0
  160. data/spec/fixtures/middleman/config_repositories.rb +7 -0
  161. data/spec/fixtures/middleman/expected_config.rb +4 -0
  162. data/spec/spec_helper.rb +2 -0
  163. data/spec/sweetie_bitbucket_spec.rb +32 -0
  164. data/spec/sweetie_bitbucket_stati_helper_spec.rb +124 -0
  165. data/spec/sweetie_conversion_spec.rb +117 -0
  166. data/spec/sweetie_helper_spec.rb +140 -0
  167. data/sweetie.gemspec +21 -22
  168. metadata +243 -165
  169. data/.travis.yml +0 -2
  170. data/bin/sweetie +0 -7
  171. data/doc/Sweetie.html +0 -125
  172. data/doc/_index.html +0 -121
  173. data/doc/class_list.html +0 -47
  174. data/doc/css/common.css +0 -1
  175. data/doc/css/full_list.css +0 -53
  176. data/doc/css/style.css +0 -320
  177. data/doc/file.README.html +0 -95
  178. data/doc/file_list.html +0 -49
  179. data/doc/frames.html +0 -13
  180. data/doc/index.html +0 -95
  181. data/doc/js/app.js +0 -205
  182. data/doc/js/full_list.js +0 -150
  183. data/doc/js/jquery.js +0 -16
  184. data/doc/method_list.html +0 -126
  185. data/doc/top-level-namespace.html +0 -103
  186. data/spec/source/_config.yml +0 -18
  187. data/spec/source/site/css/config.rb +0 -24
  188. data/spec/source/site/css/sass/site.sass +0 -180
  189. data/spec/source/site/css/stylesheets/iphone.css +0 -17
  190. data/spec/source/site/css/stylesheets/site.css +0 -246
  191. data/spec/source/site/css/stylesheets/syntax.css +0 -60
  192. data/spec/source/site/js/FancyZoom.js +0 -761
  193. data/spec/source/site/js/FancyZoomHTML.js +0 -318
  194. data/spec/source/site/test/config.rb +0 -24
  195. data/spec/source/site/test/sass/ie.scss +0 -5
  196. data/spec/source/site/test/sass/print.scss +0 -3
  197. data/spec/source/site/test/sass/screen.scss +0 -6
  198. data/spec/source/site/test/stylesheets/ie.css +0 -5
  199. data/spec/source/site/test/stylesheets/print.css +0 -3
  200. data/spec/source/site/test/stylesheets/screen.css +0 -69
  201. data/spec/sweetie_spec.rb +0 -30
@@ -0,0 +1,124 @@
1
+ require 'sweetie/bitbucket_stati_helper'
2
+
3
+ describe Sweetie::BitbucketStatiHelper do
4
+ let(:current_dir) { File.dirname(__FILE__) }
5
+ let(:repositories) { File.join(current_dir, 'fixtures', 'bitbucket', 'repositories.json') }
6
+
7
+ let(:expected_repositories) { File.join(current_dir, 'fixtures', 'bitbucket', 'expected_repositories.txt') }
8
+ # let(:site_dir) { File.join(current_dir, 'fixtures', 'jekyll', 'site') }
9
+ # let(:svn_hash) { { svn: '2011-10-16' } }
10
+
11
+ subject { Sweetie::BitbucketStatiHelper.new }
12
+
13
+ it 'parses a json file' do
14
+ # gsub replace trailing newline at the end of the file
15
+ changeset_expectation = File.open(expected_repositories).read.delete("\n")
16
+ changeset = File.open(repositories).read
17
+ changeset = subject.parse_json(changeset).to_s
18
+ expect(changeset).to eq changeset_expectation
19
+ end
20
+
21
+ it 'creates a string representation of a repository for middleman config' do
22
+ repository = { pmwiki: '2011-10-26' }
23
+ expect(subject.entry_text_middleman(repository.keys.first, repository.values.first)).to eq 'set :pmwiki, 2011-10-26'
24
+ end
25
+
26
+ it 'creates a string representation of a repository for jekyll config' do
27
+ repository = { pmwiki: '2011-10-26' }
28
+ expect(subject.entry_text_jekyll(repository.keys.first, repository.values.first)).to eq 'pmwiki: 2011-10-26'
29
+ end
30
+
31
+ it 'parses a timestamp' do
32
+ timestamp = '2011-04-20 11:31:39'
33
+ expect(subject.parse_timestamp(timestamp)).to eq '2011-04-20'
34
+ end
35
+
36
+ it 'gets the changesets of the repositories only with name' do
37
+ json_repositories = File.open(repositories).read
38
+ expected_names = ['pmwiki-linkicons-recipe',
39
+ 'pmwiki-dropcaps-recipe',
40
+ 'pmwiki-headlineimage-recipe',
41
+ 'pmwiki-syntaxlove-recipe',
42
+ 'pmwiki-twitter-recipe',
43
+ 'presentations',
44
+ 'vocabularly',
45
+ 'ruby-scripts',
46
+ 'rails-sample-app']
47
+ expect(subject.get_repositories_changes(json_repositories).keys).to eq expected_names
48
+ end
49
+
50
+ it 'get the changesets of the repositories with name and date' do
51
+ json_repositories = File.open(repositories).read
52
+ expected_changesets = { 'pmwiki-linkicons-recipe' => '2017-02-26',
53
+ 'pmwiki-dropcaps-recipe' => '2017-02-24',
54
+ 'pmwiki-headlineimage-recipe' => '2017-02-25',
55
+ 'pmwiki-syntaxlove-recipe' => '2017-02-26',
56
+ 'pmwiki-twitter-recipe' => '2017-02-26',
57
+ 'presentations' => '2017-01-15',
58
+ 'vocabularly' => '2013-01-26',
59
+ 'ruby-scripts' => '2014-05-25',
60
+ 'rails-sample-app' => '2013-01-26' }
61
+ expect(subject.get_repositories_changes(json_repositories)).to eq expected_changesets
62
+ end
63
+
64
+ it 'do not writes repository changes to config file for jekyll project if entries are not in there' do
65
+ hash = { svn: '2011-10-26', pmwiki: '2011-10-26' }
66
+ config = File.join(current_dir, 'fixtures', 'jekyll', '_config.yml')
67
+
68
+ subject.config = config
69
+ subject.write_repository_changes(hash)
70
+ config_yml_content = File.open(config).read
71
+
72
+ expect(config_yml_content).not_to include 'svn: 2011-10-26'
73
+ expect(config_yml_content).not_to include 'pmwiki: 2011-10-26'
74
+ end
75
+
76
+ it 'writes repository changes to config file for jekyll project if entries are in config file' do
77
+ hash = { svn: '2017-10-26', pmwiki: '2017-10-26' }
78
+ config = File.join(current_dir, 'fixtures', 'jekyll', '_config_repositories.yml')
79
+
80
+ subject.config = config
81
+ subject.write_repository_changes(hash)
82
+ config_yml_content = File.open(config).read
83
+
84
+ expect(config_yml_content).to include 'svn: 2017-10-26'
85
+ expect(config_yml_content).to include 'pmwiki: 2017-10-26'
86
+
87
+ # remove variables from the text-file
88
+ text = config_yml_content.gsub('pmwiki: 2017-10-26', 'pmwiki: 2011-10-26').gsub('svn: 2017-10-26', 'svn: 2011-10-26')
89
+ config_yml_content = File.open(config, 'w')
90
+ config_yml_content.puts text
91
+ config_yml_content.close
92
+ end
93
+
94
+ it 'do not writes repository changes to config file for middleman project if entries are not in there' do
95
+ hash = { svn: '2011-10-26', pmwiki: '2011-10-26' }
96
+ config = File.join(current_dir, 'fixtures', 'middleman', 'config.rb')
97
+
98
+ subject.config = config
99
+ subject.write_repository_changes(hash)
100
+ config_yml_content = File.open(config).read
101
+
102
+ expect(config_yml_content).not_to include 'set :svn, 2011-10-26'
103
+ expect(config_yml_content).not_to include 'set :pmwiki, 2011-10-26'
104
+ end
105
+
106
+ it 'writes repository changes to config file for middleman project if entries are in config file' do
107
+ hash = { :svn => '2017-10-26', 'pmwiki-dropcaps-recipe' => '2017-10-26' }
108
+ config = File.join(current_dir, 'fixtures', 'middleman', 'config_repositories.rb')
109
+
110
+ subject.config = config
111
+ subject.write_repository_changes(hash)
112
+ config_yml_content = File.open(config).read
113
+
114
+ expect(config_yml_content).to include 'set :svn, 2017-10-26'
115
+ expect(config_yml_content).to include 'set :pmwiki_dropcaps_recipe, 2017-10-26'
116
+
117
+ # remove variables from the text-file
118
+ text = config_yml_content.gsub('set :pmwiki_dropcaps_recipe, 2017-10-26', 'set :pmwiki_dropcaps_recipe, 2011-10-26').gsub('set :svn, 2017-10-26', 'set :svn, 2011-10-26')
119
+ config_yml_content = File.open(config, 'w')
120
+ config_yml_content.puts text
121
+ config_yml_content.close
122
+ end
123
+ end
124
+
@@ -0,0 +1,117 @@
1
+ require 'sweetie/conversion'
2
+
3
+ describe Sweetie::Conversion do
4
+ let(:current_dir) { File.dirname(__FILE__) }
5
+
6
+ describe 'Jekyll project' do
7
+ let(:site_dir) { File.join(current_dir, 'fixtures', 'jekyll', 'site') }
8
+ let(:about_page) { File.join(site_dir, 'about.html') }
9
+ let(:site_config) { File.join(current_dir, 'fixtures', 'jekyll', '_config.yml') }
10
+ let(:sweetie) { Sweetie::Conversion.new(site_dir, site_config) }
11
+
12
+ it 'should count links of about.html page' do
13
+ expect(sweetie.count_link_of_one_page(about_page)).to eq(11)
14
+ end
15
+
16
+ it 'should count images of about.html page' do
17
+ expect(sweetie.count_images_of_one_page(about_page)).to eq 1
18
+ end
19
+
20
+ it 'should count all html pages' do
21
+ expect(sweetie.count_all_html_pages(site_dir)).to eq 8
22
+ end
23
+
24
+ it 'should count all links of all pages' do
25
+ expect(sweetie.count_all_links(site_dir)).to eq 54
26
+ end
27
+
28
+ it 'should count all images' do
29
+ expect(sweetie.count_all_images(site_dir)).to eq 1
30
+ end
31
+
32
+ it 'creates the correct build-time' do
33
+ time = Time.now
34
+ expected_time = "#{time.month}-#{time.day}-#{time.year}"
35
+ allow(time).to receive(:now).and_return(time)
36
+ expect(sweetie.build_time).to eq expected_time
37
+ end
38
+
39
+ it 'does create stati for jekyll project' do
40
+ config_yml_file = File.open(site_config, 'w')
41
+ default_text = <<TEXT
42
+ htmlpages:
43
+ images:
44
+ links:
45
+
46
+ TEXT
47
+ config_yml_file.write(default_text)
48
+ config_yml_file.close
49
+
50
+ sweetie.create_stati
51
+
52
+ config_yml_file = File.open(site_config).readlines
53
+ expected_config = File.open(File.join(current_dir, 'fixtures', 'jekyll', '_expected_config.yml')).readlines
54
+
55
+ result = true
56
+ config_yml_file.each do |e|
57
+ result = false unless expected_config.include? e
58
+ end
59
+
60
+ expect(result).to be_truthy
61
+ end
62
+ end
63
+
64
+ describe 'Middleman project' do
65
+ let(:build_dir) { File.join(current_dir, 'fixtures', 'middleman', 'build') }
66
+ let(:site_config) { File.join(current_dir, 'fixtures', 'middleman', 'config.rb') }
67
+ let(:index_page) { File.join(build_dir, 'index.html') }
68
+ let(:sweetie) { Sweetie::Conversion.new(build_dir, File.join(current_dir, 'fixtures', 'middleman', 'config.rb')) }
69
+
70
+ subject { sweetie }
71
+
72
+ it 'should count links of index-fixtues page' do
73
+ expect(subject.count_link_of_one_page(index_page)).to eq 13
74
+ end
75
+
76
+ it 'should count images of index-fixtures page' do
77
+ expect(subject.count_images_of_one_page(index_page)).to eq 2
78
+ end
79
+
80
+ it 'should count all html pages' do
81
+ expect(subject.count_all_html_pages(build_dir)).to eq 52
82
+ end
83
+
84
+ it 'should count all links of all pages' do
85
+ expect(subject.count_all_links(build_dir)).to eq 405
86
+ end
87
+
88
+ it 'should count all images' do
89
+ expect(subject.count_all_images(build_dir)).to eq 10
90
+ end
91
+
92
+ it 'does create stati for middleman project' do
93
+ config_yml_file = File.open(site_config, 'w')
94
+ default_text = <<TEXT
95
+ set :htmlpages,
96
+ set :images,
97
+ set :links,
98
+
99
+ TEXT
100
+ config_yml_file.write(default_text)
101
+ config_yml_file.close
102
+
103
+ sweetie.create_stati
104
+
105
+ config_yml_file = File.open(site_config).readlines
106
+ expected_config = File.open(File.join(current_dir, 'fixtures', 'middleman', 'expected_config.rb')).readlines
107
+
108
+ result = true
109
+ config_yml_file.each do |e|
110
+ result = false if !expected_config.include?(e) || e.empty?
111
+ end
112
+
113
+ expect(result).to be_truthy
114
+ end
115
+ end
116
+ end
117
+
@@ -0,0 +1,140 @@
1
+ require 'sweetie/helper'
2
+ require 'nokogiri'
3
+ require 'spec_helper'
4
+
5
+ describe 'Sweetie Helper' do
6
+ let(:helper) { Class.new }
7
+
8
+ before { helper.extend Sweetie::Helper }
9
+ subject { helper }
10
+
11
+ describe '#perform_search_for_single_page' do
12
+ it 'search after all links for the file directory and return the number of found entries' do
13
+ file = double(File)
14
+ file_content = '<a href="/index.html">wikimatze</a>'
15
+
16
+ expect(File).to receive(:open).with(file).and_return(file_content)
17
+
18
+ expect(subject.perform_search_for_single_page('//a', [], file)).to eql 1
19
+ end
20
+ end
21
+
22
+ describe '#perform_global_search' do
23
+ it 'search after all links for the given directory and return the number of found entries' do
24
+ file = 'test.html'
25
+ expect(Dir).to receive(:glob).with('test/**/*').and_yield file
26
+
27
+ file_content = '<a href="/index.html">wikimatze</a>'
28
+ expect(File).to receive(:open).with(file).and_return(file_content)
29
+
30
+ expect(subject.perform_global_search('//a', [], 'test')).to eql 1
31
+ end
32
+ end
33
+
34
+ describe '#check_directory_and_config_file' do
35
+ let(:site_dir) { File.join(File.dirname(__FILE__), 'fixtures', 'jekyll', 'site') }
36
+ let(:about_page) { File.join(site_dir, 'about.html') }
37
+
38
+ it 'raise an error if dir folder does not exists' do
39
+ expect { subject.check_directory_and_config_file('not_here/', about_page) }.to \
40
+ raise_error.with_message("Can't find the _config.yml or the _site directory! Please create these files it!")
41
+ end
42
+
43
+ it 'raise an error if config file does not exists' do
44
+ expect { subject.check_directory_and_config_file(site_dir, 'not_there.txt') }.to \
45
+ raise_error.with_message("Can't find the _config.yml or the _site directory! Please create these files it!")
46
+ end
47
+
48
+ it 'raise no error if dir and config file exists' do
49
+ expect { subject.check_directory_and_config_file(site_dir, about_page) }.not_to \
50
+ raise_error.with_message("Can't find the _config.yml or the _site directory! Please create these files it!")
51
+ end
52
+ end
53
+
54
+ describe '#traverse' do
55
+ it 'harvest all the information of html files for the given directory' do
56
+ file = 'test.html'
57
+ allow(file)
58
+ expect(Dir).to receive(:glob).with('test/**/*').and_yield file
59
+
60
+ file_content = '<a href="/index.html">wikimatze</a>'
61
+ expect(File).to receive(:open).with(file).and_return(file_content)
62
+
63
+ expected_result = ['wikimatze']
64
+ expect(subject.traverse('//a', [], 'test')).to eql expected_result
65
+ end
66
+
67
+ it 'will not harvest information for text files only the given directory' do
68
+ file = 'test.txt'
69
+ allow(file)
70
+ expect(Dir).to receive(:glob).with('test/**/*').and_yield file
71
+
72
+ expect(File).to_not receive(:open).with(file)
73
+ expect(subject.traverse('//a', [], 'test')).to be_nil
74
+ end
75
+ end
76
+
77
+ describe '#write_config' do
78
+ it 'write results into file' do
79
+ file = double(File)
80
+
81
+ expect(File).to receive(:open).with(file, 'w').and_yield file
82
+ expect(file).to receive(:puts).with('Hello config')
83
+ expect(file).to receive(:close)
84
+
85
+ subject.write_config(file, 'Hello config')
86
+ end
87
+ end
88
+
89
+ describe '#output_count' do
90
+ it 'returns the number of arguments in the given array' do
91
+ test_array = %w[1 2 3]
92
+ expect(subject.output_count(test_array)).to eql 3
93
+ end
94
+
95
+ it 'returns the number of arguments in the given array and remove duplicates' do
96
+ test_aray = [1, 1, 2, 2, 3, 3]
97
+ expect(subject.output_count(test_aray)).to eql 3
98
+ end
99
+ end
100
+
101
+ describe '#harvest' do
102
+ it 'find all links' do
103
+ file = double(File)
104
+ file_content = <<-TEXT
105
+ <a href="/index.html">wikimatze</a>
106
+ <a href="http://0.0.0:4000/contact.html" title="contact me">contact me</a>
107
+ TEXT
108
+ expect(File).to receive(:open).with(file).and_return(file_content)
109
+
110
+ result = []
111
+ expected_result = ['wikimatze', 'contact me']
112
+ expect(subject.harvest('//a', file, result)).to eql expected_result
113
+ end
114
+
115
+ it 'find all images' do
116
+ file = double(File)
117
+ file_content = <<-TEXT
118
+ <img src="/images/images-global/matthias_guenther_thumbnail_small.jpg" style="float:right;"/>
119
+ TEXT
120
+
121
+ expect(File).to receive(:open).with(file).and_return(file_content)
122
+
123
+ result = []
124
+ expected_result = ['<img src="/images/images-global/matthias_guenther_thumbnail_small.jpg" style="float:right;">']
125
+ expect(subject.harvest('//img', file, result)).to eql expected_result
126
+ end
127
+
128
+ it 'find all html pages' do
129
+ file = double(File)
130
+ file_content = <<-TEXT
131
+ test
132
+ TEXT
133
+
134
+ expect(File).to receive(:open).with(file).and_return(file_content)
135
+
136
+ expect(subject.harvest('//html', file, []).count).to eql 1
137
+ end
138
+ end
139
+ end
140
+
data/sweetie.gemspec CHANGED
@@ -1,30 +1,29 @@
1
- File.expand_path("../lib", __FILE__)
2
- require 'lib/sweetie'
1
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
2
+ require 'sweetie/version'
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = 'sweetie'
6
6
  s.version = Sweetie::VERSION
7
- s.date = Sweetie::DATE
8
-
9
- s.summary = 'Count links, images, number of html pages, and last-build time of a jekyll project.'
10
- s.description = 'Sweetie counts the links, images, number of html pages, and last-build time of a jekyll project.'
11
-
12
- s.authors = ["Matthias Guenther"]
13
- s.email = 'matthias.guenther@wikimatze.de'
14
- s.homepage = 'http://github.com/matthias-guenther/sweetie'
15
-
16
- s.required_ruby_version = '>= 1.8.7'
7
+ s.date = '2012-07-15'
8
+ s.licenses = ['MIT']
9
+ s.authors = ['Matthias Guenther']
10
+ s.email = 'matthias@wikimatze.de'
11
+ s.homepage = 'https://github.com/wikimatze/sweetie'
12
+ s.summary = 'Count links, images, number of html pages, and last-build time of a
13
+ jekyll project. In addition it can get last updates of all bitbucket
14
+ repositories of a user.'
15
+
16
+ s.description = 'Sweetie counts the links, images, number of html pages, and last-build
17
+ time of a jekyll project. In addition it can get the last changes of all
18
+ bitbuckets repositories of a user.'
17
19
  s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec}/*`.split("\n")
18
21
 
19
- s.test_files = Dir.glob "spec/**/*spec.rb"
20
- s.executables = ['sweetie']
21
-
22
- s.extra_rdoc_files = ["README.md", "doc/frames.html"]
22
+ s.extra_rdoc_files = ['README.md']
23
23
 
24
- s.add_runtime_dependency 'nokogiri', ">= 1.4.6"
25
-
26
- s.has_rdoc = true
27
-
28
- s.add_development_dependency 'rspec', ">= 2.6.0"
29
- s.add_development_dependency 'yard'
24
+ s.add_runtime_dependency 'nokogiri', '~> 1.12'
25
+ s.add_runtime_dependency 'json', '~> 2.3'
26
+ s.add_development_dependency 'rake', '~> 12.3'
27
+ s.add_development_dependency 'rspec', '~> 3.3'
30
28
  end
29
+