sweetie 1.0.1 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +30 -0
  3. data/.gitignore +4 -0
  4. data/.rubocop.yml +16 -0
  5. data/Gemfile +3 -3
  6. data/README.md +264 -44
  7. data/Rakefile +3 -2
  8. data/lib/sweetie/bitbucket.rb +27 -204
  9. data/lib/sweetie/bitbucket_stati_helper.rb +247 -0
  10. data/lib/sweetie/conversion.rb +94 -67
  11. data/lib/sweetie/helper.rb +60 -55
  12. data/lib/sweetie/version.rb +2 -1
  13. data/lib/sweetie.rb +2 -2
  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 +26 -53
  164. data/spec/sweetie_bitbucket_stati_helper_spec.rb +124 -0
  165. data/spec/sweetie_conversion_spec.rb +104 -18
  166. data/spec/sweetie_helper_spec.rb +140 -0
  167. data/sweetie.gemspec +13 -17
  168. metadata +185 -86
  169. data/.travis.yml +0 -5
  170. data/spec/source/_config.yml +0 -18
  171. data/spec/source/bitbucket/user_repositories.json +0 -161
  172. data/spec/source/bitbucket/user_repositories_expectation.txt +0 -1
@@ -0,0 +1,247 @@
1
+ require 'sweetie/helper'
2
+ require 'json'
3
+
4
+ module Sweetie
5
+ # The class which do the actuall work to get and write the repositories updates in the config file
6
+ class BitbucketStatiHelper
7
+ include Sweetie::Helper
8
+
9
+
10
+ attr_writer :config, :user
11
+
12
+ # A basic initialize method.
13
+ #
14
+ # @param config [String] The config file in which the changes should be written
15
+ # @param user [String] The name of the user for which the updates should be fetched
16
+ # @return [nil]
17
+ def initialize(config = '_config.yml', user = '')
18
+ @config = config
19
+ @user = user
20
+ end
21
+
22
+ # Grab for each repository the recent update
23
+ #
24
+ # @param json_repositories [String]: A json object of the bitbucket API response
25
+ # @return [Hash] Returns a hash of the form {<repository_name> => <last_updated>}
26
+ #
27
+ # Example:
28
+ #
29
+ # get_repositories_changes(wikimatze_json)
30
+ # # => {"pmwiki-headlineimage-recipe"=>"2011-10-29", "pmwiki-linkicons-recipe"=>"2011-10-29"}
31
+ #
32
+ def get_repositories_changes(json_repositories)
33
+ repository_hash = parse_json(json_repositories)
34
+ repositories_changsets = {}
35
+
36
+ repository_hash['values'].each do |repository|
37
+ repository_name = repository['name']
38
+ repository_last_updated = parse_timestamp(repository['updated_on'])
39
+ repositories_changsets.merge!(repository_name => repository_last_updated)
40
+ end
41
+
42
+ repositories_changsets
43
+ end
44
+
45
+ # Wrapper for calling the json_parsing from JSON library
46
+ #
47
+ # @param json [String]: A JSON format from the bitbucket API response
48
+ # @return Returns Parse JSON file as a hash 2017-06-18
49
+ #
50
+ # Example:
51
+ #
52
+ # json = {
53
+ # "user": {
54
+ # "username": "wikimatze",
55
+ # "first_name": "Matthias",
56
+ # "last_name": "Guenther",
57
+ # "resource_uri": "/1.0/users/wikimatze"
58
+ # }
59
+ # }
60
+ # parse_json(json)
61
+ # => {"user"=>{"username"=>"wikimatze", "first_name"=>"Matthias", "last_name"=>"Guenther", "resource_uri"=>"/1.0/users/wikimatze"}}
62
+ #
63
+ def parse_json(json)
64
+ JSON.parse(json)
65
+ end
66
+
67
+ # Parse a hash and write its key/value pairs in a config file for jekyll and middleman projects
68
+ #
69
+ # @param repositories [Hash]- A hash in the form {<name> => <last_updated}
70
+ # @return [nil] Writes the of the repository hash specified _config.yml by the given @config variable
71
+ #
72
+ # Example:
73
+ #
74
+ # write_repository_changes({"svn" => "2011-10-26", "pmwiki" => "2011-10-26"})
75
+ # # => svn: 2011-10-26\npmwiki: 2011-10-26
76
+ def write_repository_changes(repositories)
77
+ repositories.each do |name, last_updated|
78
+ file = File.open(@config)
79
+ text = ''
80
+ project = 'middleman'
81
+
82
+ project = 'jekyll' if File.extname(file) =~ /.yml/
83
+
84
+ name = name.to_s.tr('-', '_')
85
+ while line = file.gets
86
+ text << if line =~ /#{name}/ && project == 'middleman'
87
+ entry_text_middleman(name, last_updated) + "\n"
88
+ elsif line =~ /#{name}/ && project == 'jekyll'
89
+ entry_text_jekyll(name, last_updated) + "\n"
90
+ else
91
+ line
92
+ end
93
+ end
94
+
95
+ file.close
96
+ write_config(@config, text)
97
+ end
98
+ end
99
+
100
+ # Parse a timestamp
101
+ #
102
+ # @param timestamp [String] A string in the form 2011-04-20 11:31:39
103
+ # @return [String] A string in the format "yyyy-mm-dd"
104
+ #
105
+ # Example:
106
+ #
107
+ # parse_timestamp("2011-04-20 11:31:39")
108
+ # # => 2011-04-20
109
+ #
110
+ def parse_timestamp(timestamp)
111
+ regex = Regexp.new(/(\d+)-(\d+)-(\d+)/)
112
+ regex.match(timestamp)[0]
113
+ end
114
+
115
+ # Create a string representation of a repository entry in middleman style
116
+ #
117
+ # @param name [String] A string containing the name of the repository
118
+ # @param updated [String] A string containing the date of the last change of the repo
119
+ # @return [String] Return a string in the form "set :<name> :<last_updated>"
120
+ #
121
+ # Example:
122
+ #
123
+ # entry_text_middleman({"pmwiki" => "2011-10-26"}
124
+ # # => "set :pmwiki 2011-10-26"
125
+ def entry_text_middleman(name, updated)
126
+ "set :#{name}, #{updated}"
127
+ end
128
+
129
+ # Create a string representation of a repository entry in jekyll style
130
+ #
131
+ # @param name [String] A string containing the name of the repository
132
+ # @param updated [String] A string containing the date of the last change of the repo
133
+ # @return [String] Return a string in the form "set :<name> :<last_updated>"
134
+ #
135
+ # Example:
136
+ #
137
+ # entry_text_middleman({"pmwiki" => "2011-10-26"}
138
+ # # => "pmwiki: 2011-10-26"
139
+ def entry_text_jekyll(name, updated)
140
+ "#{name}: #{updated}"
141
+ end
142
+
143
+ # Fire up curl request to bitbucket
144
+ #
145
+ # Example:
146
+ #
147
+ # bitbucket('wikimatze')
148
+ #
149
+ # # =>
150
+ # {
151
+ # "pagelen":10,
152
+ # "values":[
153
+ # {
154
+ # "scm":"git",
155
+ # "website":"",
156
+ # "has_wiki":false,
157
+ # "name":"pmwiki-linkicons-recipe",
158
+ # "links":{
159
+ # "watchers":{
160
+ # "href":"https://api.bitbucket.org/2.0/repositories/wikimatze/pmwiki-linkicons-recipe/watchers"
161
+ # },
162
+ # "branches":{
163
+ # "href":"https://api.bitbucket.org/2.0/repositories/wikimatze/pmwiki-linkicons-recipe/refs/branches"
164
+ # },
165
+ # "tags":{
166
+ # "href":"https://api.bitbucket.org/2.0/repositories/wikimatze/pmwiki-linkicons-recipe/refs/tags"
167
+ # },
168
+ # "commits":{
169
+ # "href":"https://api.bitbucket.org/2.0/repositories/wikimatze/pmwiki-linkicons-recipe/commits"
170
+ # },
171
+ # "clone":[
172
+ # {
173
+ # "href":"https://bitbucket.org/wikimatze/pmwiki-linkicons-recipe.git",
174
+ # "name":"https"
175
+ # },
176
+ # {
177
+ # "href":"ssh://git@bitbucket.org/wikimatze/pmwiki-linkicons-recipe.git",
178
+ # "name":"ssh"
179
+ # }
180
+ # ],
181
+ # "self":{
182
+ # "href":"https://api.bitbucket.org/2.0/repositories/wikimatze/pmwiki-linkicons-recipe"
183
+ # },
184
+ # "html":{
185
+ # "href":"https://bitbucket.org/wikimatze/pmwiki-linkicons-recipe"
186
+ # },
187
+ # "avatar":{
188
+ # "href":"https://bitbucket.org/wikimatze/pmwiki-linkicons-recipe/avatar/32/"
189
+ # },
190
+ # "hooks":{
191
+ # "href":"https://api.bitbucket.org/2.0/repositories/wikimatze/pmwiki-linkicons-recipe/hooks"
192
+ # },
193
+ # "forks":{
194
+ # "href":"https://api.bitbucket.org/2.0/repositories/wikimatze/pmwiki-linkicons-recipe/forks"
195
+ # },
196
+ # "downloads":{
197
+ # "href":"https://api.bitbucket.org/2.0/repositories/wikimatze/pmwiki-linkicons-recipe/downloads"
198
+ # },
199
+ # "pullrequests":{
200
+ # "href":"https://api.bitbucket.org/2.0/repositories/wikimatze/pmwiki-linkicons-recipe/pullrequests"
201
+ # }
202
+ # },
203
+ # "fork_policy":"allow_forks",
204
+ # "uuid":"{182b19dc-334d-40d7-a65d-a85aaeb46f31}",
205
+ # "language":"",
206
+ # "created_on":"2011-10-07T21:01:39.266805+00:00",
207
+ # "mainbranch":{
208
+ # "type":"branch",
209
+ # "name":"master"
210
+ # },
211
+ # "full_name":"wikimatze/pmwiki-linkicons-recipe",
212
+ # "has_issues":false,
213
+ # "owner":{
214
+ # "username":"wikimatze",
215
+ # "display_name":"Matthias Günther",
216
+ # "type":"user",
217
+ # "uuid":"{5eab05fd-a541-43c5-a0e1-5bc9b2e2005f}",
218
+ # "links":{
219
+ # "self":{
220
+ # "href":"https://api.bitbucket.org/2.0/users/wikimatze"
221
+ # },
222
+ # "html":{
223
+ # "href":"https://bitbucket.org/wikimatze/"
224
+ # },
225
+ # "avatar":{
226
+ # "href":"https://bitbucket.org/account/wikimatze/avatar/32/"
227
+ # }
228
+ # }
229
+ # },
230
+ # "updated_on":"2017-02-26T07:09:52.048642+00:00",
231
+ # "size":431470,
232
+ # "type":"repository",
233
+ # "slug":"pmwiki-linkicons-recipe",
234
+ # "is_private":false,
235
+ # "description":""
236
+ # },
237
+ # ...
238
+ # ],
239
+ # "page":1,
240
+ # "size":9
241
+ # }
242
+ def get_repositories
243
+ `curl -s https://api.bitbucket.org/2.0/repositories/#{@user}/`
244
+ end
245
+ end
246
+ end
247
+
@@ -1,85 +1,112 @@
1
- module Sweetie
2
- require 'nokogiri'
3
- require 'sweetie/helper'
1
+ require 'nokogiri'
2
+ require 'sweetie/helper'
4
3
 
