my_tags 0.0.9 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -0
- data/app/assets/javascripts/my_tags/my_tags.js.coffee +3 -3
- data/app/assets/stylesheets/my_tags.css +4 -0
- data/app/assets/stylesheets/my_tags/my_tags.css.scss +22 -0
- data/app/controllers/my_tags/tags_controller.rb +5 -0
- data/app/helpers/my_tags/application_helper.rb +24 -1
- data/app/views/my_tags/tags/tag.haml +4 -0
- data/config/locales/en.yml +3 -0
- data/config/locales/ru.yml +3 -0
- data/config/routes.rb +1 -0
- data/lib/my_tags/active_record.rb +8 -0
- data/my_tags.gemspec +1 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2225dba8ccc8fd715f288a4e55875bbbb547e373
|
4
|
+
data.tar.gz: ee554c127c1e06608c4e6feb5d4e242254de48d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 $('.
|
3
|
-
$('.
|
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
|
-
|
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,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
|
+
}
|
@@ -2,7 +2,30 @@ module MyTags
|
|
2
2
|
module ApplicationHelper
|
3
3
|
|
4
4
|
def tags_field_tag(object)
|
5
|
-
|
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
|
data/config/routes.rb
CHANGED
@@ -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
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
|
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-
|
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
|