tagcloud 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/tagcloud.rb +104 -0
- metadata +77 -0
data/lib/tagcloud.rb
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# file: tagcloud.rb
|
4
|
+
|
5
|
+
require 'dynarex'
|
6
|
+
require 'polyrex'
|
7
|
+
|
8
|
+
class TagCloud
|
9
|
+
|
10
|
+
def initialize(opt)
|
11
|
+
opts = {uri: '', tags: [], public_path: '/tags'}.merge(opt)
|
12
|
+
uri, tags, public_path = [:uri, :tags, :public_path].map{|x| opts[x]}
|
13
|
+
|
14
|
+
main(uri, tags, 'tags.xml')
|
15
|
+
index(public_path, tags, 'index.xml')
|
16
|
+
|
17
|
+
# add it to rows --> [tag]_rows.xml
|
18
|
+
rows(tags, uri)
|
19
|
+
|
20
|
+
# add it to [tag] -> [tag].xml
|
21
|
+
tag(public_path, tags)
|
22
|
+
end
|
23
|
+
|
24
|
+
def main(uri, tags=[], filename='tags.xml')
|
25
|
+
|
26
|
+
polyrex = Polyrex.new('entries/entry[tag]/urls[url]')
|
27
|
+
|
28
|
+
tags.each do |tag|
|
29
|
+
polyrex.create.entry(tag: tag) {|create| create.urls(url: uri) }
|
30
|
+
end
|
31
|
+
|
32
|
+
polyrex.save filename, pretty: true
|
33
|
+
end
|
34
|
+
|
35
|
+
def index(public_path, tags=[], filename='index.xml')
|
36
|
+
|
37
|
+
if File.exists? filename then
|
38
|
+
dynarex = Dynarex.new(filename)
|
39
|
+
else
|
40
|
+
dynarex = Dynarex.new('tags/entry(tag,url)')
|
41
|
+
end
|
42
|
+
|
43
|
+
tags.each do |tag|
|
44
|
+
dynarex.create tag: tag, url: "%s/%s.html" % [public_path, tag]
|
45
|
+
end
|
46
|
+
|
47
|
+
dynarex.save filename, pretty: true
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
def rows(tags=[], url)
|
52
|
+
|
53
|
+
tags.each do |tag|
|
54
|
+
|
55
|
+
filename = "%s_rows.xml" % tag
|
56
|
+
|
57
|
+
if File.exists? filename then
|
58
|
+
|
59
|
+
dynarex = Dynarex.new()
|
60
|
+
|
61
|
+
else
|
62
|
+
|
63
|
+
dynarex = Dynarex.new('entries/entry(url)')
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
dynarex.create url: url
|
69
|
+
|
70
|
+
dynarex.save filename, pretty: true
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
def tag(public_path, tags=[])
|
78
|
+
|
79
|
+
tags.length.times do |tag|
|
80
|
+
|
81
|
+
tags.rotate!
|
82
|
+
main_tag = tags.first
|
83
|
+
filename = "%s.xml" % main_tag
|
84
|
+
|
85
|
+
if File.exists? filename then
|
86
|
+
|
87
|
+
dynarex = Dynarex.new(filename)
|
88
|
+
|
89
|
+
else
|
90
|
+
|
91
|
+
dynarex = Dynarex.new('entries[tag]/entry(tag, url)')
|
92
|
+
end
|
93
|
+
|
94
|
+
dynarex.summary['tag'] = main_tag
|
95
|
+
tags[1..-1].each do |tag|
|
96
|
+
dynarex.create tag: tag, url: "%s/%s.html" % [public_path, tag]
|
97
|
+
end
|
98
|
+
|
99
|
+
dynarex.save filename, pretty: true
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tagcloud
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- James Robertson
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2012-04-05 00:00:00 +01:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: polyrex
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "0"
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: dynarex
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: "0"
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id002
|
38
|
+
description:
|
39
|
+
email:
|
40
|
+
executables: []
|
41
|
+
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files: []
|
45
|
+
|
46
|
+
files:
|
47
|
+
- lib/tagcloud.rb
|
48
|
+
has_rdoc: true
|
49
|
+
homepage:
|
50
|
+
licenses: []
|
51
|
+
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "0"
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
requirements: []
|
70
|
+
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.5.2
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: tagcloud
|
76
|
+
test_files: []
|
77
|
+
|