4
+ module Sweetie
5
+ # The class which can get the stati of the project including number of html pages, images, and links
5
6
  class Conversion
7
+ include Sweetie::Helper
6
8
 
7
- class << self
8
-
9
- @@config = "_config.yml"
10
- @@dir = "_site"
11
-
12
- include Sweetie::Helper
9
+ # A basic initialize method.
10
+ #
11
+ # @param dir [String] The directoy in which should search after links, images and number of HTML pages
12
+ # @param config [String] The name of the config file in which the results should be written
13
+ # @return [nil]
14
+ def initialize(dir = '_site', config = '_config.yml')
15
+ @dir = dir
16
+ @config = config
17
+ end
13
18
 
14
- # Opens the config file and search after the specified parameters.
15
- # It saves the gathered information about the build-date, the links,
16
- # the images, and the number of html-pages in the jekyll project.
17
- def conversion
18
- check_config_and_directory_file(@@config, @@dir)
19
+ # It saves the gathered information about the build-date, the links,
20
+ # the images, and the number of html-pages in the jekyll project.
21
+ #
22
+ # @return [nil]
23
+ def create_stati
24
+ check_directory_and_config_file(@dir, @config)
19
25
 
20
- file = File.open(@@config)
21
- text = ""
26
+ file = File.open(@config)
27
+ text = ''
28
+ if File.extname(file) =~ /.rb/
22
29
  while line = file.gets
