-
Notifications
You must be signed in to change notification settings - Fork 178
Do We Want some Common Name Processing? #156
Comments
The current
It would be a real contribution to this project if you (anyone) were to isolate the extent versions and develop a test suite that demonstrates their features and limitations. This could be the basis of ongoing discussion of a critical issue. Here is a template in coffeescript could belong in the /spec directory: asSlug = (name) ->
name.replace(/\s/g, '-').replace(/[^A-Za-z0-9-]/g, '').toLowerCase()
section = (comment) ->
console.log "\n\t#{comment}\n"
test = (given, expected) ->
actual = asSlug given
console.log if actual == expected then "OK\t#{given}" else "YIKES\t#{given} => #{actual}, not #{expected} as expected"
# the following test cases presume to be implementation language agnostic
# perhaps they should be included from a common file
section 'case and hyphen insensitive'
test 'Welcome Visitors', 'welcome-visitors'
test 'welcome visitors', 'welcome-visitors'
test 'Welcome-visitors', 'welcome-visitors'
section 'numbers and punctuation'
test '2012 Report', '2012-report'
test 'Ward\'s Wiki', 'wards-wiki'
section 'foreign language'
test 'Les Misérables', 'les-misérables' |
Just pushed this code as 04d6e61. Couldn't help but add a few more cases. |
Note a side benefit from having me make Wagn::Cardname into a more general gem: we already have internationalization in our work queue, and when we do this, we will certainly be making the changes in this new gem, or the Cardname class if we haven't made a gem yet. For example, plural/singular is part of the name folding and that clearly needs to be more general that what we have so far. It almost requires the objects (Pages in SFW, Cards for Wagn) have full alias capability in the naming library. |
I extracted it to a new repo and took out the Wagny parts. I'll add test cases and such as I have some more time. https://github.com/GerryG/namelogic/blob/master/lib/name_logic.rb Suggestions about what to name it or its methods or components are welcome. |
Now it has some tests. They are all taken directly from Wagn tests, and I haven't looked at how good the coverage is yet. https://github.com/GerryG/namelogic/commit/f640c695110164ecd49fc41fc95b9642a0a7969d |
@GerryG has tracked down some useful resources with respect to diacritical marks in unicode and how they might be handled in slug formation. |
Oh, I think the point I've been dancing around be not stating clearly is about keys and equivalence classes. It is perfectly ok if different Wikis in the federation have a different representation of the key (slug), but the way the namespace is structured in terms of equivalence classes has to be mappable. For all names that map to the same key, they must map to the same key in all of the wikis. I'm pretty sure this will always mean that if you take the key from a foreign system, and convert it to a key in your system, and then reverse that process and re-encode your key into the foreign system, it will end up on the same key. In fact, I think the latter is a lessor condition that may be enough for good interoperability. If I were a better mathematician I might be able to prove they are the same condition. |
Now I have to find some time to document this and create a configuration variation that matches SFW rather than Wagn. |
Do you have a preference for a name segment separator for SFW? '/' is out since you already use that. A double character like '--' seems like a reasonable options, but I don't like it that much. Even if you don't think you'll need that, I'd reserve a syntactic character for it now. |
@WardCunningham, you asked in #176 in this comment:
Rails has a
And
-- Both from https://github.com/rails/rails/blob/master/activesupport/lib/active_support/inflector/transliterate.rb |
In the hangout today we discussed whether non-ascii characters should be allowed in slugs, eg: www.example.com/تماس-با-ما I took this approach tonight in the slug generation on my 'Open Your Project' site: ...I also brought in @WardCunningham's bilingual slug test idea, as posted above. Naturally the intention is to merge this code and the fedwiki slug code into one common place (gem?) when the dust settles. I am also doing some additional processing of URLs when they used to generate slugs -- just using the path part. The code itself is here: |
Since I use slug generation in multiple contexts, I have moved the versions I find most useful into a new gem I created: https://rubygems.org/gems/superstring This has 2 "permissivity" settings (see #248 for permissivity discussion): "page" (permissive) -- and "subdomain" -- If there is interest in using this gem in SFW, I am very open to adding other options as well. Probably the issues in #248 need to be sorted out, regardless of whether it's in an external gem or not. I mention this only in the hope that the work I've done on the gem might inspire further clarity around slugs in the SFW community. |
I was thinking about what Ward said about my comments about Naming, and I had trouble even remembering where I put it. I added a Wiki page [[Naming Issues]], but I thought adding an issue for a place to discus what we might attempt to add to the code.
It occurred to me the we recently split off all of the name handling in Wagn into its own class (cardname), and that it wouldn't be that hard to pull this into an includable gem that is more general. It would need a name (cardname being Wagn specific), and there might need to be a little configuration of things that are class constants now.
Some of the key features that might make it worth considering:
Wagn name to key conventions:
This translation is in a sigle method, so it could be configured by overriding.
I'd be willing to make a gem out of it and interface it with the server code if there is interest. A side effect may be we need it translated to coffee script which would be useful for us too.
The text was updated successfully, but these errors were encountered: