adva 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (252) hide show
  1. checksums.yaml +4 -4
  2. data/adva.gemspec +3 -0
  3. data/app/assets/config/manifest.js +6 -0
  4. data/app/assets/javascripts/adva_cms/ckeditor.js.erb +12 -0
  5. data/app/assets/javascripts/adva_cms/concat_main_menus.js +13 -0
  6. data/app/assets/javascripts/adva_cms/jquery.table_tree.js +704 -0
  7. data/app/assets/javascripts/adva_cms.js +7 -0
  8. data/app/assets/javascripts/ckeditor/config.js.erb +94 -0
  9. data/app/assets/stylesheets/adva_cms/admin/common.scss +15 -1
  10. data/app/assets/stylesheets/adva_cms/admin/projection.scss +2 -5
  11. data/app/assets/stylesheets/adva_cms/admin/sidebar.scss +30 -9
  12. data/app/assets/stylesheets/adva_cms/admin.scss +1 -1
  13. data/app/controllers/admin/base_controller.rb +10 -24
  14. data/app/controllers/admin/page/articles_controller.rb +8 -27
  15. data/app/controllers/admin/page/categories_controller.rb +6 -9
  16. data/app/controllers/admin/page/links_controller.rb +6 -9
  17. data/app/controllers/admin/sections_controller.rb +7 -9
  18. data/app/controllers/admin/sites_controller.rb +9 -12
  19. data/app/controllers/admin/users_controller.rb +6 -9
  20. data/app/controllers/articles_controller.rb +30 -52
  21. data/app/controllers/base_controller.rb +8 -8
  22. data/app/controllers/password_controller.rb +3 -5
  23. data/app/controllers/session_controller.rb +3 -5
  24. data/app/helpers/activities_helper.rb +9 -20
  25. data/app/helpers/admin/base_helper.rb +4 -22
  26. data/app/helpers/base_helper.rb +1 -1
  27. data/app/helpers/content_helper.rb +7 -5
  28. data/app/helpers/resource_helper.rb +4 -5
  29. data/app/helpers/users_helper.rb +1 -1
  30. data/app/models/activity.rb +3 -0
  31. data/app/models/article.rb +0 -11
  32. data/app/models/category.rb +3 -3
  33. data/app/models/content.rb +10 -39
  34. data/app/models/link.rb +0 -1
  35. data/app/models/password_mailer.rb +6 -9
  36. data/app/models/section.rb +6 -7
  37. data/app/models/site.rb +0 -2
  38. data/app/models/user.rb +1 -2
  39. data/app/views/activity_notifier/new_content_notification.html.erb +5 -5
  40. data/app/views/admin/activities/_activities.html.erb +4 -4
  41. data/app/views/admin/activities/_comment.html.erb +21 -21
  42. data/app/views/admin/activities/_content.html.erb +4 -3
  43. data/app/views/admin/activities/_topic.html.erb +5 -5
  44. data/app/views/admin/install/confirmation.html.erb +3 -3
  45. data/app/views/admin/install/index.html.erb +14 -14
  46. data/app/views/admin/page/articles/_form.html.erb +28 -25
  47. data/app/views/admin/page/articles/_options.html.erb +3 -4
  48. data/app/views/admin/page/articles/edit.html.erb +3 -3
  49. data/app/views/admin/page/articles/new.html.erb +4 -4
  50. data/app/views/admin/page/categories/edit.html.erb +9 -9
  51. data/app/views/admin/page/categories/index.html.erb +16 -16
  52. data/app/views/admin/page/categories/new.html.erb +5 -3
  53. data/app/views/admin/page/contents/index.html.erb +3 -18
  54. data/app/views/admin/page/links/_form.html.erb +17 -17
  55. data/app/views/admin/page/links/_options.html.erb +16 -19
  56. data/app/views/admin/page/links/edit.html.erb +3 -3
  57. data/app/views/admin/page/links/new.html.erb +3 -3
  58. data/app/views/admin/sections/_form.html.haml +5 -5
  59. data/app/views/admin/sections/edit.html.haml +2 -2
  60. data/app/views/admin/sections/index.html.erb +18 -18
  61. data/app/views/admin/sections/new.html.erb +15 -13
  62. data/app/views/admin/sections/settings/_page.html.haml +4 -6
  63. data/app/views/admin/shared/_header.html.erb +5 -4
  64. data/app/views/admin/shared/_section_tree.html.erb +2 -2
  65. data/app/views/admin/sites/_email_notifications.html.erb +6 -7
  66. data/app/views/admin/sites/_form.html.erb +7 -7
  67. data/app/views/admin/sites/_recent_users.html.erb +4 -2
  68. data/app/views/admin/sites/_unapproved_comments.html.erb +1 -1
  69. data/app/views/admin/sites/index.html.erb +1 -1
  70. data/app/views/admin/sites/new.html.erb +2 -2
  71. data/app/views/admin/sites/show.html.erb +7 -8
  72. data/app/views/admin/users/edit.html.erb +1 -1
  73. data/app/views/admin/users/index.html.erb +10 -10
  74. data/app/views/admin/users/new.html.erb +1 -1
  75. data/app/views/admin/users/show.html.erb +7 -7
  76. data/app/views/layouts/admin.html.haml +3 -5
  77. data/app/views/layouts/login.html.erb +1 -1
  78. data/app/views/password/edit.html.erb +12 -5
  79. data/app/views/password/new.html.erb +7 -7
  80. data/app/views/password_mailer/reset_password_email.html.erb +21 -1
  81. data/app/views/password_mailer/updated_password_email.html.erb +3 -1
  82. data/app/views/session/new.html.erb +9 -9
  83. data/app/views/shared/_flash.html.erb +2 -2
  84. data/app/views/shared/_sidebar.html.erb +2 -2
  85. data/config/initializers/ckeditor.rb +61 -0
  86. data/config/initializers/menus.rb +1 -1
  87. data/config/initializers/time_format.rb +2 -0
  88. data/lib/adva/authenticate_user.rb +193 -0
  89. data/lib/{active_record → adva}/belongs_to_author.rb +4 -4
  90. data/lib/adva/event.rb +34 -0
  91. data/lib/adva/extensible_forms.rb +285 -0
  92. data/lib/{has_options.rb → adva/has_options.rb} +5 -7
  93. data/lib/adva/has_permalink.rb +36 -0
  94. data/lib/adva/version.rb +1 -1
  95. data/lib/adva.rb +10 -36
  96. data/lib/rails_ext/action_controller/event_helper.rb +1 -1
  97. data/lib/rails_ext.rb +0 -9
  98. data/vendor/gems/cacheable_flash/.gitignore +8 -0
  99. data/vendor/gems/cacheable_flash/Gemfile +8 -0
  100. data/vendor/gems/cacheable_flash/README.md +35 -0
  101. data/vendor/gems/cacheable_flash/Rakefile +4 -0
  102. data/vendor/gems/cacheable_flash/bin/console +15 -0
  103. data/vendor/gems/cacheable_flash/bin/setup +8 -0
  104. data/vendor/gems/cacheable_flash/cacheable_flash.gemspec +38 -0
  105. data/vendor/gems/cacheable_flash/lib/cacheable_flash/controller.rb +29 -0
  106. data/vendor/gems/cacheable_flash/lib/cacheable_flash/javascript.js +19 -0
  107. data/vendor/gems/cacheable_flash/lib/cacheable_flash/middleware.rb +30 -0
  108. data/vendor/gems/cacheable_flash/lib/cacheable_flash/version.rb +5 -0
  109. data/vendor/gems/cacheable_flash/lib/cacheable_flash.rb +12 -0
  110. data/vendor/gems/simple_taggable/lib/tag_list.rb +1 -1
  111. data/vendor/gems/tags/lib/menu.rb +1 -1
  112. data/vendor/gems/tags/lib/tags/tag.rb +1 -1
  113. metadata +72 -145
  114. data/app/assets/javascripts/adva_cms/admin/jquery.admin.js +0 -23
  115. data/app/assets/javascripts/adva_cms/admin/jquery.article.js +0 -22
  116. data/app/assets/javascripts/adva_cms/admin/jquery.cached_pages.js +0 -14
  117. data/app/assets/javascripts/adva_cms/admin/jquery.table_tree.js +0 -7
  118. data/app/assets/javascripts/adva_cms/application.js +0 -13
  119. data/app/assets/javascripts/adva_cms/base.js +0 -4
  120. data/app/assets/javascripts/adva_cms/cookie.js +0 -49
  121. data/app/assets/javascripts/adva_cms/jquery/jquery-lowpro.js +0 -224
  122. data/app/assets/javascripts/adva_cms/jquery/jquery.qtip.js +0 -2085
  123. data/app/assets/javascripts/adva_cms/jquery/jquery.table_tree.js +0 -307
  124. data/app/assets/javascripts/adva_cms/jquery/jquery.tablednd_0_5.js +0 -386
  125. data/app/assets/javascripts/adva_cms/jquery.common.js +0 -41
  126. data/app/assets/javascripts/adva_cms/jquery.dates.js +0 -51
  127. data/app/assets/javascripts/adva_cms/jquery.flash.js +0 -59
  128. data/app/assets/javascripts/adva_cms/jquery.roles.js +0 -25
  129. data/app/assets/javascripts/adva_cms/json.js +0 -139
  130. data/app/controllers/admin/base_account_controller.rb +0 -13
  131. data/app/controllers/admin/install_controller.rb +0 -61
  132. data/app/controllers/admin/plugins_controller.rb +0 -38
  133. data/app/helpers/meta_tags_helper.rb +0 -30
  134. data/app/models/account.rb +0 -7
  135. data/app/models/event.rb +0 -34
  136. data/app/views/admin/articles/_meta_tags.html.erb +0 -7
  137. data/app/views/admin/cached_pages/_filter.html.erb +0 -8
  138. data/app/views/admin/cached_pages/destroy.js.erb +0 -18
  139. data/app/views/admin/cached_pages/index.html.erb +0 -26
  140. data/app/views/admin/plugins/_form.html.erb +0 -11
  141. data/app/views/admin/plugins/index.html.erb +0 -16
  142. data/app/views/admin/plugins/show.html.erb +0 -43
  143. data/app/views/admin/shared/_language_select.html.erb +0 -6
  144. data/app/views/admin/shared/_section_summary.html.erb +0 -23
  145. data/app/views/admin/sites/_meta_tags.html.erb +0 -15
  146. data/app/views/layouts/default.html.erb +0 -38
  147. data/app/views/layouts/simple.html.erb +0 -22
  148. data/app/views/shared/_footer.html.erb +0 -4
  149. data/app/views/shared/messages/insufficient_permissions.html.erb +0 -4
  150. data/config/initializers/article.rb +0 -8
  151. data/config/initializers/has_options.rb +0 -2
  152. data/config/initializers/has_permalink.rb +0 -2
  153. data/config/initializers/site.rb +0 -8
  154. data/config/locales/en.yml +0 -1319
  155. data/lib/action_controller/authenticate_anonymous.rb +0 -69
  156. data/lib/action_controller/authenticate_user.rb +0 -203
  157. data/lib/core_ext.rb +0 -7
  158. data/lib/extensible_forms.rb +0 -284
  159. data/lib/has_permalink.rb +0 -33
  160. data/lib/login/helper_integration.rb +0 -11
  161. data/lib/login/mail_config.rb +0 -39
  162. data/lib/rails_ext/action_controller/cacheable_flash.rb +0 -30
  163. data/lib/rails_ext/action_controller/content_for_assignments.rb +0 -106
  164. data/lib/rails_ext/action_controller/page_caching.rb +0 -23
  165. data/lib/rails_ext/action_controller/responds_to_parent.rb +0 -46
  166. data/lib/rails_ext/active_record/exists.rb +0 -5
  167. data/lib/rails_ext/active_record/sti_instantiation.rb +0 -35
  168. data/lib/rails_ext/active_record/sticky_changes.rb +0 -30
  169. data/lib/rails_ext/railties/plugin.rb +0 -58
  170. data/lib/rails_ext/railties/plugin_configuration.rb +0 -72
  171. data/lib/registry.rb +0 -49
  172. data/lib/tasks/translation.rake +0 -69
  173. data/lib/time_hacks.rb +0 -57
  174. data/lib/webrat_patch.rb +0 -11
  175. data/test/meta_tags_test.rb +0 -42
  176. data/vendor/gems/has_counter/.gitignore +0 -17
  177. data/vendor/gems/has_counter/Gemfile +0 -4
  178. data/vendor/gems/has_counter/LICENSE +0 -22
  179. data/vendor/gems/has_counter/MIT-LICENSE +0 -20
  180. data/vendor/gems/has_counter/README.markdown +0 -64
  181. data/vendor/gems/has_counter/README.md +0 -29
  182. data/vendor/gems/has_counter/Rakefile +0 -2
  183. data/vendor/gems/has_counter/db/migrate/20080601194338_create_counters_table.rb.rb +0 -13
  184. data/vendor/gems/has_counter/has_counter.gemspec +0 -17
  185. data/vendor/gems/has_counter/lib/active_record/has_counter.rb +0 -67
  186. data/vendor/gems/has_counter/lib/counter.rb +0 -23
  187. data/vendor/gems/has_counter/lib/has_counter/version.rb +0 -3
  188. data/vendor/gems/has_counter/lib/has_counter.rb +0 -4
  189. data/vendor/gems/has_counter/spec/has_counter.sqlite3.db +0 -0
  190. data/vendor/gems/has_counter/spec/has_counter_spec.rb +0 -55
  191. data/vendor/gems/has_counter/spec/spec_helper.rb +0 -117
  192. data/vendor/gems/has_filter/.gitignore +0 -17
  193. data/vendor/gems/has_filter/Gemfile +0 -4
  194. data/vendor/gems/has_filter/LICENSE +0 -22
  195. data/vendor/gems/has_filter/README.md +0 -29
  196. data/vendor/gems/has_filter/Rakefile +0 -2
  197. data/vendor/gems/has_filter/app/assets/images/has_filter/filter_add.png +0 -0
  198. data/vendor/gems/has_filter/app/assets/images/has_filter/filter_button_left.png +0 -0
  199. data/vendor/gems/has_filter/app/assets/images/has_filter/filter_button_right.png +0 -0
  200. data/vendor/gems/has_filter/app/assets/images/has_filter/filter_remove.png +0 -0
  201. data/vendor/gems/has_filter/app/assets/javascripts/has_filter/filter.js +0 -35
  202. data/vendor/gems/has_filter/app/assets/javascripts/has_filter/jquery.filter.js +0 -23
  203. data/vendor/gems/has_filter/app/assets/stylesheets/has_filter/alternate/filter.scss +0 -102
  204. data/vendor/gems/has_filter/app/assets/stylesheets/has_filter/filter.scss +0 -100
  205. data/vendor/gems/has_filter/app/helpers/filter_helper.rb +0 -3
  206. data/vendor/gems/has_filter/has_filter.gemspec +0 -17
  207. data/vendor/gems/has_filter/init.rb +0 -3
  208. data/vendor/gems/has_filter/lib/has_filter/active_record/act_macro.rb +0 -102
  209. data/vendor/gems/has_filter/lib/has_filter/filter/base.rb +0 -67
  210. data/vendor/gems/has_filter/lib/has_filter/filter/categorized.rb +0 -24
  211. data/vendor/gems/has_filter/lib/has_filter/filter/chain.rb +0 -45
  212. data/vendor/gems/has_filter/lib/has_filter/filter/set.rb +0 -80
  213. data/vendor/gems/has_filter/lib/has_filter/filter/state.rb +0 -25
  214. data/vendor/gems/has_filter/lib/has_filter/filter/tagged.rb +0 -22
  215. data/vendor/gems/has_filter/lib/has_filter/filter/text.rb +0 -55
  216. data/vendor/gems/has_filter/lib/has_filter/filter.rb +0 -17
  217. data/vendor/gems/has_filter/lib/has_filter/version.rb +0 -3
  218. data/vendor/gems/has_filter/lib/has_filter.rb +0 -22
  219. data/vendor/gems/has_filter/test/db/setup.rb +0 -45
  220. data/vendor/gems/has_filter/test/db/test.sqlite3.db +0 -0
  221. data/vendor/gems/has_filter/test/fixtures.rb +0 -15
  222. data/vendor/gems/has_filter/test/has_filter/filter_chain_test.rb +0 -41
  223. data/vendor/gems/has_filter/test/has_filter/filter_scopes_test.rb +0 -102
  224. data/vendor/gems/has_filter/test/has_filter/filter_tags_test.rb +0 -113
  225. data/vendor/gems/has_filter/test/has_filter/integration.rb +0 -15
  226. data/vendor/gems/has_filter/test/has_filter/scopes_test.rb +0 -48
  227. data/vendor/gems/has_filter/test/log/test.log +0 -34346
  228. data/vendor/gems/has_filter/test/models.rb +0 -23
  229. data/vendor/gems/has_filter/test/templates/has_filter/test/index.html.erb +0 -5
  230. data/vendor/gems/has_filter/test/test_helper.rb +0 -66
  231. data/vendor/gems/xss_terminate/.gitignore +0 -17
  232. data/vendor/gems/xss_terminate/Gemfile +0 -4
  233. data/vendor/gems/xss_terminate/LICENSE +0 -22
  234. data/vendor/gems/xss_terminate/MIT-LICENSE +0 -20
  235. data/vendor/gems/xss_terminate/README +0 -94
  236. data/vendor/gems/xss_terminate/README.md +0 -29
  237. data/vendor/gems/xss_terminate/Rakefile +0 -23
  238. data/vendor/gems/xss_terminate/lib/html5lib_sanitize.rb +0 -2453
  239. data/vendor/gems/xss_terminate/lib/rails_sanitize.rb +0 -8
  240. data/vendor/gems/xss_terminate/lib/xss_terminate/version.rb +0 -3
  241. data/vendor/gems/xss_terminate/lib/xss_terminate.rb +0 -141
  242. data/vendor/gems/xss_terminate/tasks/xss_terminate_tasks.rake +0 -7
  243. data/vendor/gems/xss_terminate/test/models/comment.rb +0 -5
  244. data/vendor/gems/xss_terminate/test/models/entry.rb +0 -7
  245. data/vendor/gems/xss_terminate/test/models/message.rb +0 -3
  246. data/vendor/gems/xss_terminate/test/models/person.rb +0 -5
  247. data/vendor/gems/xss_terminate/test/models/review.rb +0 -5
  248. data/vendor/gems/xss_terminate/test/schema.rb +0 -34
  249. data/vendor/gems/xss_terminate/test/setup_test.rb +0 -16
  250. data/vendor/gems/xss_terminate/test/xss_terminate_test.rb +0 -50
  251. data/vendor/gems/xss_terminate/xss_terminate.gemspec +0 -17
  252. /data/lib/tasks/{adva_cms.rake → adva.rake} +0 -0
