Class: Scrivito::CmsRouting

Inherits:
Object
  • Object
show all
Defined in:
lib/fiona7/scrivito_patches/cms_routing.rb

Instance Method Summary collapse

Instance Method Details



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fiona7/scrivito_patches/cms_routing.rb', line 5

def convert_links(html)
  if html
    # v-- patch here
    html.to_str.gsub(%r{\bobjid:([a-f0-9]{4,})\b([^"']*)}) do
      if obj = Obj.find_by_id($1)
        options = {}

        if $2.present?
          begin
            uri = URI.parse($2)
            options.merge!(extract_query(uri))
            options[:anchor] = uri.fragment
          rescue
          end
        end

        if editing_context.display_mode == 'editing'
          options[:id] = obj.id
          scrivito_engine.base_id_path(options)
        else
          path_or_url(obj, :path, options)
        end
      else
        "#__target_object_not_reachable"
      end
    end
  end
end

#path_or_url_for_objs(obj, path_or_url, options) ⇒ Object

Use fiona connector permalinks and binary urls in legacy mode



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/fiona7/scrivito_patches/cms_routing.rb', line 56

def path_or_url_for_objs(obj, path_or_url, options)
  permalink = obj.permalink
  if permalink && (route = find_route(:permalink)) && permalink.split('/').first != 'scrivito'
    # -- patch here --
    if Fiona7.mode == :legacy
      context.public_send("cms_permalink_#{path_or_url}", options.merge(:permalink => permalink))
    else
      route.generate(path_or_url, options.merge(:permalink => permalink))
    end
    # -- patch ends here --
  elsif homepage?(obj) && route = find_route(:homepage)
    route.generate(path_or_url, options)
  elsif obj.binary?
    # -- patch here --
    if Fiona7.mode == :legacy && self.image_options.blank?
      if binary = obj.binary
        params = {
          id: obj.id,
          slug: obj.slug,
          format: obj.file_extension
        }

        # use fiona connector routes when possible
        context.public_send("cms_id_#{path_or_url}", params)
      else
        LINK_TO_EMPTY_BLOB
      end
    else
      binary_obj_url(obj) || LINK_TO_EMPTY_BLOB
    end
    # -- patch ends here --
  elsif route = find_route(:slug_id)
    slug = obj.slug.present? ? obj.slug.sub(/^\//, '') : nil
    route.generate(path_or_url, options.merge(id: obj.id, slug: slug))
  else
    raise ScrivitoError, "The required scrivito route 'slug_id' is not defined. "\
      "Please add a 'slug_id' definition to your routes.rb. See the documentation"\
      " of 'scrivito_route' for further details."
  end
end

#path_or_url_without_editing_context(target, path_or_url, options) ⇒ Object

patch for handling direct descendants of Scrivito::BasicObj



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/fiona7/scrivito_patches/cms_routing.rb', line 35

def path_or_url_without_editing_context(target, path_or_url, options)
  if target.is_a?(Link)
    path_or_url_for_links(target, path_or_url, options)
  elsif target.is_a?(::Scrivito::BasicObj) # <-- patch here
    path_or_url_for_objs(target, path_or_url, options)
  elsif target.respond_to?(:first)
    if target.first.is_a?(Link)
      path_or_url_for_links(target.first, path_or_url, options)
    else
      return LINK_TO_EMPTY_LINKLIST
    end
  elsif target.is_a?(Binary)
    binary_url(target)
  else
    raise "scrivito_path or scrivito_url was called with an instance of #{target.class}. "+
      "It must only be called with an Obj or a Link or a non-empty LinkList."
  end
end