knitkit 2.1.15 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (209) hide show
  1. checksums.yaml +7 -0
  2. data/app/controllers/knitkit/base_controller.rb +1 -1
  3. data/app/controllers/knitkit/comments_controller.rb +7 -2
  4. data/app/controllers/knitkit/erp_app/desktop/app_controller.rb +78 -98
  5. data/app/controllers/knitkit/erp_app/desktop/articles_controller.rb +65 -45
  6. data/app/controllers/knitkit/erp_app/desktop/content_controller.rb +22 -12
  7. data/app/controllers/knitkit/erp_app/desktop/file_assets_controller.rb +1 -1
  8. data/app/controllers/knitkit/erp_app/desktop/image_assets_controller.rb +28 -16
  9. data/app/controllers/knitkit/erp_app/desktop/inquiries_controller.rb +15 -49
  10. data/app/controllers/knitkit/erp_app/desktop/online_document_sections_controller.rb +4 -3
  11. data/app/controllers/knitkit/erp_app/desktop/position_controller.rb +69 -11
  12. data/app/controllers/knitkit/erp_app/desktop/theme_controller.rb +63 -60
  13. data/app/controllers/knitkit/erp_app/desktop/website_controller.rb +98 -82
  14. data/app/controllers/knitkit/erp_app/desktop/website_host_controller.rb +77 -0
  15. data/app/controllers/knitkit/erp_app/desktop/website_nav_controller.rb +64 -44
  16. data/app/controllers/knitkit/erp_app/desktop/website_nav_item_controller.rb +147 -0
  17. data/app/controllers/knitkit/erp_app/desktop/website_section_controller.rb +81 -45
  18. data/app/controllers/knitkit/mobile_controller.rb +15 -0
  19. data/app/controllers/knitkit/online_document_sections_controller.rb +2 -1
  20. data/app/controllers/knitkit/unauthorized_controller.rb +0 -1
  21. data/app/controllers/knitkit/website_sections_controller.rb +7 -4
  22. data/app/mailers/website_inquiry_mailer.rb +8 -7
  23. data/app/models/content.rb +11 -2
  24. data/app/models/document.rb +2 -17
  25. data/app/models/published_website.rb +96 -59
  26. data/app/models/theme.rb +100 -14
  27. data/app/models/website.rb +260 -28
  28. data/app/models/website_inquiry.rb +5 -12
  29. data/app/models/website_section.rb +9 -1
  30. data/app/views/knitkit/blogs/_add_comment.html.erb +44 -23
  31. data/app/views/knitkit/blogs/_comment.html.erb +4 -6
  32. data/app/views/knitkit/blogs/index.html.erb +63 -49
  33. data/app/views/knitkit/blogs/show.html.erb +17 -12
  34. data/app/views/knitkit/mobile/index.html.erb +162 -0
  35. data/app/views/knitkit/online_document_sections/index.html.erb +7 -5
  36. data/app/views/knitkit/unauthorized/index.html.erb +8 -4
  37. data/app/views/knitkit/website_sections/index.html.erb +8 -4
  38. data/app/views/layouts/knitkit/base.html.erb +79 -63
  39. data/app/views/layouts/knitkit/online_document_sections.html.erb +74 -52
  40. data/app/views/menus/knitkit/_default_menu.html.erb +4 -4
  41. data/app/views/menus/knitkit/_default_section_menu.html.erb +22 -23
  42. data/app/views/shared/knitkit/_bread_crumb.html.erb +10 -7
  43. data/app/views/shared/knitkit/_footer.html.erb +2 -2
  44. data/app/views/website_inquiry_mailer/inquiry.erb +23 -2
  45. data/app/widgets/contact_us/base.rb +25 -50
  46. data/app/widgets/contact_us/javascript/contact_us.js +7 -7
  47. data/app/widgets/contact_us/views/error.html.erb +6 -8
  48. data/app/widgets/contact_us/views/index.html.erb +28 -1
  49. data/app/widgets/contact_us/views/layouts/base.html.erb +9 -6
  50. data/app/widgets/contact_us/views/success.html.erb +3 -3
  51. data/app/widgets/google_map/views/index.html.erb +36 -36
  52. data/app/widgets/login/base.rb +1 -0
  53. data/app/widgets/login/javascript/login.js +3 -3
  54. data/app/widgets/login/views/index.html.erb +46 -26
  55. data/app/widgets/login/views/layouts/base.html.erb +15 -13
  56. data/app/widgets/login/views/login_header.html.erb +7 -9
  57. data/app/widgets/manage_profile/base.rb +116 -164
  58. data/app/widgets/manage_profile/views/_address.html.erb +184 -0
  59. data/app/widgets/manage_profile/views/_contact_information_form.html.erb +23 -192
  60. data/app/widgets/manage_profile/views/_email_address.html.erb +163 -0
  61. data/app/widgets/manage_profile/views/_password_form.html.erb +23 -20
  62. data/app/widgets/manage_profile/views/_phone_number.html.erb +165 -0
  63. data/app/widgets/manage_profile/views/_user_information_form.html.erb +49 -33
  64. data/app/widgets/manage_profile/views/error.html.erb +6 -0
  65. data/app/widgets/manage_profile/views/index.html.erb +44 -46
  66. data/app/widgets/manage_profile/views/layouts/base.html.erb +3 -1
  67. data/app/widgets/manage_profile/views/success.html.erb +5 -0
  68. data/app/widgets/reset_password/views/index.html.erb +33 -28
  69. data/app/widgets/reset_password/views/layouts/base.html.erb +10 -1
  70. data/app/widgets/search/base.rb +37 -25
  71. data/app/widgets/search/views/_inline_search_form.html.erb +12 -0
  72. data/app/widgets/search/views/_search_form.html.erb +41 -0
  73. data/app/widgets/search/views/index.html.erb +5 -3
  74. data/app/widgets/search/views/layouts/base.html.erb +13 -23
  75. data/app/widgets/search/views/show.html.erb +32 -47
  76. data/app/widgets/signup/base.rb +1 -1
  77. data/app/widgets/signup/javascript/signup.js +7 -9
  78. data/app/widgets/signup/views/_signup_form.html.erb +34 -29
  79. data/app/widgets/signup/views/error.html.erb +11 -11
  80. data/app/widgets/signup/views/index.html.erb +3 -2
  81. data/app/widgets/signup/views/layouts/base.html.erb +8 -5
  82. data/app/widgets/signup/views/success.html.erb +5 -4
  83. data/config/routes.rb +39 -28
  84. data/db/data_migrations/20120809020508_update_website_and_configuration.rb +3 -0
  85. data/db/migrate/20110211002317_setup_knitkit.rb +0 -1
  86. data/db/migrate/20131112013052_add_knitkit_missing_indexes.rb +33 -0
  87. data/db/migrate/20140622212723_update_website_inquiries.rb +22 -0
  88. data/db/migrate/20140911185022_add_publishing_to_website.rb +5 -0
  89. data/db/migrate/20141013073349_add_custom_fields_to_documents.rb +12 -0
  90. data/db/migrate/20141016101936_upgrade_remove_dynamic_attributes.rb +13 -0
  91. data/lib/knitkit.rb +0 -1
  92. data/lib/knitkit/engine.rb +1 -0
  93. data/lib/knitkit/extensions.rb +4 -0
  94. data/lib/knitkit/extensions/active_record/acts_as_commentable.rb +33 -0
  95. data/lib/knitkit/extensions/active_record/acts_as_document.rb +0 -12
  96. data/lib/knitkit/extensions/active_record/acts_as_publishable.rb +7 -10
  97. data/lib/knitkit/extensions/compass_ae/widgets/base.rb +2 -4
  98. data/lib/knitkit/extensions/compass_ae/widgets/widget_proxy_controller.rb +4 -1
  99. data/lib/knitkit/extensions/railties/action_view/helpers/blog_helper.rb +16 -13
  100. data/lib/knitkit/extensions/railties/action_view/helpers/content_helper.rb +10 -8
  101. data/lib/knitkit/extensions/railties/theme_support/asset_tag_helper.rb +123 -108
  102. data/lib/knitkit/extensions/will_paginate/link_renderer.rb +67 -0
  103. data/lib/knitkit/routing_filter/section_router.rb +10 -8
  104. data/lib/knitkit/syntax_validator.rb +2 -2
  105. data/lib/knitkit/version.rb +7 -3
  106. data/public/images/inline_edit/close.png +0 -0
  107. data/public/images/knitkit/close_window.png +0 -0
  108. data/public/images/knitkit/logo.png +0 -0
  109. data/public/images/knitkit/splash/images/add-site.png +0 -0
  110. data/public/images/knitkit/splash/images/adjust-site.png +0 -0
  111. data/public/images/knitkit/splash/images/browse-site.png +0 -0
  112. data/public/images/knitkit/splash/images/find-themes.png +0 -0
  113. data/public/images/knitkit/splash/images/settings.png +0 -0
  114. data/public/images/knitkit/splash/images/tutorials.png +0 -0
  115. data/public/images/knitkit/splash/splash.png +0 -0
  116. data/public/javascripts/erp_app/desktop/applications/knitkit/articles_grid_panel.js +656 -627
  117. data/public/javascripts/erp_app/desktop/applications/knitkit/center_region.js +444 -333
  118. data/public/javascripts/erp_app/desktop/applications/knitkit/{east_region.js → east_region/east_region.js} +33 -33
  119. data/public/javascripts/erp_app/desktop/applications/knitkit/east_region/file_assets_panel.js +332 -0
  120. data/public/javascripts/erp_app/desktop/applications/knitkit/east_region/image_assets_data_view.js +144 -0
  121. data/public/javascripts/erp_app/desktop/applications/knitkit/east_region/image_assets_panel.js +335 -0
  122. data/public/javascripts/erp_app/desktop/applications/knitkit/{widgets_panel.js → east_region/widgets_panel.js} +55 -55
  123. data/public/javascripts/erp_app/desktop/applications/knitkit/inquiries_grid_panel.js +150 -37
  124. data/public/javascripts/erp_app/desktop/applications/knitkit/module.js +228 -96
  125. data/public/javascripts/erp_app/desktop/applications/knitkit/publish_window.js +89 -85
  126. data/public/javascripts/erp_app/desktop/applications/knitkit/published_grid_panel.js +238 -217
  127. data/public/javascripts/erp_app/desktop/applications/knitkit/select_roles_window.js +59 -54
  128. data/public/javascripts/erp_app/desktop/applications/knitkit/splash_screen.js +170 -0
  129. data/public/javascripts/erp_app/desktop/applications/knitkit/top_menu/main_menu.js +1168 -0
  130. data/public/javascripts/erp_app/desktop/applications/knitkit/top_menu/websites_combo.js +71 -0
  131. data/public/javascripts/erp_app/desktop/applications/knitkit/versions_grid_panel.js +301 -306
  132. data/public/javascripts/erp_app/desktop/applications/knitkit/west_region/helpers/article.js +216 -0
  133. data/public/javascripts/erp_app/desktop/applications/knitkit/west_region/helpers/document.js +182 -153
  134. data/public/javascripts/erp_app/desktop/applications/knitkit/west_region/helpers/host.js +48 -65
  135. data/public/javascripts/erp_app/desktop/applications/knitkit/west_region/helpers/menu.js +93 -94
  136. data/public/javascripts/erp_app/desktop/applications/knitkit/west_region/helpers/section.js +523 -197
  137. data/public/javascripts/erp_app/desktop/applications/knitkit/west_region/helpers/website_nav_items.js +20 -34
  138. data/public/javascripts/erp_app/desktop/applications/knitkit/west_region/hosts_tree_panel.js +74 -0
  139. data/public/javascripts/erp_app/desktop/applications/knitkit/west_region/menu_tree_panel.js +245 -0
  140. data/public/javascripts/erp_app/desktop/applications/knitkit/west_region/site_contents_tree_panel.js +360 -0
  141. data/public/javascripts/erp_app/desktop/applications/knitkit/west_region/themes_tree_panel.js +348 -0
  142. data/public/javascripts/erp_app/desktop/applications/knitkit/west_region/west_region.js +106 -1132
  143. data/public/javascripts/knitkit/bootstrap-datepicker.js +474 -0
  144. data/public/javascripts/knitkit/bootstrap.min.js +7 -0
  145. data/public/javascripts/knitkit/confirm-bootstrap.js +110 -0
  146. data/public/javascripts/knitkit/inline_editing.js +73 -50
  147. data/public/javascripts/knitkit/jquery.maskedinput.min.js +7 -0
  148. data/public/javascripts/knitkit/mobile/app/view/Main.js +108 -0
  149. data/public/javascripts/knitkit/mobile/ux/slidenavigation/View.js +734 -0
  150. data/public/javascripts/knitkit/theme.js +76 -0
  151. data/public/stylesheets/erp_app/desktop/applications/knitkit/knitkit.css +95 -35
  152. data/public/stylesheets/knitkit/bootstrap-responsive.min.css +10 -0
  153. data/public/stylesheets/knitkit/bootstrap.min.css +7 -0
  154. data/public/stylesheets/knitkit/custom.css +122 -0
  155. data/public/stylesheets/knitkit/datepicker.css +182 -0
  156. data/public/stylesheets/knitkit/inline_editing.css +58 -58
  157. data/spec/controllers/knitkit/erp_app/desktop/website_section_controller_spec.rb +1 -1
  158. data/spec/dummy/config/application.rb +1 -1
  159. data/spec/models/article_spec.rb +3 -3
  160. data/spec/models/content_spec.rb +9 -9
  161. data/spec/models/website_spec.rb +1 -1
  162. metadata +100 -114
  163. data/app/helpers/application_helper.rb +0 -134
  164. data/app/views/knitkit/articles/index.html.erb +0 -3
  165. data/app/views/knitkit/articles/show.html.erb +0 -4
  166. data/app/views/menus/knitkit/_default_sub_menu.html.erb +0 -43
  167. data/app/views/menus/knitkit/_default_sub_section_menu.html.erb +0 -47
  168. data/app/widgets/contact_us/views/_contact_form.html.erb +0 -36
  169. data/app/widgets/dynamic_forms/base.rb +0 -139
  170. data/app/widgets/dynamic_forms/javascript/dynamic_forms.js +0 -110
  171. data/app/widgets/dynamic_forms/views/error.html.erb +0 -5
  172. data/app/widgets/dynamic_forms/views/index.html.erb +0 -8
  173. data/app/widgets/dynamic_forms/views/success.html.erb +0 -4
  174. data/app/widgets/dynamic_grid/base.rb +0 -130
  175. data/app/widgets/dynamic_grid/helpers/controller/dynamic_grid_controller_helper.rb +0 -3
  176. data/app/widgets/dynamic_grid/helpers/view/dynamic_grid_view_helper.rb +0 -3
  177. data/app/widgets/dynamic_grid/javascript/dynamic_grid.js +0 -177
  178. data/app/widgets/dynamic_grid/views/index.html.erb +0 -14
  179. data/app/widgets/login/views/reset_password.html.erb +0 -26
  180. data/app/widgets/manage_profile/views/default_type_error.html.erb +0 -5
  181. data/app/widgets/scaffold/base.rb +0 -87
  182. data/app/widgets/scaffold/helpers/controller/scaffold_controller_helper.rb +0 -3
  183. data/app/widgets/scaffold/helpers/view/scaffold_view_helper.rb +0 -3
  184. data/app/widgets/scaffold/javascript/scaffold.js +0 -337
  185. data/app/widgets/scaffold/views/index.html.erb +0 -15
  186. data/app/widgets/search/views/_search.html.erb +0 -39
  187. data/public/images/knitkit/bullet.png +0 -0
  188. data/public/images/knitkit/close.png +0 -0
  189. data/public/images/knitkit/content.png +0 -0
  190. data/public/images/knitkit/footer.png +0 -0
  191. data/public/images/knitkit/graphic.png +0 -0
  192. data/public/images/knitkit/greyFadeDown.png +0 -0
  193. data/public/images/knitkit/link.png +0 -0
  194. data/public/images/knitkit/menu.png +0 -0
  195. data/public/images/knitkit/menu_select.png +0 -0
  196. data/public/images/knitkit/search.png +0 -0
  197. data/public/images/knitkit/tooltip.gif +0 -0
  198. data/public/javascripts/ajax_pagination.js +0 -33
  199. data/public/javascripts/datepicker.js +0 -445
  200. data/public/javascripts/erp_app/desktop/applications/knitkit/file_assets_panel.js +0 -341
  201. data/public/javascripts/erp_app/desktop/applications/knitkit/image_assets_data_view.js +0 -31
  202. data/public/javascripts/erp_app/desktop/applications/knitkit/image_assets_panel.js +0 -263
  203. data/public/javascripts/erp_app/desktop/applications/knitkit/section_articles_grid_panel.js +0 -722
  204. data/public/javascripts/erp_app/desktop/applications/knitkit/themes_tree_panel.js +0 -585
  205. data/public/javascripts/erp_app/desktop/applications/knitkit/west_region/helpers/website.js +0 -155
  206. data/public/javascripts/knitkit/helpers.js +0 -26
  207. data/public/stylesheets/datepicker.css +0 -121
  208. data/public/stylesheets/extjs/resources/css/knitkit_extjs_4.css +0 -233
  209. data/public/stylesheets/knitkit/style.css +0 -426
