drg_cms 0.4.39

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +39 -0
  5. data/app/assets/images/drg_cms/add.png +0 -0
  6. data/app/assets/images/drg_cms/arrow_in.png +0 -0
  7. data/app/assets/images/drg_cms/arrow_out.png +0 -0
  8. data/app/assets/images/drg_cms/checkbox-checked.png +0 -0
  9. data/app/assets/images/drg_cms/checkbox-unchecked.png +0 -0
  10. data/app/assets/images/drg_cms/cols.png +0 -0
  11. data/app/assets/images/drg_cms/copy.png +0 -0
  12. data/app/assets/images/drg_cms/edit.png +0 -0
  13. data/app/assets/images/drg_cms/edit_design.png +0 -0
  14. data/app/assets/images/drg_cms/edit_page.png +0 -0
  15. data/app/assets/images/drg_cms/edit_site.png +0 -0
  16. data/app/assets/images/drg_cms/html.png +0 -0
  17. data/app/assets/images/drg_cms/pin.png +0 -0
  18. data/app/assets/images/drg_cms/printer.png +0 -0
  19. data/app/assets/images/drg_cms/reload.png +0 -0
  20. data/app/assets/images/drg_cms/search_16.png +0 -0
  21. data/app/assets/images/drg_cms/spinner.gif +0 -0
  22. data/app/assets/images/drg_cms/view_tile.png +0 -0
  23. data/app/assets/images/drg_cms/x.png +0 -0
  24. data/app/assets/javascripts/drg_cms/drg_cms.js +449 -0
  25. data/app/assets/javascripts/drg_cms/jquery-migrate.js +511 -0
  26. data/app/assets/javascripts/drg_cms/jquery.datetimepicker.js +1353 -0
  27. data/app/assets/javascripts/drg_cms/some_scripts.js +33 -0
  28. data/app/assets/javascripts/drg_cms_application.js +11 -0
  29. data/app/assets/javascripts/drg_cms_cms.js +28 -0
  30. data/app/assets/stylesheets/drg_cms/drg_cms.css +632 -0
  31. data/app/assets/stylesheets/drg_cms/jquery-ui.css +339 -0
  32. data/app/assets/stylesheets/drg_cms/jquery.datetimepicker.css +304 -0
  33. data/app/assets/stylesheets/drg_cms/th-bg.png +0 -0
  34. data/app/assets/stylesheets/drg_cms/theme.css +49 -0
  35. data/app/assets/stylesheets/drg_cms_application.css +12 -0
  36. data/app/assets/stylesheets/drg_cms_cms.css +26 -0
  37. data/app/controllers/cmsedit_controller.rb +673 -0
  38. data/app/controllers/dc_application_controller.rb +385 -0
  39. data/app/controllers/dc_at_the_beginning_controller.rb +120 -0
  40. data/app/controllers/dc_common_controller.rb +314 -0
  41. data/app/controllers/dc_mail_controller.rb +89 -0
  42. data/app/controllers/dc_main_controller.rb +40 -0
  43. data/app/controllers/drgcms_controls/dc_page_controls.rb +40 -0
  44. data/app/forms/all_options.yml +176 -0
  45. data/app/forms/cms_forms.yml +93 -0
  46. data/app/forms/cms_menu.yml +142 -0
  47. data/app/forms/dc_ad.yml +130 -0
  48. data/app/forms/dc_big_table.yml +59 -0
  49. data/app/forms/dc_big_table_locale.yml +41 -0
  50. data/app/forms/dc_big_table_value.yml +47 -0
  51. data/app/forms/dc_category.yml +57 -0
  52. data/app/forms/dc_design.yml +68 -0
  53. data/app/forms/dc_folder_permission.yml +49 -0
  54. data/app/forms/dc_forum_cat.yml +54 -0
  55. data/app/forms/dc_forum_forum.yml +53 -0
  56. data/app/forms/dc_forum_msg.yml +124 -0
  57. data/app/forms/dc_forum_privmsg.yml +125 -0
  58. data/app/forms/dc_forum_topic.yml +131 -0
  59. data/app/forms/dc_journal.yml +85 -0
  60. data/app/forms/dc_link.yml +55 -0
  61. data/app/forms/dc_mail.yml +88 -0
  62. data/app/forms/dc_mail_address.yml +56 -0
  63. data/app/forms/dc_mail_list.yml +44 -0
  64. data/app/forms/dc_mail_list_member.yml +42 -0
  65. data/app/forms/dc_menu.yml +62 -0
  66. data/app/forms/dc_menu_item.yml +81 -0
  67. data/app/forms/dc_page.yml +145 -0
  68. data/app/forms/dc_part.yml +102 -0
  69. data/app/forms/dc_permission.yml +50 -0
  70. data/app/forms/dc_piece.yml +105 -0
  71. data/app/forms/dc_policy.yml +57 -0
  72. data/app/forms/dc_policy_role.yml +42 -0
  73. data/app/forms/dc_policy_rule.yml +38 -0
  74. data/app/forms/dc_policy_rule_nocms.yml +38 -0
  75. data/app/forms/dc_poll.yml +113 -0
  76. data/app/forms/dc_poll_item.yml +76 -0
  77. data/app/forms/dc_simple_menu.yml +64 -0
  78. data/app/forms/dc_simple_menu_item.yml +80 -0
  79. data/app/forms/dc_site.yml +149 -0
  80. data/app/forms/dc_user.yml +142 -0
  81. data/app/forms/dc_user_role.yml +54 -0
  82. data/app/forms/drgcms_cms.yml +28 -0
  83. data/app/helpers/cmsedit_helper.rb +698 -0
  84. data/app/helpers/dc_ad_renderer.rb +206 -0
  85. data/app/helpers/dc_application_helper.rb +704 -0
  86. data/app/helpers/dc_big_menu_renderer.rb +180 -0
  87. data/app/helpers/dc_captcha_renderer.rb +100 -0
  88. data/app/helpers/dc_common_renderer.rb +132 -0
  89. data/app/helpers/dc_mail_renderer.rb +76 -0
  90. data/app/helpers/dc_menu_renderer.rb +143 -0
  91. data/app/helpers/dc_page_renderer.rb +80 -0
  92. data/app/helpers/dc_part_renderer.rb +162 -0
  93. data/app/helpers/dc_piece_renderer.rb +124 -0
  94. data/app/helpers/dc_poll_renderer.rb +219 -0
  95. data/app/helpers/dc_renderer.rb +56 -0
  96. data/app/helpers/dc_simple_menu_renderer.rb +244 -0
  97. data/app/helpers/drgcms_form_field.rb +863 -0
  98. data/app/models/__dc_global_data.rb +44 -0
  99. data/app/models/dc_ad.rb +52 -0
  100. data/app/models/dc_ad_stat.rb +34 -0
  101. data/app/models/dc_big_menu.rb +89 -0
  102. data/app/models/dc_big_table.rb +63 -0
  103. data/app/models/dc_big_table_locale.rb +35 -0
  104. data/app/models/dc_big_table_value.rb +38 -0
  105. data/app/models/dc_category.rb +48 -0
  106. data/app/models/dc_design.rb +48 -0
  107. data/app/models/dc_dummy.rb +30 -0
  108. data/app/models/dc_folder_permission.rb +43 -0
  109. data/app/models/dc_global_data.rb +44 -0
  110. data/app/models/dc_journal.rb +39 -0
  111. data/app/models/dc_key_value_store.rb +90 -0
  112. data/app/models/dc_link.rb +39 -0
  113. data/app/models/dc_mail.rb +64 -0
  114. data/app/models/dc_mail_address.rb +69 -0
  115. data/app/models/dc_mail_list.rb +48 -0
  116. data/app/models/dc_mail_list_member.rb +34 -0
  117. data/app/models/dc_menu.rb +59 -0
  118. data/app/models/dc_menu_item.rb +40 -0
  119. data/app/models/dc_page.rb +123 -0
  120. data/app/models/dc_part.rb +28 -0
  121. data/app/models/dc_permission.rb +58 -0
  122. data/app/models/dc_piece.rb +57 -0
  123. data/app/models/dc_policy.rb +94 -0
  124. data/app/models/dc_policy_role.rb +47 -0
  125. data/app/models/dc_policy_rule.rb +65 -0
  126. data/app/models/dc_poll.rb +46 -0
  127. data/app/models/dc_poll_item.rb +40 -0
  128. data/app/models/dc_sendmail.rb +48 -0
  129. data/app/models/dc_simple_menu.rb +58 -0
  130. data/app/models/dc_simple_menu_item.rb +39 -0
  131. data/app/models/dc_site.rb +92 -0
  132. data/app/models/dc_stat.rb +36 -0
  133. data/app/models/dc_user.rb +91 -0
  134. data/app/models/dc_user_role.rb +36 -0
  135. data/app/models/dc_visit.rb +35 -0
  136. data/app/views/cmsedit/_edit_stuff.html.erb +59 -0
  137. data/app/views/cmsedit/_edit_stuff.js.erb +6 -0
  138. data/app/views/cmsedit/_form.html.erb +21 -0
  139. data/app/views/cmsedit/_result.html.erb +20 -0
  140. data/app/views/cmsedit/edit.html.erb +6 -0
  141. data/app/views/cmsedit/error.html.erb +2 -0
  142. data/app/views/cmsedit/index.html.erb +6 -0
  143. data/app/views/cmsedit/new.html.erb +5 -0
  144. data/app/views/cmsedit/show.html.erb +21 -0
  145. data/app/views/dc_at_the_beginning/create.html.erb +9 -0
  146. data/app/views/dc_at_the_beginning/index.html.erb +19 -0
  147. data/app/views/dc_common/paste_clipboard.html.erb +17 -0
  148. data/app/views/dc_mail/subscribe.html.erb +7 -0
  149. data/app/views/dc_mail/unsubscribe.html.erb +19 -0
  150. data/app/views/layouts/cms.html.erb +17 -0
  151. data/app/views/layouts/cmsedit.html.erb +16 -0
  152. data/app/views/layouts/content.html.erb +16 -0
  153. data/config/initializers/kaminari_patch.rb +36 -0
  154. data/config/locales/datetimepicker.yml +13 -0
  155. data/config/locales/drgcms_en.yml +96 -0
  156. data/config/locales/drgcms_sl.yml +97 -0
  157. data/config/locales/en.yml +7 -0
  158. data/config/locales/kaminari.yml +26 -0
  159. data/config/locales/models_en.yml +790 -0
  160. data/config/locales/models_sl.yml +805 -0
  161. data/config/locales/mongoid_sl.yml +60 -0
  162. data/config/locales/sl.yml +211 -0
  163. data/config/routes.rb +2 -0
  164. data/drg_cms.gemspec +28 -0
  165. data/lib/drg_cms.rb +45 -0
  166. data/lib/drg_cms/engine.rb +30 -0
  167. data/lib/drg_cms/version.rb +3 -0
  168. data/lib/tasks/at_the_beginning.yml +26 -0
  169. data/lib/tasks/dc_cleanup.rake +94 -0
  170. data/lib/tasks/drg_cms_tasks.rake +118 -0
  171. data/lib/tasks/send_mail.rake +253 -0
  172. data/lib/tasks/site_statistics.rake +80 -0
  173. data/test/drg_cms_test.rb +7 -0
  174. data/test/dummy/README.rdoc +261 -0
  175. data/test/dummy/Rakefile +7 -0
  176. data/test/dummy/app/assets/javascripts/application.js +15 -0
  177. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  178. data/test/dummy/app/controllers/application_controller.rb +3 -0
  179. data/test/dummy/app/helpers/application_helper.rb +2 -0
  180. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  181. data/test/dummy/config.ru +4 -0
  182. data/test/dummy/config/application.rb +59 -0
  183. data/test/dummy/config/boot.rb +10 -0
  184. data/test/dummy/config/database.yml +25 -0
  185. data/test/dummy/config/environment.rb +5 -0
  186. data/test/dummy/config/environments/development.rb +37 -0
  187. data/test/dummy/config/environments/production.rb +67 -0
  188. data/test/dummy/config/environments/test.rb +37 -0
  189. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  190. data/test/dummy/config/initializers/inflections.rb +15 -0
  191. data/test/dummy/config/initializers/mime_types.rb +5 -0
  192. data/test/dummy/config/initializers/secret_token.rb +7 -0
  193. data/test/dummy/config/initializers/session_store.rb +8 -0
  194. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  195. data/test/dummy/config/locales/en.yml +5 -0
  196. data/test/dummy/config/routes.rb +58 -0
  197. data/test/dummy/public/404.html +26 -0
  198. data/test/dummy/public/422.html +26 -0
  199. data/test/dummy/public/500.html +25 -0
  200. data/test/dummy/public/favicon.ico +0 -0
  201. data/test/dummy/script/rails +6 -0
  202. data/test/integration/navigation_test.rb +10 -0
  203. data/test/test_helper.rb +15 -0
  204. metadata +375 -0
