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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9c72e80cb6e5b88d94022d6e9dc791ebb2d5534c7f8ffd1ef66ffd8ec0286cea
4
+ data.tar.gz: 2ff9a301c9c745313a7c9c09f2f7349286750fd628d960d4d7f4cbacc90bb164
5
+ SHA512:
6
+ metadata.gz: aa682817dc4378b914556e08cde7c491695e76168681ed2692146376dd0cfa6656cf2aab5cc50d404af40f595c64d0ce5278fd179e66136437bfaa334004a747
7
+ data.tar.gz: 142557f220374c97cfb200ad706f8288c4d4d2fd5be287d202683c8ec0e43314311b168e6f52bf4b1eb0421088303765924bed4f72cfc7560163a4c7d814787a
@@ -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,3 +3,7 @@
3
3
  *.gem
4
4
  *.sass-cache
5
5
  .yardoc/*
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 CHANGED
@@ -1,6 +1,6 @@
1
- source "http://rubygems.org"
1
+ source 'http://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in sweetie.gemspec
4
- gemspec
3
+ gem 'pry'
5
4
 
5
+ gemspec
6
6
 
data/README.md CHANGED
@@ -1,37 +1,83 @@
1
- Sweetie is a plugin for [jekyll](https://github.com/mojombo/jekyll) to count all links, images,
2
- pages, and the last build time on a jekyll site. You can then use this information at a any place in
3
- your jekyll project.[![Travis](http://travis-ci.org/matthias-guenther/sweetie.png)](http://travis-ci.org/matthias-guenther/sweetie)
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.
4
6
 
5
7
 
6
- ## Installation ##
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
7
10
 
8
- gem install sweetie
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)
9
13
 
10
14
 
11
- ## Possible usage ##
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")
26
+
27
+
28
+ ## Installation
29
+
30
+ ```sh
31
+ $ gem install sweetie
32
+ ```
33
+
34
+
35
+ ## Usage create stati
36
+
37
+ ### Jekyll
12
38
 
13
39
  The easiest way is to add `require 'sweetie'` on the top of your Rakefile.
14
40
 
15
41
  Before you build your page, you can run a rake task to update the status information of a page:
16
42
 
17
- desc 'write stats in the _config.yml'
18
- task :create_stati do
19
- Sweetie::Conversion.conversion
20
- end
21
43
 
22
- A similar task can be implemented for the bitbucket repositories:
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
+
23
57
 
24
- desc 'write stats in the _config.yml'
25
- task :create_bitbucket do
26
- Sweetie::Bitbucket.bitbucket("yourname")
27
- end
58
+ ```yml
59
+ build:
60
+ htmlpages:
61
+ images:
62
+ links:
63
+ ```
28
64
 
29
65
 
30
- ## Configuration variables of jekyll ##
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:
31
80
 
32
- Call the class method `Sweetie::Bitbucket.bitbucket("yourname")` and it will automatically append
33
- the `build`, `htmlpages`, `images`, and `links` in your `_config.yml` file. You can then use them
34
- everywhere in your page with the liquid snippet for example:
35
81
 
36
82
  - `{{ site.build }}`
37
83
  - `{{ site.htmlpages }}`
@@ -39,45 +85,219 @@ everywhere in your page with the liquid snippet for example:
39
85
  - `{{ site.links }}`
40
86
 
41
87
 
42
- ## Last changes of bitbucket repository ##
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
+ ```
43
152
 
44
- Call the class method `Sweetie::Bitbucket.bitbucket("yourname")` and it will automatically append
45
- the repository name an the last change of the repository in your `_config.yml`. Here is an example:
46
153
 
47
- git: 2011-10-16
48
- pmwiki-twitter-recipe: 2011-10-29
154
+ After running the script, the changes in `config.rb` will look like for example:
49
155
 
50
- You can then use this variables in the view of your jekyll project with the liquid template. For
51
- example:
52
156
 
53
- ### git ###
157
+ ```ruby
158
+ set :build, 6-18-2017
159
+ set :images, 75
160
+ set :htmlpages, 111
161
+ set :links, 694
162
+ ```
54
163
 
55
- <section class="lastupdate">
56
- Last update {{ site.git }}
57
- </section>
58
- ...
59
164
 
165
+ ### Configuration variables for Middleman
60
166
 
61
- ### Twitter ###
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
+ ```
62
192
 
63
- <section class="lastupdate">
64
- Last update {{ site.pmwiki-twitter-recipe }}
65
- </section>
66
- ...
67
193
 
68
194
  will result the following html:
69
195
 
70
196
 
71
- <h3 id="git">Git</h3>
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:
72
289
 
73
- <section class="lastupdate">
74
- Last update 2011-10-16
75
- </section>
76
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
+ ```
77
298
 
78
- <h3 id="twitter">Twitter</h3>
299
+ ## License
79
300
 
80
- <section class="lastupdate">
81
- Last update 2011-10-16
82
- </section>
301
+ This software is licensed under the [MIT license](http://en.wikipedia.org/wiki/MIT_License).
83
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
+
@@ -1,207 +1,30 @@
1
- module Sweetie
2
- require 'sweetie/helper'
1
+ require 'sweetie/helper'
2
+ require 'sweetie/bitbucket_stati_helper'
3
+ require 'json'
3
4
 
5
+ module Sweetie
6
+ # The class to get the repositorie updates from Bitbucket
4
7
  class Bitbucket
5
- require 'json'
6
-
7
- @@config = "_config.yml"
8
-
9
- class << self
10
- include Sweetie::Helper
11
-
12
- # getter for class variable @@config
13
- def config
14
- @@config
15
- end
16
-
17
- # setter for the class variable @@config
18
- def config=(config)
19
- @@config = config
20
- end
21
-
22
- # Public: Wrapper to start all the other methods
23
- #
24
- # user - The String of the bitbucket user
25
- #
26
- # Example:
27
- #
28
- # bitbucket('wikimatze')
29
- #
30
- # Returns nothing but write the changes in the _config.yml file
31
- def bitbucket(user)
32
- json_repositories = get_repositories(user)
33
- repositories_change_hashs = get_repositories_changes(json_repositories)
34
- write_repository_changes(repositories_change_hashs)
35
- end
36
-
37
- # Public: Fire up curl request to bitbucket
38
- #
39
- # user - The String of the bitbucket user
40
- #
41
- # Example:
42
- #
43
- # bitbucket('wikimatze')
44
- #
45
- # # =>
46
- # {
47
- # "repositories": [
48
- # {
49
- # "scm": "git",
50
- # "has_wiki": false,
51
- # "last_updated": "2012-07-01 07:03:08",
52
- # "creator": null,
53
- # "created_on": "2012-07-01 07:03:08",
54
- # "owner": "wikimatze",
55
- # "logo": null,
56
- # "email_mailinglist": "",
57
- # "is_mq": false,
58
- # "size": 580,
59
- # "read_only": false,
60
- # "fork_of": null,
61
- # "mq_of": null,
62
- # "followers_count": 1,
63
- # "state": "available",
64
- # "utc_created_on": "2012-07-01 05:03:08+00:00",
65
- # "website": "",
66
- # "description": "",
67
- # "has_issues": false,
68
- # "is_fork": false,
69
- # "slug": "knoppix-6-01",
70
- # "is_private": false,
71
- # "name": "knoppix-6-01",
72
- # "language": "",
73
- # "utc_last_updated": "2012-07-01 05:03:08+00:00",
74
- # "email_writers": true,
75
- # "no_public_forks": false,
76
- # "resource_uri": "/1.0/repositories/wikimatze/knoppix-6-01"
77
- # },
78
- # ... other repositories
79
- # }
80
- # ],
81
- # "user": {
82
- # "username": "wikimatze",
83
- # "first_name": "Matthias",
84
- # "last_name": "Guenther",
85
- # "avatar": "https://secure.gravatar.com/avatar/208673d619b63131cbfd7205366ad16e?d=identicon&s=32",
86
- # "resource_uri": "/1.0/users/wikimatze"
87
- # }
88
- # }
89
- #
90
- # Returns a json representation the specified user
91
- def get_repositories(user)
92
- `curl -s https://api.bitbucket.org/1.0/users/#{user}/`
93
- end
94
-
95
- # Public: Grab for each repository the recent update
96
- #
97
- # json_repositories: A json object of the bitbucket API response
98
- #
99
- # Example:
100
- #
101
- # get_repositories_changes(wikimatze_json)
102
- # # => {"pmwiki-headlineimage-recipe"=>"2011-10-29", "pmwiki-linkicons-recipe"=>"2011-10-29"}
103
- #
104
- # Returns a hash of the form {repository_name => last_updated}
105
- def get_repositories_changes(json_repositories)
106
- repository_hash = parse_json(json_repositories)
107
- repositories_changsets = {}
108
-
109
- repository_hash["repositories"].each do |repository|
110
- repository_name = repository['name']
111
- repository_last_updated = parse_timestamp(repository['last_updated'])
112
- repositories_changsets.merge!({repository_name => repository_last_updated})
113
- end
114
-
115
- repositories_changsets
116
- end
117
-
118
- # Public: Wrapper for calling the json_parsing
119
- #
120
- # file: A String in JSON format
121
- #
122
- # Example:
123
- #
124
- # json = {
125
- # "user": {
126
- # "username": "wikimatze",
127
- # "first_name": "Matthias",
128
- # "last_name": "Guenther",
129
- # "resource_uri": "/1.0/users/wikimatze"
130
- # }
131
- # }
132
-
133
- # parse_json(json)
134
- # # => {"user"=>{"username"=>"wikimatze", "first_name"=>"Matthias", "last_name"=>"Guenther", "resource_uri"=>"/1.0/users/wikimatze"}}
135
- #
136
- # Returns Parse JSON file to format be read by ruby
137
- def parse_json(json)
138
- JSON.parse(json)
139
- end
140
-
141
- # Public: Parse a timestamp in a wanted format
142
- #
143
- # timestamp - A string in the form 2011-04-20 11:31:39
144
- #
145
- # Example:
146
- #
147
- # parse_timestamp("2011-04-20 11:31:39")
148
- # # => 2011-04-20
149
- #
150
- # Returns a string in the format "yyyy-mm-dd"
151
- def parse_timestamp(timestamp)
152
- regex = Regexp.new(/(\d+)-(\d+)-(\d+)/)
153
- regex.match(timestamp)[0]
154
- end
155
-
156
- # Public: Parse a hash and write its key/value pairs in a file
157
- #
158
- # repositories - A hash in the form {<name> => <last_updated}
159
- #
160
- # Example:
161
- #
162
- # write_repository_changes({"svn" => "2011-10-26", "pmwiki" => "2011-10-26"})
163
- # # => svn: 2011-10-26\npmwiki: 2011-10-26
164
- #
165
- # Returns nothing but writes the information in the specified _config.yml file
166
- def write_repository_changes(repositories)
167
- repositories.each do |name, last_updated|
168
- file = File.open(@@config)
169
- text = ""
170
- match = false
171
- while line = file.gets
172
- if line.match(/#{name}/)
173
- match = true
174
- # create string and replace this line with the new changes
175
- text << entry_text(name, last_updated) + "\n"
176
- else
177
- text << line
178
- end
179
- end
180
-
181
- # append the name if it is not in there
182
- text << entry_text(name, last_updated) unless match
183
-
184
- file.close
185
- write_config(@@config, text)
186
- end
187
- end
188
-
189
- # Public: Create a string representation of a repository entry
190
- #
191
- # name - A string containing the name of the repository
192
- # last_updated - A string containing the date of the last change of the repo
193
- #
194
- # Example:
195
- #
196
- # entry_text({"pmwiki" => "2011-10-26"}
197
- # # => "pmwiki: 2011-10-26"
198
- #
199
- # Return a string in the form "<name>: <last_updated>"
200
- def entry_text(name, last_updated)
201
- "#{name}: #{last_updated}"
202
- end
203
-
204
- end # self
205
- end # Bitbucket
206
- end # Sweetie
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
207
30