@@ -3,7 +3,7 @@ class PublishedWebsite < ActiveRecord::Base
3
3
 
4
4
  belongs_to :website
5
5
  belongs_to :published_by, :class_name => "User"
6
- has_many :published_elements, :dependent => :destroy
6
+ has_many :published_elements, :dependent => :delete_all
7
7
 
8
8
  def published_by_username
9
9
  self.published_by.username rescue ''
@@ -25,91 +25,128 @@ class PublishedWebsite < ActiveRecord::Base
25
25
  end
26
26
 
27
27
  def publish(comment, current_user)
28
- new_publication = clone_publication(1, comment, current_user)
29
- elements = []
30
-
31
- #get a publish sections
32
- website_sections = new_publication.website.website_sections
33
- website_sections = website_sections | website_sections.collect { |section| section.descendants }.flatten
34
- website_sections.each do |website_section|
35
- #get nested elements too
36
- website_section.self_and_descendants.each do |website_section|
37
- if new_publication.published_elements.where('published_element_record_id = ? and (published_element_record_type = ? or published_element_record_type = ?)', website_section.id, website_section.class.to_s, website_section.class.superclass.to_s).first.nil?
28
+ # if the site is currently being published we need to wait
29
+ # we want to sleep for 2 seconds and only try 3 times then give up
30
+ try_count = 0
31
+ while website.reload.publishing? and try_count < 2
32
+ sleep(2.seconds)
33
+ try_count += 1
34
+ end
35
+
36
+ # lock website for publishing
37
+ website.publishing = true
38
+ website.save
39
+
40
+ # wrap in transaction so if something fails it rolls back
41
+ ActiveRecord::Base.transaction do
42
+ new_publication = clone_publication(comment, current_user)
43
+ elements = []
44
+
45
+ #get a publish sections
46
+ website_sections = new_publication.website.website_sections
47
+ website_sections = website_sections | website_sections.collect { |section| section.descendants }.flatten
48
+ website_sections.each do |website_section|
49
+ #get nested elements too
50
+ website_section.self_and_descendants.each do |website_section|
51
+ if new_publication.published_elements.where('published_element_record_id = ? and (published_element_record_type = ? or published_element_record_type = ?)', website_section.id, website_section.class.to_s, website_section.class.superclass.to_s).first.nil?
52
+ published_element = PublishedElement.new
53
+ published_element.published_website = new_publication
54
+ published_element.published_element_record = website_section
55
+ published_element.version = website_section.version
56
+ published_element.published_by = current_user
57
+ published_element.save
58
+ end
59
+ end
60
+
61
+ if website_section.is_a?(OnlineDocumentSection)
62
+ elements = elements | [website_section.documented_item.content]
63
+ else
64
+ elements = elements | website_section.contents
65
+ end
66
+ end
67
+
68
+ #make sure all elements have published_element objects
69
+ elements.each do |element|
70
+ if new_publication.published_elements.where('published_element_record_id = ? and (published_element_record_type = ? or published_element_record_type = ?)', element.id, element.class.to_s, element.class.superclass.to_s).first.nil?
38
71
  published_element = PublishedElement.new
