rsl/stringex

Namestringex
DescriptionSome [hopefully] useful extensions to Ruby’s String class. It is made up of three libraries: ActsAsUrl [permalink solution with better character translation], Unidecoder [Unicode to Ascii transliteration], and StringExtensions [miscellaneous helper methods for the String class].
LanguageRuby
Topics
Watchers975
Forks153
Open issues15
Last push12/1/2021 6:00:18 PM +00:00
Github URLhttps://github.com/rsl/stringex
Clone URLhttps://github.com/rsl/stringex.git
SSH URL[email protected]:rsl/stringex.git

Most active issues

Topic# Comments
Hi Russell,

Thought about this before v2.0 but just did not get to talk about it back then.

What would you think about extracting acts_as_url into its own gem? http://rubygems.org/gems/acts_as_url is available.

The reason is that I really like the string extensions and conversions and use them heavily but use another slug generation plugin because it fits my needs better. Also, I don't think the two (the actual string extensions / acts_as_url) are closely related other than that acts_as_url of course uses the extensions.

What do you think?

/Lasse


Read comments
26
Hi Russell,

I have this issue:

ruby
"test¤test".to_url # => "test$-test"


Thanks,
/Lasse


Read comments
25
Added an optional :skip_slash parameter to "to_url" I didn't need it for acts_as_url, but if you accept this and want me to add the option there, I will gladly do so.


Read comments
14
I have a gollum wiki on my server. Since i also tried to install redmine, I now receive the following error when creating a new page in gollum:

> undefined method `translate' for I18n:Module

In the stacktrace it shows, that the relevant call is in stringex:


/var/lib/gems/1.9.1/gems/stringex-2.0.5/lib/stringex/localization/backend/i18n.rb in i18n_translations_for
::I18n.translate("stringex", :locale => locale, :default => {})


I'm not a ruby expert, but from what i can tell, all requirements are met. Here's the output of `gem list`:


*** LOCAL GEMS ***

actionmailer (3.2.13)
actionpack (3.2.13)
activemodel (3.2.13)
activerecord (3.2.13)
activeresource (3.2.13)
activesupport (3.2.13)
arel (3.0.2)
builder (3.2.2, 3.0.0)
bundler (1.3.5)
charlock_holmes (0.6.9)
coderay (1.0.9)
diff-lcs (1.2.3)
erubis (2.7.0)
expression_parser (0.9.0)
github-markdown (0.5.3)
github-markup (0.7.5)
gollum (2.5.0, 2.4.15)
gollum-lib (1.0.4, 1.0.3)
grit (2.5.0)
hike (1.2.3)
hpricot (0.8.6)
i18n (0.6.1)
journey (1.0.4)
jquery-rails (2.0.3)
json (1.8.0)
mail (2.5.4)
mime-types (1.23, 1.22)
mini_portile (0.5.1)
multi_json (1.7.7)
mustache (0.99.4)
net-ldap (0.3.1)
nokogiri (1.6.0, 1.5.9)
polyglot (0.3.3)
posix-spawn (0.3.6)
pygments.rb (0.5.2)
rack (1.5.2, 1.4.5)
rack-cache (1.2)
rack-openid (1.3.1)
rack-protection (1.5.0)
rack-ssl (1.3.3)
rack-test (0.6.2)
rails (3.2.13)
railties (3.2.13)
rake (10.1.0)
rdoc (3.12.2)
rmagick (2.13.2)
ruby-openid (2.2.3, 2.1.8)
sanitize (2.0.6, 2.0.3)
sinatra (1.4.2)
sprockets (2.2.2)
sqlite3 (1.3.7)
stringex (2.0.5, 1.5.1)
svn2git (2.2.2)
thor (0.18.1)
tilt (1.4.1, 1.3.7)
treetop (1.4.14)
tzinfo (0.3.37)
useragent (0.6.0)
wikicloth (0.8.0)
yajl-ruby (1.1.0)
yard (0.8.6.2)


Any idea, what could have caused this issue? Everything went fine before i messed around with redmine.


Read comments
14
I find the documentation misleading. It says:

If you don’t want to use the Stringex built-in translations, you can force Stringex to use English (or another language), regardless what is in your I18n.locale. In an initializer, e.g. config/initializers/stringex.rb:
Stringex::Localization.locale = :en

But in fact by default it just changes the I18n.locale, as the Stringex backend points to Backend::I18n.

So the option is useless until I change the used by Stringex backend.


Read comments
13
I have next string:
"éç™①".to_ascii => "ec"
So "TM1" is missing.
I propose to add Unicode::normalize_KD to "to_ascii" method.
Like that:
require "unicode"
def to_ascii
LuckySneaks::Unidecoder.decode(Unicode::normalize_KD(self))
end
Than would be:
"éç™①".to_ascii => "ecTM1"
I think this much great!..


Read comments
13
It looks like [Stringex::ActsAsUrl::included](https://github.com/rsl/stringex/blob/master/lib/stringex/acts_as_url.rb#L75) overrides [ActiveSupport::Concern::included](https://github.com/rails/rails/blob/master/activesupport/lib/active_support/concern.rb#L124) causing ActiveSupport::Concern to break.

I get an error when I include a module that extends ActiveSupport::Concern.


wrong number of arguments (0 for 1) (ArgumentError) lib/stringex/acts_as_url.rb:75:in `included'.



Read comments
12
I understand the reasoning behind something like "google.com" -> "google dot com"

However, I feel that for abbreviations, "D.N.A." would be better converted to "dna"

Yay/nay ? I'd be happy to work on and submit a patch.


Read comments
12
1. Uses "pluck" to pull only the slug column rather than instantiating
all objects.
2. Assumes that the slug ends with a serial number, finds the highest
such serial number, and adds 1 to it
3. This change should make acts_as_url usable for large datasets.


Read comments
12
The typical stringex use case example with Rails involves model scaffolding that uses generated url slug instead of id. However this doesn't prevent user from creating urls that are gonna overlap with default rails routing.

Consider this setup

ruby
# config/routes.rb
resources :posts

# app/models/post.rb
class Post < AR::Base
acts_as_url :title
def to_param
url
end
end

# app/controllers/posts_controller.rb
class PostsController < ApplicationController
# standard crud stuff here
def create
@post = Post.new(post_params)
if @post.save
redirect_to @post, notice: "post created"
else
render :new
end
end
end


Say someone wants to create a post with title "New". That'll effectively generate url as "new" and the whole post path would become "/posts/new" which will take you to the new post form, not to the post itself.

I think acts-as-url component of stringex should support some kind of stop-list of url slugs (could be ["new"] by default) it needs to avoid and a policy to substitute them with something meaningful. For example, "new" slug could become "new-post".


Read comments
11