my_tags 0.0.9 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 79aedf09801daa2041a270e63c51027deb722b03
4
- data.tar.gz: f300f002cc8736dec7d0c7f5f2679651e547c89b
3
+ metadata.gz: 2225dba8ccc8fd715f288a4e55875bbbb547e373
4
+ data.tar.gz: ee554c127c1e06608c4e6feb5d4e242254de48d3
5
5
  SHA512:
6
- metadata.gz: 1700f2098059094ea8c2f526eceefab6cc5a754e2985d10f32128b3653ecc455a2c33aaedae2b167511b531b1ee5347c390dbd185e17b3273e4c09de78fced95
7
- data.tar.gz: 7c0320a13f83d6a66d22c5b8fa9c0e3490c83e3bfd77757e467bbb357812fefeb9a383beb6ce9d2d0a78b148f3e27afef25456df75a6a393d7691285ebaddd66
6
+ metadata.gz: f9966da79f34fdb4f6c743efb9aea3f0321f777100b33962c6d9a17032ea20caeca7b652048221140168700fc9d659cf7210de48eebe04fb811fa56d3f5c032f
7
+ data.tar.gz: 05c7ae6abd8d1fcfa2a487db2b8254737d5863c70c526bb6e5067e0269f71e041bffb9a27f7b3e347e37d3cbba51edd999d4106a338e6a1bd333d07147d3f683
data/README.md CHANGED
@@ -13,6 +13,10 @@ class Post < ActiveRecord::Base
13
13
  has_many_tags
