formol 0.0.4

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 (226) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +147 -0
  3. data/Rakefile +29 -0
  4. data/app/assets/images/formol/read.png +0 -0
  5. data/app/assets/images/formol/unread.png +0 -0
  6. data/app/assets/javascripts/formol/admin/categories.js.coffee +55 -0
  7. data/app/assets/javascripts/formol/admin/forums.js +2 -0
  8. data/app/assets/javascripts/formol/application.js +9 -0
  9. data/app/assets/javascripts/formol/categories.js +2 -0
  10. data/app/assets/javascripts/formol/forums.js +2 -0
  11. data/app/assets/javascripts/formol/poll_votes.js +2 -0
  12. data/app/assets/javascripts/formol/posts.js.coffee +9 -0
  13. data/app/assets/javascripts/formol/preferences.js +2 -0
  14. data/app/assets/javascripts/formol/subscriptions.js.coffee +13 -0
  15. data/app/assets/javascripts/formol/topics.js.coffee +54 -0
  16. data/app/assets/javascripts/lib/jquery.prevent_double_submit.js.coffee +11 -0
  17. data/app/assets/javascripts/markitup/jquery.markitup.js +593 -0
  18. data/app/assets/javascripts/markitup/sets/markdown/set.js +53 -0
  19. data/app/assets/stylesheets/form_struct.css.scss +39 -0
  20. data/app/assets/stylesheets/formol/admin/categories.css.scss +30 -0
  21. data/app/assets/stylesheets/formol/admin/forums.css +4 -0
  22. data/app/assets/stylesheets/formol/categories.css.scss +3 -0
  23. data/app/assets/stylesheets/formol/development.css +4 -0
  24. data/app/assets/stylesheets/formol/forums.css.scss +3 -0
  25. data/app/assets/stylesheets/formol/mixins/after_clear.css.scss +7 -0
  26. data/app/assets/stylesheets/formol/partials/breadcrumb.css.scss +9 -0
  27. data/app/assets/stylesheets/formol/partials/categories/list.css.scss +101 -0
  28. data/app/assets/stylesheets/formol/partials/formol_lists.css.scss +6 -0
  29. data/app/assets/stylesheets/formol/partials/forums/list.css.scss +97 -0
  30. data/app/assets/stylesheets/formol/partials/polls/poll.css.scss +9 -0
  31. data/app/assets/stylesheets/formol/partials/posts/post.css.scss +116 -0
  32. data/app/assets/stylesheets/formol/posts.css.scss +8 -0
  33. data/app/assets/stylesheets/formol/topics.css.scss +42 -0
  34. data/app/assets/stylesheets/markitup/sets/markdown/images/block_code.png +0 -0
  35. data/app/assets/stylesheets/markitup/sets/markdown/images/bold.png +0 -0
  36. data/app/assets/stylesheets/markitup/sets/markdown/images/code.png +0 -0
  37. data/app/assets/stylesheets/markitup/sets/markdown/images/h1.png +0 -0
  38. data/app/assets/stylesheets/markitup/sets/markdown/images/h2.png +0 -0
  39. data/app/assets/stylesheets/markitup/sets/markdown/images/h3.png +0 -0
  40. data/app/assets/stylesheets/markitup/sets/markdown/images/h4.png +0 -0
  41. data/app/assets/stylesheets/markitup/sets/markdown/images/h5.png +0 -0
  42. data/app/assets/stylesheets/markitup/sets/markdown/images/h6.png +0 -0
  43. data/app/assets/stylesheets/markitup/sets/markdown/images/italic.png +0 -0
  44. data/app/assets/stylesheets/markitup/sets/markdown/images/link.png +0 -0
  45. data/app/assets/stylesheets/markitup/sets/markdown/images/list-bullet.png +0 -0
  46. data/app/assets/stylesheets/markitup/sets/markdown/images/list-numeric.png +0 -0
  47. data/app/assets/stylesheets/markitup/sets/markdown/images/picture.png +0 -0
  48. data/app/assets/stylesheets/markitup/sets/markdown/images/preview.png +0 -0
  49. data/app/assets/stylesheets/markitup/sets/markdown/images/quotes.png +0 -0
  50. data/app/assets/stylesheets/markitup/sets/markdown/style.css +57 -0
  51. data/app/assets/stylesheets/markitup/skins/markitup/images/bg-container.png +0 -0
  52. data/app/assets/stylesheets/markitup/skins/markitup/images/bg-editor-bbcode.png +0 -0
  53. data/app/assets/stylesheets/markitup/skins/markitup/images/bg-editor-dotclear.png +0 -0
  54. data/app/assets/stylesheets/markitup/skins/markitup/images/bg-editor-html.png +0 -0
  55. data/app/assets/stylesheets/markitup/skins/markitup/images/bg-editor-json.png +0 -0
  56. data/app/assets/stylesheets/markitup/skins/markitup/images/bg-editor-markdown.png +0 -0
  57. data/app/assets/stylesheets/markitup/skins/markitup/images/bg-editor-textile.png +0 -0
  58. data/app/assets/stylesheets/markitup/skins/markitup/images/bg-editor-wiki.png +0 -0
  59. data/app/assets/stylesheets/markitup/skins/markitup/images/bg-editor-xml.png +0 -0
  60. data/app/assets/stylesheets/markitup/skins/markitup/images/bg-editor.png +0 -0
  61. data/app/assets/stylesheets/markitup/skins/markitup/images/handle.png +0 -0
  62. data/app/assets/stylesheets/markitup/skins/markitup/images/menu.png +0 -0
  63. data/app/assets/stylesheets/markitup/skins/markitup/images/submenu.png +0 -0
  64. data/app/assets/stylesheets/markitup/skins/markitup/style.css +147 -0
  65. data/app/assets/stylesheets/markitup/skins/simple/images/handle.png +0 -0
  66. data/app/assets/stylesheets/markitup/skins/simple/images/menu.png +0 -0
  67. data/app/assets/stylesheets/markitup/skins/simple/images/submenu.png +0 -0
  68. data/app/assets/stylesheets/markitup/skins/simple/style.css +118 -0
  69. data/app/assets/stylesheets/pygments/autumn.css +58 -0
  70. data/app/assets/stylesheets/pygments/borland.css +46 -0
  71. data/app/assets/stylesheets/pygments/bw.css +34 -0
  72. data/app/assets/stylesheets/pygments/colorful.css +61 -0
  73. data/app/assets/stylesheets/pygments/default.css +62 -0
  74. data/app/assets/stylesheets/pygments/emacs.css +61 -0
  75. data/app/assets/stylesheets/pygments/friendly.css +61 -0
  76. data/app/assets/stylesheets/pygments/fruity.css +70 -0
  77. data/app/assets/stylesheets/pygments/manni.css +61 -0
  78. data/app/assets/stylesheets/pygments/murphy.css +61 -0
  79. data/app/assets/stylesheets/pygments/native.css +70 -0
  80. data/app/assets/stylesheets/pygments/pastie.css +60 -0
  81. data/app/assets/stylesheets/pygments/perldoc.css +58 -0
  82. data/app/assets/stylesheets/pygments/tango.css +69 -0
  83. data/app/assets/stylesheets/pygments/trac.css +59 -0
  84. data/app/assets/stylesheets/pygments/vim.css +70 -0
  85. data/app/assets/stylesheets/pygments/vs.css +33 -0
  86. data/app/controllers/formol/admin/admin_controller.rb +11 -0
  87. data/app/controllers/formol/admin/categories_controller.rb +60 -0
  88. data/app/controllers/formol/admin/forums_controller.rb +56 -0
  89. data/app/controllers/formol/application_controller.rb +47 -0
  90. data/app/controllers/formol/categories_controller.rb +21 -0
  91. data/app/controllers/formol/forums_controller.rb +19 -0
  92. data/app/controllers/formol/poll_votes_controller.rb +23 -0
  93. data/app/controllers/formol/posts_controller.rb +71 -0
  94. data/app/controllers/formol/preferences_controller.rb +32 -0
  95. data/app/controllers/formol/subscriptions_controller.rb +29 -0
  96. data/app/controllers/formol/topics_controller.rb +91 -0
  97. data/app/helpers/formol/admin/categories_helper.rb +4 -0
  98. data/app/helpers/formol/admin/forums_helper.rb +4 -0
  99. data/app/helpers/formol/application_helper.rb +35 -0
  100. data/app/helpers/formol/categories_helper.rb +15 -0
  101. data/app/helpers/formol/forums_helper.rb +19 -0
  102. data/app/helpers/formol/poll_votes_helper.rb +4 -0
  103. data/app/helpers/formol/posts_helper.rb +27 -0
  104. data/app/helpers/formol/preferences_helper.rb +4 -0
  105. data/app/helpers/formol/subscriptions_helper.rb +4 -0
  106. data/app/helpers/formol/topics_helper.rb +27 -0
  107. data/app/mailers/formol/subscription_mailer.rb +13 -0
  108. data/app/models/formol/category.rb +42 -0
  109. data/app/models/formol/forum.rb +77 -0
  110. data/app/models/formol/poll/option.rb +20 -0
  111. data/app/models/formol/poll/vote.rb +32 -0
  112. data/app/models/formol/poll.rb +107 -0
  113. data/app/models/formol/post.rb +162 -0
  114. data/app/models/formol/post_observer.rb +9 -0
  115. data/app/models/formol/topic/subscription.rb +16 -0
  116. data/app/models/formol/topic/track.rb +57 -0
  117. data/app/models/formol/topic.rb +185 -0
  118. data/app/models/formol/tracking.rb +45 -0
  119. data/app/models/formol/user_preference.rb +18 -0
  120. data/app/views/formol/admin/categories/_category.html.erb +9 -0
  121. data/app/views/formol/admin/categories/_form.html.erb +8 -0
  122. data/app/views/formol/admin/categories/edit.html.erb +3 -0
  123. data/app/views/formol/admin/categories/index.html.erb +3 -0
  124. data/app/views/formol/admin/categories/new.html.erb +3 -0
  125. data/app/views/formol/admin/forums/_form.html.erb +9 -0
  126. data/app/views/formol/admin/forums/_forum.html.erb +12 -0
  127. data/app/views/formol/admin/forums/edit.html.erb +3 -0
  128. data/app/views/formol/admin/forums/new.html.erb +3 -0
  129. data/app/views/formol/categories/_category.html.erb +5 -0
  130. data/app/views/formol/categories/index.html.erb +5 -0
  131. data/app/views/formol/categories/show.html.erb +3 -0
  132. data/app/views/formol/forums/_forum.html.erb +13 -0
  133. data/app/views/formol/forums/_list.html.erb +16 -0
  134. data/app/views/formol/forums/show.html.erb +18 -0
  135. data/app/views/formol/poll/options/_form.html.erb +1 -0
  136. data/app/views/formol/poll_votes/_form.html.erb +8 -0
  137. data/app/views/formol/polls/_form.html.erb +14 -0
  138. data/app/views/formol/polls/_poll.html.erb +24 -0
  139. data/app/views/formol/posts/_form.html.erb +7 -0
  140. data/app/views/formol/posts/_last_post.html.erb +9 -0
  141. data/app/views/formol/posts/_list.html.erb +3 -0
  142. data/app/views/formol/posts/_post.html.erb +47 -0
  143. data/app/views/formol/posts/edit.html.erb +10 -0
  144. data/app/views/formol/posts/new.html.erb +14 -0
  145. data/app/views/formol/preferences/show.html.erb +11 -0
  146. data/app/views/formol/subscription_mailer/topic_reply.en.html.erb +8 -0
  147. data/app/views/formol/subscription_mailer/topic_reply.fr.html.erb +8 -0
  148. data/app/views/formol/topics/_form.html.erb +20 -0
  149. data/app/views/formol/topics/_list.html.erb +16 -0
  150. data/app/views/formol/topics/_topic.html.erb +13 -0
  151. data/app/views/formol/topics/edit.html.erb +5 -0
  152. data/app/views/formol/topics/new.html.erb +5 -0
  153. data/app/views/formol/topics/show.html.erb +25 -0
  154. data/app/views/layouts/formol/mail.html.erb +9 -0
  155. data/config/locales/en.yml +3 -0
  156. data/config/locales/formol/views/forums/en.yml +13 -0
  157. data/config/locales/formol/views/forums/fr.yml +13 -0
  158. data/config/locales/formol/views/poll_votes/en.yml +5 -0
  159. data/config/locales/formol/views/polls/en.yml.yml +5 -0
  160. data/config/locales/formol/views/posts/en.yml +23 -0
  161. data/config/locales/formol/views/posts/fr.yml +20 -0
  162. data/config/locales/formol/views/topics/en.yml +23 -0
  163. data/config/locales/formol/views/topics/fr.yml +20 -0
  164. data/config/routes.rb +31 -0
  165. data/db/migrate/20111221101158_create_formol_categories.rb +7 -0
  166. data/db/migrate/20111221111417_create_formol_forums.rb +10 -0
  167. data/db/migrate/20111221121010_create_formol_topics.rb +9 -0
  168. data/db/migrate/20111221123515_create_formol_posts.rb +9 -0
  169. data/db/migrate/20111221151653_add_index_on_tables.rb +15 -0
  170. data/db/migrate/20120103163438_add_user_to_models.rb +13 -0
  171. data/db/migrate/20120104132631_add_counter_cache_to_models.rb +12 -0
  172. data/db/migrate/20120104163741_add_pinned_to_topics.rb +7 -0
  173. data/db/migrate/20120105133522_add_position_to_categories.rb +7 -0
  174. data/db/migrate/20120105190708_add_position_to_forums.rb +7 -0
  175. data/db/migrate/20120105212559_add_lock_to_topics.rb +7 -0
  176. data/db/migrate/20120106130944_add_first_post_and_last_post_to_topics.rb +8 -0
  177. data/db/migrate/20120106192951_change_forum_description_to_string.rb +9 -0
  178. data/db/migrate/20120107012517_add_last_post_to_forum.rb +7 -0
  179. data/db/migrate/20120107122921_add_missing_indexes.rb +12 -0
  180. data/db/migrate/20120107123654_add_default_on_forum_counters.rb +10 -0
  181. data/db/migrate/20120108114030_add_views_to_topics.rb +7 -0
  182. data/db/migrate/20120108131533_create_formol_topic_tracks.rb +13 -0
  183. data/db/migrate/20120109115141_create_formol_topic_subscriptions.rb +10 -0
  184. data/db/migrate/20120109220633_create_formol_user_preferences.rb +11 -0
  185. data/db/migrate/20120109223624_add_display_signature_to_posts.rb +7 -0
  186. data/db/migrate/20120109233054_add_display_signatures_and_avatars_to_user_preferences.rb +8 -0
  187. data/db/migrate/20120110152548_create_formol_polls.rb +14 -0
  188. data/db/migrate/20120110152618_create_formol_poll_options.rb +11 -0
  189. data/db/migrate/20120110152632_create_formol_poll_votes.rb +12 -0
  190. data/lib/formol/config.rb +12 -0
  191. data/lib/formol/controllers/auth.rb +9 -0
  192. data/lib/formol/controllers/nested/has_parent_category.rb +11 -0
  193. data/lib/formol/controllers/nested/has_parent_forum.rb +11 -0
  194. data/lib/formol/controllers/nested/has_parent_topic.rb +11 -0
  195. data/lib/formol/controllers.rb +5 -0
  196. data/lib/formol/engine.rb +18 -0
  197. data/lib/formol/formatters/redcarpet/formatter.rb +36 -0
  198. data/lib/formol/formatters/redcarpet/syntax_highlighter.rb +23 -0
  199. data/lib/formol/formatters.rb +2 -0
  200. data/lib/formol/generators/install/install_generator.rb +94 -0
  201. data/lib/formol/generators/install/templates/config/formol.yml +29 -0
  202. data/lib/formol/generators/install/templates/initializer/formol.rb.erb +21 -0
  203. data/lib/formol/generators/install/templates/lib/permissions/special_rights.rb +24 -0
  204. data/lib/formol/generators/install/templates/migrations/add_formol_profile_to_users.rb.erb +7 -0
  205. data/lib/formol/generators/install/templates/migrations/add_posts_count_to_user.rb.erb +7 -0
  206. data/lib/formol/generators.rb +1 -0
  207. data/lib/formol/integration/user.rb +76 -0
  208. data/lib/formol/integration.rb +1 -0
  209. data/lib/formol/permissions/controllers.rb +30 -0
  210. data/lib/formol/permissions/manager.rb +29 -0
  211. data/lib/formol/permissions/profile.rb +24 -0
  212. data/lib/formol/permissions/profiles.rb +44 -0
  213. data/lib/formol/permissions/user.rb +29 -0
  214. data/lib/formol/permissions.rb +5 -0
  215. data/lib/formol/rails/engine.rb +81 -0
  216. data/lib/formol/rails.rb +1 -0
  217. data/lib/formol/version.rb +10 -0
  218. data/lib/formol/view_helpers/assets_helper.rb +11 -0
  219. data/lib/formol/view_helpers/format_helper.rb +12 -0
  220. data/lib/formol/view_helpers.rb +2 -0
  221. data/lib/formol/will_paginate/list_link_renderer.rb +29 -0
  222. data/lib/formol/will_paginate.rb +1 -0
  223. data/lib/formol.rb +61 -0
  224. data/lib/formol_.rb +13 -0
  225. data/lib/tasks/formol_tasks.rake +0 -0
  226. metadata +348 -0
