blacklight_user_generated_content 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +9 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +29 -0
- data/app/controllers/comments_controller.rb +102 -0
- data/app/controllers/tags_controller.rb +73 -0
- data/app/controllers/user_generated_content.rb +4 -0
- data/app/models/tag.rb +3 -0
- data/app/models/tagging.rb +3 -0
- data/app/views/comments/_comment.html.erb +17 -0
- data/app/views/comments/_form.html.erb +9 -0
- data/app/views/comments/edit.html.erb +2 -0
- data/app/views/comments/index.html.erb +5 -0
- data/app/views/comments/new.html.erb +3 -0
- data/app/views/comments/show.html.erb +2 -0
- data/app/views/tags/index.html.erb +1 -0
- data/app/views/tags/new.html.erb +9 -0
- data/app/views/tags/show.html.erb +2 -0
- data/app/views/user_generated_content/_index_partials/_ugc.html.erb +17 -0
- data/app/views/user_generated_content/index.html.erb +32 -0
- data/config/routes.rb +5 -0
- data/lib/blacklight_user_generated_content/active_record_duck_type.rb +81 -0
- data/lib/blacklight_user_generated_content/comment.rb +4 -0
- data/lib/blacklight_user_generated_content/commentable.rb +8 -0
- data/lib/blacklight_user_generated_content/document.rb +8 -0
- data/lib/blacklight_user_generated_content/engine.rb +19 -0
- data/lib/blacklight_user_generated_content/findable.rb +13 -0
- data/lib/blacklight_user_generated_content/helper.rb +8 -0
- data/lib/blacklight_user_generated_content/route_sets.rb +16 -0
- data/lib/blacklight_user_generated_content/solr_helper/scope.rb +23 -0
- data/lib/blacklight_user_generated_content/solr_helper.rb +5 -0
- data/lib/blacklight_user_generated_content/taggable.rb +8 -0
- data/lib/blacklight_user_generated_content.rb +27 -0
- data/lib/generators/blacklight_user_generated_content/blacklight_user_generated_content_generator.rb +63 -0
- data/lib/generators/blacklight_user_generated_content/templates/alter_commentable_id_to_string.rb +9 -0
- data/lib/generators/blacklight_user_generated_content/templates/alter_taggable_id_to_string.rb +13 -0
- metadata +186 -0
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2011 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rubygems'
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rake'
|
10
|
+
require 'rake/rdoctask'
|
11
|
+
|
12
|
+
require 'rake/testtask'
|
13
|
+
|
14
|
+
Rake::TestTask.new(:test) do |t|
|
15
|
+
t.libs << 'lib'
|
16
|
+
t.libs << 'test'
|
17
|
+
t.pattern = 'test/**/*_test.rb'
|
18
|
+
t.verbose = false
|
19
|
+
end
|
20
|
+
|
21
|
+
task :default => :test
|
22
|
+
|
23
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
24
|
+
rdoc.rdoc_dir = 'rdoc'
|
25
|
+
rdoc.title = 'BlacklightUserGeneratedContent'
|
26
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
27
|
+
rdoc.rdoc_files.include('README.rdoc')
|
28
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
29
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
class CommentsController < ApplicationController
|
2
|
+
include Blacklight::SolrHelper
|
3
|
+
load_and_authorize_resource
|
4
|
+
|
5
|
+
rescue_from CanCan::AccessDenied do |exception|
|
6
|
+
redirect_to root_url, :alert => exception.message
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
# GET /comments
|
11
|
+
# GET /comments.xml
|
12
|
+
def index
|
13
|
+
if params[:catalog_id]
|
14
|
+
@response, @documents = get_solr_response_for_field_values("id",params[:catalog_id])
|
15
|
+
@document = @documents.first
|
16
|
+
end
|
17
|
+
|
18
|
+
@comments = @comments.where(:public => true) if params[:public]
|
19
|
+
@comments = @comments.where(:commentable_id => @document.id, :commentable_type => @document.class.to_s) if @document
|
20
|
+
@comments = @comments.where(:user_id => params[:user_id]) if params[:user_id]
|
21
|
+
|
22
|
+
respond_to do |format|
|
23
|
+
format.html # index.html.erb
|
24
|
+
format.xml { render :xml => @comments }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# GET /comments/1
|
29
|
+
# GET /comments/1.xml
|
30
|
+
def show
|
31
|
+
# @comment = Comment.find(params[:id])
|
32
|
+
|
33
|
+
respond_to do |format|
|
34
|
+
format.html # show.html.erb
|
35
|
+
format.xml { render :xml => @comment }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# GET /comments/new
|
40
|
+
# GET /comments/new.xml
|
41
|
+
def new
|
42
|
+
@response, @documents = get_solr_response_for_field_values("id",params[:catalog_id])
|
43
|
+
@document = @documents.first
|
44
|
+
|
45
|
+
@comment = Comment.new :commentable => @document
|
46
|
+
|
47
|
+
respond_to do |format|
|
48
|
+
format.html # new.html.erb
|
49
|
+
format.xml { render :xml => @comment }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# GET /comments/1/edit
|
54
|
+
def edit
|
55
|
+
# @comment = Comment.find(params[:id])
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
# POST /comments
|
60
|
+
# POST /comments.xml
|
61
|
+
def create
|
62
|
+
@comment = Comment.new(params[:comment])
|
63
|
+
@comment.user = current_user
|
64
|
+
respond_to do |format|
|
65
|
+
if @comment.save
|
66
|
+
format.html { redirect_to(@comment) }
|
67
|
+
format.xml { render :xml => @comment, :status => :created, :location => @comment }
|
68
|
+
else
|
69
|
+
format.html { render :action => "new" }
|
70
|
+
format.xml { render :xml => @comment.errors, :status => :unprocessable_entity }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# PUT /comments/1
|
76
|
+
# PUT /comments/1.xml
|
77
|
+
def update
|
78
|
+
# @comment = Comment.find(params[:id])
|
79
|
+
|
80
|
+
respond_to do |format|
|
81
|
+
if @comment.update_attributes(params[:comment])
|
82
|
+
format.html { redirect_to @comment }
|
83
|
+
format.xml { head :ok }
|
84
|
+
else
|
85
|
+
format.html { render :action => "edit" }
|
86
|
+
format.xml { render :xml => @comment.errors, :status => :unprocessable_entity }
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# DELETE /comments/1
|
92
|
+
# DELETE /comments/1.xml
|
93
|
+
def destroy
|
94
|
+
# @comment = Comment.find(params[:id])
|
95
|
+
@comment.destroy
|
96
|
+
|
97
|
+
respond_to do |format|
|
98
|
+
format.html { redirect_to @comment }
|
99
|
+
format.xml { head :ok }
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
class TagsController < ApplicationController
|
2
|
+
include Blacklight::SolrHelper
|
3
|
+
|
4
|
+
def index
|
5
|
+
@response, @documents = get_solr_response_for_field_values("id",params[:catalog_id])
|
6
|
+
@document = @documents.first
|
7
|
+
|
8
|
+
@tags = @document.owner_tag_list_on(nil, :tags)
|
9
|
+
|
10
|
+
respond_to do |format|
|
11
|
+
format.html
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def show
|
16
|
+
@response, @documents = get_solr_response_for_field_values("id",params[:catalog_id])
|
17
|
+
@document = @documents.first
|
18
|
+
|
19
|
+
@tags = @document.owner_tag_list_on(nil, :tags)
|
20
|
+
|
21
|
+
respond_to do |format|
|
22
|
+
format.html
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def new
|
27
|
+
@response, @documents = get_solr_response_for_field_values("id",params[:catalog_id])
|
28
|
+
@document = @documents.first
|
29
|
+
|
30
|
+
@tags = @document.owner_tag_list_on(nil, :tags)
|
31
|
+
|
32
|
+
respond_to do |format|
|
33
|
+
format.html
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def edit
|
38
|
+
@tag = ActsAsTaggableOn::Tag.find_by_name(params[:id])
|
39
|
+
|
40
|
+
respond_to do |format|
|
41
|
+
format.html
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def create
|
46
|
+
@response, @documents = get_solr_response_for_field_values("id",params[:catalog_id])
|
47
|
+
@document = @documents.first
|
48
|
+
|
49
|
+
#@document.tag_list << params[:tags].split(",").map(&:strip)
|
50
|
+
if current_user
|
51
|
+
current_user.tag(@document, :with => params[:tags], :on => 'tags')
|
52
|
+
else
|
53
|
+
User.new.tag(@document, :with => params[:tags], :on => 'tags')
|
54
|
+
end
|
55
|
+
@document.save rescue nil
|
56
|
+
|
57
|
+
respond_to do |format|
|
58
|
+
format.html { redirect_to new_catalog_tags_path(:catalog_id => @document.id) }
|
59
|
+
format.json { render :json => @document.tag_list }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def update
|
64
|
+
@response, @documents = get_solr_response_for_field_values("id",params[:catalog_id])
|
65
|
+
@document = @documents.first
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
def destroy
|
70
|
+
@tag = ActsAsTaggableOn::Tag.find_by_name(params[:id])
|
71
|
+
@tag.destroy
|
72
|
+
end
|
73
|
+
end
|
data/app/models/tag.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
<%= content_tag :li, :class => "comment comment-#{comment.id}" do %>
|
2
|
+
<strong><%= comment.title || nil %></strong>
|
3
|
+
<div class="byline">
|
4
|
+
<% if comment.user %>
|
5
|
+
By <%= comment.user.to_s %> at
|
6
|
+
<% end %>
|
7
|
+
<%= comment.created_at.strftime("%m/%d/%Y") %></div>
|
8
|
+
<div class="comment"><%= comment.comment %></div>
|
9
|
+
|
10
|
+
<% if current_user and comment.user == current_user %>
|
11
|
+
<div>
|
12
|
+
<%= link_to 'Edit', edit_comment_path(comment) %>
|
13
|
+
<%= link_to 'Destroy', comment, :confirm => 'Are you sure?', :method => :delete %>
|
14
|
+
</div>
|
15
|
+
</li>
|
16
|
+
<% end %>
|
17
|
+
<% end %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= @tags.join " " %>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<div id="new_tag" style="overflow: visible">
|
2
|
+
<h1>Add Tag</h1>
|
3
|
+
<%= form_for :document, :url => catalog_tags_path(:catalog_id => @document.id), :html => { :method => :post } do |f| %>
|
4
|
+
<%= label_tag :tags, 'Use "," to separate each tag.' %>
|
5
|
+
<%= text_field_tag :tags %>
|
6
|
+
<%= f.submit "Add Tag" %>
|
7
|
+
<% end %>
|
8
|
+
</div>
|
9
|
+
<%= @tags.join ", " %>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<div class="defList_container">
|
2
|
+
<div class="blacklight-tags">
|
3
|
+
<div class="label">My Tags</div>
|
4
|
+
<div class="value">
|
5
|
+
<%= document.owner_tag_list_on(current_user, :tags).join(", ") %>
|
6
|
+
</div>
|
7
|
+
</div>
|
8
|
+
<div class="blacklight-comments">
|
9
|
+
<div class="label">My Notes</div>
|
10
|
+
<div class="value">
|
11
|
+
<% document.comments.where(:user_id => current_user.id).each do |c| %>
|
12
|
+
<p><span style="display: inline-block; width: 90px"><%= c.created_at.strftime("%m/%d/%Y") %></span><%= truncate(c.comment, :length => 150) %> <%= link_to '[View]', catalog_path(document.id, :anchor=> "comment-#{c.id}") %> </p>
|
13
|
+
<% end %>
|
14
|
+
</div>
|
15
|
+
</div>
|
16
|
+
|
17
|
+
</div>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<% @page_title = application_name + ": My Notes" %>
|
2
|
+
|
3
|
+
<% extra_head_content << render_opensearch_response_metadata %>
|
4
|
+
|
5
|
+
<%= render :partial => 'did_you_mean' %>
|
6
|
+
|
7
|
+
<%= render 'constraints', :localized_params=>params %>
|
8
|
+
|
9
|
+
<h1>My Notes</h1>
|
10
|
+
|
11
|
+
<div class="search-results-header">
|
12
|
+
|
13
|
+
<div class="pageEntriesInfo">
|
14
|
+
<%= page_entries_info @response.docs, :entry_name=>'item' %>
|
15
|
+
<%=link_to "Start over ".html_safe, catalog_index_path, :id=>"startOverLink" %>
|
16
|
+
</div>
|
17
|
+
|
18
|
+
<%= render 'sort_and_per_page' %>
|
19
|
+
|
20
|
+
<%= render 'results_pagination' %>
|
21
|
+
</div>
|
22
|
+
|
23
|
+
|
24
|
+
<%= render_document_list_partial %>
|
25
|
+
|
26
|
+
<% sidebar_items << capture do %>
|
27
|
+
<%= render :partial=>'facets' %>
|
28
|
+
<% end %>
|
29
|
+
|
30
|
+
<%= render 'results_pagination' %>
|
31
|
+
|
32
|
+
|
data/config/routes.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
module BlacklightUserGeneratedContent::ActiveRecordDuckType
|
2
|
+
|
3
|
+
def self.included base
|
4
|
+
# ActiveModel/ActiveRecord stuff
|
5
|
+
base.send :include, ActiveModel::Observing
|
6
|
+
base.send :extend, ActiveModel::Naming
|
7
|
+
base.send :extend, ActiveModel::Callbacks
|
8
|
+
base.send :extend, ActiveModel::Observing
|
9
|
+
base.send :define_model_callbacks, :destroy, :save
|
10
|
+
base.send :include, ActiveRecord::Associations
|
11
|
+
base.send :include, ActiveRecord::Reflection
|
12
|
+
|
13
|
+
# Mock ActiveRecord methods only to the extent required
|
14
|
+
base.send :extend, ActiveRecordClassMethods
|
15
|
+
base.send :include, ActiveRecordInstanceMethods
|
16
|
+
end
|
17
|
+
|
18
|
+
# ActiveRecord mock methods
|
19
|
+
module ActiveRecordClassMethods
|
20
|
+
def base_class
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
24
|
+
def primary_key
|
25
|
+
:id
|
26
|
+
end
|
27
|
+
|
28
|
+
def compute_type(type_name)
|
29
|
+
ActiveSupport::Dependencies.constantize(type_name)
|
30
|
+
end
|
31
|
+
|
32
|
+
def quote_value *args
|
33
|
+
ActiveRecord::Base.quote_value *args
|
34
|
+
end
|
35
|
+
|
36
|
+
def table_exists?
|
37
|
+
false
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
# ActiveRecord instance mock methods
|
43
|
+
module ActiveRecordInstanceMethods
|
44
|
+
def quoted_id
|
45
|
+
ActiveRecord::Base.quote_value id
|
46
|
+
end
|
47
|
+
|
48
|
+
def interpolate_sanitized_sql *args
|
49
|
+
active_record_model.send :interpolate_sanitized_sql, *args
|
50
|
+
end
|
51
|
+
def interpolate_and_sanitize_sql *args
|
52
|
+
# XXX interpolate_and_sanitize_sql is an ActiveRecord::Base method,
|
53
|
+
# XXX rather than create a mock object or something, just use a model we know a priori exists
|
54
|
+
active_record_model.send :interpolate_and_sanitize_sql, *args
|
55
|
+
end
|
56
|
+
|
57
|
+
def new_record?
|
58
|
+
false
|
59
|
+
end
|
60
|
+
|
61
|
+
def destroyed?
|
62
|
+
false
|
63
|
+
end
|
64
|
+
|
65
|
+
def persisted?
|
66
|
+
false
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
def active_record_model
|
71
|
+
ActsAsTaggableOn::Tag.new
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def save
|
76
|
+
_run_save_callbacks do
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
@@ -0,0 +1,8 @@
|
|
1
|
+
module BlacklightUserGeneratedContent::Commentable
|
2
|
+
|
3
|
+
# `base` is likely /NOT/ a type of ActiveRecord::Base, the acts_as_commentable plugin is not automatically included
|
4
|
+
def self.included base
|
5
|
+
base.send :include, Juixe::Acts::Commentable
|
6
|
+
base.send :acts_as_commentable
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'blacklight'
|
2
|
+
require 'blacklight_user_generated_content'
|
3
|
+
|
4
|
+
module BlacklightUserGeneratedContent
|
5
|
+
class Engine < Rails::Engine
|
6
|
+
initializer 'blacklight_user_generated_content.init', :after => 'blacklight.init' do |app|
|
7
|
+
|
8
|
+
end
|
9
|
+
|
10
|
+
config.to_prepare do
|
11
|
+
# BlacklightUserGeneratedContent.inject!
|
12
|
+
|
13
|
+
unless BlacklightUserGeneratedContent.omit_inject[:routes]
|
14
|
+
Blacklight::Routes.send(:include, BlacklightUserGeneratedContent::RouteSets)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module BlacklightUserGeneratedContent
|
2
|
+
module Findable
|
3
|
+
# Override RSolr finder method to mock ActiveRecord#find
|
4
|
+
# Provide a mock method for #find
|
5
|
+
# XXX this seems slightly dangerous as is, but seems to work well enough
|
6
|
+
def find *args
|
7
|
+
if args.first.is_a? String
|
8
|
+
return super(:qt => :document, :id => args.first).first
|
9
|
+
end
|
10
|
+
super(*args)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module BlacklightUserGeneratedContent
|
2
|
+
module RouteSets
|
3
|
+
protected
|
4
|
+
def catalog
|
5
|
+
add_routes do |options|
|
6
|
+
resources :catalog, :only => [:index, :show, :update] do
|
7
|
+
resources :comments
|
8
|
+
resource :tags
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module BlacklightUserGeneratedContent
|
2
|
+
module SolrHelper
|
3
|
+
module Scope
|
4
|
+
def self.included(some_class)
|
5
|
+
some_class.solr_search_params_logic << :restrict_to_user_generated_content_scope
|
6
|
+
end
|
7
|
+
|
8
|
+
def restrict_to_user_generated_content_scope solr_parameters, user_parameters
|
9
|
+
solr_parameters[:fq] ||= []
|
10
|
+
if current_user
|
11
|
+
if current_user.has_role? :admin and user_params[:all]
|
12
|
+
solr_parameters[:fq] << "comments_ids_i:[* TO *]"
|
13
|
+
else
|
14
|
+
solr_parameters[:fq] << "comments_user_ids_i:#{current_user.id} OR tags_user_ids_i:#{current_user.id}"
|
15
|
+
end
|
16
|
+
else
|
17
|
+
solr_parameters[:fq] << "comments_public_b:true"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'acts-as-taggable-on'
|
2
|
+
module BlacklightUserGeneratedContent::Taggable
|
3
|
+
# `base` is likely /NOT/ a type of ActiveRecord::Base, the acts_as_taggable_on plugin is not automatically included
|
4
|
+
def self.included base
|
5
|
+
base.send :extend, ActsAsTaggableOn::Taggable
|
6
|
+
base.send :acts_as_taggable_on, :tags
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'cancan'
|
2
|
+
require 'acts_as_commentable'
|
3
|
+
require 'acts-as-taggable-on'
|
4
|
+
|
5
|
+
module BlacklightUserGeneratedContent
|
6
|
+
autoload :ActiveRecordDuckType, 'blacklight_user_generated_content/active_record_duck_type'
|
7
|
+
autoload :Findable, 'blacklight_user_generated_content/findable'
|
8
|
+
autoload :Document, 'blacklight_user_generated_content/document'
|
9
|
+
autoload :SolrHelper, 'blacklight_user_generated_content/solr_helper'
|
10
|
+
autoload :Taggable, 'blacklight_user_generated_content/taggable'
|
11
|
+
autoload :Commentable, 'blacklight_user_generated_content/commentable'
|
12
|
+
autoload :Comment, 'blacklight_user_generated_content/comment'
|
13
|
+
autoload :RouteSets, 'blacklight_user_generated_content/route_sets'
|
14
|
+
|
15
|
+
require 'blacklight_user_generated_content/engine' if defined?(Rails)
|
16
|
+
|
17
|
+
@omit_inject = {}
|
18
|
+
|
19
|
+
def self.omit_inject=(value)
|
20
|
+
value = Hash.new(true) if value == true
|
21
|
+
@omit_inject = value
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.omit_inject ; @omit_inject ; end
|
25
|
+
|
26
|
+
|
27
|
+
end
|
data/lib/generators/blacklight_user_generated_content/blacklight_user_generated_content_generator.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/base'
|
3
|
+
require 'rails/generators/migration'
|
4
|
+
|
5
|
+
class BlacklightUserGeneratedContentGenerator < Rails::Generators::Base
|
6
|
+
include Rails::Generators::Migration
|
7
|
+
source_root File.expand_path('../templates', __FILE__)
|
8
|
+
|
9
|
+
# Implement the required interface for Rails::Generators::Migration.
|
10
|
+
# taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
|
11
|
+
def self.next_migration_number(dirname)
|
12
|
+
if ActiveRecord::Base.timestamped_migrations
|
13
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
14
|
+
else
|
15
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
desc """
|
20
|
+
"""
|
21
|
+
def generate_cancan_ability
|
22
|
+
generate "cancan:ability"
|
23
|
+
end
|
24
|
+
|
25
|
+
def inject_comments_roles
|
26
|
+
inject_into_file "app/models/ability.rb", :after => "def initialize(user)" do
|
27
|
+
<<-EOF
|
28
|
+
|
29
|
+
user ||= User.new
|
30
|
+
|
31
|
+
can :read, Comment
|
32
|
+
can :create, Comment
|
33
|
+
can :manage, Comment, :user_id => user.id
|
34
|
+
EOF
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def generate_acts_as_taggable_migrations
|
39
|
+
generate "acts_as_taggable_on:migration"
|
40
|
+
end
|
41
|
+
|
42
|
+
def update_taggable_id_to_string_migration
|
43
|
+
migration_template 'alter_taggable_id_to_string.rb', 'db/migrate/alter_taggable_id_to_string.rb'
|
44
|
+
end
|
45
|
+
|
46
|
+
def generate_acts_as_commentable_migrations
|
47
|
+
generate "comment"
|
48
|
+
end
|
49
|
+
|
50
|
+
def add_comment_mixin
|
51
|
+
inject_into_file "app/models/comment.rb", :after => "include ActsAsCommentable::Comment" do
|
52
|
+
"\ninclude BlacklightUserGeneratedContent::Comment"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def add_document_mixin
|
57
|
+
inject_into_file "app/models/solr_document.rb", :after => "include Blacklight::Solr::Document" do
|
58
|
+
"\ninclude BlacklightUserGeneratedContent::Document\n" +
|
59
|
+
"include BlacklightUserGeneratedContent::Commentable\n" +
|
60
|
+
"include BlacklightUserGeneratedContent::Taggable\n"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/generators/blacklight_user_generated_content/templates/alter_taggable_id_to_string.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
class AlterTaggableIdToString < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
remove_index :taggings, [:taggable_id, :taggable_type, :context]
|
4
|
+
change_column :taggings, :taggable_id, :string
|
5
|
+
add_index :taggings, [:taggable_id, :taggable_type, :context]
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.down
|
9
|
+
remove_index :taggings, [:taggable_id, :taggable_type, :context]
|
10
|
+
change_column :taggings, :taggable_id, :integer
|
11
|
+
add_index :taggings, [:taggable_id, :taggable_type, :context]
|
12
|
+
end
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,186 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: blacklight_user_generated_content
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors: []
|
13
|
+
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-06-05 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rails
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 7
|
30
|
+
segments:
|
31
|
+
- 3
|
32
|
+
- 0
|
33
|
+
version: "3.0"
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: blacklight
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
version: "0"
|
48
|
+
type: :runtime
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: rsolr-ext
|
52
|
+
prerelease: false
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 3
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
version: "0"
|
62
|
+
type: :runtime
|
63
|
+
version_requirements: *id003
|
64
|
+
- !ruby/object:Gem::Dependency
|
65
|
+
name: cancan
|
66
|
+
prerelease: false
|
67
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
hash: 3
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
version: "0"
|
76
|
+
type: :runtime
|
77
|
+
version_requirements: *id004
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: acts-as-taggable-on
|
80
|
+
prerelease: false
|
81
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
hash: 3
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
version: "0"
|
90
|
+
type: :runtime
|
91
|
+
version_requirements: *id005
|
92
|
+
- !ruby/object:Gem::Dependency
|
93
|
+
name: acts_as_commentable
|
94
|
+
prerelease: false
|
95
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
hash: 3
|
101
|
+
segments:
|
102
|
+
- 0
|
103
|
+
version: "0"
|
104
|
+
type: :runtime
|
105
|
+
version_requirements: *id006
|
106
|
+
description: Insert BlacklightUserGeneratedContent description.
|
107
|
+
email:
|
108
|
+
executables: []
|
109
|
+
|
110
|
+
extensions: []
|
111
|
+
|
112
|
+
extra_rdoc_files: []
|
113
|
+
|
114
|
+
files:
|
115
|
+
- app/controllers/comments_controller.rb
|
116
|
+
- app/controllers/tags_controller.rb
|
117
|
+
- app/controllers/user_generated_content.rb
|
118
|
+
- app/models/tag.rb
|
119
|
+
- app/models/tagging.rb
|
120
|
+
- app/views/comments/_comment.html.erb
|
121
|
+
- app/views/comments/_form.html.erb
|
122
|
+
- app/views/comments/edit.html.erb
|
123
|
+
- app/views/comments/index.html.erb
|
124
|
+
- app/views/comments/new.html.erb
|
125
|
+
- app/views/comments/show.html.erb
|
126
|
+
- app/views/tags/index.html.erb
|
127
|
+
- app/views/tags/new.html.erb
|
128
|
+
- app/views/tags/show.html.erb
|
129
|
+
- app/views/user_generated_content/_index_partials/_ugc.html.erb
|
130
|
+
- app/views/user_generated_content/index.html.erb
|
131
|
+
- lib/blacklight_user_generated_content/active_record_duck_type.rb
|
132
|
+
- lib/blacklight_user_generated_content/comment.rb
|
133
|
+
- lib/blacklight_user_generated_content/commentable.rb
|
134
|
+
- lib/blacklight_user_generated_content/document.rb
|
135
|
+
- lib/blacklight_user_generated_content/engine.rb
|
136
|
+
- lib/blacklight_user_generated_content/findable.rb
|
137
|
+
- lib/blacklight_user_generated_content/helper.rb
|
138
|
+
- lib/blacklight_user_generated_content/route_sets.rb
|
139
|
+
- lib/blacklight_user_generated_content/solr_helper/scope.rb
|
140
|
+
- lib/blacklight_user_generated_content/solr_helper.rb
|
141
|
+
- lib/blacklight_user_generated_content/taggable.rb
|
142
|
+
- lib/blacklight_user_generated_content.rb
|
143
|
+
- lib/generators/blacklight_user_generated_content/blacklight_user_generated_content_generator.rb
|
144
|
+
- lib/generators/blacklight_user_generated_content/templates/alter_commentable_id_to_string.rb
|
145
|
+
- lib/generators/blacklight_user_generated_content/templates/alter_taggable_id_to_string.rb
|
146
|
+
- config/routes.rb
|
147
|
+
- MIT-LICENSE
|
148
|
+
- Rakefile
|
149
|
+
- Gemfile
|
150
|
+
- README.rdoc
|
151
|
+
has_rdoc: true
|
152
|
+
homepage:
|
153
|
+
licenses: []
|
154
|
+
|
155
|
+
post_install_message:
|
156
|
+
rdoc_options: []
|
157
|
+
|
158
|
+
require_paths:
|
159
|
+
- lib
|
160
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
161
|
+
none: false
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
hash: 3
|
166
|
+
segments:
|
167
|
+
- 0
|
168
|
+
version: "0"
|
169
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
170
|
+
none: false
|
171
|
+
requirements:
|
172
|
+
- - ">="
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
hash: 3
|
175
|
+
segments:
|
176
|
+
- 0
|
177
|
+
version: "0"
|
178
|
+
requirements: []
|
179
|
+
|
180
|
+
rubyforge_project:
|
181
|
+
rubygems_version: 1.5.3
|
182
|
+
signing_key:
|
183
|
+
specification_version: 3
|
184
|
+
summary: Insert BlacklightUserGeneratedContent summary.
|
185
|
+
test_files: []
|
186
|
+
|