public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/technoweenie/mephisto.git
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
add more robust tagging [Moritz Angermann]

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@2434 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Sat Nov 04 11:00:37 -0800 2006
commit  9e1205a80ce8d9ffb507f75cedc388efb5001178
tree    a5c45ad08d537dbf97010d6e732afc042c5cf956
parent  b05f90d2323b2a5d28684e64f720275acf093a4f
...
1
2
 
 
 
 
3
4
5
...
1
2
3
4
5
6
7
8
9
0
@@ -1,5 +1,9 @@
0
 * SVN *
0
 
0
+* 0.7.1 PRE-RELEASE *
0
+
0
+* add more robust tagging [Moritz Angermann]
0
+
0
 * Fixed duplicate body bug in default Simpla theme when article has no excerpt
0
 
0
 * Show excerpt by default on admin edit if the article has one
...
52
53
54
55
 
56
57
58
...
72
73
74
 
 
 
75
76
77
...
52
53
54
 
55
56
57
58
...
72
73
74
75
76
77
78
79
80
0
@@ -52,7 +52,7 @@ class MetaWeblogService < XmlRpcService
0
       :categories => article.sections.collect { |c| c.name },
0
       :mt_text_more => article.body.to_s,
0
       :mt_excerpt => article.excerpt.to_s,
0
- # :mt_keywords => article.keywords.to_s,
0
+ :mt_keywords => article.tag,
0
       # :mt_allow_comments => article.allow_comments? ? 1 : 0,
0
       # :mt_allow_pings => article.allow_pings? ? 1 : 0,
0
       # :mt_convert_breaks => (article.text_filter.name.to_s rescue ''),
0
@@ -72,6 +72,9 @@ class MetaWeblogService < XmlRpcService
0
       # if no categories are supplied do not attempt to set any.
0
       article.section_ids = Section.find(:all, :conditions => ['name IN (?)', struct['categories']]).collect(&:id) if struct['categories']
0
       article.attributes = {:updater => @user, :body => struct['description'].to_s, :title => struct['title'].to_s, :excerpt => struct['mt_excerpt'].to_s}
0
+ # Keywords/Tags support
0
+ Tagging.set_on article, struct['mt_keywords'] if struct['mt_keywords'] # set/modify keywords _only_ if they are supplied. mt_keywords _overwrite_ not alter the ``tags''
0
+
0
       utc_date = Time.utc(struct['dateCreated'].year, struct['dateCreated'].month, struct['dateCreated'].day, struct['dateCreated'].hour, struct['dateCreated'].sec, struct['dateCreated'].min) rescue article.published_at || Time.now.utc
0
       article.published_at = publish == true ? utc_date : nil
0
       article.save!
...
12
13
14
15
 
 
 
 
 
 
 
 
 
16
17
 
18
19
20
...
22
23
24
25
 
26
27
 
28
29
30
...
38
39
40
41
 
42
43
44
45
46
 
...
12
13
14
 
15
16
17
18
19
20
21
22
23
24
 
25
26
27
28
...
30
31
32
 
33
34
 
35
36
37
38
...
46
47
48
 
49
50
51
52
 
53
54
0
@@ -12,9 +12,17 @@ class Tag < ActiveRecord::Base
0
     # # => ['a', 'b', 'c']
0
     def parse(list)
0
       return list if list.is_a?(Array)
0
- list.split(',').collect! { |s| s.gsub(/[^\w\ ]+/, '').downcase.strip }.delete_if { |s| s.blank? }
0
+ # more robust does handle all kinds of different tags. (comma seperated, space seperated (in quotation marks))
0
+ # should handle most the common keyword formats.
0
+ # e.g.: b'log, emacs fun, rails, ruby => "b'log", "emacs fun", "rails", "ruby"
0
+ # "b'log" "emacs fun" "rails" "ruby" => "b'log", "emacs fun", "rails", "ruby"
0
+ # 'b\'log' 'emacs fun' 'rails' 'ruby' => "b'log", "emacs fun", "rails", "ruby"
0
+ #
0
+ list.scan(/((?: |)['"]{0,1})['"]?(.*?)(?:[,'"]|$)(?:\1(?: |$))/).collect{ |tag| tag.last }.uniq.delete_if{ |tag| tag == "" }
0
+ # the old version for legacy comparison.
0
+ #list.split(',').collect! { |s| s.gsub(/[^\w\ ]+/, '').downcase.strip }.delete_if { |s| s.blank? }
0
     end
