acts-as-taggable-on-dynamic 0.0.2 → 0.0.3

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.
data/README.md CHANGED
@@ -87,6 +87,14 @@ Add dynamic tag renderer to your details view (normally show.html.erb)
87
87
  <% end %>
88
88
  ```
89
89
 
90
+ Handle magic ownership
91
+
92
+ ```ruby
93
+ @model.tag_owner = @owner
94
+ ....
95
+ @model.save!
96
+ ```
97
+
90
98
  ## Maintainer
91
99
 
92
100
  * [Dirk Eisenberg](https://github.com/dei79)
@@ -13,11 +13,13 @@ require('acts_as_taggable_on_dynamic/dynamic_mass_assignment_authorizer')
13
13
  require('acts_as_taggable_on_dynamic/dynamic_tag_context_attributes')
14
14
  require('acts_as_taggable_on_dynamic/dynamic_tag_helpers')
15
15
  require('acts_as_taggable_on_dynamic/taggable')
16
+ require('acts_as_taggable_on_dynamic/tag_owner')
16
17
  require('acts_as_taggable_on_dynamic/utils')
17
18
 
18
19
  # handle ActiveRecord stuff
19
20
  if defined?(ActiveRecord::Base)
20
21
  ActiveRecord::Base.extend ActsAsTaggableOnDynamic::Taggable
22
+ ActiveRecord::Base.send :include, ActsAsTaggableOnDynamic::TagOwner
21
23
  end
22
24
 
23
25
  if defined?(ActionView::Base)
@@ -48,7 +48,11 @@ module ActsAsTaggableOnDynamic
48
48
  # Returns the contetn of a give tag list
49
49
  #
50
50
  def tag_list_content_on(context)
51
- self.tags_on(context).map(&:to_s).join(',').chomp(',')
51
+ if (self.is_auto_tag_ownership_enabled?)
52
+ self.owner_tags_on(self.tag_owner, context).map(&:to_s).join(',').chomp(',')
53
+ else
54
+ self.tags_on(context).map(&:to_s).join(',').chomp(',')
55
+ end
52
56
  end
53
57
 
54
58
  ##
@@ -63,9 +67,9 @@ module ActsAsTaggableOnDynamic
63
67
  context = dynamic_tag_context_from_attribute(attribute).to_sym
64
68
 
65
69
  if (method_name.to_s.ends_with?("="))
66
- self.set_tag_list_on(context, args.join(',').chomp(','))
70
+ self.write_tag_list_on(context, args.join(',').chomp(','))
67
71
  else
68
- return tag_list_content_on(context)
72
+ self.tag_list_content_on(context)
69
73
  end
70
74
  else
71
75
  super
@@ -79,10 +83,22 @@ module ActsAsTaggableOnDynamic
79
83
  dynamic_tag_context_attribute?(method_name.to_s.chomp("=")) || tag_list_attribute?(method_name.to_s.chomp("=")) || super
80
84
  end
81
85
 
82
-
86
+ ##
87
+ # Returns the mass assignment authorizer
88
+ #
83
89
  def mass_assignment_authorizer(role)
84
90
  ActsAsTaggableOnDynamic::DynamicMassAssignmentAuthorizer.new(self, super(role))
85
91
  end
92
+
93
+ ##
94
+ # Handles the write request
95
+ def write_tag_list_on(context, tags)
96
+ if (self.is_auto_tag_ownership_enabled?)
97
+ self.tag_owner.tag(self, :with => tags, :on => context, :skip_save => true)
98
+ else
99
+ self.set_tag_list_on(context, tags)
100
+ end
101
+ end
86
102
  end
87
103
  end
88
104
  end
@@ -1,6 +1,6 @@
1
1
  module ActsAsTaggableOnDynamic
2
2
  module Rails
3
- VERSION = '0.0.2'
3
+ VERSION = '0.0.3'
4
4
  end
5
5
  end
6
6
 
@@ -0,0 +1,32 @@
1
+ module ActsAsTaggableOnDynamic
2
+ module TagOwner
3
+ def self.included(base)
4
+ base.send :include, ActsAsTaggableOnDynamic::TagOwner::InstanceMethods
5
+ end
6
+
7
+ module InstanceMethods
8
+
9
+ ###
10
+ # This method allows to set the owner of the tags which will be set
11
+ # during the next operations
12
+ #
13
+ def tag_owner=(owner)
14
+ @tag_owner = owner
15
+ end
16
+
17
+ ###
18
+ # Returns the tag owner which was set
19
+ #
20
+ def tag_owner
21
+ @tag_owner || nil
22
+ end
23
+
24
+ ###
25
+ # Validates if the auto tag ownership enabled
26
+ #
27
+ def is_auto_tag_ownership_enabled?
28
+ (self.tag_owner != nil)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,53 @@
1
+ $(function() {
2
+
3
+ function adjustStyleOfTagForm(el, removable) {
4
+ $(el).addClass("input string")
5
+ $(el).find("label").addClass("string control-label")
6
+ $(el).find("input").addClass("string")
7
+
8
+ $(el).find("label").each(function(index, model) {
9
+ $(model).text($(model).text().capitalize())
10
+ })
11
+
12
+ if (removable) {
13
+ $(el).append('<a href="" class="tag_action icon-remove-sign"></a>')
14
+ }
15
+ }
16
+
17
+ $("ul#user_tag_context_form li div.field").each(function(index, model) {
18
+ adjustStyleOfTagForm(model, true);
19
+ })
20
+
21
+ $("div#act-as-taggable-dynamic-new_context_form").each(function(index, model) {
22
+ adjustStyleOfTagForm(model, false);
23
+ })
24
+
25
+
26
+ $("div#act-as-taggable-dynamic-new_context_form a").addClass('icon-plus-sign')
27
+ $("div#act-as-taggable-dynamic-new_context_form a").text("")
28
+
29
+ $("ul#user_tag_context_form li div.field a.tag_action").live('click', function() {
30
+ $(this).closest('li').addClass("hide")
31
+ $(this).closest('li').find("input").attr("value", "")
32
+ return false;
33
+ })
34
+
35
+ var origAppend = $.fn.append;
36
+
37
+ $.fn.append = function () {
38
+ var result = origAppend.apply(this, arguments).trigger("append");
39
+ if($(this).parent().attr("id") == "user_tag_context_form" ) {
40
+
41
+ // add the element
42
+ $(this).find('.field').each(function(index, obj) {
43
+ adjustStyleOfTagForm(obj, true);
44
+ })
45
+
46
+ // empty the form
47
+ $('#act-as-taggable-dynamic-new_context_form input').val("")
48
+ }
49
+
50
+
51
+ return result;
52
+ };
53
+ })
@@ -0,0 +1,8 @@
1
+ ul#location_tag_context_form {
2
+ padding-left: 0px;
3
+ margin-left: 0px;
4
+ }
5
+
6
+ ul#location_tag_context_form li {
7
+ list-style: none;
8
+ }
@@ -0,0 +1,30 @@
1
+ require "spec_helper"
2
+
3
+ describe "Auto Owner" do
4
+ before(:each) do
5
+ @owner = User.create!(:name => "TestUser")
6
+ @location = Location.new()
7
+ end
8
+
9
+ after(:each) do
10
+ @location.destroy
11
+ @owner.destroy
12
+ end
13
+
14
+ it "should set the owner correct" do
15
+
16
+ # we set the tag owner
17
+ @location.tag_owner = @owner
18
+
19
+ # generate the skill list
20
+ @location.skill_list = "Dance,Read"
21
+ @location.save!
22
+
23
+ # check if the skills are there
24
+ @location.skill_list.should eql("Dance,Read")
25
+
26
+ # check if the owner got's the tags as well
27
+ @owner.owned_taggings.count.should eql(2)
28
+ end
29
+
30
+ end
@@ -1,3 +1,7 @@
1
+ class User < ActiveRecord::Base
2
+ acts_as_tagger
3
+ end
4
+
1
5
  class Location < ActiveRecord::Base
2
6
  acts_as_taggable_dynamic
3
7
  end
@@ -21,4 +21,8 @@ ActiveRecord::Schema.define :version => 0 do
21
21
  t.column :type, :string
22
22
  end
23
23
 
24
+ create_table :users, :force => true do |t|
25
+ t.column :name, :string
26
+ t.column :type, :string
27
+ end
24
28
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts-as-taggable-on-dynamic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-30 00:00:00.000000000 Z
12
+ date: 2013-05-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
@@ -181,9 +181,12 @@ files:
181
181
  - lib/acts_as_taggable_on_dynamic/dynamic_tag_helpers.rb
182
182
  - lib/acts_as_taggable_on_dynamic/rails/engine.rb
183
183
  - lib/acts_as_taggable_on_dynamic/rails/version.rb
184
+ - lib/acts_as_taggable_on_dynamic/tag_owner.rb
184
185
  - lib/acts_as_taggable_on_dynamic/taggable.rb
185
186
  - lib/acts_as_taggable_on_dynamic/utils.rb
186
187
  - lib/assets/javascripts/taggable.dynamic.js
188
+ - lib/assets/javascripts/taggable.simpleform.js
189
+ - lib/assets/stylesheets/taggable.dynamic.css
187
190
  - samples/demo-plain/.gitignore
188
191
  - samples/demo-plain/Gemfile
189
192
  - samples/demo-plain/README.rdoc
@@ -265,8 +268,9 @@ files:
265
268
  - samples/demo-plain/vendor/assets/javascripts/.gitkeep
266
269
  - samples/demo-plain/vendor/assets/stylesheets/.gitkeep
267
270
  - samples/demo-plain/vendor/plugins/.gitkeep
268
- - spec/acts_as_taggable_on_dynamic_spec.rb
271
+ - spec/auto_owner_spec.rb
269
272
  - spec/database.yml.sample
273
+ - spec/dynamic_tagging_spec.rb
270
274
  - spec/models.rb
271
275
  - spec/schema.rb
272
276
  - spec/spec_helper.rb
@@ -296,8 +300,9 @@ signing_key:
296
300
  specification_version: 3
297
301
  summary: Advanced tagging for Rails with forms and dynamic tags.
298
302
  test_files:
299
- - spec/acts_as_taggable_on_dynamic_spec.rb
303
+ - spec/auto_owner_spec.rb
300
304
  - spec/database.yml.sample
305
+ - spec/dynamic_tagging_spec.rb
301
306
  - spec/models.rb
302
307
  - spec/schema.rb
303
308
  - spec/spec_helper.rb