• Stars
    star
    150
  • Rank 241,665 (Top 5 %)
  • Language
    Ruby
  • License
    MIT License
  • Created almost 13 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

modern high performance tagging library for Rails 3.1 +

Rocket Tag

Clean, modern and maintainable, context aware tagging library for rails 3.1 +

Installation

In your gemfile

gem "rocket_tag"

Then at the command line

bundle install

Create the migration at the command line

rails generate rocket_tag:migration
rake db:migrate
rake db:test:prepare

Configuration

Add configurations to config/initializers/rocket_tag.rb:

RocketTag.configure do |config|
  config.force_lowercase = true # Automatically convert all tags to lowercase (optional, default: false)
end

Usage

class TaggableModel < ActiveRecord::Base
	attr_taggable :skills, :habits
end	

item = TaggableModel.create

item.skills = ["kiting", "surfing", "coding"]
item.habits = ["forking", "talking"]

Match any tag across any contexts

TaggableModel.tagged_with ["forking", "kiting"]  

Match all tags across any contexts

TaggableModel.tagged_with ["forking", "kiting"], :all => true

Match any tag on a specific context

TaggableModel.tagged_with ["math", "kiting"], :on => "skills"

Match all tags on a specific context

TaggableModel.tagged_with ["math", "kiting"], :all => true, :on => "skills"

Match a miniumum number of tags

TaggableModel.tagged_with ["math", "kiting", "coding", "sleeping"], :min => 2, :on => "skills"

Match tags to specific contexts

TaggableModel.tagged_with { :skills => ["math", "kiting"], :languages => ["english", "german"]

Take advantage of the tags_count synthetic column returned with every query

TaggableModel.tagged_with(["math", "kiting", "coding", "sleeping"], :on => "skills").where{tags_count>=2}	

Mix with active relation

TaggableModel.tagged_with(["forking", "kiting"]).where( ["created_at > ?", Time.zone.now.ago(5.hours)])  

or even downstream

User.where{email="[email protected]"}.documents.tagged_with ['kiting', 'math'] , :on => :skills

where we might have

class User < ActiveRecord::Base
  has_many :documents
end

class Document < ActiveRecord::Base
  belongs_to :user
  attr_taggable :tags
end 

Find similar models based on tags on a specific context and return in decending order of 'tags_count'

model.tagged_similar :on => "skills"
model.tagged_similar :on => "habits"

The two cases of tagged_similar below are functionally identical because there are only two contexts specified on the class. If there were three or more contexts specified then the two below would not be identical.

model.tagged_similar :on => ["skills", "habits"]
model.tagged_similar

Find popular tags and generate tags clouds for specific scopes

User.where{email="[email protected]"}.documents.popular_tags

where we might have

class User < ActiveRecord::Base
  has_many :documents
end

class Document < ActiveRecord::Base
  belongs_to :user
  attr_taggable :tags
end 

and you can access the field tags_count on each Tag instance returned by the above query. Generating the CSS and html for your tag cloud is outside the scope of this project but it should be easy to do.

Alias tags. If you have several tags that means the same things, then create alias for it.

#array with inctances of RocketTag::Tag
tag1, tag2, tag3 = ['ror', 'ruby-on-rails', 'rails'] 
tag1.alias << [tag2, tag3]
#Models with tag `rails`
# returns all Posts with `rails`, `ruby-on-rails` and `ror` tags 
Post.tagged_with(['rails']) 

Contributing to rocket_tag

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
  • Fork the project
  • Start a feature/bugfix branch
  • Commit and push until you are happy with your contribution
  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright

Copyright (c) 2011 Brad Phelan. See LICENSE.txt for further details.

Available for hire for your next ROR project at XTargets: Ruby On Rails Solutions

More Repositories

1

jasminerice

Pain free coffeescript testing under Rails 3.1
Ruby
481
star
2

immer.loves.svelte

TypeScript
54
star
3

SketchSolve.NET

SketchSolve ported to ( Wrapped ) for .NET
C#
9
star
4

FUNCUI.Samples

FUNCUI.Samples
F#
8
star
5

svelt3

Svelte wrapper for threejs designed to be easily extendible with minimal code
Svelte
7
star
6

ohmyderdiedas

German Language Trainer
JavaScript
7
star
7

Active-Illusion

Create read only models backed by queries not by tables
Ruby
6
star
8

wkhtmltopdf-osx

Gem for using wkhtmltopdf on osx.
Ruby
3
star
9

vimgonesurfing

Usefull vim scripts from Brad Phelan
Vim Script
2
star
10

DMValidatorFramework

Objective-C
2
star
11

openkitchen

rails backend for gobbq
Ruby
2
star
12

ImmutableObjectGraphLens

Add functional and composable lenses to the immutable object graph
C#
1
star
13

rest_kat

Ruby
1
star
14

emu-eggs

Based on snippetsEmu each snippet is factored out into a separate file
Vim Script
1
star
15

ofcourse

U3A Course manager
Ruby
1
star
16

vimrc

my vimrc file
Vim Script
1
star
17

wkhtmltopdf-rails

Meta gem depending on wkhtmltopdf-osx and wkhtmltopdf-heroku
1
star
18

loopdi

Live looper ( maybe oneday )
C#
1
star
19

Shambolics

Symbolic calculus for fsharp
F#
1
star
20

proxymock

TODO: one-line summary of your gem
Ruby
1
star
21

kinderhaus

css & php & html for kinderhaus.at
1
star
22

FSharpWPFReactiveTest

F#
1
star
23

bradgonecooking

Usefull Chef Cookbooks
Ruby
1
star
24

slackjax

Provides a slack client to enter math via wpf-math renderer
C#
1
star
25

forminator

JavaScript
1
star
26

thisfile

TODO: one-line summary of your gem
Ruby
1
star
27

acts_as_challenged

An achievements/challenge engine for your rails application
Ruby
1
star
28

svelte-x3dom-demo

A demo of using x3domn with svelte
JavaScript
1
star
29

sfml-test

C++
1
star