sweetie 0.1.2 → 2.0.0

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 (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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c1db059c1e669df16935ce777d10950815b50a92f5358cf9b5a85d1a62c9ab5a
4
+ data.tar.gz: d4f75478d20b6a6d5a0c2394c40d1b4c01a8bd406775c00fc866f969eb4c85f4
5
+ SHA512:
6
+ metadata.gz: 844e97b5dd14342c2e7119fa03d88a95527adcb6ac08ce65041f44eb7239262ab9251ac06baead2766b9eb25b5db0396a634e2fd12dfa33ae9a3e229f2b321b1
7
+ data.tar.gz: 0a4bc5e88a63a34103fb34bf225d462b541326350553fd7af76412e1e310f0af90378cc1694ba697419c3879622665305061c57950ff0fc8b527afb8ef674419
@@ -0,0 +1,30 @@
1
+ version: 2.1
2
+ orbs:
3
+ ruby: circleci/ruby@0.1.2
4
+
5
+ jobs:
6
+ build:
7
+ parameters:
8
+ ruby-version:
9
+ type: string
10
+ docker:
11
+ - image: circleci/ruby:<< parameters.ruby-version >>
12
+ executor: ruby/default
13
+ steps:
14
+ - checkout
15
+ - run:
16
+ name: Which bundler?
17
+ command: gem install bundler:2.2.26
18
+ - ruby/bundle-install
19
+ - run:
20
+ name: Run rspec tests
21
+ command: bundle exec rspec
22
+ workflows:
23
+ build_and_test:
24
+ jobs:
25
+ - build:
26
+ matrix:
27
+ parameters:
28
+ # https://github.com/CircleCI-Public/cimg-ruby
29
+ # only supports the last three ruby versions
30
+ ruby-version: ["2.6.0", "2.6.5", "2.7.4", "3.0.2"]
data/.gitignore CHANGED
@@ -3,4 +3,7 @@
3
3
  *.gem
4
4
  *.sass-cache
5
5
  .yardoc/*
6
- sweetie
6
+ Gemfile.lock
7
+ doc/
8
+ bin/
9
+ .mucksrc
data/.rubocop.yml ADDED
@@ -0,0 +1,16 @@
1
+ Documentation:
2
+ Enabled: false
3
+
4
+ Metrics/LineLength:
5
+ Max: 150
6
+ Metrics/BlockLength:
7
+ Max: 150
8
+
9
+ Layout/TrailingBlankLines:
10
+ EnforcedStyle: final_blank_line
11
+
12
+ Style/RedundantSelf:
13
+ Enabled: false
14
+ Style/HashSyntax:
15
+ EnforcedStyle: no_mixed_keys
16
+
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'pry'
4
+
5
+ gemspec
6
+
data/README.md CHANGED
@@ -1,26 +1,303 @@
1
- Sweetie is a plugin for [jekyll](https://github.com/mojombo/jekyll) to count all links, images, pages, and the last build time on a jekyll site. You can then use this information at a any place in your jekyll project.
1
+ Sweetie is a plugin for to get statistics for [jekyll](http://jekyllrb.com/ "jekyll") and
2
+ [middleman](https://middlemanapp.com/ "middleman") projects. The statistics includes the unique number of all links,
3
+ images, pages, and the last build time of the given project. You can specify the location the generated files
4
+ (normally `_site` for jekyll and `build` for middleman apps) and of the `config` file where the changes
5
+ will be written.
2
6
 
3
7
 
4
- ## Configuration variables
5
- To get the plugin working you must add `build`, `htmlpages`, `images`, and `links` in your `_config.yml` file. _sweetie_ will save the information to this variables. You can then use them everywhere in your page with the liquid snippet for example:
8
+ It can also grab the last changes of your bitbucket repositories. You can then use the information on various places in
9
+ your project
6
10
 
7
- * `{{ site.build }}`
8
- * `{{ site.htmlpages }}`
9
- * `{{ site.images }}`
10
- * `{{ site.links }}`
11
+ [![Gem Version](https://badge.fury.io/rb/sweetie.svg)](http://badge.fury.io/rb/sweetie)
12
+ [![CircleCI](https://circleci.com/gh/wikimatze/sweetie.svg?style=svg)](https://app.circleci.com/pipelines/github/wikimatze/sweetie)
11
13
 
12
- on all of your pages.
14
+
15
+ ## Toc
16
+
17
+ - [Installation](#installation)
18
+ - [Usage create stati](#usage-create-stati)
19
+ - [Jekyll](#jekyll "Jekyll projects")
20
+ - [Configuration variables for Jekyll](#configuration-variables-for-jekyll "Configuration variables for Jekyll")
21
+ - [Middleman](#middleman "Middleman projects")
22
+ - [Configuration variables for Middleman](#configuration-variables-for-middleman "Configuration variables for Middleman")
23
+ - [Usage bitbucket repositories](#usage-bitbucket-repositories "Usage bitbucket repositories")
24
+ - [Middleman](#middleman-1 "Middleman")
25
+ - [Jekyll](#jekyll-1 "Jekyll")
13
26
 
14
27
 
15
28
  ## Installation
16
- Put the `sweetie.rb` file in the root of your jekyll project and then run the file to update your `_config.yml`file. To get the right calculated number of html pages, your pages must have the file ending *.html.
17
29
 
30
+ ```sh
31
+ $ gem install sweetie
32
+ ```
33
+
34
+
35
+ ## Usage create stati
36
+
37
+ ### Jekyll
38
+
39
+ The easiest way is to add `require 'sweetie'` on the top of your Rakefile.
40
+
41
+ Before you build your page, you can run a rake task to update the status information of a page:
42
+
43
+
44
+ ```ruby
45
+ require 'sweetie'
46
+
47
+ desc 'write stats in the _config.yml file'
48
+ task :create_stati do
49
+ sweetie = Sweetie::Conversion.new('./site', './_config.yml')
50
+ sweetie.create_stati
51
+ end
52
+ ```
53
+
54
+
55
+ Make sure that the following fields are set in your `_config.yml`:
56
+
57
+
58
+ ```yml
59
+ build:
60
+ htmlpages:
61
+ images:
62
+ links:
63
+ ```
64
+
65
+
66
+ After running the script, the changes in `_config.yml` will look like:
67
+
68
+
69
+ ```ruby
70
+ build: 6-18-2017
71
+ htmlpages: 600
72
+ images: 20
73
+ links: 271
74
+ ```
75
+
76
+
77
+ ### Configuration variables for Jekyll
78
+
79
+ You can use the `build`, `htmlpages`, `images`, and `links` variables defined in your `_config.yml` file everywhere in your page with the liquid snippet for example:
80
+
81
+
82
+ - `{{ site.build }}`
83
+ - `{{ site.htmlpages }}`
84
+ - `{{ site.images }}`
85
+ - `{{ site.links }}`
86
+
87
+
88
+ If you also make use of [Usage for Bitbucket repositories](#usage-for-bitbucket-repositories "Usage for Bitbucket repositories") you can also use the last update value for your repositories:
89
+
90
+
91
+ ```html
92
+ <section class="lastupdate">
93
+ Last update {{ site.git }}
94
+ </section>
95
+ ...
96
+
97
+
98
+ <section class="lastupdate">
99
+ Last update {{ site.pmwiki-twitter-recipe }}
100
+ </section>
101
+ ...
102
+ ```
103
+
104
+
105
+ will result the following html:
106
+
107
+
108
+ ```html
109
+ <h3 id="git">Git</h3>
110
+
111
+ <section class="lastupdate">
112
+ Last update 2011-10-16
113
+ </section>
114
+
115
+
116
+ <h3 id="twitter">Twitter</h3>
117
+
118
+ <section class="lastupdate">
119
+ Last update 2011-10-16
120
+ </section>
121
+ ```
122
+
123
+
124
+
125
+ ### Middleman
126
+
127
+ The easiest way is to add `require 'sweetie'` on the top of your Rakefile.
128
+
129
+ Before you build your page, you can run a rake task to update the status information of a page:
130
+
131
+
132
+ ```ruby
133
+ require 'sweetie'
134
+
135
+ desc 'write stats in the config.rb file'
136
+ task :create_stati do
137
+ sweetie = Sweetie::Conversion.new('./build', './config.rb')
138
+ sweetie.create_stati
139
+ end
140
+ ```
141
+
142
+
143
+ Make sure that the following fields are set in your `config.rb`:
144
+
145
+
146
+ ```yml
147
+ set :build,
148
+ set :images,
149
+ set :htmlpages,
150
+ set :links,
151
+ ```
152
+
153
+
154
+ After running the script, the changes in `config.rb` will look like for example:
155
+
156
+
157
+ ```ruby
158
+ set :build, 6-18-2017
159
+ set :images, 75
160
+ set :htmlpages, 111
161
+ set :links, 694
162
+ ```
163
+
164
+
165
+ ### Configuration variables for Middleman
166
+
167
+ You can use the `build`, `htmlpages`, `images`, and `links` variables defined in your `_config.yml` file everywhere in your page with the erb snippet for example:
168
+
169
+
170
+ - `<%= config[:build] %>
171
+ - `<%= config[:htmlpages] %>
172
+ - `<%= config[:images] %>
173
+ - `<%= config[:links] %>
174
+
175
+
176
+ If you also make use of [Usage for Bitbucket repositories](#usage-for-bitbucket-repositories "Usage for Bitbucket repositories") you can also use the last update value for your repositories:
177
+
178
+
179
+ ```html
180
+
181
+ <section class="lastupdate">
182
+ Last update <%= config[:git] %>
183
+ </section>
184
+ ...
185
+
186
+
187
+ <section class="lastupdate">
188
+ Last update <%= config[:pmwiki_twitter_recipe %>
189
+ </section>
190
+ ...
191
+ ```
192
+
193
+
194
+ will result the following html:
195
+
196
+
197
+ ```html
198
+ <h3 id="git">Git</h3>
199
+
200
+ <section class="lastupdate">
201
+ Last update 2011-10-16
202
+ </section>
203
+
204
+
205
+ <h3 id="twitter">Twitter</h3>
206
+
207
+ <section class="lastupdate">
208
+ Last update 2011-10-16
209
+ </section>
210
+ ```
211
+
212
+
213
+ ## Usage Bitbucket repositories
214
+
215
+ ### Middleman
216
+
217
+ The easiest way is to add `require 'sweetie'` on the top of your Rakefile.
218
+
219
+ Before you build your page, you can run a rake task to update the status of the repositories for the given `config-file` and `username`:
220
+
221
+
222
+ ```ruby
223
+ require 'sweetie'
224
+
225
+ desc 'write repositories stats in the config.rb file'
226
+ task :create_bitbucket do
227
+ stati_helper = Sweetie::BitbucketStatiHelper.new('./config.rb', 'wikimatze')
228
+ bitbucket = Sweetie::Bitbucket.new(stati_helper)
229
+ bitbucket.update_stati
230
+ end
231
+ ```
232
+
233
+ Please note that you have to change `wikimatze` to your bitbucket user name
234
+
235
+
236
+ ```ruby
237
+ set :pmwiki_dropcaps_recipe,
238
+ set :pmwiki_syntaxlove_recipe,
239
+ set :pmwiki_twitter_recipe,
240
+ set :pmwiki_linkicons_recipe,
241
+ set :pmwiki_headlineimage_recipe,
242
+ ```
243
+
244
+
245
+ After running the script, the names in `config.rb` above will be changed to:
246
+
247
+
248
+ ```ruby
249
+ set :pmwiki_dropcaps_recipe, 2017-02-24
250
+ set :pmwiki_syntaxlove_recipe, 2017-02-26
251
+ set :pmwiki_twitter_recipe, 2017-02-26
252
+ set :pmwiki_linkicons_recipe, 2017-02-26
253
+ set :pmwiki_headlineimage_recipe, 2017-02-25
254
+ ```
255
+
256
+
257
+ ### Jekyll
258
+
259
+ The easiest way is to add `require 'sweetie'` on the top of your Rakefile.
260
+
261
+ Before you build your page, you can run a rake task to update the status of the repositories for the given `config-file` and `username`:
262
+
263
+
264
+ ```ruby
265
+ require 'sweetie'
266
+
267
+ desc 'write repositories stats in the _config.yml file'
268
+ desc 'write stats in the _config.yml'
269
+ task :create_bitbucket do
270
+ stati_helper = Sweetie::BitbucketStatiHelper.new('./_config.yml', 'wikimatze')
271
+ bitbucket = Sweetie::Bitbucket.new(stati_helper)
272
+ bitbucket.update_stati
273
+ end
274
+ ```
275
+
276
+ Please note that you have to change `wikimatze` to your bitbucket user name
277
+
278
+
279
+ ```ruby
280
+ set :pmwiki_dropcaps_recipe,
281
+ set :pmwiki_syntaxlove_recipe,
282
+ set :pmwiki_twitter_recipe,
283
+ set :pmwiki_linkicons_recipe,
284
+ set :pmwiki_headlineimage_recipe,
285
+ ```
286
+
287
+
288
+ After running the script, the names in `config.rb` above will be changed to:
289
+
290
+
291
+ ```ruby
292
+ set :pmwiki_dropcaps_recipe, 2017-02-24
293
+ set :pmwiki_syntaxlove_recipe, 2017-02-26
294
+ set :pmwiki_twitter_recipe, 2017-02-26
295
+ set :pmwiki_linkicons_recipe, 2017-02-26
296
+ set :pmwiki_headlineimage_recipe, 2017-02-25
297
+ ```
18
298
 
19
- ## Possible usage
20
- Before you deploy your page, you can run the `sweetie.rb` in a rake task:
299
+ ## License
21
300
 
22
- desc "deploy"
23
- task :create_stati do
24
- system("sweetie")
25
- end
301
+ This software is licensed under the [MIT license](http://en.wikipedia.org/wiki/MIT_License).
26
302
 
303
+ © 2011-2019 Matthias Günther <matze@wikimatze.de>.
data/Rakefile CHANGED
@@ -1,7 +1,8 @@
1
1
  task :spec do
2
- Dir.glob("spec/**/*_spec.rb") do |file|
3
- system ("rspec #{file}")
2
+ Dir.glob('spec/**/*_spec.rb') do |file|
3
+ system "rspec #{file}"
4
4
  end
5
5
  end
6
6
 
7
7
  task :default => :spec
8
+
@@ -0,0 +1,30 @@
1
+ require 'sweetie/helper'
2
+ require 'sweetie/bitbucket_stati_helper'
3
+ require 'json'
4
+
5
+ module Sweetie
6
+ # The class to get the repositorie updates from Bitbucket
7
+ class Bitbucket
8
+ include Sweetie::Helper
9
+
10
+ # A basic initialize method.
11
+ #
12
+ # @param bitbucket_stati_helper [BitbucketStatiHelper]
13
+ # @return [BitbucketStatiHelper]
14
+ def initialize(bitbucket_stati_helper)
15
+ @bitbucket_stati_helper = bitbucket_stati_helper
16
+ end
17
+
18
+ # Wrapper to start all the other methods which will use methods
19
+ # to write the changes of the bitbucket in the config file,
20
+ # which can be configured in the BitbucketStatiHelper
21
+ #
22
+ # @return [nil]
23
+ def update_stati
24
+ json_repositories = @bitbucket_stati_helper.get_repositories
25
+ repositories_change_hashs = @bitbucket_stati_helper.get_repositories_changes(json_repositories)
26
+ @bitbucket_stati_helper.write_repository_changes(repositories_change_hashs)
27
+ end
28
+ end
29
+ end
30
+
@@ -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
+