23
- if line.match(/build:/)
24
- text << "build: #{build_time}\n"
25
- elsif line.match(/htmlpages:/)
26
- text << "htmlpages: #{count_all_html_pages(@@dir)}\n"
27
- elsif line.match(/images:/)
28
- text << "images: #{count_all_images(@@dir)}\n"
29
- elsif line.match(/links:/)
30
- text << "links: #{count_all_links(@@dir)}\n"
31
- else
32
- text << line
33
- end
30
+ text << if line =~ /set :build,/
31
+ "set :build, '#{build_time}'\n"
32
+ elsif line =~ /set :htmlpages,/
33
+ "set :htmlpages, #{count_all_html_pages(@dir)}\n"
34
+ elsif line =~ /set :images,/
35
+ "set :images, #{count_all_images(@dir)}\n"
36
+ elsif line =~ /set :links,/
37
+ "set :links, #{count_all_links(@dir)}\n"
38
+ else
39
+ line
40
+ end
41
+ end
42
+ else
43
+ while line = file.gets
44
+ text << if line =~ /build:/
45
+ "build: '#{build_time}'\n"
46
+ elsif line =~ /htmlpages:/
47
+ "htmlpages: #{count_all_html_pages(@dir)}\n"
48
+ elsif line =~ /images:/
49
+ "images: #{count_all_images(@dir)}\n"
50
+ elsif line =~ /links:/
51
+ "links: #{count_all_links(@dir)}\n"
52
+ else
53
+ line
54
+ end
34
55
  end