data/config/routes.rb ADDED
@@ -0,0 +1,31 @@
1
+ Formol::Engine.routes.draw do
2
+ resources :categories, :only => [:index, :show]
3
+
4
+ resources :forums, :only => [:show] do
5
+ resources :topics, :except => [:index]
6
+ end
7
+
8
+ resources :topics do
9
+ resources :posts, :except => [:index]
10
+ resources :poll_votes, :only => [:create]
11
+
12
+ post '/subscriptions' => 'subscriptions#create'
13
+ delete '/subscriptions' => 'subscriptions#destroy'
14
+ end
15
+
16
+ resource :preference, :only => [:show, :update]
17
+
18
+ root :to => 'categories#index'
19
+
20
+ namespace :admin do
21
+ resources :categories, :except => [:show] do
22
+ put :sort, :on => :collection
23
+
24
+ resources :forums, :except => [:index, :show] do
25
+ put :reorganize, :on => :collection
26
+ end
27
+ end
28
+
29
+ root :to => 'categories#index'
30
+ end
31
+ end
@@ -0,0 +1,7 @@
1
+ class CreateFormolCategories < ActiveRecord::Migration
2
+ def change
3
+ create_table :formol_categories do |t|
4
+ t.string :label, :limit => 64
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ class CreateFormolForums < ActiveRecord::Migration
2
+ def change
3
+ create_table :formol_forums do |t|
4
+ t.belongs_to :category
5
+ t.string :label, :limit => 32
6
+ t.text :description
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ class CreateFormolTopics < ActiveRecord::Migration
2
+ def change
3
+ create_table :formol_topics do |t|
4
+ t.belongs_to :forum
5
+ t.string :title, :limit => 48
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class CreateFormolPosts < ActiveRecord::Migration
2
+ def change
3
+ create_table :formol_posts do |t|
4
+ t.belongs_to :topic
5
+ t.text :content
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ class AddIndexOnTables < ActiveRecord::Migration
2
+ def change
3
+ change_table :formol_posts do |t|
4
+ t.index :topic_id
5
+ end
6
+
7
+ change_table :formol_topics do |t|
8
+ t.index :forum_id
9
+ end
10
+
11
+ change_table :formol_forums do |t|
12
+ t.index :category_id
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ class AddUserToModels < ActiveRecord::Migration
2
+ def change
3
+ change_table :formol_posts do |t|
4
+ t.belongs_to :user
5
+ t.index :user_id
6
+ end
7
+
8
+ change_table :formol_topics do |t|
9
+ t.belongs_to :user
10
+ t.index :user_id
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ class AddCounterCacheToModels < ActiveRecord::Migration
2
+ def change
3
+ change_table :formol_forums do |t|
4
+ t.integer :topics_count
5
+ t.integer :posts_count
6
+ end
7
+
8
+ change_table :formol_topics do |t|
9
+ t.integer :posts_count
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ class AddPinnedToTopics < ActiveRecord::Migration
2
+ def change
3
+ change_table :formol_topics do |t|
4
+ t.boolean :pinned, :default => false
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ class AddPositionToCategories < ActiveRecord::Migration
2
+ def change
3
+ change_table :formol_categories do |t|
4
+ t.integer :position
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ class AddPositionToForums < ActiveRecord::Migration
2
+ def change
3
+ change_table :formol_forums do |t|
4
+ t.integer :position
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ class AddLockToTopics < ActiveRecord::Migration
2
+ def change
3
+ change_table :formol_topics do |t|
4
+ t.boolean :locked, :default => false
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ class AddFirstPostAndLastPostToTopics < ActiveRecord::Migration
2
+ def change
3
+ change_table :formol_topics do |t|
4
+ t.belongs_to :first_post
5
+ t.belongs_to :last_post
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ class ChangeForumDescriptionToString < ActiveRecord::Migration
2
+ def up
3
+ change_column :formol_forums, :description, :string, :limit => 128
4
+ end
5
+
6
+ def down
7
+ change_column :formol_forums, :description, :text
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ class AddLastPostToForum < ActiveRecord::Migration
2
+ def change
3
+ change_table :formol_forums do |t|
4
+ t.belongs_to :last_post
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ class AddMissingIndexes < ActiveRecord::Migration
2
+ def change
3
+ change_table :formol_forums do |t|
4
+ t.index :last_post_id
5
+ end
6
+
7
+ change_table :formol_topics do |t|
8
+ t.index :first_post_id
9
+ t.index :last_post_id
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ class AddDefaultOnForumCounters < ActiveRecord::Migration
2
+ def up
3
+ change_column_default :formol_forums, :topics_count, 0
4
+ change_column_default :formol_forums, :posts_count, 0
5
+ end
6
+
7
+ def down
8
+ #no need to rollback this migration
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ class AddViewsToTopics < ActiveRecord::Migration
2
+ def change
3
+ change_table :formol_topics do |t|
4
+ t.integer :views_count, :default => 0
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ class CreateFormolTopicTracks < ActiveRecord::Migration
2
+ def change
3
+ create_table :formol_topic_tracks do |t|
4
+ t.belongs_to :user
5
+ t.belongs_to :forum
6
+ t.belongs_to :topic
7
+ t.datetime :marked_at
8
+ end
9
+
10
+ add_index :formol_topic_tracks, :user_id
11
+ add_index :formol_topic_tracks, [:user_id, :forum_id]
12
+ end
13
+ end
@@ -0,0 +1,10 @@
1
+ class CreateFormolTopicSubscriptions < ActiveRecord::Migration
2
+ def change
3
+ create_table :formol_topic_subscriptions do |t|
4
+ t.belongs_to :topic
5
+ t.belongs_to :subscriber
6
+ end
7
+
8
+ add_index :formol_topic_subscriptions, [:topic_id, :subscriber_id], :unique => true
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ class CreateFormolUserPreferences < ActiveRecord::Migration
2
+ def change
3
+ create_table :formol_user_preferences do |t|
4
+ t.belongs_to :user
5
+ t.string :signature, :limit => 120
6
+ t.boolean :use_signature, :default => true
7
+ end
8
+
9
+ add_index :formol_user_preferences, :user_id, :unique => true
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ class AddDisplaySignatureToPosts < ActiveRecord::Migration
2
+ def change
3
+ change_table :formol_posts do |t|
4
+ t.boolean :display_signature
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ class AddDisplaySignaturesAndAvatarsToUserPreferences < ActiveRecord::Migration
2
+ def change
3
+ change_table :formol_user_preferences do |t|
4
+ t.boolean :display_signatures, :default => true
5
+ t.boolean :display_avatars, :default => true
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,14 @@
1
+ class CreateFormolPolls < ActiveRecord::Migration
2
+ def change
3
+ create_table :formol_polls do |t|
4
+ t.belongs_to :topic
5
+ t.string :question, :limit => 64
6
+ t.integer :duration
7
+ t.integer :max_options
8
+ t.integer :votes_count
9
+ t.datetime :created_at
10
+ end
11
+
12
+ add_index :formol_polls, :topic_id, :unique => true
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ class CreateFormolPollOptions < ActiveRecord::Migration
2
+ def change
3
+ create_table :formol_poll_options do |t|
4
+ t.belongs_to :poll
5
+ t.string :answer, :limit => 32
6
+ t.integer :votes_count
7
+ end
8
+
9
+ add_index :formol_poll_options, :poll_id
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ class CreateFormolPollVotes < ActiveRecord::Migration
2
+ def change
3
+ create_table :formol_poll_votes do |t|
4
+ t.belongs_to :option
5
+ t.belongs_to :voter
6
+ t.datetime :created_at
7
+ end
8
+
9
+ add_index :formol_poll_votes, :voter_id
10
+ add_index :formol_poll_votes, :option_id
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ module Formol
2
+ class Config < Struct.new(:user_class,
3
+ :current_user_helper_method,
4
+ :formatter,
5
+ :email_from,
6
+ :text_formatter)
7
+
8
+ def user
9
+ @user ||= user_class.constantize
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ module Formol
2
+ module Controllers
3
+ module Auth
4
+ def current_formol_user
5
+ send(Formol.config.current_user_helper_method.to_sym)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ module Formol
2
+ module Controllers
3
+ module Nested
4
+ module HasParentCategory
5
+ def category
6
+ @category ||= Formol::Category.find(params[:category_id])
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Formol
2
+ module Controllers
3
+ module Nested
4
+ module HasParentForum
5
+ def forum
6
+ @forum ||= Formol::Forum.ready_for_breadcrumb.find(params[:forum_id])
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Formol
2
+ module Controllers
3
+ module Nested
4
+ module HasParentTopic
5
+ def topic
6
+ @topic ||= Formol::Topic.ready_for_breadcrumb.find(params[:topic_id])
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ require "formol/controllers/auth"
2
+
3
+ require "formol/controllers/nested/has_parent_category"
4
+ require "formol/controllers/nested/has_parent_forum"
5
+ require "formol/controllers/nested/has_parent_topic"
@@ -0,0 +1,18 @@
1
+ module Formol
2
+ class Engine < Rails::Engine
3
+ isolate_namespace Formol
4
+
5
+ engine_name 'formol'
6
+
7
+ config.generators do |g|
8
+ g.test_framework = :rspec
9
+ end
10
+
11
+ config.i18n.railties_load_path = []
12
+
13
+ config.active_record.observers = [:'formol/post_observer']
14
+
15
+ #Needed to have proper locales organization
16
+ paths['config/locales'] << 'config/locales/**/'
17
+ end
18
+ end
@@ -0,0 +1,36 @@
1
+ require 'redcarpet'
2
+ require 'pygments.rb'
3
+
4
+ module Formol
5
+ module Formatters
6
+ module Redcarpet
7
+ class Formatter
8
+ def initialize
9
+ @renderer = SyntaxHighlighter.new(:hard_wrap => true,
10
+ :filter_html => true)
11
+ @processor = ::Redcarpet::Markdown.new(@renderer, :fenced_code_blocks => true,
12
+ :no_intra_emphasis => true,
13
+ :autolink => true,
14
+ :space_after_headers => false,
15
+ :superscript => false)
16
+ end
17
+
18
+ def to_html(text)
19
+ @processor.render(text).html_safe
20
+ end
21
+
22
+ def quote(text)
23
+ quoted_text = ""
24
+
25
+ text.split("\n").each_with_index do |l|
26
+ quoted_text << '> ' if (l.strip.blank? || l.start_with?('>'))
27
+ quoted_text << l
28
+ quoted_text << "\n"
29
+ end
30
+
31
+ quoted_text
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,23 @@
1
+ require 'redcarpet'
2
+ require 'pygments.rb'
3
+
4
+ module Formol
5
+ module Formatters
6
+ module Redcarpet
7
+ class SyntaxHighlighter < ::Redcarpet::Render::XHTML
8
+ def block_code(code, language)
9
+ title_block(language) + Pygments.highlight(code, :lexer => language,
10
+ :options => {
11
+ :linenos => 'inline'
12
+ })
13
+ end
14
+
15
+ private
16
+
17
+ def title_block(language)
18
+ %{<div class="highlight_title #{language.downcase}">#{language.downcase.capitalize}</div>}
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,2 @@
1
+ require 'formol/formatters/redcarpet/formatter'
2
+ require 'formol/formatters/redcarpet/syntax_highlighter'
@@ -0,0 +1,94 @@
1
+ require 'rails/generators'
2
+
3
+ module Formol
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+ attr_accessor :user_class, :current_user_helper
7
+
8
+ source_root File.expand_path('../templates', __FILE__)
9
+
10
+ desc 'Formol installation...'
11
+
12
+ def get_user_class
13
+ self.user_class = ask("What is you user model called? [User]")
14
+ self.user_class = 'user' if user_class.blank?
15
+
16
+ self.user_class = user_class.classify
17
+ end
18
+
19
+ def get_current_user_helper
20
+ self.current_user_helper = ask("What is the 'current_user' helper called in your main app? [current_user]")
21
+ self.current_user_helper = 'current_user' if current_user_helper.blank?
22
+ end
23
+
24
+ def install_migrations
25
+ rake 'formol:install:migrations'
26
+ end
27
+
28
+ def install_formol_user_migrations
29
+ template 'migrations/add_formol_profile_to_users.rb.erb', "#{Rails.root}/db/migrate/#{next_migration_number}_add_formol_profile_to_user.rb"
30
+ template 'migrations/add_posts_count_to_user.rb.erb', "#{Rails.root}/db/migrate/#{next_migration_number}_add_posts_count_to_user.rb"
31
+ end
32
+
33
+ def install_formol_initializer
34
+ template 'initializer/formol.rb.erb', "#{Rails.root}/config/initializers/formol.rb"
35
+ end
36
+
37
+ def copy_formol_config_yml
38
+ template 'config/formol.yml', "#{Rails.root}/config/formol.yml"
39
+ end
40
+
41
+ def copy_special_rights
42
+ template 'lib/permissions/special_rights.rb', "#{Rails.root}/lib/formol/permissions/special_rights.rb"
43
+ end
44
+
45
+ def mount_engine
46
+ inject_into_file("#{Rails.root}/config/routes.rb", %{ mount Formol::Engine => "/forums", :as => :formol\n}, :after => /routes.draw.do\n/)
47
+ end
48
+
49
+ def finished
50
+ puts <<END
51
+ #{'=' * 90}
52
+ Formol is now installed into your application
53
+ You can access it with http://yourhost/forums
54
+
55
+ * Formol migrations were copied into db/migrate and there was also two migrations for #{user_class} created.
56
+ * A new initializer called formol has been added to 'config/initializers'
57
+ * A yaml file wich contains profiles and permissions has been added to 'config'
58
+ * A module to define special rights has been added to 'lib/formol/permissions/special_rights'
59
+ * The formol engine was mounted in 'config/routes.rb'
60
+
61
+ What you need to do if you wanna formol work:
62
+
63
+ * run 'rake db:migrate'
64
+ * add '<%= include_formol_javascripts %>' in the head section of your application layout
65
+ * add 'include Formol::Integration::User' in your #{user_class} model
66
+
67
+ If you want to change where the forums are located, just change the "forums" path in 'config/routes.rb'.
68
+
69
+ Formol is delivered with no warranty under MIT license.
70
+ However, if you have any question, suggestion or issue, you can post them on our github repository, at the following address: https://github.com/mulasse/formol/issues
71
+
72
+ Thank your for using Formol.
73
+ #{'=' * 90}
74
+
75
+ END
76
+ end
77
+
78
+ private
79
+
80
+ def next_migration_number
81
+ @prev_migration_number = if @prev_migration_number.blank?
82
+ last_migration = Dir[Rails.root.join('db/migrate/*.rb')].sort.last.split("/").last
83
+ last_migration_number = last_migration.split('_').first
84
+
85
+ last_migration_number.to_i + 1
86
+ else
87
+ @prev_migration_number + 1
88
+ end
89
+
90
+ @prev_migration_number.to_s
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,29 @@
1
+ formol:
2
+ profiles:
3
+ admin:
4
+ rights:
5
+ - administrate
6
+ #administrate right grants all rights
7
+
8
+ #default profile is used for unregistered users
9
+ default:
10
+ rights:
11
+ - read_category
12
+ - read_forum
13
+ - read_topic
14
+
15
+ registered:
16
+ extends: default
17
+ rights:
18
+ - create_topic
19
+ - create_post
20
+ - vote_poll
21
+ - subscribe_topic
22
+
23
+ moderator:
24
+ extends: registered
25
+ rights:
26
+ - edit_topic
27
+ - edit_post
28
+ - lock_topic
29
+ - pin_topic
@@ -0,0 +1,21 @@
1
+ Formol.configure do
2
+ # formol needs to know what is your User class
3
+ # almost everything (topics, posts, votes ...) is attached to a user
4
+ # this params must be a string, not a constant
5
+ config.user_class = '<%= user_class %>'
6
+
7
+ # formol need to know how to access to authenticated user
8
+ # usually, helper method is called 'current_user'
9
+ config.current_user_helper_method = :<%= current_user_helper %>
10
+
11
+ # choose what text formatter you need
12
+ # actually only :markdown is available
13
+ # we will add :bbcode in a near future
14
+ config.text_formatter = :markdown
15
+
16
+ # you need to provide an email adress wich will be used as sender adress in all
17
+ # email that formol will send
18
+ #
19
+ # actually, only subscriptions send emails
20
+ config.email_from = 'noreply@example.com'
21
+ end
@@ -0,0 +1,24 @@
1
+ module Formol
2
+ module Permissions
3
+ # add methods to this module to define some rights that acts
4
+ # differently than just checking if user has right for his profile.
5
+ #
6
+ # For instance, a user can edit a post without having 'edit_post' right
7
+ # if he wrotes it, he's able to edit it
8
+ module SpecialRights
9
+ # a user can edit a topic if he wrotes it
10
+ def able_to_edit_topic?(topic)
11
+ has_right?(:edit_topic) || (!topic.locked? && topic.user_id == user.id)
12
+ end
13
+
14
+ # a user can edit a post if he wrotes it
15
+ def able_to_edit_post?(post)
16
+ has_right?(:edit_post) || (!post.topic.locked? && post.user_id == user.id)
17
+ end
18
+
19
+ def able_to_create_post?(topic)
20
+ has_right?(:create_post) && !topic.locked?
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,7 @@
1
+ class AddFormolProfileToUser < ActiveRecord::Migration
2
+ def change
3
+ change_table :<%= user_class.constantize.table_name %> do |t|
4
+ t.string :formol_profile, :limit => 16
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ class AddPostsCountToUser < ActiveRecord::Migration
2
+ def change
3
+ change_table :<%= user_class.constantize.table_name %> do |t|
4
+ t.integer :formol_posts_count, :default => 0
5
+ end
6
+ end
7
+ end
@@ -0,0 +1 @@
1
+ require 'formol/generators/install/install_generator'