infopark_cloud_connector 6.9.2.1.125136549 → 6.9.3.1.36404185

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -1,5 +1,7 @@
1
1
  = Infopark Cloud Connector
2
2
 
3
- Infopark Cloud Connector integrates the {https://rubygems.org/gems/infopark_rails_connector Infopark Rails Connector} with the Infopark Cloud Express CMS.
3
+ Infopark Cloud Connector is part of {https://rubygems.org/gems/infopark_rails_connector Infopark Rails Connector}.
4
4
 
5
- For more information about Infopark Rails and Cloud Connector, please visit {http://kb.infopark.de/ Infopark’s Knowledge Base}. Details about recent changes to Infopark Cloud Express CMS and the Cloud Connector can be found in the {https://kb.infopark.de/cms-news Latest CMS News}.
5
+ The Cloud Connector makes CMS objects maintained by means of the cloud-based Infopark CMS available to your Rails application. It offers easy-to-use functionality for rendering CMS content, doing searches, etc.
6
+
7
+ For more information about Infopark Rails and Cloud Connector, please visit {http://dev.infopark.net/ the Infopark Dev Center}. For details regarding recent changes to the Infopark CMS and the Cloud Connector can be found in our {http://dev.infopark.net/blog Dev Center Blog}.
@@ -1,7 +1,8 @@
1
1
  module RailsConnector
2
2
 
3
3
  class ObjsController < WebserviceController
4
- before_filter :load_object, only: [:show, :edit, :update, :destroy, :create_widget]
4
+ before_filter :load_object, only: [:show, :edit, :update, :destroy, :widget_class_selection,
5
+ :create_widget, :edit_widget]
5
6
 
6
7
  def show
7
8
  render json: {markup: render_to_string(layout: false)}
@@ -16,9 +17,7 @@ module RailsConnector
16
17
  end
17
18
 
18
19
  def edit
19
- markup = WidgetRenderer.new(request).
20
- process(:edit, @obj, current_page, params[:field_name], @obj.widget_container)
21
- render json: {markup: markup}
20
+ render json: {markup: render_to_string(@obj.edit_view_path, layout: false)}
22
21
  end
23
22
 
24
23
  def update
@@ -35,28 +34,30 @@ module RailsConnector
35
34
  end
36
35
 
37
36
  def page_class_selection
38
- thumbnails = {}
39
- obj_classes = CmsRestApi.task_unaware_request(:get,
40
- "revisions/#{Workspace.current.revision_id}/obj_classes"
41
- )
42
- obj_classes['results'].each do |obj_class|
37
+ valid_page_classes = Obj.valid_page_classes_beneath(params[:parent_path]) || all_page_classes
38
+ valid_page_classes.map!(&:to_s)
39
+
40
+ page_class_names = valid_page_classes.map do |page_class_name|
43
41
  begin
44
- name = obj_class['name']
45
- thumbnails[name] = render_to_string("#{name.underscore}/thumbnail")
42
+ markup = render_to_string("#{page_class_name.underscore}/thumbnail")
43
+ {name: page_class_name, markup: markup}
46
44
  rescue ActionView::MissingTemplate
47
45
  end
48
46
  end
49
- render json: thumbnails
47
+
48
+ render json: page_class_names.compact
50
49
  end
51
50
 
52
51
  def widget_class_selection
53
- widgets = {}
54
- Dir[Rails.root + 'app/widgets/*'].each do |widget_path|
55
- widget_dir = File.basename(widget_path)
56
- widget_class_name = widget_dir.camelize
57
- widgets[widget_class_name] = WidgetRenderer.new(request).process('thumbnail', widget_dir)
52
+ valid_widget_classes = @obj.valid_widget_classes_for(params[:field_name]) || all_widget_classes
53
+ valid_widget_classes.map!(&:to_s)
54
+
55
+ widgets_classes = valid_widget_classes.map do |widget_class_name|
56
+ markup = WidgetRenderer.new(request).process('thumbnail', widget_class_name.underscore)
57
+ {name: widget_class_name, markup: markup}
58
58
  end
59
- render json: widgets
59
+
60
+ render json: widgets_classes
60
61
  end
61
62
 
62
63
  def create_widget
@@ -74,6 +75,12 @@ module RailsConnector
74
75
  render json: {markup: render_to_string(layout: false)}
75
76
  end
76
77
 
78
+ def edit_widget
79
+ markup = WidgetRenderer.new(request).
80
+ process(:edit, @obj, current_page, params[:field_name], @obj.widget_container)
81
+ render json: {markup: markup}
82
+ end
83
+
77
84
  private
78
85
 
79
86
  def load_object
@@ -101,6 +108,16 @@ module RailsConnector
101
108
  Obj.find(params[:current_page_id]) if params[:current_page_id].present?
102
109
  end
103
110
  helper_method :current_page
111
+
112
+ def all_page_classes
113
+ page_classes = CmsRestApi.task_unaware_request(:get,
114
+ "revisions/#{Workspace.current.revision_id}/obj_classes")['results']
115
+ page_classes.map { |page_class| page_class['name'] }.sort
116
+ end
117
+
118
+ def all_widget_classes
119
+ Dir[Rails.root + 'app/widgets/*'].map { |path| File.basename(path).camelize }.sort
120
+ end
104
121
  end
105
122
 
106
123
  end
@@ -2,6 +2,7 @@ module RailsConnector
2
2
 
3
3
  # @api public
4
4
  module CmsTagHelper
5
+ FIELD_TYPES_WITH_ORIGINAL_CONTENT = %w[string text html enum multienum]
5
6
  VOID_TAGS = %w[area base br col command embed hr img input keygen
6
7
  link meta param source track wbr]
7
8
 
@@ -48,23 +49,12 @@ module RailsConnector
48
49
  end
49
50
  inner_html = safe_join(rendered_widgets)
50
51
  else
51
- block_result = nil
52
- if inplace_editing_allowed?
53
- original_value = if block_given?
54
- block_result = capture { yield }
55
- else
56
- display_original_value(obj[attribute])
57
- end
58
- original_value ||= ''
59
- # Concate with empty string to disable html_safe:
60
- options['data-ip-field-original-content'] = '' + original_value
52
+ if inplace_editing_allowed? && FIELD_TYPES_WITH_ORIGINAL_CONTENT.include?(field_type)
53
+ original_content = MultiJson.encode(display_original_value(obj[attribute]))
54
+ options['data-ip-field-original-content'] = original_content
61
55
  end
62
56
 
63
- inner_html = if block_given?
64
- block_result || capture { yield }
65
- else
66
- display_value(obj[attribute])
67
- end
57
+ inner_html = block_given? ? capture { yield } : display_value(obj[attribute])
68
58
  end
69
59
 
70
60
  if VOID_TAGS.include?(tag_name.to_s)
@@ -0,0 +1,105 @@
1
+ module RailsConnector
2
+
3
+ # This module contains a helper that can be used to render attributes of the CMS models.
4
+ # @api public
5
+ module DisplayHelper
6
+
7
+ # For a consistent look of your site and easy maintenance, only the display helpers
8
+ # should be used to render an attribute <em>value</em> of a CMS model.
9
+ #
10
+ # <%= display_value @obj.title %>
11
+ # Renders the value, taking its type into account.
12
+ # * An HtmlString will be exported by converting its links
13
+ # * A Time will be exported in an international form: Year-Month-Day Hour:Minutes
14
+ # * A non-HTML String will be quoted
15
+ # * other values will be rendered unchanged
16
+ #
17
+ # @api public
18
+ def display_value(value)
19
+ case value
20
+ when HtmlString then convert_links(value).html_safe
21
+ when String then h(value)
22
+ when Time then h(l(value))
23
+ else value
24
+ end
25
+ end
26
+
27
+ def display_original_value(value)
28
+ case value
29
+ when HtmlString then convert_links(value, :ignore_body_data_url => true).html_safe
30
+ else display_value(value)
31
+ end
32
+ end
33
+
34
+ # Renders a field from the CMS, including an edit marker for the preview
35
+ # If the option :marker is +false+, no edit marker will be rendered.
36
+ #
37
+ # <%= display_field @obj, :title %>
38
+ #
39
+ # When creating an edit marker, all options except :marker are passed to {MarkerHelper#edit_marker}.
40
+ #
41
+ # @api public
42
+ def display_field(obj, attr, options = {})
43
+ options.reverse_merge!({
44
+ :marker => ![:id, :path, :created, :last_changed, :version].include?(attr.to_sym)
45
+ })
46
+ if options.delete :marker
47
+ edit_marker(obj, attr, options) do |obj, attr|
48
+ display_value obj[attr]
49
+ end
50
+ else
51
+ display_value obj[attr]
52
+ end
53
+ end
54
+
55
+ # Legacy method - deprecated
56
+ #
57
+ # Use display_value and display_field instead
58
+ def display(*args)
59
+ if args.last.kind_of? Hash
60
+ options = args.pop
61
+ else
62
+ options = {}
63
+ end
64
+ return display_value(args.first) if args.size == 1
65
+ display_field(args[0], args[1], options)
66
+ end
67
+
68
+ private
69
+
70
+ LINK_PATTERN = '<?\binternallink:(\d+)\b>?'
71
+ LINK_EXPRESSION = %r(#{LINK_PATTERN})
72
+
73
+ def convert_links(content_attribute, cms_path_options = {})
74
+ return content_attribute unless content_attribute =~ LINK_EXPRESSION
75
+ link_map = content_attribute.source.text_links.each_with_object({}) do |link, map|
76
+ map[link.id.to_s] = link
77
+ end
78
+ content_attribute.gsub(%r(#{LINK_PATTERN}(['"]?))) do
79
+ link = link_map[$1.to_s]
80
+ if link.blank?
81
+ "#{CmsRoutingHelper::LINK_TO_UNREACHABLE}#{$2}"
82
+ else
83
+ uri = "#{cms_path(link, cms_path_options)}#{$2}"
84
+ html_link(link, uri)
85
+ end
86
+ end
87
+ end
88
+
89
+ def html_link(link, uri)
90
+ subst = uri
91
+ name, value =
92
+ case link.tag_name
93
+ when 'img', 'input'
94
+ ['alt', link.title || ""]
95
+ when 'a', 'link'
96
+ ['title', begin link.title unless link.title.blank? end]
97
+ end
98
+ if value
99
+ subst << %( #{name}="#{h(value)}")
100
+ end
101
+ subst << %( target="#{h(link.target)}") unless link.target.blank?
102
+ subst
103
+ end
104
+ end
105
+ end
@@ -16,6 +16,12 @@ module RailsConnector
16
16
  Configuration.editing_auth_callback.call(request.env)
17
17
  end
18
18
 
19
+ def current_page_has_edit_view?
20
+ @obj && lookup_context.find(@obj.edit_view_path).present?
21
+ rescue ActionView::MissingTemplate
22
+ false
23
+ end
24
+
19
25
  end
20
26
 
21
27
  end
@@ -9,7 +9,8 @@
9
9
  })
10
10
  );
11
11
  infopark.obj.current_page_id = "<%= @obj.try(:id) %>";
12
- infopark.admin_gui_base_url = "<%= RailsConnector::CmsRestApi.credentials[:url] %>";
12
+ infopark.obj.current_page_has_edit_view = <%= current_page_has_edit_view? %>;
13
+ infopark.admin_gui_base_url = "<%= RailsConnector::CmsRestApi.configuration.url %>";
13
14
  infopark.editing.initialize();
14
15
  });
15
16
  <% end %>