Module: Iron::Routing

Defined in:
lib/iron/routing.rb

Instance Method Summary collapse

Instance Method Details

#iron_pagesObject



3
4
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
33
34
35
36
37
38
# File 'lib/iron/routing.rb', line 3

def iron_pages
  published_page_constraint = Iron::PublishedPageConstraint.new

  direct :iron_entry do |entry|
    locale = entry..locale
    locale_prefix = locale && locale != Iron::Account.first.default_locale ? "/#{locale.code}" : ""
    "#{locale_prefix}#{entry..web.path}"
  end

  Iron::ContentType.web_published.each do |content_type|
    if content_type.base_path.present?
      get "(/:locale)/#{content_type.base_path}/*route",
          to: "pages#show",
          defaults: { content_type: content_type.handle },
          constraints: published_page_constraint
    else
      get "(/:locale)/*route",
          to: "pages#show",
          defaults: { content_type: content_type.handle },
          constraints: lambda { |req|
            published_page_constraint.matches?(req) &&
            req.params[:route].present?
          }

      get ":locale",
          to: "pages#show",
          defaults: { content_type: content_type.handle, route: "" },
          constraints: published_page_constraint

      get "/",
          to: "pages#show",
          defaults: { content_type: content_type.handle, route: "" },
          constraints: published_page_constraint
    end
  end
end