tagliatelle 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +29 -0
- data/.rubocop.yml +17 -0
- data/Gemfile +12 -0
- data/MIT-LICENSE +20 -0
- data/README.md +73 -0
- data/Rakefile +34 -0
- data/db/migrate/1_create_tags_and_taggings.rb +16 -0
- data/lib/generators/tagliatelle/install_generator.rb +29 -0
- data/lib/tagliatelle.rb +9 -0
- data/lib/tagliatelle/tag.rb +15 -0
- data/lib/tagliatelle/taggable.rb +29 -0
- data/lib/tagliatelle/tagging.rb +12 -0
- data/lib/tagliatelle/version.rb +3 -0
- data/lib/tasks/tagliatelle_tasks.rake +4 -0
- data/tagliatelle.gemspec +24 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/images/.keep +0 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/controllers/concerns/.keep +0 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/mailers/.keep +0 -0
- data/test/dummy/app/models/.keep +0 -0
- data/test/dummy/app/models/concerns/.keep +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +29 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +26 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +41 -0
- data/test/dummy/config/environments/production.rb +79 -0
- data/test/dummy/config/environments/test.rb +42 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +56 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/lib/assets/.keep +0 -0
- data/test/dummy/log/.keep +0 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/taggable_test.rb +56 -0
- data/test/test_helper.rb +40 -0
- metadata +174 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: da28c1f8368d09b6c8b46dd8c54cb1c8666a8d71
|
4
|
+
data.tar.gz: 0541d85da93083c004510535afb7398eeae78166
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 728d34d3f74f79058fd5bf4944fe054868aa8fe36b5fbebf7c25f98fdc343b946475af0404df56e9145bd79cf7fb18b7fd0793e28aacddd122586611ec672ae6
|
7
|
+
data.tar.gz: e821b0837c7a068eef2d4ab5550dacd2f0c85ea191c3b22221d92bde833ab9d7132421389922846c8b4cf69aad9bb91507876d6732a8bb718839544979a000c8
|
data/.gitignore
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
*.rbc
|
2
|
+
*.sassc
|
3
|
+
.sass-cache
|
4
|
+
capybara-*.html
|
5
|
+
.rspec
|
6
|
+
.rvmrc
|
7
|
+
/.bundle
|
8
|
+
/vendor/bundle
|
9
|
+
/log/*
|
10
|
+
/tmp/*
|
11
|
+
/db/*.sqlite3
|
12
|
+
/public/system/*
|
13
|
+
/public/uploads/*
|
14
|
+
/coverage/
|
15
|
+
/spec/tmp/*
|
16
|
+
**.orig
|
17
|
+
rerun.txt
|
18
|
+
pickle-email-*.html
|
19
|
+
.project
|
20
|
+
config/initializers/secret_token.rb
|
21
|
+
.DS_Store
|
22
|
+
*.swp
|
23
|
+
test/dummy/db/*.sqlite3
|
24
|
+
test/dummy/db/*.sqlite3-journal
|
25
|
+
test/dummy/log/*.log
|
26
|
+
test/dummy/tmp/
|
27
|
+
test/dummy/.sass-cache
|
28
|
+
Gemfile.lock
|
29
|
+
tags
|
data/.rubocop.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Declare your gem's dependencies in tagliatelle.gemspec.
|
4
|
+
# Bundler will treat runtime dependencies like base dependencies, and
|
5
|
+
# development dependencies will be added by default to the :development group.
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
group :test do
|
9
|
+
gem "minitest", "~> 5.6"
|
10
|
+
gem "simplecov", "~> 0.9"
|
11
|
+
gem "temping", "~> 3.2"
|
12
|
+
end
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2015 Varvet
|
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.md
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# Tagliatelle
|
2
|
+
|
3
|
+
[![Gem Version](http://img.shields.io/gem/v/tagliatelle.svg)](https://rubygems.org/gems/tagliatelle)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem "tagliatelle"
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```sh
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Generate model classes and migrations:
|
20
|
+
|
21
|
+
```sh
|
22
|
+
$ rails generate tagliatelle:install
|
23
|
+
```
|
24
|
+
|
25
|
+
Review the generated migrations then migrate:
|
26
|
+
|
27
|
+
```sh
|
28
|
+
$ rake db:migrate
|
29
|
+
```
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
Tagliatelle expects two classes to be defined:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
class Tag < ActiveRecord::Base
|
37
|
+
include Tagliatelle::Tag
|
38
|
+
end
|
39
|
+
|
40
|
+
class Tagging < ActiveRecord::Base
|
41
|
+
include Tagliatelle::Tagging
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
You can add or override behavior to these classes as needed.
|
46
|
+
|
47
|
+
Then to make an object taggable:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
class Article < ActiveRecord::Base
|
51
|
+
include Tagliatelle::Taggable
|
52
|
+
end
|
53
|
+
```
|
54
|
+
|
55
|
+
To tag an object:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
article = Article.first
|
59
|
+
article.tag_list = "foo, bar"
|
60
|
+
article.save
|
61
|
+
```
|
62
|
+
|
63
|
+
To retrieve the tags of an object:
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
article = Article.first
|
67
|
+
article.tag_list
|
68
|
+
```
|
69
|
+
|
70
|
+
To query objects based on tags:
|
71
|
+
```ruby
|
72
|
+
Article.tagged_with(["foo", "bar"])
|
73
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Tagliatelle'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
Bundler::GemHelper.install_tasks
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'lib'
|
28
|
+
t.libs << 'test'
|
29
|
+
t.pattern = 'test/**/*_test.rb'
|
30
|
+
t.verbose = false
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
task default: :test
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class CreateTagsAndTaggings < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :tags do |t|
|
4
|
+
t.string :name
|
5
|
+
t.timestamps
|
6
|
+
end
|
7
|
+
add_index :tags, :name, unique: true
|
8
|
+
|
9
|
+
create_table :taggings do |t|
|
10
|
+
t.references :taggable, polymorphic: true, index: true
|
11
|
+
t.references :tag, index: true
|
12
|
+
t.timestamps
|
13
|
+
end
|
14
|
+
add_index :taggings, [:taggable_id, :taggable_type, :tag_id], unique: true
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Tagliatelle
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
def create_tag_model
|
5
|
+
create_file "app/models/tag.rb" do
|
6
|
+
<<-END.strip_heredoc
|
7
|
+
class Tag < ActiveRecord::Base
|
8
|
+
include Tagliatelle::Tag
|
9
|
+
end
|
10
|
+
END
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_tagging_model
|
15
|
+
create_file "app/models/tagging.rb" do
|
16
|
+
<<-END.strip_heredoc
|
17
|
+
class Tagging < ActiveRecord::Base
|
18
|
+
include Tagliatelle::Tagging
|
19
|
+
end
|
20
|
+
END
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def copy_migrations
|
25
|
+
system("bundle exec rake tagliatelle:install:migrations")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/tagliatelle.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module Tagliatelle
|
2
|
+
module Taggable
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
has_many :taggings, as: :taggable, dependent: :destroy
|
7
|
+
has_many :tags, through: :taggings
|
8
|
+
end
|
9
|
+
|
10
|
+
def tag_list
|
11
|
+
tags.map(&:name).join(", ")
|
12
|
+
end
|
13
|
+
|
14
|
+
def tag_list=(value)
|
15
|
+
self.tags = value.split(",").map(&:strip).uniq.map do |tag|
|
16
|
+
::Tag.find_or_initialize_by(name: tag)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
module ClassMethods
|
21
|
+
def tagged_with(tags)
|
22
|
+
joins(:tags)
|
23
|
+
.where(tags: { name: tags.map(&:to_s) })
|
24
|
+
.preload(:tags)
|
25
|
+
.distinct
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/tagliatelle.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
|
3
|
+
# Maintain your gem's version:
|
4
|
+
require "tagliatelle/version"
|
5
|
+
|
6
|
+
# Describe your gem and declare its dependencies:
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "tagliatelle"
|
9
|
+
spec.version = Tagliatelle::VERSION
|
10
|
+
spec.authors = ["Jens Ljungblad"]
|
11
|
+
spec.email = ["jens.ljungblad@gmail.com"]
|
12
|
+
spec.homepage = "https://github.com/varvet/tagliatelle"
|
13
|
+
spec.summary = "Simple tagging for Rails 4+"
|
14
|
+
spec.description = "Simple tagging for Rails 4+"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files`.split($/)
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
|
21
|
+
spec.add_dependency "rails", "~> 4.0"
|
22
|
+
|
23
|
+
spec.add_development_dependency "sqlite3"
|
24
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|
data/test/dummy/Rakefile
ADDED
File without changes
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
File without changes
|
File without changes
|