@@ -0,0 +1,193 @@
1
+ module Adva
2
+ module AuthenticateUser
3
+ def self.included(target)
4
+ target.extend(ClassMethods)
5
+ target.helper_method(:current_user, :logged_in?, :authenticated?)
6
+ end
7
+
8
+ # Methods available as macro-style methods on any controller
9
+ module ClassMethods
10
+ # Sets up the controller so that authentication is required. If
11
+ # the user is not authenticated then they will be redirected to
12
+ # the login screen.
13
+ #
14
+ # The page requested will be saved so that once the login has
15
+ # occured they will be sent back to the page they first
16
+ # requested. If no page was requested (they went to the login
17
+ # page directly) then they will be directed to profiles/home
18
+ # after login which is a placeholder for the app to override.
19
+ #
20
+ # Options given are passed directly to the before_action method
21
+ # so feel free to provide :only and :except options.
22
+ def authentication_required
23
+ before_action :require_authentication
24
+ end
25
+
26
+ # Will remove authentication from certain actions. Options given
27
+ # are passed directly to skip_before_action so feel free to use
28
+ # :only and :except options.
29
+ #
30
+ # This method is useful in cases where you have locked down the
31
+ # entire application by putting authentication_required in your
32
+ # ApplicationController but then want to open an action back up
33
+ # in a specific controller.
34
+ def no_authentication_required
35
+ skip_before_action :require_authentication
36
+ end
37
+ end
38
+
39
+ def authenticate_user(credentials)
40
+ User.authenticate(credentials).tap do |user|
41
+ if user
42
+ # prevent session hijacking - unnecessary according to http://dev.rubyonrails.org/ticket/10108
43
+ # reset_session_except :return_location
44
+ session[:uid] = user.id
45
+ set_user_cookie!(user)
46
+ end
47
+ end
48
+ end
49
+
50
+ # Will retrieve the current_user. Will not force a login but
51
+ # simply load the current user if a person is logged in. If
52
+ # you need the user object loaded with extra options (such as
53
+ # eager loading) then create a private method called
54
+ # "user_find_options" on your controller that returns a hash
55
+ # of the find options you want.
56
+ #
57
+ # This method will also inform the models of the current user
58
+ # if the current user is logged in and the "User" class responds
59
+ # to the class method current_user=. This is a nice way to
60
+ # communciate the current user down to the model level for
61
+ # model-level security. This means you will want to call this
62
+ # method at least once before using the model-level security.
63
+ # Usually you will call it in a before filter. This method is
64
+ # called automatically when authentication_required is applied to
65
+ # an action.
66
+ def current_user
67
+ @current_user ||= begin
68
+ # Check for session[:uid] here? That would mean that for token auth the
69
+ # user always needs to be logged out (e.g. in UserController#create).
70
+ # Looks a bit more robust this way:
71
+ try_login
72
+ if session && session[:uid]
73
+ user = find_current_user
74
+ set_user_cookie!(user)
75
+ user
76
+ else
77
+ User.anonymous
78
+ end
79
+ end
80
+ end
81
+
82
+ def authenticated?
83
+ !current_user.anonymous?
84
+ end
85
+ alias :logged_in? :authenticated?
86
+
87
+ # killed this because it's just the wrong way to do it
88
+ #
89
+ # # Will store the current params so that we can return here on
90
+ # # successful login. If you want to redirect to the login yourself
91
+ # # (perhaps you are applying your own security instead of just
92
+ # # determining if the user is logged in) then you will want to
93
+ # # call this before issuing your redirect to the login screen.
94
+ # def store_return_location
95
+ # session[:return_location] = params
96
+ # end
97
+
98
+ private
99
+
100
+ # Will actually test to see if the user is authorized
101
+ def require_authentication
102
+ # No matter what the app does a user can always login, forgot
103
+ # password and register. The controllers provided by this
104
+ # plugin alreaddy have these controllers/actions on an
105
+ # exception list but this prevents a mistake an overridden
106
+ # controller from preventing the normal login behavior.
107
+ %w(session password user).each do |c|
108
+ %w(new create).each do |a|
109
+ return if (controller_name == c) && (action_name == a)
110
+ end
111
+ end
112
+
113
+ # If we cannot get the current user store the requested page
114
+ # and send them to the login page.
115
+ if current_user.anonymous?
116
+ redirect_to login_url(:return_to => request.url) and false
117
+ end
118
+ end
119
+
120
+ def logout
121
+ reset_session
122
+ forget_me!
123
+ end
124
+
125
+ def forget_me!
126
+ cookies[:remember_me] = nil
127
+ cookies[:uid] = nil
128
+ cookies[:uname] = nil
129
+ end
130
+
131
+ def remember_me!
132
+ token = current_user.assign_token!('remember me')
133
+ cookies[:remember_me] = { :value => "#{current_user.id};#{token}", :expires => 10.years.from_now }
134
+ end
135
+
136
+ def set_user_cookie!(user = current_user)
137
+ unless user.anonymous?
138
+ cookies[:uid] = user.id.to_s
139
+ cookies[:uname] = user.name
140
+ end
141
+ end
142
+
143
+ # There are a few ways that a user can login without going through
144
+ # a login screen. These methods all rely on authenticating with
145
+ # the information given in the request. If any of these methods
146
+ # are successful then session[:uid] will be set with the current
147
+ # user id and current_user will return the current user
148
+ def try_login
149
+ if user = http_auth_login || validation_login || remember_me_login
150
+ session[:uid] = user.id
151
+ end
152
+ end
153
+
154
+ # Will attempt to authenticate with HTTP Auth. HTTP Auth will not
155
+ # be required. We are just checking if it is provided mainly for
156
+ # RESTful requests.
157
+ def http_auth_login
158
+ # FIXME: Implement
159
+ end
160
+
161
+ # Will use the URL param :token to see if we can do a token
162
+ # authentication.
163
+ def validation_login
164
+ validate_token User, params[:token]
165
+ end
166
+
167
+ # Will check for a :remember_me cookie for a token that will
168
+ # authenticate the user.
169
+ def remember_me_login
170
+ validate_token User, cookies[:remember_me]
171
+ end
172
+
173
+ # The tokens are stored in various places as id;token. This method
174
+ # will split that out and validate it. If everything is successful
175
+ # then the user object is returned. Otherwise nil is returned.
176
+ # The full token should be passed in.
177
+ def validate_token(klass, token, options = {})
178
+ return nil if token.blank?
179
+ return nil unless token =~ /\;/
180
+
181
+ uid, token = token.split ';'
182
+ if object = klass.find_by_id(uid)
183
+ return object if object.authenticate(token)
184
+ end
185
+ nil
186
+ end
187
+
188
+ def find_current_user
189
+ User.find_by_id(session[:uid])
190
+ end
191
+ end
192
+ end
193
+
@@ -1,13 +1,13 @@
1
- require "active_record/belongs_to_cacheable"
1
+ require "belongs_to_cacheable"
2
2
 