39
72
  published_element.published_website = new_publication
40
- published_element.published_element_record = website_section
41
- published_element.version = website_section.version
73
+ published_element.published_element_record = element
74
+ published_element.version = element.version
42
75
  published_element.published_by = current_user
43
76
  published_element.save
44
77
  end
45
78
  end
46
79
 
47
- if website_section.is_a?(OnlineDocumentSection)
48
- elements = elements | [website_section.documented_item.content]
49
- else
50
- elements = elements | website_section.contents
80
+ #get latest version for all elements
81
+ new_publication.published_elements.each do |published_element|
82
+ published_element.version = published_element.published_element_record.version
83
+ published_element.save
51
84
  end
52
- end
53
85
 
54
- #make sure all elements have published_element objects
55
- elements.each do |element|
56
- if new_publication.published_elements.where('published_element_record_id = ? and (published_element_record_type = ? or published_element_record_type = ?)', element.id, element.class.to_s, element.class.superclass.to_s).first.nil?
57
- published_element = PublishedElement.new
58
- published_element.published_website = new_publication
59
- published_element.published_element_record = element
60
- published_element.version = element.version
61
- published_element.published_by = current_user
62
- published_element.save
86
+ #check if we want to auto active this publication
87
+ if new_publication.website.auto_activate_publication?
88
+ PublishedWebsite.activate(new_publication.website, new_publication.version, current_user)
63
89
  end
