radiant-taggable-extension 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +125 -0
- data/Rakefile +136 -0
- data/VERSION +1 -0
- data/app/controllers/admin/taggings_controller.rb +8 -0
- data/app/controllers/admin/tags_controller.rb +17 -0
- data/app/models/tag.rb +200 -0
- data/app/models/tagging.rb +50 -0
- data/app/views/admin/pages/_edit_title.html.haml +28 -0
- data/app/views/admin/tags/_form.html.haml +23 -0
- data/app/views/admin/tags/_search_results.html.haml +10 -0
- data/app/views/admin/tags/cloud.html.haml +17 -0
- data/app/views/admin/tags/edit.html.haml +14 -0
- data/app/views/admin/tags/index.html.haml +53 -0
- data/app/views/admin/tags/new.html.haml +13 -0
- data/app/views/admin/tags/show.html.haml +32 -0
- data/config/routes.rb +6 -0
- data/db/migrate/001_create_tags.rb +26 -0
- data/db/migrate/002_import_keywords.rb +11 -0
- data/lib/taggable_admin_page_controller.rb +18 -0
- data/lib/taggable_admin_ui.rb +41 -0
- data/lib/taggable_model.rb +128 -0
- data/lib/taggable_page.rb +48 -0
- data/lib/taggable_tags.rb +456 -0
- data/lib/tasks/taggable_extension_tasks.rake +55 -0
- data/pkg/radiant-taggable-extension-1.2.0.gem +0 -0
- data/public/images/admin/new-tag.png +0 -0
- data/public/images/admin/tag.png +0 -0
- data/public/images/furniture/detag.png +0 -0
- data/public/stylesheets/admin/tags.css +20 -0
- data/public/stylesheets/sass/tagcloud.sass +29 -0
- data/radiant-taggable-extension.gemspec +84 -0
- data/spec/datasets/tag_sites_dataset.rb +9 -0
- data/spec/datasets/tags_dataset.rb +43 -0
- data/spec/lib/taggable_page_spec.rb +93 -0
- data/spec/models/tag_spec.rb +39 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +36 -0
- data/taggable_extension.rb +36 -0
- metadata +123 -0
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'digest/sha1'
|
2
|
+
|
3
|
+
class TagsDataset < Dataset::Base
|
4
|
+
datasets = [:pages]
|
5
|
+
datasets << :tag_sites if defined? Site
|
6
|
+
uses *datasets
|
7
|
+
|
8
|
+
def load
|
9
|
+
create_tag "colourless"
|
10
|
+
create_tag "green"
|
11
|
+
create_tag "ideas"
|
12
|
+
create_tag "sleep"
|
13
|
+
create_tag "furiously"
|
14
|
+
|
15
|
+
apply_tag :colourless, pages(:first)
|
16
|
+
apply_tag :ideas, pages(:first), pages(:another), pages(:grandchild)
|
17
|
+
apply_tag :sleep, pages(:first)
|
18
|
+
apply_tag :furiously, pages(:first)
|
19
|
+
end
|
20
|
+
|
21
|
+
helpers do
|
22
|
+
def create_tag(title, attributes={})
|
23
|
+
attributes = tag_attributes(attributes.update(:title => title))
|
24
|
+
tag = create_model Tag, title.symbolize, attributes
|
25
|
+
end
|
26
|
+
|
27
|
+
def tag_attributes(attributes={})
|
28
|
+
title = attributes[:name] || "Tag"
|
29
|
+
attributes = {
|
30
|
+
:title => title
|
31
|
+
}.merge(attributes)
|
32
|
+
attributes[:site] = sites(:test) if defined? Site
|
33
|
+
attributes
|
34
|
+
end
|
35
|
+
|
36
|
+
def apply_tag(tag, *items)
|
37
|
+
tag = tag.is_a?(Tag) ? tag : tags(tag)
|
38
|
+
items.each { |i| i.attached_tags << tag }
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Page do
|
4
|
+
dataset :tags
|
5
|
+
|
6
|
+
it "should report itself taggable" do
|
7
|
+
Page.is_taggable?.should be_true
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should return a list of pages form tag list" do
|
11
|
+
Page.tagged_with("colourless").should == [pages(:first)]
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should return a weighted list of tags from page list" do
|
15
|
+
Page.tags_for_cloud_from([pages(:first)]).should == Tag.from_list("colourless, ideas, sleep, furiously")
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "instantiated with tags" do
|
19
|
+
before do
|
20
|
+
@page = pages(:first)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should return tag list" do
|
24
|
+
@page.attached_tags.should == Tag.from_list("colourless, ideas, sleep, furiously")
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should add and remove tags" do
|
28
|
+
@page.add_tag("howdy")
|
29
|
+
@page.attached_tags.should == Tag.from_list("colourless, ideas, sleep, furiously, howdy")
|
30
|
+
@page.remove_tag("howdy")
|
31
|
+
@page.attached_tags.should == Tag.from_list("colourless, ideas, sleep, furiously")
|
32
|
+
Tag.for('Howdy').pages.include?(@page).should be_false
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should return tags string as keywords" do
|
36
|
+
@page.keywords.should == "colourless, ideas, sleep, furiously"
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should accept tags string as keywords=" do
|
40
|
+
@page.keywords = "Lovable, Rogue"
|
41
|
+
@page.attached_tags.should == [Tag.for("Lovable"), Tag.for("Rogue")]
|
42
|
+
@page.keywords.should == "Lovable, Rogue"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should return keywords string to keywords_before_type_cast (for form helpers)" do
|
46
|
+
@page.keywords_before_type_cast.should == "colourless, ideas, sleep, furiously"
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should return a list of related pages" do
|
50
|
+
@page.related.include?(pages(:another)).should be_true
|
51
|
+
@page.related.include?(pages(:child)).should be_false
|
52
|
+
@page.related.include?(pages(:grandchild)).should be_true
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should have related_pages methods" do
|
56
|
+
@page.respond_to?(:related_pages).should be_true
|
57
|
+
@page.respond_to?(:closely_related_pages).should be_true
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "when cloud-building" do
|
63
|
+
describe "across the whole collection" do
|
64
|
+
before do
|
65
|
+
@tags = Tag.sized(Tag.most_popular(10))
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should weight the tags" do
|
69
|
+
tag = @tags.select{|t| t.title = "Ideas"}.first
|
70
|
+
tag.cloud_size.should_not be_nil
|
71
|
+
tag.use_count.should == "3" # counting every use
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
before do
|
76
|
+
@page = pages(:parent)
|
77
|
+
@tags = @page.tags_for_cloud
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should gather its descendants" do
|
81
|
+
@page.with_children.length.should == 6
|
82
|
+
@page.with_children.include?(pages(:child_2)).should be_true
|
83
|
+
@page.with_children.include?(pages(:great_grandchild)).should be_true
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should return a weighted list of tags attached to itself and descendants" do
|
87
|
+
@tags.first.should == tags(:ideas)
|
88
|
+
@tags.first.cloud_size.should_not be_nil
|
89
|
+
@tags.first.use_count.should == "1" # counting only within this family tree
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Tag do
|
4
|
+
dataset :tags
|
5
|
+
|
6
|
+
it "should reuse an existing tag if possible" do
|
7
|
+
tag = Tag.for('colourless')
|
8
|
+
tag.should == tags(:colourless)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should create a tag where none exists" do
|
12
|
+
tag = Tag.for('calumny')
|
13
|
+
tag.should be_valid
|
14
|
+
tag.new_record?.should be_false
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should find_or_create tags from a list" do
|
18
|
+
tags = Tag.from_list('colourless,ideas,lifebelt')
|
19
|
+
tags[0].should == tags(:colourless)
|
20
|
+
tags[1].should == tags(:ideas)
|
21
|
+
tags[2].created_at.should be_close((Time.now).utc, 10.seconds)
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "instantiated" do
|
25
|
+
before do
|
26
|
+
@tag = tags(:sleep)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should have retrieval methods for taggable models" do
|
30
|
+
@tag.respond_to?(:page_taggings).should be_true
|
31
|
+
@tag.respond_to?(:pages).should be_true
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should return its list of pages" do
|
35
|
+
@tag.pages.should == [pages(:first)]
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
unless defined? RADIANT_ROOT
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
case
|
4
|
+
when ENV["RADIANT_ENV_FILE"]
|
5
|
+
require ENV["RADIANT_ENV_FILE"]
|
6
|
+
when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
|
7
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../../")}/config/environment"
|
8
|
+
else
|
9
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../")}/config/environment"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
require "#{RADIANT_ROOT}/spec/spec_helper"
|
13
|
+
|
14
|
+
Dataset::Resolver.default << (File.dirname(__FILE__) + "/datasets")
|
15
|
+
|
16
|
+
if File.directory?(File.dirname(__FILE__) + "/matchers")
|
17
|
+
Dir[File.dirname(__FILE__) + "/matchers/*.rb"].each {|file| require file }
|
18
|
+
end
|
19
|
+
|
20
|
+
Spec::Runner.configure do |config|
|
21
|
+
# config.use_transactional_fixtures = true
|
22
|
+
# config.use_instantiated_fixtures = false
|
23
|
+
# config.fixture_path = RAILS_ROOT + '/spec/fixtures'
|
24
|
+
|
25
|
+
# You can declare fixtures for each behaviour like this:
|
26
|
+
# describe "...." do
|
27
|
+
# fixtures :table_a, :table_b
|
28
|
+
#
|
29
|
+
# Alternatively, if you prefer to declare them only once, you can
|
30
|
+
# do so here, like so ...
|
31
|
+
#
|
32
|
+
# config.global_fixtures = :table_a, :table_b
|
33
|
+
#
|
34
|
+
# If you declare global fixtures, be aware that they will be declared
|
35
|
+
# for all of your examples, even those that don't use them.
|
36
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class TaggableExtension < Radiant::Extension
|
2
|
+
version "1.2.0"
|
3
|
+
description "General purpose tagging and retrieval extension: more versatile but less focused than the tags extension"
|
4
|
+
url "http://github.com/spanner/radiant-taggable-extension"
|
5
|
+
|
6
|
+
def activate
|
7
|
+
ActiveRecord::Base.send :include, TaggableModel # provide is_taggable for everything but don't call it for anything
|
8
|
+
Page.send :is_taggable # make pages taggable
|
9
|
+
Page.send :include, TaggablePage # then fake the keywords column and add some inheritance
|
10
|
+
Page.send :include, TaggableTags # and the basic radius tags for showing page tags and tag pages
|
11
|
+
Admin::PagesController.send :include, TaggableAdminPageController # tweak the admin interface to make page tags more prominent
|
12
|
+
UserActionObserver.instance.send :add_observer!, Tag # tags get creator-stamped
|
13
|
+
|
14
|
+
unless defined? admin.tag
|
15
|
+
Radiant::AdminUI.send :include, TaggableAdminUI
|
16
|
+
admin.tag = Radiant::AdminUI.load_default_tag_regions
|
17
|
+
end
|
18
|
+
|
19
|
+
if respond_to?(:tab)
|
20
|
+
tab("Content") do
|
21
|
+
add_item("Tags", "/admin/tags")
|
22
|
+
end
|
23
|
+
else
|
24
|
+
admin.tabs.add "Tags", "/admin/tags", :after => "Layouts", :visibility => [:all]
|
25
|
+
if admin.tabs['Tags'].respond_to?(:add_link)
|
26
|
+
admin.tabs['Tags'].add_link('tag list', '/admin/tags')
|
27
|
+
admin.tabs['Tags'].add_link('tag cloud', '/admin/tags/cloud')
|
28
|
+
admin.tabs['Tags'].add_link('new tag', '/admin/tags/new')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def deactivate
|
34
|
+
admin.tabs.remove "Tags" unless respond_to?(:tab)
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: radiant-taggable-extension
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 31
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 1.2.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- spanner
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-09-10 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: radiant
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 59
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 9
|
33
|
+
- 0
|
34
|
+
version: 0.9.0
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
description: "General purpose tagging extension: more versatile but less focused than the tags extension"
|
38
|
+
email: will@spanner.org
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files:
|
44
|
+
- README.md
|
45
|
+
files:
|
46
|
+
- README.md
|
47
|
+
- Rakefile
|
48
|
+
- VERSION
|
49
|
+
- app/controllers/admin/taggings_controller.rb
|
50
|
+
- app/controllers/admin/tags_controller.rb
|
51
|
+
- app/models/tag.rb
|
52
|
+
- app/models/tagging.rb
|
53
|
+
- app/views/admin/pages/_edit_title.html.haml
|
54
|
+
- app/views/admin/tags/_form.html.haml
|
55
|
+
- app/views/admin/tags/_search_results.html.haml
|
56
|
+
- app/views/admin/tags/cloud.html.haml
|
57
|
+
- app/views/admin/tags/edit.html.haml
|
58
|
+
- app/views/admin/tags/index.html.haml
|
59
|
+
- app/views/admin/tags/new.html.haml
|
60
|
+
- app/views/admin/tags/show.html.haml
|
61
|
+
- config/routes.rb
|
62
|
+
- db/migrate/001_create_tags.rb
|
63
|
+
- db/migrate/002_import_keywords.rb
|
64
|
+
- lib/taggable_admin_page_controller.rb
|
65
|
+
- lib/taggable_admin_ui.rb
|
66
|
+
- lib/taggable_model.rb
|
67
|
+
- lib/taggable_page.rb
|
68
|
+
- lib/taggable_tags.rb
|
69
|
+
- lib/tasks/taggable_extension_tasks.rake
|
70
|
+
- pkg/radiant-taggable-extension-1.2.0.gem
|
71
|
+
- public/images/admin/new-tag.png
|
72
|
+
- public/images/admin/tag.png
|
73
|
+
- public/images/furniture/detag.png
|
74
|
+
- public/stylesheets/admin/tags.css
|
75
|
+
- public/stylesheets/sass/tagcloud.sass
|
76
|
+
- radiant-taggable-extension.gemspec
|
77
|
+
- spec/datasets/tag_sites_dataset.rb
|
78
|
+
- spec/datasets/tags_dataset.rb
|
79
|
+
- spec/lib/taggable_page_spec.rb
|
80
|
+
- spec/models/tag_spec.rb
|
81
|
+
- spec/spec.opts
|
82
|
+
- spec/spec_helper.rb
|
83
|
+
- taggable_extension.rb
|
84
|
+
has_rdoc: true
|
85
|
+
homepage: http://github.com/spanner/radiant-taggable-extension
|
86
|
+
licenses: []
|
87
|
+
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options:
|
90
|
+
- --charset=UTF-8
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
hash: 3
|
99
|
+
segments:
|
100
|
+
- 0
|
101
|
+
version: "0"
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
hash: 3
|
108
|
+
segments:
|
109
|
+
- 0
|
110
|
+
version: "0"
|
111
|
+
requirements: []
|
112
|
+
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 1.3.7
|
115
|
+
signing_key:
|
116
|
+
specification_version: 3
|
117
|
+
summary: Taggable Extension for Radiant CMS
|
118
|
+
test_files:
|
119
|
+
- spec/datasets/tag_sites_dataset.rb
|
120
|
+
- spec/datasets/tags_dataset.rb
|
121
|
+
- spec/lib/taggable_page_spec.rb
|
122
|
+
- spec/models/tag_spec.rb
|
123
|
+
- spec/spec_helper.rb
|