35
- file.close
36
-
37
- write_config(file, text)
38
56
  end
39
57
 
40
- # Counts the link of on html page
41
- # @param [page] the path of a html page
42
- # @return the number of unique links
43
- def count_link_of_one_page(page)
44
- perform_search_for_single_page('//a', [], page)
45
- end
58
+ file.close
46
59
 
47
- # Count the images of one html page
48
- # @param (see #self.count_link_of_one_page)
49
- # @return the number of unique images
50
- def count_images_of_one_page(page)
51
- perform_search_for_single_page('//img', [], page)
52
- end
60
+ write_config(file, text)
61
+ end
53
62
 
54
- # Counts all html pages
55
- # @param [Dir] the path of the directory
56
- # @return [Fixnum] the number of unique html pages
57
- def count_all_html_pages(dir)
58
- perform_global_search('//html', [], dir)
59
- end
63
+ # Counts the link of on html page.
64
+ #
65
+ # @param page [String] The path of a html page
66
+ # @return [Integer] The number of unique links for the given page
67
+ def count_link_of_one_page(page)
68
+ perform_search_for_single_page('//a', [], page)
69
+ end
60
70
 
61
- # Counts all the links of all html pages
62
- # @param (see #self.count_all_html_pages)
63
- # @return (see #self.count_all_html_pages)
64
- def count_all_links(dir)
65
- perform_global_search('//a', [], dir)
66
- end
71
+ # Count the images of one html page.
72
+ #
73
+ # @param page [String] The path of a html page
74
+ # @return [Integer] The number of unique images for the given page
75
+ def count_images_of_one_page(page)
76
+ perform_search_for_single_page('//img', [], page)
77
+ end
67
78
 