14
14
  ```
15
15
 
16
+ Run rake `my_tags:install:migrations` and `rake:db:migrate`
17
+
18
+ Done!
19
+
16
20
  ###### Done, ready for using:
17
21
 
18
22
  post = Post.create(name: 'Post with tags')
@@ -29,6 +33,10 @@ post.tags.first.delete
29
33
 
30
34
  post.tags.count => 0
31
35
 
36
+ Or you can use this method:
37
+
38
+ `@post.process_tags('animals, pets')` or `@post.process_tags(['animals', ['pets'])`
39
+
32
40
 
33
41
  ### UI features:
34
42
 
@@ -1,6 +1,6 @@
1
1
  ready = ->
2
- if $('.taggable').length
3
- $('.taggable').keyup (elm) ->
2
+ if $('.my_taggable').length
3
+ $('.my_taggable').keyup (elm) ->
4
4
  tags_separator = ','
5
5
 
6
6
  # Search by last separated word
@@ -38,7 +38,7 @@ tags_list_popup = (tag_list, object) ->
38
38
  .addClass('ui-all')
39
39
  .text(tag.name)
40
40
  .appendTo(li)
41
- a.click ->
41
+ li.click ->
42
42
  already_filled_in_tags = $(object).val().split(',')
43
43
  already_filled_in_tags.pop()
44
44
  already_filled_in_tags.push(tag.name + ', ')
@@ -0,0 +1,4 @@
1
+ /*
2
+ *= require_tree .
3
+ *= require_self
4
+ */
@@ -0,0 +1,22 @@
1
+ #tags_popup {
2
+ position: absolute;
3
+ border: 1px solid grey;
4
+ padding: 0;
5
+
6
+ ul {
7
+ list-style-type: none;
8
+ padding-left: 0;
9
+ width: 200px;
10
+
11
+ li {
12
+ padding: 4px;
13
+ width: 100%;
14
+ cursor: pointer;
15
+ }
16
+
17
+ li:hover {
18
+ background-color: yellowgreen;
19
+ }
20
+ }
21
+
22
+ }
@@ -5,5 +5,10 @@ module MyTags
5
5
  def list
6
6
  respond_with (params[:starts_with].blank? ? Tag.all : Tag.where("name LIKE '#{params[:starts_with]}%'"))
7
7
  end
8
+
9
+ def tag
10
+ tag = Tag.find_by_name(params[:tag])
11
+ @taggables = tag.taggings.map(&:taggable)
12
+ end
8
13
  end
9
14
  end
@@ -2,7 +2,30 @@ module MyTags
2
2
  module ApplicationHelper
3
3
 
4
4
  def tags_field_tag(object)
5
- text_field_tag "#{object.class.to_s.downcase}[tags]", nil, placeholder: 'Tags', class: 'taggable', 'data-tags_list_path' => my_tags_list_path
5
+ html_value = object.tags.blank? ? nil : (object.tags.map(&:name).join(', ') + ', ')
6
+ text_field_tag "#{object.class.to_s.downcase}[tag_list]", html_value, placeholder: 'Tags', class: 'my_taggable', 'data-tags_list_path' => my_tags_list_path
7
+ end
8
+
9
+ # Show all object tags
10
+ def tag_list(obj, opts = {})
11
+ content_tag :div, class: opts.fetch(:html_class, nil) do
12
+ tag_list_with_link(obj.tags)
13
+ end.html_safe
14
+ end
15
+
16
+ # Show all tags
17
+ def all_tags(opts = {})
18
+ content_tag :div, class: opts.fetch(:html_class, nil) do
19
+ tag_list_with_link(Tag.uniq(:name))
20
+ end.html_safe
21
+ end
22
+
23
+ def tag_list_with_link(tag_list)
24
+ tag_list.map do |tag|
25
+ content_tag :a, href: tag_path(tag.name) do
26
+ tag.name.capitalize
27
+ end
28
+ end.join(', ').html_safe
6
29
  end
7
30
 
8
31
  end
@@ -0,0 +1,4 @@
1
+ %h3= t('my_tags.taggables_list_header', tag: params[:tag])
2
+
3
+ -@taggables.each do |taggable|
4
+ =link_to "#{taggable.class.to_s}: #{taggable.name}", eval("#{taggable.class.to_s.downcase}_path(#{taggable.id})")
@@ -0,0 +1,3 @@
1
+ en:
2
+ my_tags:
3
+ taggables_list_header: "Relative articles with '%{tag}' tag"
@@ -0,0 +1,3 @@
1
+ en:
2
+ my_tags:
3
+ taggables_list_header: "Записи, связанные с '%{tag}' тегом"
data/config/routes.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  Rails.application.routes.draw do
2
2
  get '/my_tags/list', to: 'my_tags/tags#list'
3
+ get '/tag/:tag', to: 'my_tags/tags#tag', as: 'tag'
3
4
  end
@@ -11,6 +11,14 @@ module MyTags::ActiveRecord
11
11
  @tag_names = names.is_a?(MyTags::TagList) ? names : MyTags::TagList.new_with_names(self, names)
12
12
  end
13
13
 
14
+ # Add/Update tags for object
15
+ # @post.process_tags('cat, dog')
16
+ # @post.process_tags(['cat','dog'])
17
+ def process_tags(tag_list)
18
+ tag_list = tag_list.split(',').map(&:strip) unless tag_list.is_a?(Array)
19
+ self.tag_list = tag_list
20
+ end
21
+
14
22
  module ClassMethods
15
23
  def has_many_tags
16
24
  has_many :taggings, :class_name => 'MyTags::Tagging', :as => :taggable, :dependent => :destroy
data/my_tags.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'my_tags'
3
- s.version = '0.0.9'
3
+ s.version = '1.0.0'
4
4
  s.authors = ['Vitaly Omelchenko']
5
5
  s.email = ['prosto.vint@gmail.com']
6
6
  s.homepage = 'https://github.com/vintyara/my_tags'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: my_tags
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vitaly Omelchenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-30 00:00:00.000000000 Z
11
+ date: 2014-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -78,11 +78,16 @@ files:
78
78
  - README.md
79
79
  - app/assets/javascripts/my_tags.js
80
80
  - app/assets/javascripts/my_tags/my_tags.js.coffee
81
+ - app/assets/stylesheets/my_tags.css
82
+ - app/assets/stylesheets/my_tags/my_tags.css.scss
81
83
  - app/controllers/my_tags/application_controller.rb
82
84
  - app/controllers/my_tags/tags_controller.rb
83
85
  - app/helpers/my_tags/application_helper.rb
84
86
  - app/models/my_tags/tag.rb
85
87
  - app/models/my_tags/tagging.rb
88
+ - app/views/my_tags/tags/tag.haml
89
+ - config/locales/en.yml
90
+ - config/locales/ru.yml
86
91
  - config/routes.rb
87
92
  - db/migrate/1_tag_tables.rb
88
93
  - lib/my_tags.rb