64
- end
65
90
 
66
- #get latest version for all elements
67
- new_publication.published_elements.each do |published_element|
68
- published_element.version = published_element.published_element_record.version
69
- published_element.save
70
91
  end
71
92
 
72
- #check if we want to auto active this publication
73
- if new_publication.website.auto_activate_publication?
74
- PublishedWebsite.activate(new_publication.website, new_publication.version, current_user)
75
- end
93
+ # unlock website for publishing
94
+ website.publishing = false
95
+ website.save
76
96
  end
77
97
 
78
98
  def publish_element(comment, element, version, current_user)
79
- new_publication = clone_publication(0.1, comment, current_user)
99
+ # if the site is currently being published we need to wait
100
+ # we want to sleep for 2 seconds and only try 3 times then give up
101
+ try_count = 0
102
+ while website.reload.publishing? and try_count < 2
103
+ sleep(2.seconds)
104
+ try_count += 1
105
+ end
80
106
 
81
- published_element = new_publication.published_elements.where('published_element_record_id = ? and (published_element_record_type = ? or published_element_record_type = ?)', element.id, element.class.to_s, element.class.superclass.to_s).first
107
+ # lock website for publishing
108
+ website.publishing = true
109
+ website.save
82
110
 
83
- unless published_element.nil?
84
- published_element.version = version
85
- published_element.published_by = current_user
86
- published_element.save
87
- else
88
- new_published_element = PublishedElement.new
89
- new_published_element.published_website = new_publication
90
- new_published_element.published_element_record = element
91
- new_published_element.version = version
92
- new_published_element.published_by = current_user
93
- new_published_element.save
94
- end
111
+ # wrap in transaction so if something fails it rolls back
112
+ ActiveRecord::Base.transaction do
113
+ new_publication = clone_publication(comment, current_user)
95
114
 
96
- #check if we want to auto active this publication
97
- if new_publication.website.auto_activate_publication?
98
- PublishedWebsite.activate(new_publication.website, new_publication.version, current_user)
115
+ published_element = new_publication.published_elements.where('published_element_record_id = ? and (published_element_record_type = ? or published_element_record_type = ?)', element.id, element.class.to_s, element.class.superclass.to_s).first
116
+
117
+ unless published_element.nil?
118
+ published_element.version = version
119
+ published_element.published_by = current_user
120
+ published_element.save
121
+ else
122
+ new_published_element = PublishedElement.new
123
+ new_published_element.published_website = new_publication
124
+ new_published_element.published_element_record = element
125
+ new_published_element.version = version
126
+ new_published_element.published_by = current_user
127
+ new_published_element.save
128
+ end
129
+
130
+ #check if we want to auto active this publication
131
+ if new_publication.website.auto_activate_publication?
132
+ PublishedWebsite.activate(new_publication.website, new_publication.version, current_user)
133
+ end
99
134
  end
135
+
136
+ # unlock website for publishing
137
+ website.publishing = false
138
+ website.save
100
139
  end
101
140
 
102
141
  private
103
142
 
104
- def clone_publication(version_increment, comment, current_user)
143
+ def clone_publication(comment, current_user)
105
144
  #create new PublishedWebsite with comment
106
145
  published_website = PublishedWebsite.new
107
146
  published_website.website = self.website
108
- if version_increment == 1
109
- published_website.version = (self.version.to_i + version_increment)
110
- else
111
- published_website.version = (self.version + version_increment).round(6)
112
- end
147
+
148
+ published_website.version = (self.version.to_i + 1)
149
+
113
150
  published_website.published_by = current_user
114
151
  published_website.comment = comment
115
152
  published_website.save
@@ -5,15 +5,79 @@ class Theme < ActiveRecord::Base
5
5
  attr_protected :created_at, :updated_at
6
6
 
7
7
  THEME_STRUCTURE = ['stylesheets', 'javascripts', 'images', 'templates']