0
-
0
+
0
     # Parses comma separated tag list and returns tags for them.
0
     #
0
     # Tag.parse_to_tags('a, b, c')
0
@@ -22,9 +30,9 @@ class Tag < ActiveRecord::Base
0
     def parse_to_tags(list)
0
       find_or_create(parse(list))
0
     end
0
-
0
+
0
     # Returns Tags from an array of tag names
0
- #
0
+ #
0
     # Tag.find_or_create(['a', 'b', 'c'])
0
     # # => [Tag, Tag, Tag]
0
     def find_or_create(tag_names)
0
@@ -38,8 +46,8 @@ class Tag < ActiveRecord::Base
0
   def ==(comparison_object)
0
     super || name == comparison_object.to_s
0
   end
0
-
0
+
0
   def to_s() name end
0
   alias to_param to_s
0
   alias to_liquid to_s
0
-end
0
\ No newline at end of file
0
+end
...
151
152
153
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
155
156
...
195
196
197
198
199
200
201
...
253
254
255
256
257
...
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
...
243
244
245
 
246
247
248
...
300
301
302
 
303
0
@@ -151,6 +151,54 @@ class BackendControllerTest < Test::Unit::TestCase
0
     end
0
   end
0
 
0
+ def test_meta_weblog_new_post_tags
0
+ # test weather we can create a new post, set tags and get away with it...
0
+ tags = 'blog, emacs, fun, rails, ruby'
0
+ article = MetaWeblogStructs::Article.new(:title => 'This is a title', :description => 'This is a post', :mt_keywords => tags)
0
+
0
+ args = [ 1, 'quentin', 'test', article, 1 ]
0
+
0
+ result = invoke_layered :metaWeblog, :newPost, *args
0
+ # assert result
0
+ new_post = Article.find(result)
0
+ assert_equal Tag.parse_to_tags(tags).collect(&:name).sort, new_post.tags.collect(&:name).sort
0
+ end
0
+
0
+ def test_meta_weblog_edit_post_tags
0
+ # changing tags
0
+ tags = 'blog, emacs, fun, rails, ruby'
0
+ article = MetaWeblogStructs::Article.new(:title => 'This is a title', :description => 'This is a post', :mt_keywords => tags)
0
+ args = [ 1, 'quentin', 'test', article, 1 ]
0
+ post_id = invoke_layered :metaWeblog, :newPost, *args
0
+
0
+ new_post = Article.find(post_id)
0
+ assert_equal Tag.parse_to_tags(tags).collect(&:name).sort, new_post.tags.collect(&:name).sort
0
+
0
+ tags = 'bar, baz, foo'
0
+ article = MetaWeblogStructs::Article.new(:title => 'This is a title', :description => 'This is a post', :mt_keywords => tags)
0
+ args = [ post_id, 'quentin', 'test', article, 1]
0
+ edit_result = invoke_layered :metaWeblog, :editPost, *args
0
+ assert_equal true, edit_result
0
+
0
+ new_post = Article.find(post_id)
0
+ assert_equal Tag.parse_to_tags(tags).collect(&:name).sort, new_post.tags.collect(&:name).sort
0
+ end
0
+
0
+ def test_meta_weblog_get_post_with_tags
0
+ # set tags and see if we recive them!
0
+ tags = 'blog, emacs, fun, rails, ruby'
0
+ article = MetaWeblogStructs::Article.new(:title => 'This is a title', :description => 'This is a post', :mt_keywords => tags)
0
+
0
+ args = [ 1, 'quentin', 'test', article, 1 ]
0
+ post_id = invoke_layered :metaWeblog, :newPost, *args
0
+
0
+ args = [ post_id, 'quentin', 'test' ]
0
+ result = invoke_layered :metaWeblog, :getPost, *args
0
+
0
+ assert_equal tags, result['mt_keywords']
0
+ end
0
+
0
+
0
   def test_meta_weblog_new_post_min