3
- module ActiveRecord
3
+ module Adva
4
4
  module BelongsToAuthor
5
5
  def self.included(base)
6
6
  base.include BelongsToCacheable
7
- base.extend ActMacro
7
+ base.extend ClassMethods
8
8
  end
9
9
 
10
- module ActMacro
10
+ module ClassMethods
11
11
  def belongs_to_user(*args)
12
12
  options = args.extract_options!
13
13
  args = (args.empty? ? [:user] : args)
data/lib/adva/event.rb ADDED
@@ -0,0 +1,34 @@
1
+ module Adva
2
+ class Event
3
+ cattr_accessor :observers
4
+ @@observers = []
5
+
6
+ attr_reader :type # what happened
7
+ attr_reader :object # the object that the event is about, e.g. payment
8
+ attr_reader :source # the origin or the event, e.g. payment processor
9
+ attr_reader :options # optional options for the event
10
+
11
+ def self.trigger(type, object, source, options = {})
12
+ event = new(type, object, source, options)
13
+ observers.each do |observer|
14
+ observer = observer.constantize if observer.is_a?(String)
15
+ callback = :"handle_#{event.type}!"
16
+
17
+ if observer.respond_to?(callback)
18
+ observer.send(callback, event)
19
+ elsif observer.respond_to?(:handle_event!)
20
+ observer.handle_event!(event)
21
+ end
22
+ end
23
+ end
24
+
25
+ def initialize(type, object, source, options = {})
26
+ @type, @object, @source, @options = type, object, source, options
27
+ end
28
+
29
+ def method_missing(name, *args)
30
+ return @options[name] if @options.has_key?(name)
31
+ super
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,285 @@
1
+ require 'action_view'
2
+ require 'action_view/helpers'
3
+ require 'action_view/helpers/form_helper'
4
+
5
+ module ActionView
6
+ module Helpers
7
+ module FormHelper
8
+ def field_set(object_name, name, content = nil, options = {}, &block)
9
+ options.delete(:object)
10
+ options[:name] ||= name
11
+ options[:id] ||= name
12
+ content ||= self.capture(&block) if block_given?
13
+ content_tag("fieldset", raw(content), options).html_safe
14
+ end
15
+
16
+ protected
17
+
18
+ def singular_class_name(name)
19
+ ActiveModel::Naming.singular(name)
20
+ end
21
+
22
+ def pick_form_builder(name)
23
+ name = "#{name.to_s.classify}FormBuilder"
24
+ name.constantize
25
+ rescue NameError
26
+ Object.const_set(name, Class.new(ActionView::Base.default_form_builder)) rescue ActionView::Base.default_form_builder
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ module Adva
33
+ class ExtensibleFormBuilder < ActionView::Helpers::FormBuilder
34
+ class_attribute :callbacks
35
+ self.callbacks = { :before => {}, :after => {} }
36
+
37
+ class_attribute :tabs
38
+ self.tabs = []
39
+
40
+ class_attribute :options
41
+ self.options = { :labels => false, :wrap => false, :default_class_names => {} }
42
+
43
+ class << self
44
+ [:labels, :wrap].each do |option|
45
+ define_method(:"#{option}=") { |value| self.options[option] = value }
46
+ end
47
+
48
+ def default_class_names(type = nil)
49
+ if type
50
+ self.options[:default_class_names][type] ||= []
51
+ else
52
+ self.options[:default_class_names]
53
+ end
54
+ end
55
+
56
+ def before(object_name, method, string = nil, &block)
57
+ add_callback(:before, object_name, method, string || block)
58
+ end
59
+
60
+ def after(object_name, method, string = nil, &block)
61
+ add_callback(:after, object_name, method, string || block)
62
+ end
63
+
64
+ def tab(name, options = {}, &block)
65
+ self.tabs.reject! { |n, b| name == n }
66
+ self.tabs += [[name, block]]
67
+ end
68
+
69
+ protected
70
+
71
+ def add_callback(stage, object_name, method, callback)
72
+ method = method.to_sym
73
+ callbacks[stage][object_name] ||= { }
74
+ callbacks[stage][object_name][method] ||= []
75
+ callbacks[stage][object_name][method] << callback
76
+ end
77
+ end
78
+
79
+ helpers = field_helpers + %w(select date_select datetime_select time_select time_zone_select collection_select) -
80
+ %w(hidden_field label fields_for apply_form_for_options!)
81
+
82
+ helpers.each do |method_name|
83
+ class_eval <<-src, __FILE__, __LINE__
84
+ def #{method_name}(*args, &block)
85
+ type = #{method_name.to_sym.inspect}
86
+
87
+ options = args.extract_options!
88
+ options = add_default_class_names(options, type)
89
+ # options = add_tabindex(options, type)
90
+
91
+ label, wrap, hint = options.delete(:label), options.delete(:wrap), options.delete(:hint)
92
+ name = args.first
93
+
94
+ hint = I18n.t(hint) if hint.is_a?(Symbol)
95
+ options[:title] = hint
96
+
97
+ with_callbacks(name) do
98
+ tag = super(*(args << options), &block)
99
+ # remember_tabindex(tag, options)
100
+ tag = labelize(type, tag, name, label) if label || self.options[:labels]
101
+ tag = wrap(tag) if wrap || self.options[:wrap]
102
+ tag
103
+ end
104
+ end
105
+ src
106
+ end
107
+
108
+ def field_set(*args, &block)
109
+ options = args.extract_options!
110
+ options = add_default_class_names(options, :field_set)
111
+
112
+ name = args.first
113
+ name ||= :default_fields
114
+
115
+ @template.concat with_callbacks(name) {
116
+ legend = options.delete(:legend) || ''
117
+ legend = @template.content_tag('legend', legend) unless legend.blank?
118
+ @template.field_set(@object_name, name, nil, objectify_options(options)) do
119
+ legend.to_s + (block ? block.call.to_s : '')
120
+ end
121
+ }
122
+ end
123
+
124
+ def tabs
125
+ yield if block_given?
126
+ assign_ivars!
127
+ @template.content_tag(:div, :class => 'tabs') {
128
+ self.class.tabs.map.with_index { |(name, _), index|
129
+ active = self.class.tabs.first.first == name
130
+ %(<input type="radio" id="adva_current_tab_#{index}" name="adva_current_tab" #{"checked" if active}>)
131
+ }.join.html_safe +
132
+
133
+ @template.content_tag(:ul) {
134
+ self.class.tabs.map.with_index { |(name, _), index|
135
+ @template.content_tag(:li) {
136
+ title = I18n.t(name, :scope => :'adva.titles')
137
+ %(<label for="adva_current_tab_#{index}">#{title}</label>).html_safe
138
+ }
139
+ }.join.html_safe
140
+ } +
141
+
142
+ self.class.tabs.map.with_index { |(name, block), index|
143
+ klass = self.class.tabs.first.first == name ? 'tab active' : 'tab'
144
+ @template.content_tag 'fieldset', block.call(self), id: "tab_#{name}", class: klass, for: "adva_current_tab_#{index}"
145
+ }.join.html_safe
146
+ }.html_safe
147
+ end
148
+
149
+ def tab(name, &block)
150
+ with_callbacks(:"tab_#{name}") {
151
+ self.class.tab(name, &block)
152
+ }
153
+ end
154
+
155
+ def buttons(name = :submit_buttons, &block)
156
+ @template.concat with_callbacks(name) {
157
+ @template.capture { @template.buttons(&block) }
158
+ }
159
+ end
160
+
161
+ def render(*args)
162
+ @template.send(:render, *args)
163
+ end
164
+
165
+ protected
166
+
167
+ def labelize(type, tag, method, label = nil)
168
+ label = case label
169
+ when String then label
170
+ when Symbol then I18n.t(label)
171
+ when TrueClass then
172
+ scope = [:activerecord, :attributes] + object.class.to_s.underscore.split('/')
173
+ string = I18n.t(method, :scope => scope)
174
+ string.is_a?(String) ? string : method.to_s.titleize
175
+ else nil
176
+ end
177
+
178
+ case type
179
+ when :check_box, :radio_button
180
+ tag + self.label(method, label, :class => 'inline light', :for => extract_id(tag), :id => "#{extract_id(tag)}_label")
181
+ else
182
+ self.label(method, label) + tag
183
+ end
184
+ end
185
+
186
+ def wrap(tag)
187
+ @template.content_tag(:p, tag)
188
+ end
189
+
190
+ def hint(tag, hint)
191
+ tag + @template.content_tag(:span, "", title: hint, class: 'hint', for: extract_id(tag))
192
+ end
193
+
194
+ def add_default_class_names(options, type)
195
+ options[:class] = (Array(options[:class]) + self.class.default_class_names(type)).join(' ')
196
+ options.delete(:class) if options[:class].blank?
197
+ options
198
+ end
199
+
200
+ def tabindex_increment!
201
+ @tabindex_count ||= 0
202
+ @tabindex_count += 1
203
+ end
204
+
205
+ def set_tabindex_position(index = nil, position = nil)
206
+ position = case position
207
+ when :after then tabindexes[index] + 1
208
+ when :before then tabindexes[index] - 1
209
+ when :same then tabindexes[index]
210
+ else tabindex_increment!
211
+ end
212
+ position
213
+ end
214
+
215
+ def add_tabindex(options, type)
216
+ index = options[:tabindex]
217
+
218
+ if index.is_a?(Hash)
219
+ key = index.keys.first
220
+ options[:tabindex] = set_tabindex_position(index[key], key)
221
+ elsif index.is_a?(Symbol)
222
+ options[:tabindex] = set_tabindex_position(index, :same)
223
+ elsif index.blank?
224
+ options[:tabindex] = set_tabindex_position
225
+ end
226
+
227
+ options
228
+ end
229
+
230
+ def tabindexes
231
+ @tabindexes ||= {}
232
+ end
233
+
234
+ def remember_tabindex(tag, options)
235
+ id = extract_id(tag)
236
+ tabindexes[:"#{id}"] = options[:tabindex] unless id.blank?
237
+ end
238
+
239
+ def with_callbacks(method, &block)
240
+ result = ''
241
+ result += run_callbacks(:before, method) if method
242
+ result += yield.to_s
243
+ result += run_callbacks(:after, method) if method
244
+ result.html_safe
245
+ end
246
+
247
+ def run_callbacks(stage, method)
248
+ if callbacks = callbacks_for(stage, method.to_sym)
249
+ callbacks.inject('') do |result, callback|
250
+ result + case callback
251
+ when Proc
252
+ assign_ivars!
253
+ instance_eval(&callback)
254
+ else
255
+ callback
256
+ end.to_s
257
+ end
258
+ end || ''
259
+ end
260
+
261
+ def callbacks_for(stage, method)
262
+ object_name = @object_name.try(:to_sym)
263
+ self.callbacks[stage][object_name] and
264
+ self.callbacks[stage][object_name][method.to_sym]
265
+ end
266
+
267
+ def assign_ivars!
268
+ unless @ivars_assigned
269
+ @template.assigns.each { |key, value| instance_variable_set("@#{key}", value) }
270
+ vars = @template.controller.instance_variable_names
271
+ vars.each { |name| instance_variable_set(name, @template.controller.instance_variable_get(name)) }
272
+ @ivars_assigned = true
273
+ end
274
+ end
275
+
276
+ # yep, we gotta do this crap because there doesn't seem to be a sane way
277
+ # to hook into actionview's form_helper methods
278
+ def extract_id(tag)
279
+ tag =~ /id="([^"]+)"/
280
+ $1
281
+ end
282
+ end
283
+ end
284
+
285
+ ActionView::Base.default_form_builder = Adva::ExtensibleFormBuilder
@@ -1,12 +1,9 @@
1
- # TODO allow a :type option and typecast the value
2
-
3
- module HasOptions
4
- class << self
5
- def included(base)
1
+ module Adva
2
+ module HasOptions
3
+ def self.included(base)
6
4
  base.class_eval do