68
- # Counts all the images of all html pages
69
- # @param (see #self.count_all_html_pages)
70
- # @return (see #self.count_all_html_pages)
71
- def count_all_images(dir)
72
- perform_global_search('//img', [], dir)
73
- end
79
+ # Counts all html pages for the given directory.
80
+ #
81
+ # @param dir [String] The path of the directory
82
+ # @return [Integer] The number of unique html pages
83
+ def count_all_html_pages(dir)
84
+ perform_global_search('//html', [], dir)
85
+ end
74
86
 
75
- # Create the actual build time
76
- # @return [String] in the date format mm-dd-yyyy
77
- def build_time
78
- time = Time.now
79
- "#{time.month}-#{time.day}-#{time.year}"
80
- end
87
+ # Counts all the links for the given directory.
88
+ #
89
+ # @param dir [String] The path of the directory
90
+ # @return [Integer] The number of unique links for the given dir
91
+ def count_all_links(dir)
92
+ perform_global_search('//a', [], dir)
93
+ end
94
+
95
+ # Counts all the images for the given directory.
96
+ #
97
+ # @param dir [String] The path of the directory
98
+ # @return [Integer] The number of all images for the given dir
99
+ def count_all_images(dir)
100
+ perform_global_search('//img', [], dir)
81
101
  end
82
- end
83
102
 
103
+ # Create the actual build time.
104
+ #
105
+ # @return [String] in the date format mm-dd-yyyy
106
+ def build_time
107
+ time = Time.now
108
+ "#{time.month}-#{time.day}-#{time.year}"
109
+ end
110
+ end
84
111
  end
85
112
 
@@ -1,68 +1,74 @@
1
1
  module Sweetie
2
-
2
+ # The Helper module which can get the stati of the project including number of html pages, images, and links
3
3
  module Helper
4
-
5
4
  # Traverse the page after the pattern and return the number of occurences on it
6
- # @param [pattern] need for nokogiri to parse the html page
7
- # @param [array] array to save the results
8
- # @param [page] a single page which will be taken for the search
9
- def perform_search_for_single_page(pattern, array, page)
10
- harvest(pattern, page, array)
11
- output_count(array)
12
- end
13
-
14
- # Traverse the dir after the pattern and return the number of occurences in the pages
15
- # @param [pattern] need for nokogiri to parse the html page
16
- # @param [array] array to save the results
17
- # @param [dir] the main directory in which the by jekyll generated files are stored
18
- def perform_global_search(pattern, array, dir)
19
- traverse(pattern, array, dir)
20
- output_count(array)
21
- end
22
-
23
- # Traverse the jekyll directory and get the information about a specific pattern
24
- # @param [pattern] is a string for nokogiri after which the html pages should be parsed
25
- # @param [ar] is an empty Array which is used by the harvest method
26
- # @param [dir] the directory in which the html files are stored
27
- def traverse(pattern, ar, dir)
28
- Dir.glob(dir+"/**/*") do |file|
29
- next if file == '.' or file == '..' or file.include?("html~")
30
- if file.match(/(.*).html/)
31
- harvest(pattern, file, ar)
32
- end
33
- end
5
+ #
6
+ # @param pattern [String] need for nokogiri to parse the html page
7
+ # @param arr [Array] array to save the results
8
+ # @param page [String] The path to a file which will be taken for the search
9
+ def perform_search_for_single_page(pattern, arr, page)
10
+ harvest(pattern, page, arr)
11
+ output_count(arr)
34
12
  end
35
13
 
36
14
  # Traverse each html page and gather information about the specified html element
37
- # @param [pattern] important for nokogiri
38
- # @param [html] the path for the html file
39
- # @param [ar] and array which stores all the findings produces by nokogiri
40
- def harvest(pattern, html, ar)
15
+ #
16
+ # @param pattern [String] The xpath regular for Nokogiri expressions after which the HTML is grabbed
17
+ # @param html [String] An array to save the results
18
+ # @param arr [Array] An array which stores all the findings produces by nokogiri
19
+ # @return [Array] The number of found results
20
+ def harvest(pattern, html, arr)
41
21
  file = File.open(html)
