infopark_rails_connector 6.8.0.beta.200.621.4c8e1b0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (184) hide show
  1. data/README +59 -0
  2. data/app/assets/images/admin/minus.gif +0 -0
  3. data/app/assets/images/bg80.png +0 -0
  4. data/app/assets/images/edit.png +0 -0
  5. data/app/assets/images/icons/mm_generic.png +0 -0
  6. data/app/assets/images/icons/mm_menu.png +0 -0
  7. data/app/assets/images/ratings/star.gif +0 -0
  8. data/app/assets/images/time_machine/calendar-menuarrow.gif +0 -0
  9. data/app/assets/images/time_machine/calendar_bg.png +0 -0
  10. data/app/assets/images/time_machine/icon.png +0 -0
  11. data/app/assets/images/time_machine/slider_bg.png +0 -0
  12. data/app/assets/images/time_machine/slider_handle.png +0 -0
  13. data/app/assets/images/time_machine/timemachine_bg.png +0 -0
  14. data/app/assets/javascripts/comments.js +29 -0
  15. data/app/assets/javascripts/editmarker.js +240 -0
  16. data/app/assets/javascripts/infopark_rails_connector.js.erb +3 -0
  17. data/app/assets/javascripts/initializer.js +9 -0
  18. data/app/assets/javascripts/ratings.js +26 -0
  19. data/app/assets/javascripts/time_machine/calendar-setup.js +200 -0
  20. data/app/assets/javascripts/time_machine/calendar.js +1806 -0
  21. data/app/assets/javascripts/time_machine/lang/calendar-de.js +127 -0
  22. data/app/assets/javascripts/time_machine/lang/calendar-en.js +127 -0
  23. data/app/assets/javascripts/time_machine/lang/calendar-es.js +129 -0
  24. data/app/assets/javascripts/time_machine/lang/calendar-fr.js +125 -0
  25. data/app/assets/javascripts/time_machine/lang/calendar-it.js +124 -0
  26. data/app/assets/javascripts/time_machine/slider.js +278 -0
  27. data/app/assets/javascripts/time_machine.js +8 -0
  28. data/app/assets/stylesheets/editmarker.css +70 -0
  29. data/app/assets/stylesheets/infopark_rails_connector.css.erb +4 -0
  30. data/app/assets/stylesheets/ratings.css +97 -0
  31. data/app/assets/stylesheets/time_machine/time_machine.css +292 -0
  32. data/app/assets/stylesheets/time_machine.css +6 -0
  33. data/app/controllers/cms_controller.rb +6 -0
  34. data/app/controllers/comments_controller.rb +6 -0
  35. data/app/controllers/crm_form_controller.rb +2 -0
  36. data/app/controllers/pdf_controller.rb +6 -0
  37. data/app/controllers/rails_connector/default_cms_controller.rb +40 -0
  38. data/app/controllers/rails_connector/default_comments_controller.rb +71 -0
  39. data/app/controllers/rails_connector/default_crm_form_controller.rb +167 -0
  40. data/app/controllers/rails_connector/default_pdf_controller.rb +136 -0
  41. data/app/controllers/rails_connector/default_ratings_controller.rb +84 -0
  42. data/app/controllers/rails_connector/default_rss_controller.rb +29 -0
  43. data/app/controllers/rails_connector/default_search_controller.rb +60 -0
  44. data/app/controllers/rails_connector/default_user_controller.rb +267 -0
  45. data/app/controllers/rails_connector/pdf_external_controller.rb +54 -0
  46. data/app/controllers/rails_connector/time_machine_controller.rb +48 -0
  47. data/app/controllers/ratings_controller.rb +6 -0
  48. data/app/controllers/rss_controller.rb +6 -0
  49. data/app/controllers/search_controller.rb +2 -0
  50. data/app/controllers/seo_sitemap_controller.rb +12 -0
  51. data/app/controllers/user_controller.rb +2 -0
  52. data/app/helpers/cms_helper.rb +6 -0
  53. data/app/helpers/cms_routing_helper.rb +6 -0
  54. data/app/helpers/crm_form_helper.rb +3 -0
  55. data/app/helpers/rails_connector/cms_asset_helper.rb +51 -0
  56. data/app/helpers/rails_connector/default_cms_helper.rb +27 -0
  57. data/app/helpers/rails_connector/default_cms_routing_helper.rb +93 -0
  58. data/app/helpers/rails_connector/default_crm_form_helper.rb +58 -0
  59. data/app/helpers/rails_connector/default_ratings_helper.rb +38 -0
  60. data/app/helpers/rails_connector/default_user_helper.rb +90 -0
  61. data/app/helpers/rails_connector/display_helper.rb +117 -0
  62. data/app/helpers/rails_connector/error_messages_helper.rb +23 -0
  63. data/app/helpers/rails_connector/layout_helper.rb +30 -0
  64. data/app/helpers/rails_connector/link_helper.rb +88 -0
  65. data/app/helpers/rails_connector/mandatory_label_helper.rb +10 -0
  66. data/app/helpers/rails_connector/marker_helper.rb +363 -0
  67. data/app/helpers/rails_connector/menu_helper.rb +72 -0
  68. data/app/helpers/rails_connector/micronav_helper.rb +107 -0
  69. data/app/helpers/rails_connector/seo_helper.rb +44 -0
  70. data/app/helpers/rails_connector/table_of_contents_helper.rb +20 -0
  71. data/app/helpers/rails_connector/time_machine_helper.rb +24 -0
  72. data/app/helpers/rails_connector/tracking_helper.rb +32 -0
  73. data/app/helpers/ratings_helper.rb +4 -0
  74. data/app/helpers/user_helper.rb +3 -0
  75. data/app/mailers/confirmation_mailer.rb +13 -0
  76. data/app/models/crm_form.rb +2 -0
  77. data/app/models/named_link.rb +2 -0
  78. data/app/models/obj.rb +9 -0
  79. data/app/models/rails_connector/default_comment.rb +28 -0
  80. data/app/models/rails_connector/default_rating.rb +20 -0
  81. data/app/models/rails_connector/link_list.rb +30 -0
  82. data/app/views/cms/_comments.html.erb +44 -0
  83. data/app/views/cms/_index.html.erb +7 -0
  84. data/app/views/cms/_rating.html.erb +31 -0
  85. data/app/views/cms/index.html.erb +3 -0
  86. data/app/views/comments/_comment.html.erb +28 -0
  87. data/app/views/confirmation_mailer/register_confirmation.erb +5 -0
  88. data/app/views/confirmation_mailer/reset_password.erb +5 -0
  89. data/app/views/crm_form/_flash_messages.html.erb +11 -0
  90. data/app/views/crm_form/_form.html.erb +17 -0
  91. data/app/views/crm_form/confirmation.html.erb +3 -0
  92. data/app/views/crm_form/index.html.erb +5 -0
  93. data/app/views/crm_form/not_logged_in.html.erb +1 -0
  94. data/app/views/errors/403_forbidden.html.erb +3 -0
  95. data/app/views/errors/410_gone.html.erb +7 -0
  96. data/app/views/layouts/rails_connector/time_machine.html.erb +12 -0
  97. data/app/views/pdf/index.html.erb +7 -0
  98. data/app/views/pdf/index.xsl +1240 -0
  99. data/app/views/rails_connector/time_machine/index.html.erb +88 -0
  100. data/app/views/rss/_item.rss.builder +11 -0
  101. data/app/views/rss/index.rss.builder +11 -0
  102. data/app/views/search/_hit.html.erb +12 -0
  103. data/app/views/search/_hits.html.erb +11 -0
  104. data/app/views/search/_mini_panel.html.erb +4 -0
  105. data/app/views/search/_pagination.html.erb +5 -0
  106. data/app/views/search/_panel.html.erb +4 -0
  107. data/app/views/search/search.html.erb +12 -0
  108. data/app/views/seo_sitemap/show.xml.builder +16 -0
  109. data/app/views/user/_flash_messages.html.erb +11 -0
  110. data/app/views/user/edit.html.erb +6 -0
  111. data/app/views/user/edit_password.html.erb +11 -0
  112. data/app/views/user/forgot_password.html.erb +7 -0
  113. data/app/views/user/login.html.erb +15 -0
  114. data/app/views/user/new.html.erb +11 -0
  115. data/app/views/user/profile.html.erb +8 -0
  116. data/app/views/user/register_pending.html.erb +1 -0
  117. data/app/views/user/set_password.html.erb +14 -0
  118. data/config/cms_routes.rb +13 -0
  119. data/config/locales/de.rails_connector.controllers.yml +30 -0
  120. data/config/locales/de.rails_connector.errors.yml +11 -0
  121. data/config/locales/de.rails_connector.helpers.yml +9 -0
  122. data/config/locales/de.rails_connector.lib.yml +6 -0
  123. data/config/locales/de.rails_connector.models.yml +8 -0
  124. data/config/locales/de.rails_connector.views.yml +87 -0
  125. data/config/locales/en.rails_connector.controllers.yml +30 -0
  126. data/config/locales/en.rails_connector.errors.yml +10 -0
  127. data/config/locales/en.rails_connector.helpers.yml +9 -0
  128. data/config/locales/en.rails_connector.lib.yml +6 -0
  129. data/config/locales/en.rails_connector.models.yml +8 -0
  130. data/config/locales/en.rails_connector.views.yml +87 -0
  131. data/config/routes.rb +37 -0
  132. data/lib/generators/rails_connector/comments/comments_generator.rb +21 -0
  133. data/lib/generators/rails_connector/comments/templates/migration.rb +17 -0
  134. data/lib/generators/rails_connector/install/install_generator.rb +38 -0
  135. data/lib/generators/rails_connector/install/templates/initializers/rails_connector.rb +58 -0
  136. data/lib/generators/rails_connector/install/templates/local/configuration.rb +2 -0
  137. data/lib/generators/rails_connector/install/templates/obj_extensions.rb +25 -0
  138. data/lib/generators/rails_connector/ratings/ratings_generator.rb +21 -0
  139. data/lib/generators/rails_connector/ratings/templates/migration.rb +15 -0
  140. data/lib/infopark_rails_connector.rb +31 -0
  141. data/lib/obj_extensions.rb +6 -0
  142. data/lib/rails_connector/authenticable.rb +30 -0
  143. data/lib/rails_connector/cms_accessible.rb +114 -0
  144. data/lib/rails_connector/cms_dispatch_controller.rb +47 -0
  145. data/lib/rails_connector/cms_env.rb +55 -0
  146. data/lib/rails_connector/cms_test_request.rb +23 -0
  147. data/lib/rails_connector/commentable.rb +23 -0
  148. data/lib/rails_connector/configuration/google_analytics.rb +29 -0
  149. data/lib/rails_connector/configuration/pdf_generator.rb +15 -0
  150. data/lib/rails_connector/configuration/rss.rb +46 -0
  151. data/lib/rails_connector/configuration.rb +235 -0
  152. data/lib/rails_connector/core_extensions/time.rb +18 -0
  153. data/lib/rails_connector/core_extensions.rb +1 -0
  154. data/lib/rails_connector/crm.rb +282 -0
  155. data/lib/rails_connector/engine.rb +78 -0
  156. data/lib/rails_connector/fop.rb +18 -0
  157. data/lib/rails_connector/fop_on_rails/document/dom_tree.rb +42 -0
  158. data/lib/rails_connector/fop_on_rails/document/images.rb +34 -0
  159. data/lib/rails_connector/fop_on_rails/document/tables.rb +67 -0
  160. data/lib/rails_connector/fop_on_rails/document.rb +25 -0
  161. data/lib/rails_connector/fop_on_rails.rb +92 -0
  162. data/lib/rails_connector/googlebot_checker.rb +47 -0
  163. data/lib/rails_connector/html_string.rb +19 -0
  164. data/lib/rails_connector/infopark_base.rb +2 -0
  165. data/lib/rails_connector/link_resolvable.rb +9 -0
  166. data/lib/rails_connector/liquid_support/action_marker.rb +69 -0
  167. data/lib/rails_connector/liquid_support/field_value_drop.rb +22 -0
  168. data/lib/rails_connector/liquid_support/general_helper_tag.rb +44 -0
  169. data/lib/rails_connector/liquid_support/link_drop.rb +22 -0
  170. data/lib/rails_connector/liquid_support/liquid_template_handler.rb +162 -0
  171. data/lib/rails_connector/liquid_support/named_object_drop.rb +14 -0
  172. data/lib/rails_connector/liquid_support/obj_drop.rb +43 -0
  173. data/lib/rails_connector/liquid_support/obj_filters.rb +77 -0
  174. data/lib/rails_connector/liquid_support.rb +23 -0
  175. data/lib/rails_connector/markdown_string.rb +19 -0
  176. data/lib/rails_connector/rateable.rb +57 -0
  177. data/lib/rails_connector/seo.rb +52 -0
  178. data/lib/rails_connector/ses.rb +72 -0
  179. data/lib/rails_connector/string_tagging.rb +29 -0
  180. data/lib/rails_connector/syndicateable.rb +11 -0
  181. data/lib/search_request.rb +2 -0
  182. data/lib/tasks/check.rake +25 -0
  183. data/lib/tasks/cms_license_check.rake +17 -0
  184. metadata +489 -0
