rails_admin_tag_list 0.1.2

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/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,97 @@
1
+ Introduction
2
+ ============
3
+
4
+ Greate [rails_admin](https://github.com/sferik/rails_admin) gem does not work with another great gem - [acts_as_taggable_on](https://github.com/mbleigh/acts-as-taggable-on), because rails_admin knows nothing about the virtual attributes *_list (tag_list, skill_list etc.), which created by acts_as_taggable_on for display and edit tags.
5
+
6
+ This problem is solved with [rails_admin_tag_list](https://github.com/kryzhovnik/rails_admin_tag_list) gem.
7
+
8
+ Installation
9
+ ============
10
+
11
+ In your `Gemfile`:
12
+
13
+ gem 'rails_admin'
14
+ gem 'rails_admin_tag_list'
15
+
16
+ and run:
17
+
18
+ $ bundle install
19
+
20
+ Usage and Configuration
21
+ =======================
22
+
23
+ rails_admin_tag_list by default does the following:
24
+
25
+ 1. Register new field type `TagList` for rails_admin
26
+ 2. Finds acts_as_taggable_on virtual attributes (`*_list` - `tag_list`, `skill_list` etc.) and adds them to `RailsAdmin.config`
27
+
28
+ There is your model:
29
+
30
+ class Player < ActiveRecord::Base
31
+ attr_accessible :name
32
+ attr_accessible :tag_list, :skill_list
33
+
34
+ acts_as_taggable
35
+ acts_as_taggable_on :skills
36
+ end
37
+
38
+
39
+
40
+ > *Note that tag_list (skill_list, etc.) attribute should be available for mass-assignment by rails_admin users.*
41
+
42
+ > *Since Rails 3.2.3 `config.active_record.whitelist_attributes` option is true by default; this means that you should put tag_list (skill_list, etc.) attribute in the white list, like in example above:*
43
+
44
+ > `attr_accessible :tag_list, :skill_list`
45
+
46
+ This gem comes with two tag field partial's named `form_tag_list` (default) and `tag_list_with_suggestions`. You can try the second one:
47
+
48
+ RailsAdmin.config do |config|
49
+ config.models do
50
+ edit do
51
+ fields_of_type :tag_list do
52
+ partial 'tag_list_with_suggestions'
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ You can do with tag_list fields whatever what allows to do rails_admin:
59
+
60
+ **rename lable**
61
+
62
+ RailsAdmin.config do |config|
63
+ config.model Player do
64
+ edit do
65
+ field :tag_list do
66
+ label "Tags"
67
+ end
68
+ field :skill_list
69
+ end
70
+ end
71
+ end
72
+
73
+ **hide all tag_list fields**
74
+
75
+ RailsAdmin.config do |config|
76
+ config.model Player do
77
+ edit do
78
+ fields_of_type :tag_list do
79
+ hide
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ **reassing partial**
86
+
87
+ RailsAdmin.config do |config|
88
+ config.model Player do
89
+ edit do
90
+ fields_of_type :tag_list do
91
+ partial 'awesome_tag_list'
92
+ end
93
+ end
94
+ end
95
+ end
96
+
97
+ Create you custom partial and put it to `app/views/rails_admin/main/` in your own project folder
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'RailsAdminTagList'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
@@ -0,0 +1,30 @@
1
+ module RailsAdminTagList
2
+ module SuggestionsHelper
3
+ def tag_suggestions(field, options = {})
4
+ defaults = {
5
+ :order => { :count => :desc },
6
+ :length => 5
7
+ }
8
+ options = defaults.deep_merge(options)
9
+
10
+ model = field.abstract_model.model_name.constantize
11
+ tags_name = field.name.to_s.gsub(/_list/, '').pluralize.to_sym
12
+ tags = model.tag_counts_on(tags_name)
13
+ tags = sort_tags(tags, options[:order])
14
+ tags[0..options[:length]].map(&:name)
15
+ end
16
+
17
+ private
18
+ def sort_tags(tags, options)
19
+ if options.is_a?(Hash)
20
+ if options[:count]
21
+ tags = tags.sort_by(&:count)
22
+ tags = tags.reverse if options[:count] == :desc
23
+ end
24
+ elsif [:rand, :random, :shuffle].include?(options)
25
+ tags = tags.shuffle
26
+ end
27
+ tags
28
+ end
29
+ end
30
+ end
@@ -0,0 +1 @@
1
+ = form.send field.view_helper, field.method_name, field.html_attributes
@@ -0,0 +1,33 @@
1
+ = form.send field.view_helper, field.method_name, field.html_attributes
2
+
3
+ - tag_suggestions(field, :length => 5, :order => { :count => :desc }).each do |tag|
4
+ = link_to tag, '#', :class => 'tag_suggestion', :data => { :input_id => form.dom_id(field) }
5
+
6
+ :javascript
7
+ jQuery(function(){
8
+ var input_id = '#{form.dom_id(field)}'
9
+ $('.tag_suggestion[data-input-id=' + input_id + ']').click(function(event){
10
+ var tag_list, new_value;
11
+ tag_list = $(this).siblings('input#' + input_id);
12
+
13
+ if (!tag_list.val().match(/\S/)) {
14
+ new_value = this.innerHTML;
15
+ } else {
16
+ new_value = [tag_list.val(), this.innerHTML].join(', ');
17
+ };
18
+ tag_list.val(new_value);
19
+
20
+ event.preventDefault();
21
+ return false;
22
+ });
23
+ });
24
+
25
+ %style
26
+ :sass
27
+ .tag_suggestion
28
+ color: #777
29
+ border-bottom: 1px dotted #b94a48
30
+ &:hover
31
+ color: #aaa
32
+ border-bottom: 1px dotted #953b39
33
+ text-decoration: none
@@ -0,0 +1,4 @@
1
+ module RailsAdminTagList
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module RailsAdminTagList
2
+ VERSION = "0.1.2"
3
+ end
@@ -0,0 +1,49 @@
1
+ require "rails_admin_tag_list/engine"
2
+
3
+ module RailsAdminTagList
4
+ end
5
+
6
+ require 'rails_admin/config/fields'
7
+ require 'rails_admin/config/fields/base'
8
+
9
+ module RailsAdmin
10
+ module Config
11
+ module Fields
12
+ module Types
13
+ class TagList < RailsAdmin::Config::Fields::Base
14
+ RailsAdmin::Config::Fields::Types::register(self)
15
+ register_instance_option(:formatted_value) do
16
+ value.join(', ')
17
+ end
18
+
19
+ register_instance_option(:pretty_value) do
20
+ value.join(', ')
21
+ end
22
+ # Accessor for field's label.
23
+ #
24
+ # @see RailsAdmin::AbstractModel.properties
25
+ register_instance_option(:help) do
26
+ I18n.t(:tag_list_help, :scope => [:admin, :new], :default => 'Use commas to separate tags')
27
+ end
28
+ register_instance_option(:partial) do
29
+ :form_tag_list
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ RailsAdmin::Config::Fields.register_factory do |parent, properties, fields|
38
+ model = parent.abstract_model.model
39
+
40
+ if defined?(::ActsAsTaggableOn) && model.taggable?
41
+ tag_types = model.tag_types
42
+ if tag_types.include?(properties[:name])
43
+ name = "#{properties[:name].to_s.singularize}_list".to_sym
44
+
45
+ fields << RailsAdmin::Config::Fields::Types::TagList.new(parent, name, properties)
46
+ end
47
+ end
48
+ false
49
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_admin_tag_list
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andrey Samsonov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-31 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.2'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.2'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rails_admin
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 0.0.1
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.0.1
46
+ - !ruby/object:Gem::Dependency
47
+ name: sqlite3
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Implements field type and partial for "tag_list"(*_list) virtual attribute.
63
+ email:
64
+ - andrey.samsonov@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - app/helpers/rails_admin_tag_list/suggestions_helper.rb
70
+ - app/views/rails_admin/main/_form_tag_list.html.haml
71
+ - app/views/rails_admin/main/_tag_list_with_suggestions.html.haml
72
+ - lib/rails_admin_tag_list.rb
73
+ - lib/rails_admin_tag_list/version.rb
74
+ - lib/rails_admin_tag_list/engine.rb
75
+ - MIT-LICENSE
76
+ - Rakefile
77
+ - README.md
78
+ homepage: https://github.com/kryzhovnik/rails_admin_tag_list
79
+ licenses: []
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 1.8.24
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: Support acts_as_taggable_on gem for rails_admin
102
+ test_files: []