7
5
  extend ClassMethods
8
- class_attribute :option_definitions
9
- self.option_definitions = {}
6
+ class_attribute :option_definitions, default: {}
10
7
  serialize :options
11
8
  end
12
9
  end
@@ -46,3 +43,4 @@ module HasOptions
46
43
  end
47
44
  end
48
45
  end
46
+
@@ -0,0 +1,36 @@
1
+ require "friendly_id"
2
+
3
+ module Adva
4
+ module HasPermalink
5
+ def self.included(base)
6
+ base.extend ClassMethods
7
+ end
8
+
9
+ module ClassMethods
10
+ def has_permalink column, options={}
11
+ extend FriendlyId
12
+
13
+ friendly_id column do |config|
14
+ config.use :slugged, :finders
15
+ if options[:scope]
16
+ config.use :scoped
17
+ config.scope = options[:scope]
18
+ end
19
+ config.slug_column = options[:url_attribute]
20
+ end
21
+
22
+ self.class_eval do
23
+ def should_generate_new_friendly_id?
24
+ permalink.blank?
25
+ end
26
+ end
27
+
28
+ define_method :"#{options[:url_attribute]}=" do |value|
29
+ value = value.parameterize if value
30
+ super value
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+
data/lib/adva/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Adva
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/adva.rb CHANGED
@@ -1,66 +1,40 @@
1
- # require "adva_cms/version"
2
1
  require "rails"