0
     # This is going to test weather a post is correctly submited or not without the published_at field!
0
     # See http://www.xmlrpc.com/metaWeblogApi#theStruct or
0
@@ -195,7 +243,6 @@ class BackendControllerTest < Test::Unit::TestCase
0
         assert_equal 'This is a title', new_post.title
0
         assert_equal c[:expect], new_post.status
0
       end
0
-
0
     end
0
   end
0
 
0
@@ -253,5 +300,4 @@ class BackendControllerTest < Test::Unit::TestCase
0
         'bits' => Base64.encode64(File.open(File.expand_path(RAILS_ROOT) + '/public/images/mephisto/shadow.png', 'rb') { |f| f.read })
0
       ))
0
     end
0
-
0
 end
...
5
6
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
9
10
...
22
23
24
25
 
26
27
28
29
30
 
31
32
33
...
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
...
39
40
41
 
42
43
44
45
46
 
47
48
49
50
0
@@ -5,6 +5,23 @@ class TagTest < Test::Unit::TestCase
0
 
0
   def test_should_parse_comma_separated_tags
0
     assert_equal %w(a b c), Tag.parse('a, b, c')
0
+ assert_equal %w(a b\ c), Tag.parse('a, b c')
0
+ end
0
+
0
+ def test_should_parse_simple_tags
0
+ assert_equal %w(a b c), Tag.parse("'a' 'b' 'c'")
0
+ assert_equal %w(a b c), Tag.parse('"a" "b" "c"')
0
+ end
0
+
0
+ def test_should_parse_more_complicated_tags
0
+ # with quotation marks _in_ the string.
0
+ assert_equal %w(tagging it's weirdness), Tag.parse('tagging, it\'s, weirdness')
0
+ assert_equal %w(tagging it"s weirdness), Tag.parse('tagging, it"s, weirdness')
0
+ assert_equal %w(tagging it's weirdness), Tag.parse('"tagging" "it\'s" "weirdness"')
0
+ assert_equal %w(tagging it's weirdness), Tag.parse("'tagging' 'it's' 'weirdness'")
0
+ # with spaces...
0
+ assert_equal %w(tagging it's\ weirdness), Tag.parse("'tagging' 'it's weirdness'")
0
+ assert_equal %w(tagging it's\ weirdness), Tag.parse('"tagging" "it\'s weirdness"')
0
   end
0
 
0
   def test_should_return_tag_array
0
@@ -22,12 +39,12 @@ class TagTest < Test::Unit::TestCase
0
       Tag.parse_to_tags 'ruby, a, b, rails, c'
0
     end
0
   end
0
-
0
+
0
   def test_tag_equality
0
     assert_equal tags(:ruby), 'ruby'
0
     assert_equal Tag.find_by_name('ruby'), tags(:ruby)
0
   end
0
-
0
+
0
   def test_should_select_tags_by_name
0
     assert_equal tags(:ruby), Tag[:ruby]
0
   end
...
24
25
26
27
 
28
29
30
...
63
64
65
66
 
67
68
69
...
24
25
26
 
27
28
29
30
...
63
64
65
 
66
67
68
69
0
@@ -24,7 +24,7 @@ context "Asset Tagging" do
0
     end
0
     assert_equal [], assets(:gif).reload.tags
0
   end
0
-
0
+
0
   specify "should change tags" do
0
     assert_difference Tagging, :count, 2 do
0
       assert_difference Tag, :count do
0
@@ -63,7 +63,7 @@ context "Article Tagging" do
0
     end
0
     assert_equal [], contents(:another).reload.tags
0
   end
0
-
0
+
0
   specify "should change tags" do
0
     assert_difference Tagging, :count, 2 do
0
       assert_difference Tag, :count do

Comments

    No one has commented yet.