olelo 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (282) hide show
  1. data/.gitignore +10 -0
  2. data/.gitmodules +3 -0
  3. data/Gemfile +3 -0
  4. data/README.markdown +104 -0
  5. data/Rakefile +92 -0
  6. data/bin/olelo +5 -0
  7. data/config.ru +86 -0
  8. data/config/aspects.rb +256 -0
  9. data/config/config.yml.default +154 -0
  10. data/config/initializers/00-mime_types.rb +29 -0
  11. data/config/initializers/01-slim.rb +2 -0
  12. data/config/interwiki.yml +11 -0
  13. data/doc/AUTHORS +7 -0
  14. data/doc/LICENSE +22 -0
  15. data/lib/olelo.rb +39 -0
  16. data/lib/olelo/application.rb +294 -0
  17. data/lib/olelo/attributes.rb +285 -0
  18. data/lib/olelo/config.rb +88 -0
  19. data/lib/olelo/extensions.rb +252 -0
  20. data/lib/olelo/helper.rb +290 -0
  21. data/lib/olelo/hooks.rb +142 -0
  22. data/lib/olelo/html_safe.rb +29 -0
  23. data/lib/olelo/initializer.rb +76 -0
  24. data/lib/olelo/locale.rb +63 -0
  25. data/lib/olelo/locale.yml +284 -0
  26. data/lib/olelo/menu.rb +101 -0
  27. data/lib/olelo/middleware/blacklist.rb +25 -0
  28. data/lib/olelo/middleware/degrade_mime_type.rb +19 -0
  29. data/lib/olelo/middleware/flash.rb +97 -0
  30. data/lib/olelo/middleware/force_encoding.rb +41 -0
  31. data/lib/olelo/page.rb +266 -0
  32. data/lib/olelo/patch.rb +311 -0
  33. data/lib/olelo/plugin.rb +188 -0
  34. data/lib/olelo/repository.rb +225 -0
  35. data/lib/olelo/routing.rb +223 -0
  36. data/lib/olelo/templates.rb +30 -0
  37. data/lib/olelo/user.rb +132 -0
  38. data/lib/olelo/util.rb +233 -0
  39. data/lib/olelo/version.rb +3 -0
  40. data/lib/olelo/virtualfs.rb +161 -0
  41. data/lib/rack/olelo_patches.rb +33 -0
  42. data/lib/rack/relative_redirect.rb +44 -0
  43. data/lib/rack/static_cache.rb +93 -0
  44. data/lib/yard/addons.rb +1 -0
  45. data/lib/yard/addons/hook_handler.rb +25 -0
  46. data/lib/yard/addons/override_tag.rb +14 -0
  47. data/lib/yard/addons/route_handler.rb +33 -0
  48. data/lib/yard/addons/sanitize_anchor.rb +16 -0
  49. data/olelo.gemspec +31 -0
  50. data/plugins/aspects/changelog.rb +45 -0
  51. data/plugins/aspects/documentbrowser.rb +57 -0
  52. data/plugins/aspects/download.rb +11 -0
  53. data/plugins/aspects/highlight.rb +8 -0
  54. data/plugins/aspects/image.rb +41 -0
  55. data/plugins/aspects/imageinfo.rb +64 -0
  56. data/plugins/aspects/locale.yml +60 -0
  57. data/plugins/aspects/main.rb +199 -0
  58. data/plugins/aspects/pageinfo.rb +37 -0
  59. data/plugins/aspects/source.rb +6 -0
  60. data/plugins/aspects/subpages.rb +44 -0
  61. data/plugins/aspects/text.rb +9 -0
  62. data/plugins/blog/blog.css +1 -0
  63. data/plugins/blog/blog.scss +37 -0
  64. data/plugins/blog/locale.yml +12 -0
  65. data/plugins/blog/main.rb +85 -0
  66. data/plugins/editor/locale.yml +18 -0
  67. data/plugins/editor/markup/main.rb +3 -0
  68. data/plugins/editor/markup/script.js +10 -0
  69. data/plugins/editor/markup/script/00-jquery.textselection.js +267 -0
  70. data/plugins/editor/markup/script/01-olelo.markupeditor.js +116 -0
  71. data/plugins/editor/markup/script/init.js +10 -0
  72. data/plugins/editor/preview.rb +52 -0
  73. data/plugins/editor/recaptcha.rb +56 -0
  74. data/plugins/filters/creole.rb +37 -0
  75. data/plugins/filters/disposition.rb +9 -0
  76. data/plugins/filters/editsection.rb +67 -0
  77. data/plugins/filters/fix_img_tag.rb +16 -0
  78. data/plugins/filters/html_wrapper.rb +12 -0
  79. data/plugins/filters/interwiki.rb +19 -0
  80. data/plugins/filters/link_classifier.rb +26 -0
  81. data/plugins/filters/locale.yml +15 -0
  82. data/plugins/filters/main.rb +202 -0
  83. data/plugins/filters/markdown_nowiki.rb +15 -0
  84. data/plugins/filters/numbering.xsl +93 -0
  85. data/plugins/filters/orgmode.rb +6 -0
  86. data/plugins/filters/rubypants.rb +6 -0
  87. data/plugins/filters/s5/main.rb +32 -0
  88. data/plugins/filters/s5/s5.xsl +118 -0
  89. data/plugins/filters/tilt.rb +17 -0
  90. data/plugins/filters/toc.rb +50 -0
  91. data/plugins/filters/xhtml2latex.xsl +232 -0
  92. data/plugins/filters/xslt.rb +22 -0
  93. data/plugins/gallery/gallery.css +1 -0
  94. data/plugins/gallery/gallery.scss +28 -0
  95. data/plugins/gallery/main.rb +34 -0
  96. data/plugins/misc/fancybox/images/blank.gif +0 -0
  97. data/plugins/misc/fancybox/images/fancy_close.png +0 -0
  98. data/plugins/misc/fancybox/images/fancy_loading.png +0 -0
  99. data/plugins/misc/fancybox/images/fancy_nav_left.png +0 -0
  100. data/plugins/misc/fancybox/images/fancy_nav_right.png +0 -0
  101. data/plugins/misc/fancybox/images/fancy_shadow_e.png +0 -0
  102. data/plugins/misc/fancybox/images/fancy_shadow_n.png +0 -0
  103. data/plugins/misc/fancybox/images/fancy_shadow_ne.png +0 -0
  104. data/plugins/misc/fancybox/images/fancy_shadow_nw.png +0 -0
  105. data/plugins/misc/fancybox/images/fancy_shadow_s.png +0 -0
  106. data/plugins/misc/fancybox/images/fancy_shadow_se.png +0 -0
  107. data/plugins/misc/fancybox/images/fancy_shadow_sw.png +0 -0
  108. data/plugins/misc/fancybox/images/fancy_shadow_w.png +0 -0
  109. data/plugins/misc/fancybox/images/fancy_title_left.png +0 -0
  110. data/plugins/misc/fancybox/images/fancy_title_main.png +0 -0
  111. data/plugins/misc/fancybox/images/fancy_title_over.png +0 -0
  112. data/plugins/misc/fancybox/images/fancy_title_right.png +0 -0
  113. data/plugins/misc/fancybox/images/fancybox-x.png +0 -0
  114. data/plugins/misc/fancybox/images/fancybox-y.png +0 -0
  115. data/plugins/misc/fancybox/images/fancybox.png +0 -0
  116. data/plugins/misc/fancybox/jquery.fancybox.css +1 -0
  117. data/plugins/misc/fancybox/jquery.fancybox.scss +323 -0
  118. data/plugins/misc/fancybox/main.rb +4 -0
  119. data/plugins/misc/fancybox/script.js +37 -0
  120. data/plugins/misc/fancybox/script/00-jquery.mousewheel.js +84 -0
  121. data/plugins/misc/fancybox/script/01-jquery.easing.js +205 -0
  122. data/plugins/misc/fancybox/script/02-jquery.fancybox.js +1156 -0
  123. data/plugins/misc/fancybox/script/init.js +18 -0
  124. data/plugins/misc/system.rb +192 -0
  125. data/plugins/misc/variables.rb +29 -0
  126. data/plugins/misc/webdav.rb +45 -0
  127. data/plugins/repositories/git_grep.rb +69 -0
  128. data/plugins/repositories/gitrb_repository.rb +204 -0
  129. data/plugins/repositories/locale.yml +12 -0
  130. data/plugins/repositories/rugged_repository.rb +454 -0
  131. data/plugins/security/acl.rb +57 -0
  132. data/plugins/security/basic_auth.rb +21 -0
  133. data/plugins/security/locale.yml +21 -0
  134. data/plugins/security/persistent_login.rb +32 -0
  135. data/plugins/security/portal.rb +28 -0
  136. data/plugins/security/private_wiki.rb +24 -0
  137. data/plugins/security/readonly_wiki.rb +25 -0
  138. data/plugins/security/stack.rb +20 -0
  139. data/plugins/security/yamlfile.rb +66 -0
  140. data/plugins/tags/code.rb +6 -0
  141. data/plugins/tags/footnotes.rb +35 -0
  142. data/plugins/tags/gist-embed.css +123 -0
  143. data/plugins/tags/gist.rb +13 -0
  144. data/plugins/tags/html.rb +57 -0
  145. data/plugins/tags/include.rb +20 -0
  146. data/plugins/tags/main.rb +353 -0
  147. data/plugins/tags/math.rb +117 -0
  148. data/plugins/tags/scripting.rb +64 -0
  149. data/plugins/tags/sort.rb +7 -0
  150. data/plugins/tags/tabs.rb +20 -0
  151. data/plugins/treeview/images/collapsed.png +0 -0
  152. data/plugins/treeview/images/expanded.png +0 -0
  153. data/plugins/treeview/images/menu.png +0 -0
  154. data/plugins/treeview/images/tree.png +0 -0
  155. data/plugins/treeview/images/wait.gif +0 -0
  156. data/plugins/treeview/main.rb +16 -0
  157. data/plugins/treeview/script.js +5 -0
  158. data/plugins/treeview/script/00-jquery.treeview.js +164 -0
  159. data/plugins/treeview/script/init.js +25 -0
  160. data/plugins/treeview/treeview.css +1 -0
  161. data/plugins/treeview/treeview.scss +113 -0
  162. data/plugins/utils/assets.rb +74 -0
  163. data/plugins/utils/cache.rb +53 -0
  164. data/plugins/utils/image_magick.rb +34 -0
  165. data/plugins/utils/pygments.css +1 -0
  166. data/plugins/utils/pygments.rb +50 -0
  167. data/plugins/utils/pygments.scss +83 -0
  168. data/plugins/utils/semaphore.rb +50 -0
  169. data/plugins/utils/shell.rb +45 -0
  170. data/plugins/utils/store.rb +315 -0
  171. data/plugins/utils/worker.rb +36 -0
  172. data/plugins/utils/xml.rb +29 -0
  173. data/static/images/favicon.png +0 -0
  174. data/static/script.js +267 -0
  175. data/static/script/00-json2.js +486 -0
  176. data/static/script/01-jstorage.js +217 -0
  177. data/static/script/02-jquery.js +9440 -0
  178. data/static/script/03-jquery.ui.core.js +337 -0
  179. data/static/script/04-jquery.ui.widget.js +502 -0
  180. data/static/script/05-jquery.ui.position.js +517 -0
  181. data/static/script/06-jquery.ui.menu.js +609 -0
  182. data/static/script/07-jquery.ui.autocomplete.js +601 -0
  183. data/static/script/08-olelo.i18n.js +37 -0
  184. data/static/script/09-olelo.unsaved.js +68 -0
  185. data/static/script/10-olelo.historytable.js +40 -0
  186. data/static/script/11-olelo.pagination.js +18 -0
  187. data/static/script/13-olelo.tabwidget.js +57 -0
  188. data/static/script/14-olelo.timeago.js +70 -0
  189. data/static/script/15-olelo.underliner.js +31 -0
  190. data/static/script/16-olelo.ui.combobox.js +32 -0
  191. data/static/script/init.js +48 -0
  192. data/static/themes/atlantis/constants.scss +15 -0
  193. data/static/themes/atlantis/iehacks.scss +38 -0
  194. data/static/themes/atlantis/images/actions/delete.png +0 -0
  195. data/static/themes/atlantis/images/actions/edit.png +0 -0
  196. data/static/themes/atlantis/images/actions/history.png +0 -0
  197. data/static/themes/atlantis/images/actions/home.png +0 -0
  198. data/static/themes/atlantis/images/actions/move.png +0 -0
  199. data/static/themes/atlantis/images/actions/new.png +0 -0
  200. data/static/themes/atlantis/images/actions/page.png +0 -0
  201. data/static/themes/atlantis/images/bg/button.png +0 -0
  202. data/static/themes/atlantis/images/bg/container.png +0 -0
  203. data/static/themes/atlantis/images/bg/content.png +0 -0
  204. data/static/themes/atlantis/images/bg/footer.png +0 -0
  205. data/static/themes/atlantis/images/bg/header.jpg +0 -0
  206. data/static/themes/atlantis/images/bg/header.orig.jpg +0 -0
  207. data/static/themes/atlantis/images/bg/header_gray.jpg +0 -0
  208. data/static/themes/atlantis/images/bug.png +0 -0
  209. data/static/themes/atlantis/images/filetypes/7z.png +0 -0
  210. data/static/themes/atlantis/images/filetypes/_archive.png +0 -0
  211. data/static/themes/atlantis/images/filetypes/_audio.png +0 -0
  212. data/static/themes/atlantis/images/filetypes/_code.png +0 -0
  213. data/static/themes/atlantis/images/filetypes/_linux.png +0 -0
  214. data/static/themes/atlantis/images/filetypes/_picture.png +0 -0
  215. data/static/themes/atlantis/images/filetypes/_video.png +0 -0
  216. data/static/themes/atlantis/images/filetypes/bz2.png +0 -0
  217. data/static/themes/atlantis/images/filetypes/doc.png +0 -0
  218. data/static/themes/atlantis/images/filetypes/flac.png +0 -0
  219. data/static/themes/atlantis/images/filetypes/gz.png +0 -0
  220. data/static/themes/atlantis/images/filetypes/html.png +0 -0
  221. data/static/themes/atlantis/images/filetypes/java.png +0 -0
  222. data/static/themes/atlantis/images/filetypes/jpg.png +0 -0
  223. data/static/themes/atlantis/images/filetypes/midi.png +0 -0
  224. data/static/themes/atlantis/images/filetypes/mp3.png +0 -0
  225. data/static/themes/atlantis/images/filetypes/ogg.png +0 -0
  226. data/static/themes/atlantis/images/filetypes/pdf.png +0 -0
  227. data/static/themes/atlantis/images/filetypes/php.png +0 -0
  228. data/static/themes/atlantis/images/filetypes/png.png +0 -0
  229. data/static/themes/atlantis/images/filetypes/ppt.png +0 -0
  230. data/static/themes/atlantis/images/filetypes/psd.png +0 -0
  231. data/static/themes/atlantis/images/filetypes/rar.png +0 -0
  232. data/static/themes/atlantis/images/filetypes/rb.png +0 -0
  233. data/static/themes/atlantis/images/filetypes/sh.png +0 -0
  234. data/static/themes/atlantis/images/filetypes/tar.png +0 -0
  235. data/static/themes/atlantis/images/filetypes/txt.png +0 -0
  236. data/static/themes/atlantis/images/filetypes/wma.png +0 -0
  237. data/static/themes/atlantis/images/filetypes/xls.png +0 -0
  238. data/static/themes/atlantis/images/filetypes/zip.png +0 -0
  239. data/static/themes/atlantis/images/folder.png +0 -0
  240. data/static/themes/atlantis/images/folder_open.png +0 -0
  241. data/static/themes/atlantis/images/loading.gif +0 -0
  242. data/static/themes/atlantis/images/loading.xcf +0 -0
  243. data/static/themes/atlantis/images/not_found.png +0 -0
  244. data/static/themes/atlantis/images/page.png +0 -0
  245. data/static/themes/atlantis/images/search.png +0 -0
  246. data/static/themes/atlantis/layout.scss +115 -0
  247. data/static/themes/atlantis/menu.scss +99 -0
  248. data/static/themes/atlantis/print.scss +129 -0
  249. data/static/themes/atlantis/screen.scss +495 -0
  250. data/static/themes/atlantis/style.css +3 -0
  251. data/static/themes/lib/autocomplete.scss +39 -0
  252. data/static/themes/lib/headlines.scss +10 -0
  253. data/static/themes/lib/horizontal-list.scss +31 -0
  254. data/static/themes/lib/patch.scss +88 -0
  255. data/static/themes/lib/reset.scss +114 -0
  256. data/static/themes/lib/rounded.scss +46 -0
  257. data/static/themes/lib/shadow.scss +14 -0
  258. data/test/config_test.rb +28 -0
  259. data/test/factory_test.rb +29 -0
  260. data/test/hash_extensions_test.rb +16 -0
  261. data/test/helper.rb +38 -0
  262. data/test/hooks_test.rb +85 -0
  263. data/test/object_extensions_test.rb +20 -0
  264. data/test/page_test.rb +168 -0
  265. data/test/request_test.rb +166 -0
  266. data/test/string_extensions_test.rb +32 -0
  267. data/test/templates_test.rb +39 -0
  268. data/test/util_test.rb +71 -0
  269. data/views/changes.slim +22 -0
  270. data/views/compare.slim +8 -0
  271. data/views/delete.slim +9 -0
  272. data/views/deleted.slim +2 -0
  273. data/views/edit.slim +65 -0
  274. data/views/error.slim +6 -0
  275. data/views/history.slim +20 -0
  276. data/views/layout.slim +38 -0
  277. data/views/login.slim +37 -0
  278. data/views/move.slim +10 -0
  279. data/views/not_found.slim +6 -0
  280. data/views/profile.slim +26 -0
  281. data/views/show.slim +9 -0
  282. metadata +488 -0
