Coder Social home page Coder Social logo

rocket_tag's Introduction

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

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.

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

rocket_tag's People

Contributors

beanieboi avatar beans0063 avatar bradphelan avatar derekcroft avatar do-zen avatar fntz avatar jacki3lene avatar keithpitt avatar ksoderstrom avatar matenia avatar mlitwiniuk avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.