@@ -0,0 +1,2 @@
1
+ class SearchController < RailsConnector::DefaultSearchController
2
+ end
@@ -0,0 +1,12 @@
1
+ # Renders a search engine optimized sitemap.xml
2
+ # Enable via <tt>RailsConnector::Configuration.enable(:seo_sitemap)</tt>
3
+ class SeoSitemapController < ApplicationController
4
+ layout nil
5
+
6
+ # Finds all objects which are to be shown in the SEO sitemap. Responds to xml only.
7
+ def show
8
+ @objects = Obj.find_all_for_sitemap
9
+ respond_to { |format| format.xml }
10
+ end
11
+
12
+ end
@@ -0,0 +1,2 @@
1
+ class UserController < RailsConnector::DefaultUserController
2
+ end
@@ -0,0 +1,6 @@
1
+ # CmsHelper is a wrapper around RailsConnector::DefaultCmsHelper.
2
+ # It can be replaced in your application in order to add or
3
+ # modify helpers.
4
+ module CmsHelper
5
+ include RailsConnector::DefaultCmsHelper
6
+ end
@@ -0,0 +1,6 @@
1
+ # CmsRoutingHelper is a wrapper around RailsConnector::DefaultCmsRoutingHelper.
2
+ # It can be replaced in your application in order to add or
3
+ # modify helpers.
4
+ module CmsRoutingHelper
5
+ include RailsConnector::DefaultCmsRoutingHelper
6
+ end
@@ -0,0 +1,3 @@
1
+ module CrmFormHelper
2
+ include RailsConnector::DefaultCrmFormHelper
3
+ end
@@ -0,0 +1,51 @@
1
+ module RailsConnector
2
+
3
+ # This module contains helpers that can be used to reference images and other assets stored in the CMS.
4
+ #
5
+ # Use this helper to take advantage of rails' asset host mechanism.
6
+ # (See http://api.rubyonrails.com/classes/ActionView/Helpers/AssetTagHelper.html for details about asset hosts.)
7
+ # If your application does not use any asset hosts, the helper will generate regular (=non asset host) pathes.
8
+ module CmsAssetHelper
9
+
10
+ # Returns an html image tag for an image stored in the CMS.
11
+ #
12
+ # +target+ is the image from the cms to be referenced in the image tag.
13
+ # +target+ can be an +Obj+ or a +Link+ or a +LinkList+.
14
+ # +options+ can be used to specify additional html attributes for the tag.
15
+ # If you do not specify an html alt attribute, the helper method will use
16
+ # +target+'s +display_title+ as the html alt attribute.
17
+ # If your application is configured to use asset hosts, the images tag will reference
18
+ # the image using one of your asset hosts.
19
+ def cms_image_tag(target, options = {})
20
+ options.symbolize_keys!
21
+
22
+ options[:src] = cms_asset_path(target)
23
+ options[:alt] ||= display_title(target)
24
+
25
+ tag("img", options)
26
+ end
27
+
28
+ # Calculate the path to an asset stored in the CMS.
29
+ #
30
+ # The path can be used to reference a cms object inside an html page.
31
+ # +target+ can be an +Obj+ or a +Link+ or a +LinkList+.
32
+ # If your application is configured to use asset hosts, the path will reference
33
+ # the object using one of your asset hosts.
34
+ def cms_asset_path(target)
35
+ regular_path = cms_path(target)
36
+ return regular_path if regular_path.first == "#"
37
+ asset_paths.compute_public_path(regular_path, nil)
38
+ end
39
+
40
+ private
41
+
42
+ def display_title(target)
43
+ if target.respond_to?(:display_title)
44
+ return target.display_title
45
+ elsif target.respond_to?(:first) && target.first.respond_to?(:display_title)
46
+ return target.first.display_title
47
+ end
48
+ end
49
+
50
+ end
51
+ end
@@ -0,0 +1,27 @@
1
+ module RailsConnector
2
+
3
+ # This is a wrapper module for the default set of Rails Connector helper modules.
4
+ #
5
+ # To make autoloading from +CmsController+ work, this module must be wrapped
6
+ # by a module named +CmsHelper+:
7
+ #
8
+ # module CmsHelper
9
+ # include RailsConnector::DefaultCmsHelper
10
+ # end
11
+
12
+ module DefaultCmsHelper
13
+ include DisplayHelper
14
+ include MarkerHelper
15
+ include CmsAssetHelper
16
+ include SeoHelper
17
+ include RailsConnector::MenuHelper
18
+ include RailsConnector::MicronavHelper
19
+ include RailsConnector::TimeMachineHelper
20
+ include RailsConnector::LinkHelper
21
+ include RailsConnector::CmsAssetHelper
22
+ include RailsConnector::TableOfContentsHelper
23
+ include RatingsHelper
24
+ include RailsConnector::LayoutHelper
25
+ end
26
+
27
+ end
@@ -0,0 +1,93 @@
1
+ module RailsConnector
2
+
3
+ module DefaultCmsRoutingHelper
4
+ # Returns the path for +target+ using the +CmsController+ routes.
5
+ # +target+ can be an +Obj+ or a +Link+ or a +LinkList+.
6
+ # If +target+ is a +Linklist+, it must be non-empty. The first +Link+ from the +LinkList+ will be used.
7
+ # +options+ are optional and include url settings such as path parameters or protocol
8
+ # +options+ are only passed on if +target+ is an +Obj+.
9
+ def cms_path(target, options = {})
10
+ cms_path_or_url(target, "path", options)
11
+ end
12
+
13
+ # Returns the absolute URL for target using the +CmsController+ routes.
14
+ # +target+ can be an +Obj+ or a +Link+ or a +LinkList+.
15
+ # If +target+ is a +Linklist+, it must be non-empty. The first +Link+ from the +LinkList+ will be used.
16
+ # +options+ are optional and include url settings such as path parameters or protocol
17
+ # +options+ are only passed on if +target+ is an +Obj+.
18
+ def cms_url(target, options = {})
19
+ cms_path_or_url(target, "url", options)
20
+ end
21
+
22
+ LINK_TO_UNRELEASED = "#__target_object_not_released" #:nodoc:
23
+ LINK_TO_EMPTY_LINKLIST = "#__empty_linklist" #:nodoc:
24
+
25
+ def cms_path_or_url(target, path_or_url, options = {}) #:nodoc:
26
+ if target.is_a?(Link)
27
+ cms_path_or_url_for_links(target, path_or_url)
28
+ elsif target.is_a?(Obj)
29
+ cms_path_or_url_for_objs(target, path_or_url, options)
30
+ elsif target.respond_to?(:first)
31
+ if target.first.is_a?(Link)
32
+ cms_path_or_url_for_links(target.first, path_or_url)
33
+ else
34
+ return LINK_TO_EMPTY_LINKLIST
35
+ end
36
+ else
37
+ raise "cms_path or cms_url was called with an instance of #{target.class}. "+
38
+ "It must only be called with an Obj or a Link or a non-empty LinkList."
39
+ end
40
+ end
41
+
42
+ def cms_path_or_url_for_links(link, path_or_url) #:nodoc:
43
+ return LINK_TO_UNRELEASED if link.internal? && link.destination_object.nil?
44
+ append_search_and_fragment(
45
+ basic_url_or_path_for_link(link, path_or_url), link
46
+ )
47
+ end
48
+
49
+ def cms_path_or_url_for_objs(obj, path_or_url, options = {}) #:nodoc:
50
+ permalink = obj.permalink
51
+ if permalink && !Configuration.editor_interface_enabled?
52
+ __send__("cms_permalink_#{path_or_url}", options.merge(:permalink => permalink))
53
+ elsif obj.homepage? && !Configuration.editor_interface_enabled?
54
+ __send__("root_#{path_or_url}", options)
55
+ else
56
+ if obj.body_data_url
57
+ obj.body_data_url
58
+ elsif obj.binary? && !obj.file_extension.blank?
59
+ __send__("cms_id_#{path_or_url}",
60
+ options.merge(:id => obj.id, :name => obj.name, :format => obj.file_extension))
61
+ else
62
+ routing_options = options.merge(:id => obj.id, :name => obj.name.presence)
63
+ __send__("cms_id_#{path_or_url}", routing_options)
64
+ end
65
+ end
66
+ end
67
+
68
+ private
69
+
70
+ def basic_url_or_path_for_link(link, path_or_url)
71
+ if link.internal?
72
+ __send__("cms_#{path_or_url}", link.destination_object)
73
+ else
74
+ if link.external_prefix?
75
+ remove_external_prefix(link.url)
76
+ else
77
+ link.url
78
+ end
79
+ end
80
+ end
81
+
82
+ def remove_external_prefix(link)
83
+ link.gsub(/external:/, "").strip
84
+ end
85
+
86
+ def append_search_and_fragment(url,link)
87
+ result = url
88
+ result += "?#{link.search}" unless link.search.blank?
89
+ result += "##{link.fragment}" unless link.fragment.blank?
90
+ result
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,58 @@
1
+ module RailsConnector
2
+
3
+ module DefaultCrmFormHelper
4
+
5
+ include ::RailsConnector::DefaultUserHelper
6
+ include ::RailsConnector::MandatoryLabelHelper
7
+ include ::RailsConnector::ErrorMessagesHelper
8
+
9
+ def custom_fields_for(form)
10
+ activity = instance_variable_get("@#{form.object_name}")
11
+ custom_attribute_defs = Infopark::Crm::CustomType.find(activity.kind).custom_attributes
12
+ content = "".html_safe
13
+ custom_attribute_defs.each do |attribute|
14
+ custom_attr = "custom_#{attribute.name}"
15
+ next unless allow_custom_attribute?(custom_attr)
16
+ value = activity.__send__(custom_attr).to_s
17
+ input_field =
18
+ case attribute.type
19
+ when 'enum'
20
+ form.select(custom_attr, [''] + attribute.valid_values, :value => value)
21
+ when 'text'
22
+ form.text_area(custom_attr, :value => value, :cols => 50, :rows => 5)
23
+ else
24
+ form.text_field(custom_attr, :value => value, :size => "40")
25
+ end
26
+ content << content_tag(:div, :class => 'label') do
27
+ if attribute.mandatory
28
+ mandatory_label_for(form, custom_attr, h(attribute.title))
29
+ else
30
+ form.label(custom_attr, h(attribute.title))
31
+ end
32
+ end
33
+ content << content_tag(:div, input_field, :class => 'field')
34
+ end
35
+ content
36
+ end
37
+
38
+ def title_field_for(form)
39
+ content = "".html_safe
40
+ if has_title_input_field?
41
+ content << content_tag(:div, :class => 'label') do
42
+ mandatory_label_for(form, :title, t(:"rails_connector.views.crm_form.title"))
43
+ end
44
+ content << content_tag(:div, :class => 'field') do
45
+ form.text_field :title
46
+ end
47
+ end
48
+ content
49
+ end
50
+
51
+ def logged_in_as(user)
52
+ content_tag(:em) do
53
+ t('rails_connector.views.crm_form.logged_in_as',
54
+ :user => content_tag(:strong, user)).html_safe
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,38 @@
1
+ module RailsConnector
2
+ #
3
+ # This helper provides methods for use with ratings.
4
+ module DefaultRatingsHelper
5
+ # Determines whether the current user has rated a CMS object.
6
+ def rated_by_current_user?(obj)
7
+ session[:rated_objs] && session[:rated_objs][obj.id]
8
+ end
9
+
10
+ # Builds the HTML markup for the ratings section.
11
+ def stars_for_rating(obj)
12
+ stars = "".html_safe
13
+ (Rating::MINIMUM..Rating::MAXIMUM).collect do |score|
14
+ stars << content_tag(:li, link_a_star(score, obj))
15
+ end
16
+ stars
17
+ end
18
+
19
+ private
20
+
21
+ def link_a_star(score, obj)
22
+ css_classes = ["", "one-star", "two-stars", "three-stars", "four-stars", "five-stars"]
23
+ descriptions = ["",
24
+ t(:"rails_connector.helpers.ratings.bad"),
25
+ t(:"rails_connector.helpers.ratings.mediocre"),
26
+ t(:"rails_connector.helpers.ratings.average"),
27
+ t(:"rails_connector.helpers.ratings.good"),
28
+ t(:"rails_connector.helpers.ratings.very_good")
29
+ ]
30
+ html_options = {
31
+ :title => "#{score} von #{Rating::MAXIMUM} Sternen",
32
+ :class => css_classes[score],
33
+ "data-description" => descriptions[score]
34
+ }
35
+ link_to(score.to_s, ratings_url(:action => :rate, :id => obj.id, :score => score), html_options)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,90 @@
1
+ require "recaptcha"
2
+
3
+ module RailsConnector
4
+
5
+ # This module contains helpers for the +UserController+ and +DefaultUserController+
6
+ module DefaultUserHelper
7
+
8
+ include ::ReCaptcha::ViewHelper
9
+ include ::RailsConnector::MandatoryLabelHelper
10
+ include ::RailsConnector::ErrorMessagesHelper
11
+
12
+ # Returns mandatory user fields as array of symbols.
13
+ def mandatory_user_fields
14
+ [:email, :gender, :language, :last_name]
15
+ end
16
+
17
+ # Generates part of a form for the given attributes:
18
+ #
19
+ # In your view, use:
20
+ #
21
+ # <%= form_for @user, :as => :user do |f| -%>
22
+ # <%= user_fields_for(f, 'contact', :first_name, :last_name) %>
23
+ # <% end -%>
24
+ #
25
+ # to generate labels and fields for the contact:
26
+ #
27
+ # <form>
28
+ # <div class="label"><label for="user_first_name">First name</label></div>
29
+ # <div class="field"><input id="user_first_name" name="user[first_name]" size="30" type="text" /></div>
30
+ # <div class="label"><label for="user_last_name">Last name</label></div>
31
+ # <div class="field"><input id="user_last_name" name="user[last_name]" size="30" type="text" /></div>
32
+ # </form>
33
+ #
34
+ # Labels are localized automatically, using the scope views.contact and views.location,
35
+ # respectively. For example:
36
+ #
37
+ # views:
38
+ # user:
39
+ # first_name: First name
40
+ # last_name: Last name
41
+ def user_fields_for(form, model_name, *attributes)
42
+ output = "".html_safe
43
+ attributes.flatten.each do |attr|
44
+ output += content_tag(:div, :class => 'label') do
45
+ if mandatory_user_fields.include?(attr)
46
+ mandatory_label_for(form, attr, t("rails_connector.views.user.#{model_name}.#{attr}"))
47
+ else
48
+ form.label(attr, t("rails_connector.views.user.#{model_name}.#{attr}"))
49
+ end
50
+ end
51
+ form_field = case attr
52
+ when :gender
53
+ form.select(:gender, genders_for_select)
54
+ when :language
55
+ languages = Infopark::Crm::CustomType.find('contact').languages
56
+ form.select(:language, languages_for_select_for(languages),
57
+ :selected => (@user ? @user.language : I18n.locale.to_s) )
58
+ else
59
+ form.text_field(attr)
60
+ end
61
+ output += content_tag(:div, form_field, :class => 'field')
62
+ end
63
+ output
64
+ end
65
+
66
+ def genders_for_select
67
+ [
68
+ ['', 'N'],
69
+ [t('rails_connector.views.user.gender_female'),'F'],
70
+ [t('rails_connector.views.user.gender_male'), 'M']
71
+ ]
72
+ end
73
+
74
+ def languages_for_select_for(*languages)
75
+ options = []
76
+ languages.flatten.each do |lang|
77
+ options << [t(:"rails_connector.views.user.languages.#{lang}"), lang]
78
+ end
79
+ options
80
+ end
81
+
82
+ def profile_fields_for(form, editable_attributes={})
83
+ output = "".html_safe
84
+ output += user_fields_for(form, "contact", editable_attributes[:contact])
85
+ output
86
+ end
87
+
88
+ end
89
+
90
+ end
@@ -0,0 +1,117 @@
1
+ module RailsConnector
2
+
3
+ # This module contains a helper that can be used to render attributes of the CMS models.
4
+ module DisplayHelper
5
+
6
+ # For a consistent look of your site and easy maintenance, only the display helpers
7
+ # should be used to render an attribute <em>value</em> of a CMS model.
8
+ #
9
+ # <%= display_value @obj.title %>
10
+ # Renders the value, taking its type into account.
11
+ # * An HtmlString will be exported by converting its links
12
+ # * A Time will be exported in an international form: Year-Mounth-Day Hour:Minutes
13
+ # * A non-HTML String will be quoted
14
+ # * other values will be rendered unchanged
15
+ #
16
+ def display_value(value)
17
+ case value
18
+ when MarkdownString then markdown(convert_links(value)).html_safe
19
+ when HtmlString then convert_links(value).html_safe
20
+ when String then h(value)
21
+ when Time then h(l(value))
22
+ else value
23
+ end
24
+ end
25
+
26
+ # Renders a field from the CMS, including an edit marker for the preview
27
+ # If the option :marker is false, no edit marker will be rendered.
28
+ #
29
+ # <%= display_field @obj, :title %>
30
+ #
31
+ # When creating an edit marker, all options except :marker are passed to MarkerHelper::edit_marker.
32
+ #
33
+ def display_field(obj, attr, options = {})
34
+ options.reverse_merge!({
35
+ :marker => ![:id, :path, :created, :last_changed, :version].include?(attr.to_sym)
36
+ })
37
+ if options.delete :marker
38
+ edit_marker(obj, attr, options) do |obj, attr|
39
+ display_value obj[attr]
40
+ end
41
+ else
42
+ display_value obj[attr]
43
+ end
44
+ end
45
+
46
+ # Legacy method - deprecated
47
+ #
48
+ # Use display_value and display_field instead
49
+ #
50
+ def display(*args) #:nodoc:
51
+ if args.last.kind_of? Hash
52
+ options = args.pop
53
+ else
54
+ options = {}
55
+ end
56
+ return display_value(args.first) if args.size == 1
57
+ display_field(args[0], args[1], options)
58
+ end
59
+
60
+ private
61
+
62
+ def markdown(string)
63
+ require 'maruku'
64
+ Maruku.new(string).to_html
65
+ end
66
+
67
+ LINK_PATTERN = '<?\binternallink:(\d+)\b>?'
68
+ LINK_EXPRESSION = %r(#{LINK_PATTERN})
69
+
70
+ def convert_links(content_attribute)
71
+ return content_attribute unless content_attribute =~ LINK_EXPRESSION
72
+ link_map = content_attribute.source.text_links.each_with_object({}) do |link, map|
73
+ map[link.id.to_s] = link
74
+ end
75
+ content_attribute.gsub(%r(#{LINK_PATTERN}(['"]?))) do
76
+ link = link_map[$1.to_s]
77
+ if link.blank?
78
+ "#{CmsRoutingHelper::LINK_TO_UNRELEASED}#{$2}"
79
+ else
80
+ uri = "#{cms_path(link)}#{$2}"
81
+ if link.markdown?
82
+ markdown_link(link, uri)
83
+ else
84
+ html_link(link, uri)
85
+ end
86
+ end
87
+ end
88
+ end
89
+
90
+ def html_link(link, uri)
91
+ subst = uri
92
+ name, value =
93
+ case link.tag_name
94
+ when 'img', 'input'
95
+ ['alt', link.title || ""]
96
+ when 'a', 'link'
97
+ ['title', begin link.title unless link.title.blank? end]
98
+ end
99
+ if value
100
+ subst << %( #{name}="#{h(value)}")
101
+ end
102
+ subst << %( target="#{h(link.target)}") unless link.target.blank?
103
+ subst
104
+ end
105
+
106
+ def markdown_link(link, uri)
107
+ subst = "<#{uri}>"
108
+ unless link.title.blank?
109
+ case link.markdown_type
110
+ when 'inline', 'reference'
111
+ subst << %( "#{h(link.title)}")
112
+ end
113
+ end
114
+ subst
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,23 @@
1
+ module RailsConnector
2
+ module ErrorMessagesHelper
3
+ # Shortened error_messages_for from git://github.com/rails/dynamic_form.git
4
+ def error_messages(*objects)
5
+ objects.compact!
6
+ count = objects.inject(0) {|sum, object| sum + object.errors.count }
7
+ return '' if count.zero?
8
+
9
+ content_tag(:div, :class => 'errorExplanation') do
10
+ c = ''.html_safe
11
+ c << content_tag(:ul) do
12
+ li = ''.html_safe
13
+ objects.each do |object|
14
+ object.errors.full_messages.each do |msg|
15
+ li << content_tag(:li, msg)
16
+ end
17
+ end
18
+ li
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,30 @@
1
+ module RailsConnector
2
+
3
+ # This module contains helpers that render tags for the html head
4
+ # and the end of the html body.
5
+ module LayoutHelper
6
+ include TrackingHelper
7
+
8
+ # Renders all tags needed in the html head for the enabled features.
9
+ def rails_connector_header_tags
10
+ html = "".html_safe
11
+ html += tag('meta', :name => 'generator',
12
+ :content => "Rails Connector for Infopark CMS Fiona by Infopark AG (www.infopark.de); "\
13
+ "Version #{Gem.loaded_specs['infopark_rails_connector'].version}")
14
+ if Configuration.enabled?(:rss)
15
+ html += auto_discovery_link_tag(:rss, rss_url, :title => 'RSS Feed')
16
+ end
17
+ html += include_edit_marker_support
18
+ html
19
+ end
20
+
21
+ # Renders all tags needed at the end of the body tag for the enabled features.
22
+ def rails_connector_after_content_tags
23
+ html = "".html_safe
24
+ html += render_marker_code
25
+ html += google_analytics if Configuration.enabled?(:google_analytics)
26
+ html
27
+ end
28
+ end
29
+
30
+ end
@@ -0,0 +1,88 @@
1
+ require "uri"
2
+
3
+ module RailsConnector
4
+
5
+ # This module contains a helper that can be used to build markup for a link, e.g. a download link.
6
+ module LinkHelper
7
+ # Generates a link by producing the corresponding HTML markup.
8
+ # <em>link</em> is the Link to be rendered, you may specify the following <em>options</em>:
9
+ #
10
+ # [:file_extension] specifies the file extension if the link object is an internal link.
11
+ # An external link has no file extension since there is no destination object from which
12
+ # the file extension could be taken. File extensions are, for example, 'pdf', 'zip', or 'doc'.
13
+ #
14
+ # The HTML text generated depends on the kind of Link passed to the helper:
15
+ #
16
+ # <%= link(@myLinkObject) %>
17
+ #
18
+ # [With an internal Link] The helper will produce the following HTML where path is
19
+ # the path created by the PageHelper, file extension is the file_extension of the
20
+ # destination object. For a Content, the display title is the Link's display_title and
21
+ # size is the size of its body (in KB or MB):
22
+ # <a href='path' class='link'>
23
+ # <span class='file extension'>
24
+ # display title
25
+ # <span class='link_size'> (size)</span>
26
+ # </span>
27
+ # </a></tt>
28
+ #
29
+ # [With an external Link] The helper will produce the following HTML where url
30
+ # is the external url of the link and display title is the display_title of the Link:
31
+ #
32
+ # <a class='link' href='url'>
33
+ # <span>display title</span>
34
+ # </a>
35
+ #
36
+ # Normally, you do not know the file extension of the external source, so by default
37
+ # there will be no CSS class generated for the nested <tt><span></tt> tag. In the case
38
+ # that you do know it or want some external links to have a special style, you can
39
+ # specify the file extension with the :file_extension option:
40
+ #
41
+ # <%= link(@myLinkObject, :file_extension => 'file_extension' %>
42
+ #
43
+ # The helper would then produce the following:
44
+ #
45
+ # <a class='link' href='destination'>
46
+ # <span class='file_extension'>title</span>
47
+ # </a>
48
+ def link(link, options = {})
49
+ link_attributes = {
50
+ :href => cms_path(link),
51
+ :class => 'link'
52
+ }
53
+ link_attributes[:target] = link.target unless link.target.blank?
54
+ content_tag(:a,
55
+ content_tag(:span,
56
+ display_value(link.display_title) + size_content(link),
57
+ :class => options[:file_extension] || link.file_extension
58
+ ),
59
+ link_attributes
60
+ )
61
+ end
62
+
63
+ # Displays a link list as an HTML list.
64
+ # <em>link_list</em> is the link list to be rendered. For each link #link is called.
65
+ # For a list of valid <em>options</em> see #link.
66
+ #
67
+ # The generated list element has the CSS class 'linklist'.
68
+ def link_list(link_list, options = {})
69
+ return if link_list.blank?
70
+ markup = "<ul class='linklist'>"
71
+ link_list.each do |l|
72
+ markup << "<li>#{link l, options}</li>"
73
+ end
74
+ markup << "</ul>"
75
+ end
76
+
77
+ private
78
+
79
+ def size_content(link)
80
+ return "" unless link.internal? && link.destination_object && link.destination_object.binary?
81
+ size = ' (' + number_to_human_size(link.destination_object.body_length) + ')'
82
+ content_tag(:span, size, :class => 'link_size')
83
+ end
84
+
85
+ include DisplayHelper
86
+ end
87
+
88
+ end
@@ -0,0 +1,10 @@
1
+ module RailsConnector
2
+ module MandatoryLabelHelper
3
+ def mandatory_label_for(form, object, label)
4
+ html = "".html_safe
5
+ html += label
6
+ html += content_tag(:span, " *", :class => "mandatory_star")
7
+ form.label(object, html, :class => "mandatory")
8
+ end
9
+ end
10
+ end