module RoutingFilter

If the path is, aside from a slash and an optional locale, the leftmost part of the path, replace it by “sections/:id” segments.

Protected Instance Methods

generate_pattern() click to toggle source
# File lib/knitkit/routing_filter/section_router.rb, line 71
def generate_pattern
  types = WebsiteSection.types.map { |type| type.downcase.pluralize }.join('|')
  %r((#{types})/([\w]+(/?))(\.?)) # ?(?=\b)?
end
paths_for_website(website) click to toggle source
# File lib/knitkit/routing_filter/section_router.rb, line 50
def paths_for_website(website)
  website ? website.all_section_paths.map { |path| path[1..path.length] }.sort { |a, b| b.size <=> a.size }.join('|') : []
end
recognize_pattern(paths) click to toggle source
# File lib/knitkit/routing_filter/section_router.rb, line 67
def recognize_pattern(paths)
  %r(^/([\w]{2,4}/)?(#{paths})(?=/|\.|$))
end
website_section_by_path(website, path) click to toggle source
# File lib/knitkit/routing_filter/section_router.rb, line 54
def website_section_by_path(website, path)
  path = "/#{path}"
  valid_section = website.website_sections.detect { |website_section| website_section.path == path }
  if valid_section.nil?
    website.website_sections.each do |website_section|
      valid_section = website_section.child_by_path(path)
      break unless valid_section.nil?
    end
  end

  valid_section
end