Class: RoutingFilter::SectionRouter
- Inherits:
-
Filter
- Object
- Filter
- RoutingFilter::SectionRouter
- Defined in:
- lib/knitkit/routing_filter/section_router.rb
Instance Method Summary collapse
- #around_generate(params, &block) ⇒ Object
- #around_recognize(path, env, &block) ⇒ Object
- #excluded_paths ⇒ Object
Instance Method Details
#around_generate(params, &block) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/knitkit/routing_filter/section_router.rb', line 39 def around_generate(params, &block) yield.tap do |path| result = result.first if result.is_a?(Array) if result =~ generate_pattern section = WebsiteSection.find $2.to_i result.sub! "#{$1}/#{$2}", "#{section.path[1..section.path.length]}#{$3}" end end end |
#around_recognize(path, env, &block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/knitkit/routing_filter/section_router.rb', line 15 def around_recognize(path, env, &block) unless excluded_paths.include?(path.split('/').second) website = Website.find_by_host(env["HTTP_HOST"]) if website paths = paths_for_website(website) if path.to_sym == :/ home_page_url = website.configurations.first.get_configuration_item(ConfigurationItemType.find_by_internal_identifier('homepage_url'))..first.value valid_section = website.website_sections.detect { |website_section| website_section.path == home_page_url } type = valid_section.type.pluralize.downcase path.sub!('/', "/#{$1}#{type}/#{valid_section.id}#{$3}") else if !Rails.application.config.knitkit.ignored_prefix_paths.include?(path) and !paths.empty? and path =~ recognize_pattern(paths) if section = website_section_by_path(website, $2) type = section.type.pluralize.downcase path.sub! %r(^/([\w]{2,4}/)?(#{paths})(?=/|\.|$)), "/#{$1}#{type}/#{section.id}#{$3}" end end end end end yield end |
#excluded_paths ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/knitkit/routing_filter/section_router.rb', line 7 def excluded_paths paths = %w{ erp_app session } paths.push(Rails.configuration.assets.prefix.split('/').second) paths end |