3
2
  require "will_paginate"
4
3
  require "awesome_nested_set"
5
4
  require "actionpack/page_caching"
6
-
7
- require 'extensible_forms'
8
- require 'time_hacks'
9
- require 'core_ext'
10
- require 'rails_ext'
11
5
  require "rails-observers"
6
+ require "jquery-rails"
12
7
 
13
- # require 'menu'
14
- # require 'event' # need to force these to be loaded now, so Rails won't
15
- # require 'registry' # reload them between requests (FIXME ... this doesn't seem to happen?)
8
+ require "rails_ext"
16
9
 
17
- # config.to_prepare do
18
- # Registry.set :redirect, {
19
- # :login => lambda { |c| c.send(:admin_sites_url) },
20
- # :verify => '/',
21
- # :site_deleted => lambda { |c| c.send(:admin_sites_url) }
22
- # }
23
- # end
24
10
  # load vendored gems
25
- Dir["#{File.expand_path("#{File.dirname(__FILE__)}/../vendor/gems")}/**/lib"].each do |vendored_gem_path|
11
+ Dir["#{File.expand_path("#{__dir__}/../vendor/gems")}/**/lib"].each do |vendored_gem_path|
26
12
  $: << vendored_gem_path
27
13
  end
28
14
 
29
- require "has_counter"
30
15
  require "belongs_to_cacheable"
16
+ require "cacheable_flash"
31
17
  require "filtered_column"
32
- require "has_filter"
33
18
  require "simple_taggable"
34
19
  require "tags"
35
20
  require "table_builder"
36
- require "xss_terminate"
37
21
  require "authentication"
22
+ require "adva/event"
23
+ require "adva/extensible_forms"
38
24
 
39
25
  module Adva
40
26
  class Engine < Rails::Engine
41
27
  initializer "add assets to precompilation list" do |app|
42
- app.config.assets.precompile += %w(adva_cms/application.js)
43
- app.config.assets.precompile += %w(adva_cms/admin.css adva_cms/admin/activities.css)
28
+ app.config.assets.precompile += %w(adva_cms.js)
29
+ app.config.assets.precompile += %w(adva_cms/admin.css)
44
30
  app.config.assets.precompile += %w(admin.css admin.js)
45
- end
46
31
 
47
- initializer "setup xss_terminate" do
48
- XssTerminate.untaint_after_find = true
32
+ app.config.assets.precompile += %w(adva_cms/icons/tick.png adva_cms/icons/cross.png)
49
33
  end
50
34
 
51
35
  initializer "adva_user.init" do
52
- ActionController::Base.send :include, ActionController::AuthenticateUser
53
- ActionController::Base.send :include, ActionController::AuthenticateAnonymous
54
- ActiveRecord::Base.send :include, ActiveRecord::BelongsToAuthor
55
- ActionView::Base.send :include, Login::HelperIntegration
56
-
57
- Event.observers << 'PasswordMailer'
36
+ Adva::Event.observers << 'PasswordMailer'
58
37
  end
59
38
  end
60
39
  end
61
40
 
62
- require "action_controller/authenticate_user"
63
- require "action_controller/authenticate_anonymous"
64
- require "active_record/belongs_to_author"
65
- require "login/helper_integration"
66
-
@@ -10,7 +10,7 @@ module ActionController
10
10
 
11
11
  def trigger_event(object, change = nil, options = {})
12
12
  type = :"#{object.class.name.underscore}_#{change}"
13
- Event.trigger type, object, self, options
13
+ Adva::Event.trigger type, object, self, options
14
14
  end
15
15
  end
16
16
  end
data/lib/rails_ext.rb CHANGED
@@ -1,14 +1,5 @@
1
- require 'rails_ext/action_controller/cacheable_flash'
2
1
  require 'rails_ext/action_controller/default_params'
3
2
  require 'rails_ext/action_controller/event_helper'
4
- require 'rails_ext/action_controller/page_caching'
5
- require 'rails_ext/action_controller/content_for_assignments'
6
- require 'rails_ext/action_controller/responds_to_parent'
7
3
  require 'rails_ext/action_controller/render_with_error_proc'
8
4
  require 'rails_ext/action_controller/url_for_returning'
9
5
 
10
- require 'rails_ext/active_record/sti_instantiation'
11
- require 'rails_ext/active_record/sticky_changes'
12
-
13
- require 'rails_ext/railties/plugin_configuration'
14
-