8
- class << self; attr_accessor :base_layouts_views_path, :knitkit_website_stylesheets_path, :knitkit_website_images_path end
8
+ class << self
9
+ attr_accessor :base_layouts_views_path, :knitkit_website_stylesheets_path,
10
+ :knitkit_website_images_path, :knitkit_website_javascripts_path
11
+ end
9
12
  @base_layouts_views_path = "#{Knitkit::Engine.root.to_s}/app/views"
10
13
  @knitkit_website_stylesheets_path = "#{Knitkit::Engine.root.to_s}/public/stylesheets/knitkit"
14
+ @knitkit_website_javascripts_path = "#{Knitkit::Engine.root.to_s}/public/javascripts/knitkit"
11
15
  @knitkit_website_images_path = "#{Knitkit::Engine.root.to_s}/public/images/knitkit"
12
16
 
13
17
  protected_with_capabilities
14
18
  has_file_assets
15
19
 
20
+ def import_download_item_file(file)
21
+ file_support = ErpTechSvcs::FileSupport::Base.new(:storage => Rails.application.config.erp_tech_svcs.file_storage)
22
+
23
+ theme_root = Theme.find_theme_root_from_file(file)
24
+
25
+ Zip::ZipFile.open(file) do |zip|
26
+ zip.each do |entry|
27
+ if entry.name == 'about.yml'
28
+ data = ''
29
+ entry.get_input_stream { |io| data = io.read }
30
+ data = StringIO.new(data) if data.present?
31
+ about = YAML.load(data)
32
+ self.author = about['author'] if about['author']
33
+ self.version = about['version'] if about['version']
34
+ self.homepage = about['homepage'] if about['homepage']
35
+ self.summary = about['summary'] if about['summary']
36
+ else
37
+ name = entry.name.sub(/__MACOSX\//, '')
38
+ name = Theme.strip_path(name, theme_root)
39
+ data = ''
40
+ entry.get_input_stream { |io| data = io.read }
41
+ data = StringIO.new(data) if data.present?
42
+ theme_file = self.files.where("name = ? and directory = ?", File.basename(name), File.join(self.url,File.dirname(name))).first
43
+ unless theme_file.nil?
44
+ theme_file.data = data
45
+ theme_file.save
46
+ else
47
+ self.add_file(data, File.join(file_support.root, self.url,name)) rescue next
48
+ end
49
+ end
50
+ end
51
+ end
52
+ activate!
53
+ end
54
+
16
55
  class << self
56
+ def import_download_item(tempfile, website)
57
+ name_and_id = tempfile.gsub(/(^.*(\\|\/))|(\.zip$)/, '')
58
+ theme_name = name_and_id.split('[').first
59
+ theme_id = name_and_id.split('[').last.gsub(']','')
60
+ Theme.create(:name => theme_name.sub(/-theme/, ''), :theme_id => theme_id, :website_id => website.id).tap do |theme|
61
+ theme.import_download_item_file(tempfile)
62
+ end
63
+ end
64
+
65
+
66
+ def find_theme_root_from_file(file)
67
+ theme_root = ''
68
+ Zip::ZipFile.open(file) do |zip|
69
+ zip.each do |entry|
70
+ entry.name.sub!(/__MACOSX\//, '')
71
+ if theme_root == root_in_path(entry.name)
72
+ break
73
+ end
74
+ end
75
+ end
76
+ theme_root
77
+ end
78
+
79
+
80
+
17
81
  def root_dir
18
82
  @@root_dir ||= "#{Rails.root}/public"
19
83
  end
@@ -120,8 +184,6 @@ class Theme < ActiveRecord::Base
120
184
  Zip::ZipFile.open(file.path) do |zip|
121
185
  zip.each do |entry|
122
186
  if entry.name == 'about.yml'
123
- #TODO
124
- #FIXME this does not work for some reason
125
187
  data = ''
126
188
  entry.get_input_stream { |io| data = io.read }
127
189
  data = StringIO.new(data) if data.present?
@@ -146,6 +208,7 @@ class Theme < ActiveRecord::Base
146
208
  end
147
209
  end
148
210
  end
211
+
149
212
  end
150
213
 
151
214
  def export
@@ -213,6 +276,7 @@ class Theme < ActiveRecord::Base
213
276
  file_support = ErpTechSvcs::FileSupport::Base.new
214
277
  create_theme_files_for_directory_node(file_support.build_tree(Theme.base_layouts_views_path, :preload => true), :templates, :path_to_replace => Theme.base_layouts_views_path)
215
278
  create_theme_files_for_directory_node(file_support.build_tree(Theme.knitkit_website_stylesheets_path, :preload => true), :stylesheets, :path_to_replace => Theme.knitkit_website_stylesheets_path)
279
+ create_theme_files_for_directory_node(file_support.build_tree(Theme.knitkit_website_javascripts_path, :preload => true), :javascripts, :path_to_replace => Theme.knitkit_website_javascripts_path)
216
280
  create_theme_files_for_directory_node(file_support.build_tree(Theme.knitkit_website_images_path, :preload => true), :images, :path_to_replace => Theme.knitkit_website_images_path)
217
281
  end
218
282
 
@@ -225,18 +289,40 @@ class Theme < ActiveRecord::Base
225
289
  end
226
290
 
227
291
  def save_theme_file(path, type, options)
228
- contents = IO.read(path)
229
- contents.gsub!("../../images/knitkit","../images") unless path.scan('style.css').empty?
230
- contents.gsub!("<%= static_stylesheet_link_tag('knitkit/style.css') %>","<%= theme_stylesheet_link_tag('#{self.theme_id}','style.css') %>") unless path.scan('base.html.erb').empty?
231
-
232
- path = case type
233
- when :widgets
234
- path.gsub(options[:path_to_replace], "#{self.url}/widgets/#{options[:widget_name]}")
235
- else
236
- path.gsub(options[:path_to_replace], "#{self.url}/#{type.to_s}")
292
+ ignored_css = [
293
+ 'bootstrap.min.css',
294
+ 'bootstrap-responsive.min.css',
295
+ 'datepicker.css',
296
+ 'inline_editing.css',
297
+ ]
298
+
299
+ ignored_js = [
300
+ 'bootstrap.min.js',
301
+ 'bootstrap-datepicker.js',
302
+ 'confirm-bootstrap.js',
303
+ 'inline_editing.js',
304
+ 'jquery.maskedinput.min.js',
305
+ 'Main.js',
306
+ 'View.js'
307
+ ]
308
+
309
+ ignored_files = (ignored_css | ignored_js).flatten
310
+
311
+ unless ignored_files.any? { |w| path =~ /#{w}/ }
312
+ contents = IO.read(path)
313
+ contents.gsub!("<%= static_stylesheet_link_tag 'knitkit/custom.css' %>","<%= theme_stylesheet_link_tag '#{self.theme_id}','custom.css' %>") unless path.scan('base.html.erb').empty?
314
+ contents.gsub!("<%= static_javascript_include_tag 'knitkit/theme.js' %>","<%= theme_javascript_include_tag '#{self.theme_id}','theme.js' %>") unless path.scan('base.html.erb').empty?
315
+
316
+ path = case type
317
+ when :widgets
318
+ path.gsub(options[:path_to_replace], "#{self.url}/widgets/#{options[:widget_name]}")
319
+ else
320
+ path.gsub(options[:path_to_replace], "#{self.url}/#{type.to_s}")
321
+ end
322
+
323
+ self.add_file(contents, path)
237
324
  end
238
325
 
239
- self.add_file(contents, path)
240
326
  end
241
-
242
327
  end
328
+
@@ -1,9 +1,9 @@
1
1
  class Website < ActiveRecord::Base
2
2
  attr_protected :created_at, :updated_at
3
3
 
4
- after_destroy :remove_sites_directory, :remove_website_role
4
+ after_destroy :remove_sites_directory, :remove_website_role
5
5
  before_destroy :destroy_sections
6
- after_create :setup_website
6
+ after_create :setup_website
7
7
 
8
8
  protected_with_capabilities
9
9
  has_file_assets
@@ -54,7 +54,7 @@ class Website < ActiveRecord::Base
54
54
 
55
55
  alias :sections :website_sections
56
56
  alias :hosts :website_hosts
57
-
57
+
58
58
  #We only want to destroy parent sections as better nested set will destroy children for us
59
59
  def destroy_sections
60
60
  parents = []
@@ -63,8 +63,12 @@ class Website < ActiveRecord::Base
63
63
  parents << section
64
64
  end
65
65
  end
66
-
67
- parents.each {|parent| parent.destroy}
66
+
67
+ parents.each { |parent| parent.destroy }
68
+ end
69
+
70
+ def publishing?
71
+ self.publishing
68
72
  end
69
73
 
70
74
  def to_label
@@ -150,9 +154,7 @@ class Website < ActiveRecord::Base
150
154
  def setup_website
151
155
  PublishedWebsite.create(:website => self, :version => 0, :active => true, :comment => 'New Site Created')
152
156
  SecurityRole.create(:description => "Website #{self.title}", :internal_identifier => website_role_iid) if self.role.nil?
153
- configuration = ::Configuration.find_template('default_website_configuration').clone(true)
154
- configuration.description = "Website #{self.name} Configuration"
155
- configuration.internal_identifier = configuration.description.underscore
157
+ configuration = ::Configuration.find_template('default_website_configuration').clone(true, "Website #{self.title} Configuration", "Website #{self.title} Configuration".underscore)
156
158
  configuration.update_configuration_item(ConfigurationItemType.find_by_internal_identifier('login_url'), '/login')
157
159
  configuration.update_configuration_item(ConfigurationItemType.find_by_internal_identifier('homepage_url'), '/home')
158
160
  self.configurations << configuration
@@ -230,7 +232,7 @@ class Website < ActiveRecord::Base
230
232
  end
231
233
 
232
234
  self.files.where("directory like '%/#{Rails.application.config.erp_tech_svcs.file_assets_location}/sites/#{self.iid}%'").all.each do |file_asset|
233
- setup_hash[:files] << {:path => file_asset.directory, :name => file_asset.name, :roles => file_asset.roles.uniq.collect{|r| r.internal_identifier}}
235
+ setup_hash[:files] << {:path => file_asset.directory, :name => file_asset.name, :roles => file_asset.roles.uniq.collect { |r| r.internal_identifier }}
234
236
  end
235
237
 
236
238
  setup_hash
@@ -258,10 +260,8 @@ class Website < ActiveRecord::Base
258
260
  file_assets_path = Pathname.new(File.join(tmp_dir, 'files'))
259
261
  FileUtils.mkdir_p(file_assets_path) unless file_assets_path.exist?
260
262
 
261
- sections.each do |website_section|
262
- unless website_section.layout.blank?
263
- File.open(File.join(sections_path, "#{website_section.internal_identifier}.rhtml"), 'wb+') { |f| f.puts(website_section.layout) }
264
- end
263
+ sections.where('parent_id is null').each do |website_section|
264
+ save_section_layout_to_file(sections_path, website_section)
265
265
  end
266
266
 
267
267
  contents = sections.collect(&:contents).flatten.uniq
@@ -307,11 +307,49 @@ class Website < ActiveRecord::Base
307
307
  zip.add('setup.yml', tmp_dir + 'setup.yml')
308
308
  end
309
309
  end
310
+
311
+ end
312
+
313
+ def save_section_layout_to_file(sections_path, website_section)
314
+ unless website_section.layout.blank?
315
+ File.open(File.join(sections_path, "#{website_section.permalink}.rhtml"), 'wb+') { |f| f.puts(website_section.layout) }
316
+ end
317
+
318
+ # we need to handle child sections because internal identifier uniqueness is scoped by parent_id and website_id
319
+ # get all children of this section
320
+ unless website_section.children.empty?
321
+ sections_path = Pathname.new(File.join(sections_path, website_section.permalink))
322
+ FileUtils.mkdir_p(sections_path) unless sections_path.exist?
323
+
324
+ website_section.children.each do |website_section_child|
325
+ save_section_layout_to_file(sections_path, website_section_child)
326
+ end
327
+ end
328
+ end
329
+
330
+ def export_template
331
+ tmp_dir = Website.make_tmp_dir
332
+ template_zip_path = export
333
+
334
+ if !themes.active.first.is_a?(Theme)
335
+ return false
336
+ end
337
+
338
+ theme_zip_path = themes.active.first.export
339
+
340
+ zip_file_name = File.join(tmp_dir, self.iid + '-composite.zip')
341
+
342
+ Zip::ZipFile.open(zip_file_name, Zip::ZipFile::CREATE) do |zip_file|
343
+ zip_file.add(File.basename(template_zip_path, '.zip') + '-template.zip', template_zip_path)
344
+ zip_file.add(File.basename(theme_zip_path, '.zip') + '-theme.zip', theme_zip_path)
345
+ end
346
+
347
+ File.join(tmp_dir, self.iid + '-composite.zip')
310
348
  end
311
349
 
312
350
  class << self
313
351
  def make_tmp_dir
314
- Pathname.new(Rails.root + "/tmp/website_export/tmp_#{Time.now.to_i.to_s}/").tap do |dir|
352
+ Pathname.new(File.join(Rails.root, "/tmp/website_export/tmp_#{Time.now.to_i.to_s}")).tap do |dir|
315
353
  FileUtils.mkdir_p(dir) unless dir.exist?
316
354
  end
317
355
  end
@@ -319,7 +357,7 @@ class Website < ActiveRecord::Base
319
357
  def import(file, current_user)
320
358
  file_support = ErpTechSvcs::FileSupport::Base.new(:storage => Rails.application.config.erp_tech_svcs.file_storage)
321
359
  message = ''
322
- success = true
360
+ website = nil
323
361
 
324
362
  file = ActionController::UploadedTempfile.new("uploaded-theme").tap do |f|
325
363
  f.puts file.read
@@ -404,7 +442,7 @@ class Website < ActiveRecord::Base
404
442
  file = website.add_file(content[:data], File.join(file_support.root, file_asset[:path], file_asset[:name]))
405
443
 
406
444
  #handle security
407
- unless file_asset[:roles].empty?
445
+ unless file_asset[:roles].empty?
408
446
  capability = file.add_capability(:download)
409
447
  file_asset[:roles].each do |role_iid|
410
448
  role = SecurityRole.find_by_internal_identifier(role_iid)
@@ -443,6 +481,173 @@ class Website < ActiveRecord::Base
443
481
 
444
482
  website.publish("Website Imported", current_user)
445
483
 
484
+ rescue => ex
485
+ Rails.logger.error "#{ex.inspect} #{ex.backtrace}"
486
+ website.destroy unless website.nil?
487
+ raise ex
488
+ end
489
+
490
+ website.save
491
+ else
492
+ message = 'Website already exists with that internal_identifier'
493
+ end
494
+
495
+ return website, message
496
+ end
497
+
498
+ def import_template_director(file, current_user)
499
+ file_object = file.tempfile
500
+ file_path = file_object.path
501
+
502
+ entries = []
503
+ begin
504
+ Zip::ZipFile.open(file_path) { |zip_file|
505
+ zip_file.each { |f|
506
+ f_path=File.join('public/waste', f.name)
507
+ FileUtils.mkdir_p(File.dirname(f_path))
508
+ zip_file.extract(f, f_path) unless File.exist?(f_path)
509
+ entries << f.name
510
+ }
511
+ }
512
+
513
+ entries.each do |entry|
514
+ if entry.match(/-template.zip/)
515
+ @website_result = import_template('public/waste/' + entry, current_user)
516
+ end
517
+ end
518
+ entries.each do |entry|
519
+ if entry.match(/-theme.zip/)
520
+ Theme.import_download_item('public/waste/' + entry, @website_result[0])
521
+ end
522
+ end
523
+ return @website_result[0], @website_result[1]
524
+ rescue Exception => e
525
+ return false, "Error"
526
+ end
527
+ end
528
+
529
+ def import_template(file, current_user)
530
+ file_support = ErpTechSvcs::FileSupport::Base.new(:storage => Rails.application.config.erp_tech_svcs.file_storage)
531
+ message = ''
532
+ website = nil
533
+
534
+ entries = []
535
+ setup_hash = nil
536
+
537
+ tmp_dir = Website.make_tmp_dir
538
+
539
+ Zip::ZipFile.open(file) do |zip|#passing in a file
540
+ #Zip::ZipFile.open(file.path) do |zip|
541
+ zip.each do |entry|
542
+ f_path = File.join(tmp_dir.to_s, entry.name)
543
+ FileUtils.mkdir_p(File.dirname(f_path))
544
+ zip.extract(entry, f_path) unless File.exist?(f_path)
545
+
546
+ next if entry.name =~ /__MACOSX\//
547
+ if entry.name =~ /setup.yml/
548
+ data = ''
549
+ entry.get_input_stream { |io| data = io.read }
550
+ data = StringIO.new(data) if data.present?
551
+ setup_hash = YAML.load(data)
552
+ else
553
+ type = entry.name.split('/')[0]
554
+ name = entry.name.split('/').last
555
+ next if name.nil?
556
+
557
+ if File.exist?(f_path) and !File.directory?(f_path)
558
+ entry_hash = {:type => type, :name => name, :path => entry.name}
559
+ entries << entry_hash unless name == 'sections' || name == 'articles' || name == 'excerpts' || name == 'documented contents'
560
+ entry_hash[:data] = File.open(f_path, "rb") { |io| io.read }
561
+ end
562
+ end
563
+
564
+ end
565
+ end
566
+ entries.uniq!
567
+ FileUtils.rm_rf(tmp_dir.to_s)
568
+
569
+ if Website.find_by_internal_identifier(setup_hash[:internal_identifier]).nil?
570
+ website = Website.new(
571
+ :name => setup_hash[:name],
572
+ :title => setup_hash[:title],
573
+ :subtitle => setup_hash[:subtitle],
574
+ :internal_identifier => setup_hash[:internal_identifier]
575
+ )
576
+
577
+ #TODO update to handle configurations
578
+
579
+ website.save!
580
+
581
+ #set default publication published by user
582
+ first_publication = website.published_websites.first
583
+ first_publication.published_by = current_user
584
+ first_publication.save
585
+
586
+ begin
587
+ #handle images
588
+ # entries.each do |entry|
589
+ # puts "entry type '#{entry[:type]}'"
590
+ # puts "entry name '#{entry[:name]}'"
591
+ # puts "entry path '#{entry[:path]}'"
592
+ # puts "entry data #{!entry[:data].blank?}"
593
+ # end
594
+ # puts "------------------"
595
+ setup_hash[:images].each do |image_asset|
596
+ filename = 'images' + image_asset[:path] + '/' + image_asset[:name]
597
+ #puts "image_asset '#{filename}'"
598
+ content = entries.find { |entry| entry[:type] == 'images' and entry[:path] == filename }
599
+ unless content.nil?
600
+ website.add_file(content[:data], File.join(file_support.root, image_asset[:path], image_asset[:name]))
601
+ end
602
+ end
603
+
604
+ #handle files
605
+ setup_hash[:files].each do |file_asset|
606
+ filename = 'files' + file_asset[:path] + '/' + file_asset[:name]
607
+ #puts "file_asset '#{filename}'"
608
+ content = entries.find { |entry| entry[:type] == 'files' and entry[:path] == filename }
609
+ unless content.nil?
610
+ file = website.add_file(content[:data], File.join(file_support.root, file_asset[:path], file_asset[:name]))
611
+
612
+ #handle security
613
+ unless file_asset[:roles].empty?
614
+ capability = file.add_capability(:download)
615
+ file_asset[:roles].each do |role_iid|
616
+ role = SecurityRole.find_by_internal_identifier(role_iid)
617
+ role.add_capability(capability)
618
+ end
619
+ end
620
+ end
621
+ end
622
+
623
+ #handle hosts
624
+ if WebsiteHost.last
625
+ setup_hash.merge(:hosts => 'localhost:3000')
626
+ end
627
+
628
+ if !setup_hash[:hosts].blank? and !setup_hash[:hosts].empty?
629
+ #set first host as primary host in configuration
630
+ website.configurations.first.update_configuration_item(ConfigurationItemType.find_by_internal_identifier('primary_host'), 'localhost:3000')
631
+ website.save
632
+ end
633
+
634
+ #handle sections
635
+ setup_hash[:sections].each do |section_hash|
636
+ build_section(section_hash, entries, website, current_user)
637
+ end
638
+ website.website_sections.update_paths!
639
+
640
+ #handle website_navs
641
+ setup_hash[:website_navs].each do |website_nav_hash|
642
+ website_nav = WebsiteNav.new(:name => website_nav_hash[:name])
643
+ website_nav_hash[:items].each do |item|
644
+ website_nav.website_nav_items << build_menu_item(item)
645
+ end
646
+ website.website_navs << website_nav
647
+ end
648
+
649
+ website.publish("Website Imported", current_user)
650
+
446
651
  rescue Exception => ex
447
652
  Rails.logger.error "#{ex.inspect} #{ex.backtrace}"
448
653
  website.destroy unless website.nil?
@@ -450,17 +655,38 @@ class Website < ActiveRecord::Base
450
655
  end
451
656
 
452
657
  website.save
453
- success = true
454
658
  else
455
659
  message = 'Website already exists with that internal_identifier'
456
- success = false
457
660
  end
458
661
 
459
- return success, message
662
+ return website, message
663
+ end
664
+
665
+
666
+ def find_site_entry_in_zip(file)
667
+ zf = Zip::ZipFile.open(file)
668
+ zf.each_with_index { |entry, index|
669
+ if entry.name.match(/-template.zip/) && !entry.name.match(/_./)
670
+ return entry
671
+ end
672
+ }
673
+ end
674
+
675
+ def find_theme_entries_in_zip(file)
676
+ entries = []
677
+ zf = Zip::ZipFile.new(file)
678
+ zf.each_with_index { |entry, index|
679
+ if entry.name.match(/-theme.zip/) && !entry.name.match(/_./)
680
+ entries << entry
681
+ end
682
+ }
683
+ entries
460
684
  end
461
685
 
686
+
462
687
  protected
463
688
 
689
+
464
690
  def build_menu_item(hash)
465
691
  website_item = WebsiteNavItem.new(
466
692
  :title => hash[:title],
@@ -475,16 +701,16 @@ class Website < ActiveRecord::Base
475
701
  child_website_item = build_menu_item(item)
476
702
  child_website_item.move_to_child_of(website_item)
477
703
  end
478
-
704
+
479
705
  #handle security
480
- unless hash[:roles].empty?
706
+ unless hash[:roles].empty?
481
707
  capability = website_item.add_capability(:view)
482
708
  hash[:roles].each do |role_iid|
483
709
  role = SecurityRole.find_by_internal_identifier(role_iid)
484
710
  role.add_capability(capability)
485
711
  end
486
712
  end
487
-
713
+
488
714
  website_item
489
715
  end
490
716
 
@@ -498,7 +724,9 @@ class Website < ActiveRecord::Base
498
724
  section.internal_identifier = hash[:internal_identifier]
499
725
  section.permalink = hash[:permalink]
500
726
  section.path = hash[:path]
501
- content = entries.find { |entry| entry[:type] == 'sections' and entry[:name] == "#{hash[:internal_identifier]}.rhtml" }
727
+ content = entries.find do |entry|
728
+ entry[:type] == 'sections' and entry[:name] == "#{hash[:permalink]}.rhtml" and entry[:path].split('.')[0] == "sections#{hash[:path]}"
729
+ end
502
730
 
503
731
  section.layout = content[:data] unless content.nil?
504
732
 
@@ -529,7 +757,7 @@ class Website < ActiveRecord::Base
529
757
  if section.is_a? OnlineDocumentSection
530
758
  section.use_markdown = hash[:use_markdown]
531
759
  section.save
532
- extension_type = hash[:use_markdown] ? 'md' : 'html'
760
+ extension_type = hash[:use_markdown] ? 'md' : 'html'
533
761
  entry_data = entries.find { |entry| entry[:type] == 'documented contents' and entry[:name] == "#{section.internal_identifier}.#{extension_type}" }[:data]
534
762
  documented_content = DocumentedContent.create(:title => section.title, :body_html => entry_data)
535
763
  DocumentedItem.create(:documented_content_id => documented_content.id, :online_document_section_id => section.id)
@@ -541,27 +769,31 @@ class Website < ActiveRecord::Base
541
769
  child_section.save
542
770
  child_section.move_to_child_of(section)
543
771
  # CREATE THE DOCUMENTED CONTENT HERE
544
- extension_type = section_hash[:use_markdown] ? 'md' : 'html'
772
+ extension_type = section_hash[:use_markdown] ? 'md' : 'html'
545
773
  entry_data = entries.find { |entry| entry[:type] == 'documented contents' and entry[:name] == "#{child_section.internal_identifier}.#{extension_type}" }[:data]
546
774
  documented_content = DocumentedContent.create(:title => child_section.title, :body_html => entry_data)
547
775
  DocumentedItem.create(:documented_content_id => documented_content.id, :online_document_section_id => child_section.id)
548
776
  end
549
777
  end
550
-
778
+
551
779
  #handle security
552
780
  if hash[:roles] #if this is a OnlineDocumentSection will not have roles
553
- unless hash[:roles].empty?
781
+ unless hash[:roles].empty?
554
782
  capability = section.add_capability(:view)
555
783
  hash[:roles].each do |role_iid|
556
784
  role = SecurityRole.find_by_internal_identifier(role_iid)
785
+ if role.nil?
786
+ role = SecurityRole.create(internal_identifier: role_iid, description: role_iid.humanize)
787
+ end
557
788
  role.add_capability(capability)
558
789
  end
559
790
  end
560
791
  end
561
-
792
+
562
793
  section
563
794
  end
564
795
 
796
+
565
797
  end
566
798
 
567
799
  def website_role_iid