module Dibbler
*****************************************************************************
-
Copyright © 2019 Matěj Outlý
***************************************************************************** *
*
-
Author: Matěj Outlý
-
Date : 9. 6. 2015
* *****************************************************************************
*****************************************************************************
-
Copyright © 2019 Matěj Outlý
***************************************************************************** *
-
URL helper
*
-
Author: Matěj Outlý
-
Date : 22. 7. 2015
* *****************************************************************************
*****************************************************************************
-
Copyright © 2019 Matěj Outlý
***************************************************************************** *
-
Recognize locale based on request
*
-
Author: Matěj Outlý
-
Date : 22. 7. 2015
* *****************************************************************************
*****************************************************************************
-
Copyright © 2019 Matěj Outlý
***************************************************************************** *
-
Request translation based on DB slugs
*
-
Author: Matěj Outlý
-
Date : 21. 7. 2015
* *****************************************************************************
*****************************************************************************
-
Copyright © 2019 Matěj Outlý
***************************************************************************** *
-
Hierarchical slug generator
*
-
Author: Matěj Outlý
-
Date : 21. 7. 2015
* *****************************************************************************
*****************************************************************************
-
Copyright © 2019 Matěj Outlý
***************************************************************************** *
-
Slug
*
-
Author: Matěj Outlý
-
Date : 21. 7. 2015
* *****************************************************************************
*****************************************************************************
-
Copyright © 2019 Matěj Outlý
***************************************************************************** *
-
Linear slug generator
*
-
Author: Matěj Outlý
-
Date : 21. 7. 2015
* *****************************************************************************
*****************************************************************************
-
Copyright © 2019 Matěj Outlý
***************************************************************************** *
-
Railtie
for view helpers integration
*
-
Author: Matěj Outlý
-
Date : 22. 7. 2015
* *****************************************************************************
Public Class Methods
# 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
************************************************************************* 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
# 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
Default way to setup module
# File lib/dibbler.rb, line 123 def self.setup yield self end
# File lib/dibbler.rb, line 138 def self.slug_model return @@slug_model.constantize end
# 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
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