@@ -0,0 +1,143 @@
1
+ #coding: utf-8
2
+ #--
3
+ # Copyright (c) 2014+ Damjan Rems
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #++
24
+
25
+ ########################################################################
26
+ #
27
+ ########################################################################
28
+ class DcMenuRenderer
29
+
30
+ include DcApplicationHelper
31
+ ########################################################################
32
+ #
33
+ ########################################################################
34
+ def initialize( parent, opts )
35
+ @parent = parent
36
+ opts[:name] ||= parent.site.menu_name # default in site
37
+ @menu = DcMenu.find_by(name: opts[:name].to_s)
38
+ @opts = opts
39
+ self
40
+ end
41
+
42
+ ########################################################################
43
+ # Return selected topmenu level
44
+ ########################################################################
45
+ def find_selected
46
+ ret = @menu.dc_menu_items.find( @parent.page.menu_id ) if @parent.page.menu_id
47
+ # return first if not found (something is wrong)
48
+ ret ||= @menu.dc_menu_items[0]
49
+ end
50
+
51
+ ########################################################################
52
+ # Creates edit link if in edit mode.
53
+ ########################################################################
54
+ def link_4edit(opts)
55
+ html = ''
56
+ if @opts[:edit_mode] > 1
57
+ opts.merge!( { controller: 'cmsedit', action: 'edit' } )
58
+ title = "#{t('drgcms.edit')}: "
59
+ opts[:title] = "#{title} #{opts[:title]}"
60
+ html << '<li>'+dc_link_for_edit(opts)+'</li>'
61
+ end
62
+ html
63
+ end
64
+
65
+ ########################################################################
66
+ # Returns html code required for link in a menu.
67
+ ########################################################################
68
+ def link_4menu(item)
69
+ # Error in early development. Throw out
70
+ item.link = ((item.link[0] == '/' ? '' : '/') + item.link) unless item.link.match('http')
71
+ target = item.target.blank? ? nil : item.target
72
+ # - in first place won't write caption text
73
+ caption = item.caption[0] == '-' ? '' : item.caption.to_s
74
+ img_title = item.caption.to_s.sub('-','')
75
+ (item.picture.blank? ? '' : @parent.link_to( @parent.image_tag(item.picture), item.link, {title: img_title, target: target} )) +
76
+ ( caption.blank? ? '' : @parent.link_to(caption, item.link, {target: target}) )
77
+ end
78
+
79
+ ########################################################################
80
+ # Creates html required for submenu on one level
81
+ ########################################################################
82
+ def do_menu_level(menu, options={})
83
+ html = '<ul>'
84
+ if @opts[:edit_mode] > 1
85
+ options[:title] = menu.respond_to?('name') ? menu.name : menu.caption # 1. level or submenus
86
+ options[:id] = menu._id
87
+ html << link_4edit(options)
88
+ end
89
+ # sort items acording to :order
90
+ menu.dc_menu_items.order_by(order: 1).each do |item|
91
+ next unless item.active
92
+ # menu can be hidden from user
93
+ can_view, msg = dc_user_can_view(@parent, item)
94
+ next unless can_view
95
+
96
+ html << if item.id == @selected.id
97
+ "<li class=\"menu-selected\">#{ link_4menu(item) }"
98
+ else
99
+ "<li>#{ link_4menu(item) }"
100
+ end
101
+ # do submenu
102
+ if (sub = item.dc_menu_items).size > 0
103
+ if @opts[:edit_mode] > 1
104
+ opts = options.clone
105
+ opts[:ids] = (opts[:ids] ? "#{opts[:ids]};" : '') + menu._id.to_s
106
+ opts[:table] = (opts[:table] ? "#{opts[:table]};" : '') + 'dc_menu_item'
107
+ end
108
+ html << do_menu_level(item, opts)
109
+ end
110
+ html << '</li>'
111
+ end
112
+ html << '</ul>'
113
+ end
114
+
115
+ ########################################################################
116
+ # Creates default menu.
117
+ ########################################################################
118
+ def default
119
+ return "(#{@opts[:name]}) menu not found!" if @menu.nil?
120
+ #
121
+ @selected = find_selected
122
+ html = ''
123
+ html << "<div id='#{@menu.div_name}'>" unless @menu.div_name.blank?
124
+ html << do_menu_level(@menu, table: 'dc_menu')
125
+ html << "</div>" unless @menu.div_name.blank?
126
+ end
127
+
128
+ ########################################################################
129
+ #
130
+ ########################################################################
131
+ def render_html
132
+ method = @opts[:method] || 'default'
133
+ respond_to?(method) ? send(method) : "Error DcMenu: Method #{method} doesn't exist!"
134
+ end
135
+
136
+ ########################################################################
137
+ #
138
+ ########################################################################
139
+ def render_css
140
+ @menu.css if @menu
141
+ end
142
+
143
+ end
@@ -0,0 +1,80 @@
1
+ #--
2
+ # Copyright (c) 2012+ Damjan Rems
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ ########################################################################
25
+ #
26
+ ########################################################################
27
+ class DcPageRenderer
28
+
29
+ include DcApplicationHelper
30
+
31
+ ########################################################################
32
+ #
33
+ ########################################################################
34
+ def initialize( parent, opts={} )
35
+ @parent = parent
36
+ @opts = opts
37
+ @page = @parent.page
38
+ end
39
+
40
+ =begin
41
+ #########################################################################
42
+ # Return code for editing this piece.
43
+ ########################################################################
44
+ def link_4edit()
45
+ html = ''
46
+ if @opts[:edit_mode] > 1
47
+ html << dc_page_edit_menu() # @opts[:editparams] )
48
+ end
49
+ html
50
+ end
51
+ =end
52
+
53
+ #########################################################################
54
+ # default DcPage render method
55
+ #########################################################################
56
+ def default
57
+ can_view, msg = dc_user_can_view(@parent, @page)
58
+ return msg unless can_view
59
+ #
60
+ html = ''
61
+ html << dc_page_edit_menu() if @opts[:edit_mode] > 1
62
+ html << @page.body
63
+ end
64
+
65
+ #########################################################################
66
+ # render html
67
+ ########################################################################
68
+ def render_html
69
+ method = @opts[:method] || 'default'
70
+ respond_to?(method) ? send(method) : "Error DcPage: Method #{method} doesn't exist!"
71
+ end
72
+
73
+ ########################################################################
74
+ # render css
75
+ ########################################################################
76
+ def render_css
77
+ @page.css
78
+ end
79
+
80
+ end
@@ -0,0 +1,162 @@
1
+ #--
2
+ # Copyright (c) 2012+ Damjan Rems
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ ########################################################################
25
+ #
26
+ ########################################################################
27
+ class DcPartRenderer
28
+
29
+ include DcApplicationHelper
30
+
31
+ ########################################################################
32
+ #
33
+ ########################################################################
34
+ def initialize( parent, opts={} )
35
+ @parent = parent
36
+ @opts = opts
37
+ @part_css = ''
38
+ self
39
+ end
40
+
41
+ ########################################################################
42
+ # Render single particle
43
+ ########################################################################
44
+ def render_particle(particle, opts)
45
+ # Check if policy allows to view page
46
+ can_view, msg = dc_user_can_view(@parent, particle)
47
+ return msg unless can_view
48
+ html = ''
49
+ if @opts[:edit_mode] > 1
50
+ opts[:editparams].merge!(title: "#{t('drgcms.edit')}: #{particle.name}", controller: :cmsedit)
51
+ html << dc_link_for_edit( opts[:editparams] )
52
+ end
53
+ #
54
+ if particle.piece_id
55
+ opts[:id] = particle.piece_id
56
+ piece = DcPieceRenderer.new(@parent, opts)
57
+ html << piece.render_html
58
+ @part_css << piece.render_css
59
+ else
60
+ html << particle.body
61
+ @part_css << particle.css.to_s
62
+ end
63
+ html
64
+ end
65
+
66
+ ########################################################################
67
+ # Load parts defined in design, page or dc_piece
68
+ ########################################################################
69
+ def load_parts
70
+ @parent.parts = []
71
+ # Start with parts in design. Collect to array and add values needed for editing
72
+ if @parent.design
73
+ @parent.design.dc_parts.where(active: true).each do |part|
74
+ type = decamelize_type(part._type) || 'dc_part'
75
+ @parent.parts << [part, @parent.design.id, type, "dc_design;#{type}"]
76
+ end
77
+ end
78
+ # add parts in page
79
+ @parent.page.dc_parts.where(active: true).each do |part|
80
+ type = decamelize_type(part._type) || 'dc_part'
81
+ @parent.parts << [part, @parent.page.id, type, "#{@parent.site.page_table};#{type}"]
82
+ end
83
+ # add parts belonging to site, defined in dc_pieces
84
+ DcPiece.where(site_id: @parent.site._id, active: true).each do |part|
85
+ @parent.parts << [part, part._id, 'dc_piece', 'dc_piece']
86
+ end
87
+ end
88
+
89
+ ########################################################################
90
+ # Default part_renderer method will collect all parts with the div_id defined
91
+ # by position and create html output defined by order.
92
+ ########################################################################
93
+ def default
94
+ html = ''
95
+ # Load all parts only once per call
96
+ load_parts if @parent.parts.nil?
97
+ p 'DcPart: Parameter location will be deprecated! Please use position keyword.' if @opts['location']
98
+ @opts[:position] ||= @opts['position'] || @opts[:location] || @opts['location'] # symbols are not strings. Ensure that it works.
99
+ # Select parts
100
+ parts = []
101
+ @parent.parts.each { |v| parts << v if v[0].div_id == @opts[:position] }
102
+ # Edit link
103
+ @opts[:editparams].merge!( { controller: 'cmsedit', action: 'edit' } )
104
+ if parts.size > 0
105
+ parts.sort! {|a,b| a[0].order <=> b[0].order }
106
+
107
+ parts.each do |part|
108
+ @opts[:editparams].merge!( id: part[0], ids: "#{part[1]}", formname: part[2], table: part[3] )
109
+ html << render_particle(part[0], @opts)
110
+ end
111
+ end
112
+ html
113
+ end
114
+
115
+ ########################################################################
116
+ # This method will search and render single part defined in page. Part may
117
+ # be defined in current page or in any page in current pages file.
118
+ #
119
+ # Options:
120
+ # required :name : Name of part.
121
+ # optional :page_id : Id of page where part is saved if not current page.
122
+ # optional :page_link : Subject link of page where part is saved if not current page.
123
+ ########################################################################
124
+ def in_page
125
+ # Part is in page with id
126
+ page = if @opts[:page_id]
127
+ pageclass = @parent.site.page_table.classify.constantize
128
+ pageclass.find(@opts[:page_id])
129
+ # Part is in page with subject link
130
+ elsif @opts[:page_link]
131
+ pageclass = @parent.site.page_table.classify.constantize
132
+ @page = pageclass.find_by(dc_site_id: @parent.site._id, subject_link: @opts[:page_link])
133
+ # Part is in current page
134
+ else
135
+ @parent.page
136
+ end
137
+ return "Error DcPart: Page not found!" if page.nil?
138
+ #
139
+ if part = page.dc_parts.find_by(name: @opts[:name])
140
+ @opts[:editparams].merge!(id: part, ids: page._id, formname: 'dc_part', table: "#{@parent.site.page_table};dc_part" )
141
+ render_particle(part, @opts)
142
+ else
143
+ "Part with name #{@opts[:name]} not found in page!"
144
+ end
145
+ end
146
+
147
+ ########################################################################
148
+ #
149
+ ########################################################################
150
+ def render_html
151
+ method = @opts[:method] || 'default'
152
+ respond_to?(method) ? send(method) : "Error DcPart: Method #{method} doesn't exist!"
153
+ end
154
+
155
+ ########################################################################
156
+ #
157
+ ########################################################################
158
+ def render_css
159
+ @part_css
160
+ end
161
+
162
+ end
@@ -0,0 +1,124 @@
1
+ #--
2
+ # Copyright (c) 2012+ Damjan Rems
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ ########################################################################
25
+ #
26
+ ########################################################################
27
+ class DcPieceRenderer
28
+
29
+ include DcApplicationHelper
30
+
31
+ ########################################################################
32
+ #
33
+ ########################################################################
34
+ def initialize( parent, opts={} )
35
+ @parent = parent
36
+ @opts = opts
37
+ @piece = DcPiece.find(opts[:id]) if opts[:id]
38
+ if @piece.nil? # alternatively find by name
39
+ name = opts[:name] || opts[:id]
40
+ @piece = if @opts[:site]
41
+ DcPiece.find_by(name: name, site_id: dc_get_site._id)
42
+ else
43
+ DcPiece.find_by(name: name)
44
+ end
45
+ end
46
+ end
47
+
48
+ #########################################################################
49
+ # Return code for editing this piece.
50
+ ########################################################################
51
+ def link_4edit()
52
+ html = ''
53
+ if @opts[:edit_mode] > 1
54
+ @opts[:editparams].merge!( { table: 'dc_piece',
55
+ controller: 'cmsedit',
56
+ action: 'edit',
57
+ id: @piece.id,
58
+ title: "#{t('drgcms.edit')}: #{@piece.name}" } )
59
+ html << dc_link_for_edit( @opts[:editparams] )
60
+ end
61
+ html
62
+ end
63
+
64
+ ########################################################################
65
+ # script renderer expects rails erb code (view) in the script field.
66
+ #
67
+ # Usefull when you have many designs which have lots pieces of code in common.
68
+ ########################################################################
69
+ def script
70
+ html = link_4edit()
71
+ html << @parent.render(inline: @piece.script, layout: @opts[:layout])
72
+ end
73
+
74
+ ########################################################################
75
+ # script renderer expects rails erb code (view) in the script field.
76
+ # Used for designs with common code and one part which is different.
77
+ # It function is similar to dc_replace_in_design method except that design
78
+ # is defined in dc_piece document and not in site document.
79
+ #
80
+ # Example: As used in design. Backslashing < and % is important \<\%
81
+ # <% part = "<div class='some-class'>\<\%= dc_render(:my_renderer, method: 'render_method') \%\></div>" %>
82
+ # <%= dc_render(:dc_piece, id: 'common', method: 'script', replace: '[main]', with: part) %>
83
+ #
84
+ # Want to replace more than one part. Use array.
85
+ # <%= dc_render(:dc_piece, id: 'common', method: 'script', replace: ['[part1]','[part2]'], with: [part1, part2]) %>
86
+ ########################################################################
87
+ def script
88
+ s = @piece.script
89
+ if @opts[:replace]
90
+ # replace more than one part of code
91
+ if @opts[:replace].class == Array
92
+ 0.upto(@opts[:replace].size - 1) {|i| s.sub!(@opts[:replace][i], @opts[:with][i])}
93
+ else
94
+ s.sub!(@opts[:replace], @opts[:with])
95
+ end
96
+ end
97
+ @parent.render(inline: s, layout: @opts[:layout])
98
+ end
99
+
100
+ #########################################################################
101
+ # default DcPiece render method
102
+ ########################################################################
103
+ def default
104
+ html = link_4edit()
105
+ html << @piece.body
106
+ end
107
+
108
+ #########################################################################
109
+ # render html
110
+ ########################################################################
111
+ def render_html
112
+ return "DcPiece #{@opts[:id]} #{@opts[:name]} not found!" unless @piece
113
+ method = @opts[:method] || 'default'
114
+ respond_to?(method) ? send(method) : "Error DcPiece: Method #{method} doesn't exist!"
115
+ end
116
+
117
+ ########################################################################
118
+ # render css
119
+ ########################################################################
120
+ def render_css
121
+ @piece ? "#{@piece.css}" : ''
122
+ end
123
+
124
+ end