radiant-taggable-extension 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/app/models/tag.rb +4 -1
- data/lib/natcmp.rb +76 -0
- data/lib/radiant-taggable-extension.rb +0 -0
- data/lib/taggable_tags.rb +3 -3
- data/radiant-taggable-extension.gemspec +4 -4
- data/spec/models/tag_spec.rb +14 -0
- data/taggable_extension.rb +2 -1
- metadata +6 -6
- data/pkg/radiant-taggable-extension-1.2.0.gem +0 -0
- data/public/images/furniture/detag.png +0 -0
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.2
|
data/app/models/tag.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
class Tag < ActiveRecord::Base
|
2
|
-
|
3
2
|
attr_accessor :cloud_band, :cloud_size
|
4
3
|
|
5
4
|
belongs_to :created_by, :class_name => 'User'
|
@@ -64,6 +63,10 @@ class Tag < ActiveRecord::Base
|
|
64
63
|
}
|
65
64
|
}
|
66
65
|
|
66
|
+
def <=>(othertag)
|
67
|
+
String.natcmp(self.title, othertag.title)
|
68
|
+
end
|
69
|
+
|
67
70
|
def to_s
|
68
71
|
title
|
69
72
|
end
|
data/lib/natcmp.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# natcmp.rb
|
2
|
+
#
|
3
|
+
# Natural order comparison of two strings
|
4
|
+
# e.g. "my_prog_v1.1.0" < "my_prog_v1.2.0" < "my_prog_v1.10.0"
|
5
|
+
# which does not follow alphabetically
|
6
|
+
#
|
7
|
+
# Based on Martin Pool's "Natural Order String Comparison" originally written in C
|
8
|
+
# http://sourcefrog.net/projects/natsort/
|
9
|
+
#
|
10
|
+
# This implementation is Copyright (C) 2003 by Alan Davies
|
11
|
+
# <cs96and_AT_yahoo_DOT_co_DOT_uk>
|
12
|
+
#
|
13
|
+
# This software is provided 'as-is', without any express or implied
|
14
|
+
# warranty. In no event will the authors be held liable for any damages
|
15
|
+
# arising from the use of this software.
|
16
|
+
#
|
17
|
+
# Permission is granted to anyone to use this software for any purpose,
|
18
|
+
# including commercial applications, and to alter it and redistribute it
|
19
|
+
# freely, subject to the following restrictions:
|
20
|
+
#
|
21
|
+
# 1. The origin of this software must not be misrepresented; you must not
|
22
|
+
# claim that you wrote the original software. If you use this software
|
23
|
+
# in a product, an acknowledgment in the product documentation would be
|
24
|
+
# appreciated but is not required.
|
25
|
+
# 2. Altered source versions must be plainly marked as such, and must not be
|
26
|
+
# misrepresented as being the original software.
|
27
|
+
# 3. This notice may not be removed or altered from any source distribution.
|
28
|
+
|
29
|
+
class String
|
30
|
+
|
31
|
+
# 'Natural order' comparison of two strings
|
32
|
+
def String.natcmp(str1, str2, caseInsensitive=false)
|
33
|
+
str1, str2 = str1.dup, str2.dup
|
34
|
+
compareExpression = /^(\D*)(\d*)(.*)$/
|
35
|
+
|
36
|
+
if caseInsensitive
|
37
|
+
str1.downcase!
|
38
|
+
str2.downcase!
|
39
|
+
end
|
40
|
+
|
41
|
+
# Remove all whitespace
|
42
|
+
str1.gsub!(/\s*/, '')
|
43
|
+
str2.gsub!(/\s*/, '')
|
44
|
+
|
45
|
+
while (str1.length > 0) or (str2.length > 0) do
|
46
|
+
# Extract non-digits, digits and rest of string
|
47
|
+
str1 =~ compareExpression
|
48
|
+
chars1, num1, str1 = $1.dup, $2.dup, $3.dup
|
49
|
+
|
50
|
+
str2 =~ compareExpression
|
51
|
+
chars2, num2, str2 = $1.dup, $2.dup, $3.dup
|
52
|
+
|
53
|
+
# Compare the non-digits
|
54
|
+
case (chars1 <=> chars2)
|
55
|
+
when 0 # Non-digits are the same, compare the digits...
|
56
|
+
# If either number begins with a zero, then compare alphabetically,
|
57
|
+
# otherwise compare numerically
|
58
|
+
if (num1[0] != 48) and (num2[0] != 48)
|
59
|
+
num1, num2 = num1.to_i, num2.to_i
|
60
|
+
end
|
61
|
+
|
62
|
+
case (num1 <=> num2)
|
63
|
+
when -1 then return -1
|
64
|
+
when 1 then return 1
|
65
|
+
end
|
66
|
+
when -1 then return -1
|
67
|
+
when 1 then return 1
|
68
|
+
end # case
|
69
|
+
|
70
|
+
end # while
|
71
|
+
|
72
|
+
# Strings are naturally equal
|
73
|
+
return 0
|
74
|
+
end
|
75
|
+
|
76
|
+
end # class String
|
File without changes
|
data/lib/taggable_tags.rb
CHANGED
@@ -83,7 +83,7 @@ module TaggableTags
|
|
83
83
|
tag 'tags:cloud' do |tag|
|
84
84
|
if tag.locals.tags && tag.locals.tags.length > 1
|
85
85
|
options = tag.attr.dup
|
86
|
-
tag.locals.tags = Tag.for_cloud(tag.locals.tags).
|
86
|
+
tag.locals.tags = Tag.for_cloud(tag.locals.tags).sort
|
87
87
|
result = []
|
88
88
|
result << %{<div class="cloud">}
|
89
89
|
tag.locals.tags.each do |t|
|
@@ -152,7 +152,7 @@ module TaggableTags
|
|
152
152
|
tag.locals.page = found
|
153
153
|
end
|
154
154
|
raise TagError, "no page for tag_cloud" unless tag.locals.page
|
155
|
-
tag.locals.tags = tag.locals.page.tags_for_cloud(limit) # page.tags_for_cloud does a lot of inheritance work
|
155
|
+
tag.locals.tags = tag.locals.page.tags_for_cloud(limit).sort # page.tags_for_cloud does a lot of inheritance work
|
156
156
|
tag.render('tags:cloud', options)
|
157
157
|
end
|
158
158
|
|
@@ -176,7 +176,7 @@ module TaggableTags
|
|
176
176
|
tag.locals.page = found
|
177
177
|
end
|
178
178
|
raise TagError, "no page for tag_list" unless tag.locals.page
|
179
|
-
tag.locals.tags = tag.locals.page.tags_for_cloud(limit)
|
179
|
+
tag.locals.tags = tag.locals.page.tags_for_cloud(limit).sort
|
180
180
|
tag.render('tags:list', options)
|
181
181
|
end
|
182
182
|
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{radiant-taggable-extension}
|
8
|
-
s.version = "1.2.
|
8
|
+
s.version = "1.2.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["spanner"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-03-13}
|
13
13
|
s.description = %q{General purpose tagging extension: more versatile but less focused than the tags extension}
|
14
14
|
s.email = %q{will@spanner.org}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -34,16 +34,16 @@ Gem::Specification.new do |s|
|
|
34
34
|
"config/routes.rb",
|
35
35
|
"db/migrate/001_create_tags.rb",
|
36
36
|
"db/migrate/002_import_keywords.rb",
|
37
|
+
"lib/natcmp.rb",
|
38
|
+
"lib/radiant-taggable-extension.rb",
|
37
39
|
"lib/taggable_admin_page_controller.rb",
|
38
40
|
"lib/taggable_admin_ui.rb",
|
39
41
|
"lib/taggable_model.rb",
|
40
42
|
"lib/taggable_page.rb",
|
41
43
|
"lib/taggable_tags.rb",
|
42
44
|
"lib/tasks/taggable_extension_tasks.rake",
|
43
|
-
"pkg/radiant-taggable-extension-1.2.0.gem",
|
44
45
|
"public/images/admin/new-tag.png",
|
45
46
|
"public/images/admin/tag.png",
|
46
|
-
"public/images/furniture/detag.png",
|
47
47
|
"public/stylesheets/admin/tags.css",
|
48
48
|
"public/stylesheets/sass/tagcloud.sass",
|
49
49
|
"radiant-taggable-extension.gemspec",
|
data/spec/models/tag_spec.rb
CHANGED
@@ -21,6 +21,20 @@ describe Tag do
|
|
21
21
|
tags[2].created_at.should be_close((Time.now).utc, 10.seconds)
|
22
22
|
end
|
23
23
|
|
24
|
+
it "should stringify as title" do
|
25
|
+
"#{tags(:colourless)}".should == 'colourless'
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should <=> by title" do
|
29
|
+
tags = Tag.from_list('ideas,colourless,lifebelt')
|
30
|
+
tags.sort.first.should == tags(:colourless)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should sort tags naturally" do
|
34
|
+
tags = Tag.from_list('item2, item11, item13, item20, item1, item0')
|
35
|
+
tags.sort.join(' ').should == %{item0 item1 item2 item11 item13 item20}
|
36
|
+
end
|
37
|
+
|
24
38
|
describe "instantiated" do
|
25
39
|
before do
|
26
40
|
@tag = tags(:sleep)
|
data/taggable_extension.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
class TaggableExtension < Radiant::Extension
|
2
|
-
version "1.2.
|
2
|
+
version "1.2.2"
|
3
3
|
description "General purpose tagging and retrieval extension: more versatile but less focused than the tags extension"
|
4
4
|
url "http://github.com/spanner/radiant-taggable-extension"
|
5
5
|
|
6
6
|
def activate
|
7
|
+
require 'natcmp' # a natural sort algorithm. possibly not that efficient.
|
7
8
|
ActiveRecord::Base.send :include, TaggableModel # provide is_taggable for everything but don't call it for anything
|
8
9
|
Page.send :is_taggable # make pages taggable
|
9
10
|
Page.send :include, TaggablePage # then fake the keywords column and add some inheritance
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: radiant-taggable-extension
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 1.2.
|
9
|
+
- 2
|
10
|
+
version: 1.2.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- spanner
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-03-13 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -61,16 +61,16 @@ files:
|
|
61
61
|
- config/routes.rb
|
62
62
|
- db/migrate/001_create_tags.rb
|
63
63
|
- db/migrate/002_import_keywords.rb
|
64
|
+
- lib/natcmp.rb
|
65
|
+
- lib/radiant-taggable-extension.rb
|
64
66
|
- lib/taggable_admin_page_controller.rb
|
65
67
|
- lib/taggable_admin_ui.rb
|
66
68
|
- lib/taggable_model.rb
|
67
69
|
- lib/taggable_page.rb
|
68
70
|
- lib/taggable_tags.rb
|
69
71
|
- lib/tasks/taggable_extension_tasks.rake
|
70
|
-
- pkg/radiant-taggable-extension-1.2.0.gem
|
71
72
|
- public/images/admin/new-tag.png
|
72
73
|
- public/images/admin/tag.png
|
73
|
-
- public/images/furniture/detag.png
|
74
74
|
- public/stylesheets/admin/tags.css
|
75
75
|
- public/stylesheets/sass/tagcloud.sass
|
76
76
|
- radiant-taggable-extension.gemspec
|
Binary file
|
Binary file
|