@@ -0,0 +1,57 @@
1
+ description 'Access control lists'
2
+
3
+ class ::Olelo::Page
4
+ attributes do
5
+ group :acl do
6
+ list :write
7
+ list :create
8
+ list :delete
9
+ end
10
+ end
11
+
12
+ # New page is writable if parent allows page creation
13
+ # Existing page is writable if page is writable
14
+ def writable?
15
+ new? ? (root? || parent.access?(:create)) : access?(:write)
16
+ end
17
+
18
+ # Page is deletable if parent is writable
19
+ def deletable?
20
+ parent && parent.access?(:delete)
21
+ end
22
+
23
+ # Page is movable if page is deletable and destination is writable
24
+ def movable?(destination = nil)
25
+ deletable? && (!destination || (Page.find(destination) || Page.new(destination)).writable?)
26
+ end
27
+
28
+ def access?(type)
29
+ acl = saved_attributes['acl'] || {}
30
+ names = [*acl[type.to_s]].compact
31
+ names.empty? ||
32
+ names.include?(User.current.name) ||
33
+ User.current.groups.any? {|group| names.include?('@'+group) }
34
+ end
35
+
36
+ before :save, 999 do
37
+ raise(AccessDenied) if !writable?
38
+ end
39
+
40
+ before :delete, 999 do
41
+ raise(AccessDenied) if !deletable?
42
+ end
43
+
44
+ before :move, 999 do |destination|
45
+ raise(AccessDenied) if !movable?(destination)
46
+ end
47
+ end
48
+
49
+ class ::Olelo::Application
50
+ hook :menu, 999 do |menu|
51
+ if menu.name == :actions && page
52
+ menu.remove('edit/delete') if !page.deletable?
53
+ menu.remove('edit/move') if !page.movable?
54
+ menu['edit'].options.delete(:href) if menu['edit'] && !page.writable?
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,21 @@
1
+ description 'HTTP basic authentication'
2
+ require 'rack/auth/basic'
3
+
4
+ class ::Olelo::Application
5
+ hook :auto_login do
6
+ if params[:auth] && !User.current
7
+ auth = Rack::Auth::Basic::Request.new(env)
8
+ unauthorized if !auth.provided?
9
+ halt :bad_request if !auth.basic?
10
+ User.current = User.authenticate(auth.credentials[0], auth.credentials[1]) rescue nil
11
+ unauthorized if !User.current
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def unauthorized
18
+ response['WWW-Authenticate'] = 'Basic realm="Olelo"'
19
+ halt :unauthorized
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ en:
2
+ attribute_acl_write: 'Write access'
3
+ attribute_acl_create: 'Create subpages'
4
+ attribute_acl_delete: 'Delete subpages'
5
+ group_acl: 'Access control lists'
6
+ persistent_login: 'Persistent login'
7
+ login_first: 'You have to login first'
8
+ de:
9
+ attribute_acl_write: 'Schreibzugriff'
10
+ attribute_acl_create: 'Unterseiten anlegen'
11
+ attribute_acl_delete: 'Unterseiten löschen'
12
+ group_acl: 'Zugriffslisten'
13
+ persistent_login: 'Dauerhaft anmelden'
14
+ login_first: 'Sie müssen sich zuerst anmelden'
15
+ cs_CZ:
16
+ attribute_acl_write: 'Právo zápisu'
17
+ attribute_acl_create: 'Vytvářet podstránky'
18
+ attribute_acl_delete: 'Mazat podstránky'
19
+ group_acl: 'Řízení přístupů (ACL)'
20
+ persistent_login: 'Trvalé přihlášení'
21
+ login_first: 'Musíte se nejprve přihlásit'
@@ -0,0 +1,32 @@
1
+ description 'Persistent login'
2
+
3
+ class ::Olelo::Application
4
+ TOKEN_NAME = 'olelo.token'
5
+ TOKEN_LIFETIME = 24*60*60*365
6
+
7
+ hook :auto_login do
8
+ if !User.current
9
+ token = request.cookies[TOKEN_NAME]
10
+ if token
11
+ user, hash = token.split('-', 2)
12
+ User.current = User.find(user) if sha256(user + Config['rack.session_secret']) == hash
13
+ end
14
+ end
15
+ end
16
+
17
+ before :login_buttons do
18
+ %{<input type="checkbox" name="persistent" id="persistent" value="1"/>
19
+ <label for="persistent">#{escape_html :persistent_login.t}</label><br/>}
20
+ end
21
+
22
+ after :action do |method, path|
23
+ if path == '/login'
24
+ if User.logged_in? && params[:persistent]
25
+ token = "#{User.current.name}-#{sha256(User.current.name + Config['rack.session_secret'])}"
26
+ response.set_cookie(TOKEN_NAME, :value => token, :expires => Time.now + TOKEN_LIFETIME)
27
+ end
28
+ elsif path == '/logout'
29
+ response.delete_cookie(TOKEN_NAME)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,28 @@
1
+ description 'Proprietary web portal based user storage'
2
+ require 'open-uri'
3
+ require 'openssl'
4
+
5
+ class PortalService < User::Service
6
+ def initialize(config)
7
+ @url = config[:url]
8
+ end
9
+
10
+ # @override
11
+ def authenticate(name, password)
12
+ xml = open(@url,
13
+ :ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE,
14
+ :http_basic_authentication => [name, password]).read
15
+ # User data is exposed via REST/XML-API
16
+ doc = Nokogiri::XML(xml)
17
+ email = (doc/'person/email').text
18
+ name = (doc/'person/user/name').text
19
+ groups = (doc/'person/groups/group/name').to_a.map(&:text)
20
+ raise AuthenticationError if name.blank?
21
+ email = "#{name}@localhost" if email.blank?
22
+ User.new(name, email, groups)
23
+ rescue
24
+ raise AuthenticationError, :wrong_user_or_pw.t
25
+ end
26
+ end
27
+
28
+ User::Service.register :portal, PortalService
@@ -0,0 +1,24 @@
1
+ description 'Forbid anonymous access, redirect to login'
2
+
3
+ class ::Olelo::Application
4
+ PUBLIC_ACCESS = %w(/login)
5
+
6
+ redefine_method :include_page do |path|
7
+ User.logged_in? ? super(path) : ''
8
+ end
9
+
10
+ hook :menu, 999 do |menu|
11
+ menu.clear if menu.name == :actions && !User.logged_in?
12
+ end
13
+
14
+ before :routing do
15
+ if !User.logged_in?
16
+ if !PUBLIC_ACCESS.include?(request.path_info)
17
+ flash.error :login_first.t
18
+ session[:olelo_goto] = request.path_info if request.get? && request.path_info !~ %r{^/_/}
19
+ redirect build_path(:login)
20
+ end
21
+ @disable_assets = true
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ description 'Read-only installation (editable only if logged in)'
2
+
3
+ class ::Olelo::Page
4
+ before(:save, 999) do
5
+ raise(AccessDenied) if !User.logged_in?
6
+ end
7
+
8
+ before(:delete, 999) do
9
+ raise(AccessDenied) if !User.logged_in?
10
+ end
11
+
12
+ before(:move, 999) do |destination|
13
+ raise(AccessDenied) if !User.logged_in?
14
+ end
15
+ end
16
+
17
+ class ::Olelo::Application
18
+ hook :render, 999 do |name, xml, layout|
19
+ xml.gsub!(/<a[^>]+class="[^"]*editsection.*?<\/a>/, '') if !User.logged_in?
20
+ end
21
+
22
+ hook :menu, 999 do |menu|
23
+ menu.remove(:edit) if menu.name == :actions && !User.logged_in?
24
+ end
25
+ end
@@ -0,0 +1,20 @@
1
+ description 'Authentication service stack'
2
+
3
+ class StackService < User::Service
4
+ def initialize(config)
5
+ @stack = config.map do |name|
6
+ User::Service[name].new(Config['authentication'][name])
7
+ end
8
+ end
9
+
10
+ # @override
11
+ def authenticate(name, password)
12
+ @stack.any? do |service|
13
+ user = service.authenticate(name, password) rescue nil
14
+ return user if user
15
+ end
16
+ raise AuthenticationError, :wrong_user_or_pw.t
17
+ end
18
+ end
19
+
20
+ User::Service.register :stack, StackService
@@ -0,0 +1,66 @@
1
+ description 'YAML based user storage'
2
+ require 'yaml/store'
3
+
4
+ class YamlfileService < User::Service
5
+ def initialize(config)
6
+ FileUtils.mkpath(File.dirname(config[:store]))
7
+ @store = ::YAML::Store.new(config[:store])
8
+ end
9
+
10
+ # @override
11
+ def find(name)
12
+ @store.transaction(true) do |store|
13
+ user = store[name]
14
+ user && User.new(name, user['email'], user['groups'])
15
+ end
16
+ end
17
+
18
+ # @override
19
+ def authenticate(name, password)
20
+ @store.transaction(true) do |store|
21
+ user = store[name]
22
+ raise AuthenticationError, :wrong_user_or_pw.t if !user || user['password'] != crypt(password)
23
+ User.new(name, user['email'], user['groups'])
24
+ end
25
+ end
26
+
27
+ # @override
28
+ def create(user, password)
29
+ @store.transaction do |store|
30
+ raise :user_already_exists.t(:name => user.name) if store[user.name]
31
+ store[user.name] = {
32
+ 'email' => user.email,
33
+ 'password' => crypt(password),
34
+ 'groups' => user.groups.to_a
35
+ }
36
+ end
37
+ end
38
+
39
+ # @override
40
+ def update(user)
41
+ @store.transaction do |store|
42
+ raise NameError, "User #{user.name} not found" if !store[user.name]
43
+ store[user.name]['email'] = user.email
44
+ store[user.name]['groups'] = user.groups.to_a
45
+ end
46
+ end
47
+
48
+ # @override
49
+ def change_password(user, oldpassword, password)
50
+ @store.transaction do |store|
51
+ check do |errors|
52
+ errors << 'User not found' if !store[user.name]
53
+ errors << :wrong_password.t if crypt(oldpassword) != store[user.name]['password']
54
+ end
55
+ store[user.name]['password'] = crypt(password)
56
+ end
57
+ end
58
+
59
+ private
60
+
61
+ def crypt(s)
62
+ s.blank? ? s : sha256(s)
63
+ end
64
+ end
65
+
66
+ User::Service.register :yamlfile, YamlfileService
@@ -0,0 +1,6 @@
1
+ description 'Code tag with syntax highlighting'
2
+ dependencies 'utils/pygments'
3
+
4
+ Tag.define :code, :requires => :lang do |context, attrs, content|
5
+ Pygments.pygmentize(content, attrs['lang'])
6
+ end
@@ -0,0 +1,35 @@
1
+ description 'Footnote support'
2
+
3
+ Tag.define :ref, :optional => :name, :description => 'Create footnote' do |context, attrs, content|
4
+ footnotes = context[:footnotes] ||= []
5
+ hash = context[:footnotes_hash] ||= {}
6
+ name = attrs['name']
7
+ if content.blank?
8
+ raise(ArgumentError, 'Attribute name missing') if name.blank?
9
+ raise(NameError, "Footnote #{name} not found") if !hash.include?(name)
10
+ note_id = hash[name]
11
+ ref_id = "#{note_id}_#{footnotes[note_id-1][2].size + 1}"
12
+ footnotes[note_id-1][2] << ref_id
13
+ else
14
+ note_id = ref_id = footnotes.size + 1
15
+ content = subfilter(context.subcontext, content)
16
+ footnotes << [note_id, content.gsub(/^\s*<p>\s*|\s*<\/p>\s*$/, ''), [ref_id]]
17
+ hash[name] = note_id if !name.blank?
18
+ end
19
+ %{<a class="ref" id="ref#{ref_id}" href="#note#{note_id}">[#{note_id}]</a>}
20
+ end
21
+
22
+ Tag.define :references, :description => 'Print all footnotes' do |context, attrs|
23
+ footnotes = context[:footnotes]
24
+ render :footnotes, :locals => {:footnotes => footnotes} if footnotes
25
+ end
26
+
27
+ __END__
28
+
29
+ @@ footnotes.slim
30
+ ol
31
+ - footnotes.each do |id, note, refs|
32
+ li id="note#{id}"
33
+ - refs.each do |ref|
34
+ a.backref ref="#ref#{ref}" ↑
35
+ == note
@@ -0,0 +1,123 @@
1
+ .gist {
2
+ color: #000;
3
+ }
4
+
5
+ .gist div {
6
+ padding: 0;
7
+ margin: 0;
8
+ }
9
+
10
+ .gist .gist-file {
11
+ border: 1px solid #dedede; /* gray */
12
+ font-family: Monaco, "Courier New", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace;
13
+ margin-bottom: 1em;
14
+ }
15
+
16
+ .gist .gist-file .gist-meta {
17
+ overflow: hidden;
18
+ font-size: 85%;
19
+ padding: .5em;
20
+ color: #666;
21
+ background-color: #eaeaea;
22
+ }
23
+
24
+ .gist .gist-file .gist-meta a {
25
+ color: #369;
26
+ }
27
+
28
+ .gist .gist-file .gist-meta a:visited {
29
+ color: #737;
30
+ }
31
+
32
+ .gist .gist-file .gist-data {
33
+ overflow: auto;
34
+ word-wrap: normal;
35
+ background-color: #f8f8ff;
36
+ border-bottom: 1px solid #ddd;
37
+ font-size: 100%;
38
+ }
39
+
40
+ .gist .gist-file .gist-data pre {
41
+ font-family: 'Bitstream Vera Sans Mono', 'Courier', monospace;
42
+ background: transparent !important;
43
+ margin: 0 !important;
44
+ border: none !important;
45
+ padding: .25em .5em .5em .5em !important;
46
+ }
47
+
48
+ .gist .gist-file .gist-data .gist-highlight {
49
+ background: transparent !important;
50
+ }
51
+
52
+ .gist .gist-file .gist-data .gist-line-numbers {
53
+ background-color: #ececec;
54
+ color: #aaa;
55
+ border-right: 1px solid #ddd;
56
+ text-align: right;
57
+ }
58
+
59
+ .gist .gist-file .gist-data .gist-line-numbers span {
60
+ clear: right;
61
+ display: block;
62
+ }
63
+
64
+ .gist-syntax { background: #ffffff; }
65
+ .gist-syntax .c { color: #999988; font-style: italic } /* Comment */
66
+ .gist-syntax .err { color: #a61717; background-color: #e3d2d2 } /* Error */
67
+ .gist-syntax .k { color: #000000; font-weight: bold } /* Keyword */
68
+ .gist-syntax .o { color: #000000; font-weight: bold } /* Operator */
69
+ .gist-syntax .cm { color: #999988; font-style: italic } /* Comment.Multiline */
70
+ .gist-syntax .cp { color: #999999; font-weight: bold } /* Comment.Preproc */
71
+ .gist-syntax .c1 { color: #999988; font-style: italic } /* Comment.Single */
72
+ .gist-syntax .cs { color: #999999; font-weight: bold; font-style: italic } /* Comment.Special */
73
+ .gist-syntax .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
74
+ .gist-syntax .gd .x { color: #000000; background-color: #ffaaaa } /* Generic.Deleted.Specific */
75
+ .gist-syntax .ge { color: #000000; font-style: italic } /* Generic.Emph */
76
+ .gist-syntax .gr { color: #aa0000 } /* Generic.Error */
77
+ .gist-syntax .gh { color: #999999 } /* Generic.Heading */
78
+ .gist-syntax .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
79
+ .gist-syntax .gi .x { color: #000000; background-color: #aaffaa } /* Generic.Inserted.Specific */
80
+ .gist-syntax .go { color: #888888 } /* Generic.Output */
81
+ .gist-syntax .gp { color: #555555 } /* Generic.Prompt */
82
+ .gist-syntax .gs { font-weight: bold } /* Generic.Strong */
83
+ .gist-syntax .gu { color: #aaaaaa } /* Generic.Subheading */
84
+ .gist-syntax .gt { color: #aa0000 } /* Generic.Traceback */
85
+ .gist-syntax .kc { color: #000000; font-weight: bold } /* Keyword.Constant */
86
+ .gist-syntax .kd { color: #000000; font-weight: bold } /* Keyword.Declaration */
87
+ .gist-syntax .kp { color: #000000; font-weight: bold } /* Keyword.Pseudo */
88
+ .gist-syntax .kr { color: #000000; font-weight: bold } /* Keyword.Reserved */
89
+ .gist-syntax .kt { color: #445588; font-weight: bold } /* Keyword.Type */
90
+ .gist-syntax .m { color: #009999 } /* Literal.Number */
91
+ .gist-syntax .s { color: #d14 } /* Literal.String */
92
+ .gist-syntax .na { color: #008080 } /* Name.Attribute */
93
+ .gist-syntax .nb { color: #0086B3 } /* Name.Builtin */
94
+ .gist-syntax .nc { color: #445588; font-weight: bold } /* Name.Class */
95
+ .gist-syntax .no { color: #008080 } /* Name.Constant */
96
+ .gist-syntax .ni { color: #800080 } /* Name.Entity */
97
+ .gist-syntax .ne { color: #990000; font-weight: bold } /* Name.Exception */
98
+ .gist-syntax .nf { color: #990000; font-weight: bold } /* Name.Function */
99
+ .gist-syntax .nn { color: #555555 } /* Name.Namespace */
100
+ .gist-syntax .nt { color: #000080 } /* Name.Tag */
101
+ .gist-syntax .nv { color: #008080 } /* Name.Variable */
102
+ .gist-syntax .ow { color: #000000; font-weight: bold } /* Operator.Word */
103
+ .gist-syntax .w { color: #bbbbbb } /* Text.Whitespace */
104
+ .gist-syntax .mf { color: #009999 } /* Literal.Number.Float */
105
+ .gist-syntax .mh { color: #009999 } /* Literal.Number.Hex */
106
+ .gist-syntax .mi { color: #009999 } /* Literal.Number.Integer */
107
+ .gist-syntax .mo { color: #009999 } /* Literal.Number.Oct */
108
+ .gist-syntax .sb { color: #d14 } /* Literal.String.Backtick */
109
+ .gist-syntax .sc { color: #d14 } /* Literal.String.Char */
110
+ .gist-syntax .sd { color: #d14 } /* Literal.String.Doc */
111
+ .gist-syntax .s2 { color: #d14 } /* Literal.String.Double */
112
+ .gist-syntax .se { color: #d14 } /* Literal.String.Escape */
113
+ .gist-syntax .sh { color: #d14 } /* Literal.String.Heredoc */
114
+ .gist-syntax .si { color: #d14 } /* Literal.String.Interpol */
115
+ .gist-syntax .sx { color: #d14 } /* Literal.String.Other */
116
+ .gist-syntax .sr { color: #009926 } /* Literal.String.Regex */
117
+ .gist-syntax .s1 { color: #d14 } /* Literal.String.Single */
118
+ .gist-syntax .ss { color: #990073 } /* Literal.String.Symbol */
119
+ .gist-syntax .bp { color: #999999 } /* Name.Builtin.Pseudo */
120
+ .gist-syntax .vc { color: #008080 } /* Name.Variable.Class */
121
+ .gist-syntax .vg { color: #008080 } /* Name.Variable.Global */
122
+ .gist-syntax .vi { color: #008080 } /* Name.Variable.Instance */
123
+ .gist-syntax .il { color: #009999 } /* Literal.Number.Integer.Long */