module Dibbler

*****************************************************************************

***************************************************************************** *

*

* *****************************************************************************

*****************************************************************************

***************************************************************************** *

*

* *****************************************************************************

*****************************************************************************

***************************************************************************** *

*

* *****************************************************************************

*****************************************************************************

***************************************************************************** *

*

* *****************************************************************************

*****************************************************************************

***************************************************************************** *

*

* *****************************************************************************

*****************************************************************************

***************************************************************************** *

*

* *****************************************************************************

*****************************************************************************

***************************************************************************** *

*

* *****************************************************************************

*****************************************************************************

***************************************************************************** *

*

* *****************************************************************************

Public Class Methods

assemble(locale, path) click to toggle source
# File lib/dibbler.rb, line 64
def self.assemble(locale, path)
  if locale && (Dibbler.disable_default_locale || (I18n.default_locale.to_sym != locale.to_sym))
    if path == "/"
      path = "/" + locale.to_s
    elsif path.starts_with?("http")
      split1 = path.split("//")
      split2 = split1[1].to_s.split("/")
      split1[1] = split2.insert(1, locale.to_s).join("/")
      path = split1.join("//")
    else
      path = "/" + locale.to_s + path
    end
  end
  return path
end
disassemble(path) click to toggle source

************************************************************************* Interface *************************************************************************

# File lib/dibbler.rb, line 40
def self.disassemble(path)
  # TODO work correctly with http:// and https:// links

  # Match locale from path
  match = /^\/(#{I18n.available_locales.join("|")})\//.match(path + "/")
  if match
    locale = match[1].to_sym
  else
    locale = nil
  end

  # Remove locale from path
  if locale
    path = path[(1 + locale.to_s.length)..-1]
  end

  # Root
  if path.blank?
    path = "/"
  end

  return [locale, path]
end
localify(path) click to toggle source
# File lib/dibbler.rb, line 80
def self.localify(path)
  return path if path == "#"

  # Match locale from path
  locale, path = self.disassemble(path)

  # Take current locale if path locale not defined
  if locale.nil?
    locale = I18n.locale
  end

  # Assemble back into path with locale
  path = self.assemble(locale, path)

  return path
end
setup() { |self| ... } click to toggle source

Default way to setup module

# File lib/dibbler.rb, line 123
def self.setup
  yield self
end
slug_model() click to toggle source
# File lib/dibbler.rb, line 138
def self.slug_model
  return @@slug_model.constantize
end
slugify(path) click to toggle source
# File lib/dibbler.rb, line 97
def self.slugify(path)

  # Match locale from path
  locale, original = self.disassemble(path)

  # Translate from original
  tmp_uri = URI.parse(original)
  tmp_path = Dibbler.slug_model.original_to_translation((locale ? locale : I18n.default_locale), tmp_uri.path)
  if tmp_path
    tmp_uri.path = tmp_path
    translation = tmp_uri.to_s
  else
    translation = original
  end

  # Add locale if defined
  translation = self.assemble(locale, translation)

  return translation
end
table_name_prefix() click to toggle source

This will keep Rails Engine from generating all table prefixes with the engines name

# File lib/dibbler.rb, line 33
def self.table_name_prefix
end