42
22
  doc = Nokogiri::HTML(file)
43
23
  doc.xpath(pattern).each do |node|
44
- if pattern == "//a"
45
- ar << node.text
46
- elsif pattern == "//img" and ar.include?(node.to_s)
47
- elsif pattern == "//img"
48
- ar << node.to_s
49
- elsif pattern == "//html"
50
- ar << node
51
- else
24
+ if pattern == '//a'
25
+ arr << node.text
26
+ elsif pattern == '//img' && arr.include?(node.to_s)
27
+ elsif pattern == '//img'
28
+ arr << node.to_s
29
+ elsif pattern == '//html'
30
+ arr << node
52
31
  end
53
32
  end
54
- ar
33
+ arr
55
34
  end
56
35
 
57
36
  # Count the elements
58
- # @param [ar] is an array with all the found html parts
59
- def output_count(ar)
60
- ar.uniq.count # remove duplicates with uniq
37
+ #
38
+ # @param arr [Array] An array with all the found html parts.
39
+ # @return [Integer] The number of uniq results in the given array.
40
+ def output_count(arr)
41
+ arr.uniq.count # remove duplicates with uniq
42
+ end
43
+
44
+ # Traverse the dir after the pattern and return the number of occurences in the pages
45
+ #
46
+ # @param pattern [String] The xpath regular for Nokogiri expressions after which the HTML is grabbed.
47
+ # @param arr [Array] array to save the results.
48
+ # @param dir [String] The main directory in which the search should be performed.
49
+ # @return [Integer] The number of found results.
50
+ def perform_global_search(pattern, arr, dir)
51
+ traverse(pattern, arr, dir)
52
+ output_count(arr)
53
+ end
54
+
55
+ # Traverse the jekyll directory and get the information about a specific pattern
56
+ #
57
+ # @param pattern [String] The xpath regular for Nokogiri expressions after which the HTML is grabbed.
58
+ # @param arr [Array] array to save the results.
59
+ # @param dir [String] The directory in which the html files are stored.
60
+ def traverse(pattern, arr, dir)
61
+ Dir.glob(dir + '/**/*') do |file|
62
+ next if file == '.' || file == '..' || file.include?('html~')
63
+ harvest(pattern, file, arr) if file =~ /(.*).html/
64
+ end
61
65
  end
62
66
 
63
67
  # Write in the file the text
64
- # @param [file] is the _config.yml file of the jekyll project
65
- # @param [text] is a multiline string which will be written in the file
68
+ #
69
+ # @param file [String] The path to the config file
70
+ # @param text [String] Is a multiline string of text
71
+ # @return [nil]
66
72
  def write_config(file, text)
67
73
  File.open(file, 'w') do |file|
68
74
  file.puts text
@@ -70,16 +76,15 @@ module Sweetie
70
76
  end
71
77
  end
72
78
 
73
- # Check the existence of needed files for sweetie
74
- # @param [config] the _config.yml file
75
- # @param [dir] the directory of the generated jekyll page
76
- def check_config_and_directory_file(config, dir)
77
- if !File.exist? config or !Dir.exist? dir
79
+ # Check the existence of given directory and config
80
+ #
81
+ # @param dir [String] The directory of the files.
82
+ # @param config [String] The path to the config file.
83
+ def check_directory_and_config_file(dir = '', config = '')
84
+ if !Dir.exist?(dir) || !File.exist?(config)
78
85
  raise "Can't find the _config.yml or the _site directory! Please create these files it!"
79
86
  end
80
87
  end
81
-
82
88
  end
83
-
84
89
  end
85
90
 
@@ -1,4 +1,5 @@
1
1
  module Sweetie
2
- VERSION = "1.0.1"
2
+ # A wrapper to current sweetie gem version
3
+ VERSION = '2.0.1'.freeze
3
4
  end
4
5
 
data/lib/sweetie.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'sweetie/conversion'
2
2
  require 'sweetie/bitbucket'
3
3
 
4
- module Sweetie
4
+ # The wrapper class for the gem
5
+ module Sweetie; end
5
6
 
6
- end